From c62ddd06ff62e627ffd411b8ccb0fa881e1591d0 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Wed, 25 Nov 2009 05:02:55 +0000 Subject: Bug 530252: Create a script that sets up the framework of an extension Patch by Max Kanat-Alexander (module owner) a=mkanat --- extensions/create.pl | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 extensions/create.pl (limited to 'extensions/create.pl') diff --git a/extensions/create.pl b/extensions/create.pl new file mode 100644 index 000000000..c4d911c2a --- /dev/null +++ b/extensions/create.pl @@ -0,0 +1,85 @@ +#!/usr/bin/perl -w +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Everything Solved, Inc. +# Portions created by the Initial Developer are Copyright (C) 2009 the +# Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Max Kanat-Alexander + +use strict; +use lib qw(. lib); +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Error; +use Bugzilla::Util qw(get_text); + +use File::Path qw(mkpath); +use DateTime; + +my $base_dir = bz_locations()->{'extensionsdir'}; + +my $name = $ARGV[0] or ThrowUserError('extension_create_no_name'); +if ($name !~ /^[A-Z]/) { + ThrowUserError('extension_first_letter_caps', { name => $name }); +} + +my $extension_dir = "$base_dir/$name"; +mkpath($extension_dir) + || die "$extension_dir already exists or cannot be created.\n"; + +my $lcname = lc($name); +foreach my $path (qw(lib template/en/default/hook), + "template/en/default/$lcname") +{ + mkpath("$extension_dir/$path") || die "$extension_dir/$path: $!"; +} + +my $year = DateTime->now()->year; + +my $template = Bugzilla->template; +my $vars = { year => $year, name => $name, path => $extension_dir }; +my %create_files = ( + 'config.pm.tmpl' => 'Config.pm', + 'extension.pm.tmpl' => 'Extension.pm', + 'util.pm.tmpl' => 'lib/Util.pm', + 'hook-readme.txt.tmpl' => 'template/en/default/hook/README', + 'name-readme.txt.tmpl' => "template/en/default/$lcname/README", +); + +foreach my $template_file (keys %create_files) { + my $target = $create_files{$template_file}; + my $output; + $template->process("extensions/$template_file", $vars, \$output) + or ThrowTemplateError($template->error()); + open(my $fh, '>', "$extension_dir/$target"); + print $fh $output; + close($fh); +} + +print get_text('extension_created', $vars), "\n"; + +__END__ + +=head1 NAME + +extensions/create.pl - Create a framework for a new Bugzilla Extension. + +=head1 SYNOPSIS + + extensions/create.pl NAME + + Creates a framework for an extension called NAME in the F + directory. -- cgit v1.2.3-24-g4f1b