2013-06-21 16:02:07 -04:00
< ? php
/*!
2014-03-24 16:46:02 -04:00
* Pattern Lab Builder CLI - v0 . 7.12
2013-06-21 16:02:07 -04:00
*
2014-01-13 16:21:58 -05:00
* Copyright ( c ) 2013 - 2014 Dave Olsen , http :// dmolsen . com
2013-06-21 16:02:07 -04:00
* Licensed under the MIT license
*
*/
2014-03-17 10:43:00 -04:00
/*******************************
* General Set - up
*******************************/
2014-02-08 19:39:54 -05:00
// check to see if json_decode exists. might be disabled in installs of PHP 5.5
if ( ! function_exists ( " json_decode " )) {
print " Please check that your version of PHP includes the JSON extension. It's required for Pattern Lab to run. Aborting. \n " ;
exit ;
}
2014-01-13 15:44:31 -05:00
// auto-load classes
2014-05-09 16:19:19 -04:00
require ( __DIR__ . '/lib/autoload.php' );
2014-01-13 15:44:31 -05:00
2014-03-17 10:43:00 -04:00
/*******************************
* Console Set - up
*******************************/
2014-01-13 16:16:16 -05:00
2014-03-17 10:43:00 -04:00
$console = new PatternLab\Console ;
2014-01-23 14:50:49 -05:00
2014-03-17 10:43:00 -04:00
// set-up the generate command and options
$console -> setCommand ( " g " , " generate " , " Generate Pattern Lab " , " The generate command generates an entire site a single time. By default it removes old content in public/, compiles the patterns and moves content from source/ into public/ " );
$console -> setCommandOption ( " g " , " p " , " patternsonly " , " Generate only the patterns. Does NOT clean public/. " , " To generate only the patterns: " );
$console -> setCommandOption ( " g " , " n " , " nocache " , " Set the cacheBuster value to 0. " , " To turn off the cacheBuster: " );
$console -> setCommandOption ( " g " , " c " , " enablecss " , " Generate CSS for each pattern. Resource intensive. " , " To run and generate the CSS for each pattern: " );
2014-01-20 09:41:08 -05:00
2014-03-17 10:43:00 -04:00
// set-up an alias for the generate command
$console -> setCommand ( " b " , " build " , " Alias for the generate command " , " Alias for the generate command. Please refer to it's help for full options. " );
// set-up the watch command and options
$console -> setCommand ( " w " , " watch " , " Watch for changes and regenerate " , " The watch command builds Pattern Lab, watches for changes in source/ and regenerates Pattern Lab when there are any. " );
$console -> setCommandOption ( " w " , " p " , " patternsonly " , " Watches only the patterns. Does NOT clean public/. " , " To watch and generate only the patterns: " );
2014-03-18 14:49:22 -04:00
$console -> setCommandOption ( " w " , " n " , " nocache " , " Set the cacheBuster value to 0. " , " To turn off the cacheBuster: " );
2014-03-17 10:43:00 -04:00
$console -> setCommandOption ( " w " , " r " , " autoreload " , " Turn on the auto-reload service. " , " To turn on auto-reload: " );
2014-05-06 10:00:47 -04:00
// set-up the snapshot command and options
2014-05-09 17:02:50 -04:00
$console -> setCommand ( " s " , " snapshot " , " Take a snapshot of public/ " , " The snapshot command copies the current state of public/ and puts it in snapshots/v*/. " );
2014-05-09 17:03:12 -04:00
$console -> setCommandOption ( " s " , " d: " , " dir: " , " Optional directory path " , " To add an optional directory path instead of the defaul v*/ path: " , " example-path/ " );
2014-05-06 10:00:47 -04:00
2014-05-07 16:04:38 -04:00
// set-up the fetch command and options
2014-05-09 17:02:50 -04:00
$console -> setCommand ( " f: " , " fetch: " , " Fetch a starter kit " , " The fetch command grabs a starter kit from GitHub and puts it into source/. " );
2014-05-12 12:05:47 -04:00
$console -> setCommandSample ( " f " , " Install a starter kit: " , " github-org/github-repo " );
$console -> setCommandSample ( " f " , " Install a tagged version of a starter kit: " , " github-org/github-repo#tag " );
2014-05-07 16:04:38 -04:00
2014-03-17 10:43:00 -04:00
// set-up the version command
$console -> setCommand ( " v " , " version " , " Print the version number " , " The version command prints out the current version of Pattern Lab. " );
2014-04-20 14:15:14 -04:00
// set-up the help command
2014-05-12 12:06:19 -04:00
$console -> setCommand ( " h: " , " help: " , " Print the help for a given command " , " The help command prints out the help for a given flag. Just use -h with another command and it will tell you all of the options. " );
2014-04-20 14:15:14 -04:00
2014-03-17 10:43:00 -04:00
/*******************************
* Figure out what to run
*******************************/
// get what was passed on the command line
$console -> getArguments ();
2014-05-12 12:06:19 -04:00
if ( $console -> findCommand ( " h|help " )) {
2014-01-20 19:03:19 -05:00
2014-05-12 12:06:19 -04:00
$helpCommand = $console -> findCommandValue ( " h|help " );
$helpCommand = str_replace ( " - " , " " , $helpCommand );
$helpCommand = ( strlen ( $helpCommand ) == 1 ) ? $helpCommand : $console -> findCommandShort ( $helpCommand );
$helpCommand ? $console -> writeHelpCommand ( $helpCommand ) : $console -> writeHelp ();
2014-03-06 09:37:17 -05:00
2014-03-17 10:43:00 -04:00
} else if ( $command = $console -> getCommand ()) {
2014-01-13 15:44:31 -05:00
2014-03-17 10:43:00 -04:00
// run commands
2014-03-06 09:37:17 -05:00
2014-03-17 10:43:00 -04:00
// load Pattern Lab's config, if first time set-up move files appropriately too
$configurer = new PatternLab\Configurer ;
$config = $configurer -> getConfig ();
2014-03-07 12:44:43 -05:00
2014-03-17 10:43:00 -04:00
// set-up required vars
2014-05-06 10:04:32 -04:00
$enableCSS = $console -> findCommandOption ( " c|enablecss " );
2014-03-17 10:43:00 -04:00
$moveStatic = ( $console -> findCommandOption ( " p|patternsonly " )) ? false : true ;
2014-05-06 10:04:32 -04:00
$noCacheBuster = $console -> findCommandOption ( " n|nocache " );
$autoReload = $console -> findCommandOption ( " r|autoreload " );
2014-01-13 15:44:31 -05:00
2014-03-17 10:43:00 -04:00
if (( $command == " g " ) || ( $command == " b " )) {
// load the generator
$g = new PatternLab\Generator ( $config );
$g -> generate ( $enableCSS , $moveStatic , $noCacheBuster );
2014-01-21 21:15:29 -05:00
$g -> printSaying ();
2014-03-17 10:43:00 -04:00
} else if ( $command == " w " ) {
// CSS feature should't be used with watch
$enableCSS = false ;
// load the generator
$g = new PatternLab\Generator ( $config );
$g -> generate ( $enableCSS , $moveStatic , $noCacheBuster );
// load the watcher
$w = new PatternLab\Watcher ( $config );
2014-03-18 14:49:22 -04:00
$w -> watch ( $autoReload , $moveStatic , $noCacheBuster );
2014-03-17 10:43:00 -04:00
2014-05-06 10:00:47 -04:00
} else if ( $command == " s " ) {
// run the snapshot command
2014-05-09 16:19:45 -04:00
$snapshotDir = $console -> findCommandOptionValue ( " d|dir " );
2014-05-06 10:00:47 -04:00
$s = new PatternLab\Snapshot ( $config );
$s -> takeSnapshot ( $snapshotDir );
2014-05-09 16:20:14 -04:00
} else if ( $command == " f " ) {
// run the snapshot command
$starterKit = $console -> findCommandValue ( " f|fetch " );
$sk = new PatternLab\StarterKit ( $config );
$sk -> fetch ( $starterKit );
2014-03-17 10:43:00 -04:00
} else if ( $command == " v " ) {
// write out the version number
print " You're running v " . $config [ " v " ] . " of the PHP version of Pattern Lab. \n " ;
exit ;
2014-01-21 21:15:29 -05:00
}
2014-03-17 10:43:00 -04:00
} else {
2014-01-13 15:44:31 -05:00
2014-03-17 10:43:00 -04:00
// write the generic help
$console -> writeHelp ();
2014-01-13 15:44:31 -05:00
2013-06-21 16:02:07 -04:00
}