#!/usr/bin/perl -w # Script for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ # # Copyright (C) 2006-2008 ProjectContributors. All rights reserved. # ProjectContributors are listed in the AUTHORS file in the root of # the distribution. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html # use strict; sub ask { my ( $q, $default ) = @_; my $reply; local $/ = "\n"; $q .= '?' unless $q =~ /\?\s*$/; my $yorn = 'y/n'; if ( defined $default ) { if ( $default =~ /y/i ) { $default = 'yes'; $yorn = 'Y/n'; } elsif ( $default =~ /n/i ) { $default = 'no'; $yorn = 'y/N'; } else { $default = undef; } } print $q. ' [' . $yorn . '] '; while ( ( $reply = ) !~ /^[yn]/i ) { if ( $reply =~ /^\s*$/ && defined($default) ) { $reply = $default; last; } print "Please answer yes or no\n"; } return ( $reply =~ /^y/i ) ? 1 : 0; } sub prompt { my ( $q, $default ) = @_; local $/ = "\n"; my $reply = ''; while ( !$reply ) { print $q; print " ($default)" if defined $default; print ': '; $reply = ; chomp($reply); $reply ||= $default; } return $reply; } sub usage { print STDERR < HERE } use File::Path; # For each key in %def, the corresponding %$..% string will be expanded # in all output files. So %$MODULE% will expand to the name of the module. # %$...% keys not found will be left unexpanded. my %def; $def{MODULE} = $ARGV[0]; usage(), exit 1 unless $def{MODULE}; usage(), exit 1 if -d $def{MODULE}; $def{MODULE} =~ /^.*?(Skin|Plugin|Contrib|AddOn)$/; $def{TYPE} = $1; usage(), exit 1 unless $def{TYPE}; $def{STUBS} = $def{TYPE} eq 'Plugin' ? 'Plugins' : 'Contrib'; $def{SHORTDESCRIPTION} = prompt( "Enter a one-line description of the extension: ", '' ); $def{SHORTDESCRIPTION} =~ s/'/\\'/g; # Templates for all required files are in this script, after __DATA__ $/ = undef; my @DATA = split( /<<<< (.*?) >>>>\s*\n/, ); shift @DATA; my %data = @DATA; my $stubPath = "$def{MODULE}/lib/Foswiki/$def{STUBS}"; if ( $def{TYPE} eq 'Plugin' ) { my $rewrite; # Look in all the possible places for EmptyPlugin if (-e "EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm") { # probably running in a checkout $rewrite = getFile("EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm"); } elsif (-e "../EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm") { # core subdir in a new-style checkout $rewrite = getFile("../EmptyPlugin/lib/Foswiki/Plugins/EmptyPlugin.pm"); } elsif (-e "lib/Foswiki/Plugins/EmptyPlugin.pm") { # last ditch, get it from the install $rewrite = getFile("lib/Foswiki/Plugins/EmptyPlugin.pm"); } # Tidy up $rewrite =~ s/Copyright .*(# This program)/$1/s; $rewrite =~ s/^.*?__NOTE:__ /$data{PLUGIN_HEADER}/s; $rewrite =~ s/^# change the package name.*$//m; $rewrite =~ s/(SHORTDESCRIPTION = ').*?'/$1%\$SHORTDESCRIPTION%'/; $rewrite =~ s/EmptyPlugin/%\$MODULE%/sg; writeFile( $stubPath, "$def{MODULE}.pm", $rewrite ); } else { writeFile( $stubPath, "$def{MODULE}.pm", $data{PM} . ( $data{"PM_$def{TYPE}"} || '' ) ); } my $modPath = "$stubPath/$def{MODULE}"; $def{UPLOADTARGETPUB} = 'http://foswiki.org/pub'; $def{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin'; $def{UPLOADTARGETSUFFIX} = ''; $def{UPLOADTARGETWEB} = "Extensions"; while (1) { print <$path/$file" ) || die "Failed to create $path/$file: $!"; print F expandVars($content); close(F); } sub getFile { my $file = shift; local $/ = undef; open( F, "<$file" ) || die "Failed to open $file: $!"; my $content = ; close(F); return $content; } __DATA__ <<<< build.pl >>>> #!/usr/bin/perl -w BEGIN { unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} ); } use Foswiki::Contrib::Build; # Create the build object $build = new Foswiki::Contrib::Build('%$MODULE%'); # (Optional) Set the details of the repository for uploads. # This can be any web on any accessible Foswiki installation. # These defaults will be used when expanding tokens in .txt # files, but be warned, they can be overridden at upload time! # name of web to upload to $build->{UPLOADTARGETWEB} = '%$UPLOADTARGETWEB%'; # Full URL of pub directory $build->{UPLOADTARGETPUB} = '%$UPLOADTARGETPUB%'; # Full URL of bin directory $build->{UPLOADTARGETSCRIPT} = '%$UPLOADTARGETSCRIPT%'; # Script extension $build->{UPLOADTARGETSUFFIX} = '%$UPLOADTARGETSUFFIX%'; # Build the target on the command line, or the default target $build->build($build->{target}); <<<< DEPENDENCIES >>>> # Dependencies for %$MODULE% # Example: # Time::ParseDate,>=2003.0211,cpan,Required. # Foswiki::Plugins,>=1.2,perl,Requires version 1.2 of handler API. <<<< MANIFEST >>>> # Release manifest for %$MODULE% data/System/%$MODULE%.txt 0644 Documentation lib/Foswiki/%$STUBS%/%$MODULE%.pm 0644 Perl module <<<< PLUGIN_HEADER >>>> # %$TYPE% for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html =pod ---+ package Foswiki::Plugins::%$MODULE% <<<< PM >>>> # %$TYPE% for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html package Foswiki::%$STUBS%::%$MODULE%; use strict; use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION ); $VERSION = '$Rev$'; # version of *this file*. # This is *not* the version of the package, which should be set in the # | Version: | line in the extension topic. $SHORTDESCRIPTION = '%$SHORTDESCRIPTION%'; <<<< TXT >>>> ---+!! !%$MODULE% %SHORTDESCRIPTION% %TOC% ---++ Usage ---++ Examples ---++ Installation Instructions %$INSTALL_INSTRUCTIONS% ---++ Info Many thanks to the following sponsors for supporting this work: * Acknowledge any sponsors here | Author(s): | | | Copyright: | © | | License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] | | Version: | %$VERSION% | | Change History: |   | | Dependencies: | %$DEPENDENCIES% | | Home page: | %$UPLOADTARGETSCRIPT%/view%$UPLOADTARGETSUFFIX%/%$UPLOADTARGETWEB%/%$MODULE% |