1
0
mirror of https://github.com/pattern-lab/patternlab-php.git synced 2025-01-17 22:29:12 +01:00
patternlab-php/core/builder.php

137 lines
5.3 KiB
PHP
Raw Normal View History

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
*
*/
/*******************************
* 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
/*******************************
* Console Set-up
*******************************/
$console = new PatternLab\Console;
// 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:");
// 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:");
$console->setCommandOption("w","n","nocache","Set the cacheBuster value to 0.","To turn off the cacheBuster:");
$console->setCommandOption("w","r","autoreload","Turn on the auto-reload service.","To turn on auto-reload:");
// set-up the snapshot command and options
$console->setCommand("s","snapshot","Take a snapshot of public/","The snapshot command copies the current state of public/ and puts it in snapshots/v*/.");
$console->setCommandOption("s","d:","dir:","Optional directory path","To add an optional directory path instead of the defaul v*/ path:","example-path/");
2014-05-07 16:04:38 -04:00
// set-up the fetch command and options
$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
// set-up the version command
$console->setCommand("v","version","Print the version number","The version command prints out the current version of Pattern Lab.");
// set-up the help command
$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.");
/*******************************
* Figure out what to run
*******************************/
// get what was passed on the command line
$console->getArguments();
if ($console->findCommand("h|help")) {
2014-01-20 19:03:19 -05:00
$helpCommand = $console->findCommandValue("h|help");
$helpCommand = str_replace("-","",$helpCommand);
$helpCommand = (strlen($helpCommand) == 1) ? $helpCommand : $console->findCommandShort($helpCommand);
$helpCommand ? $console->writeHelpCommand($helpCommand) : $console->writeHelp();
} else if ($command = $console->getCommand()) {
2014-01-13 15:44:31 -05:00
// run commands
// load Pattern Lab's config, if first time set-up move files appropriately too
$configurer = new PatternLab\Configurer;
$config = $configurer->getConfig();
// set-up required vars
2014-05-06 10:04:32 -04:00
$enableCSS = $console->findCommandOption("c|enablecss");
$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
if (($command == "g") || ($command == "b")) {
// load the generator
$g = new PatternLab\Generator($config);
$g->generate($enableCSS,$moveStatic,$noCacheBuster);
$g->printSaying();
} 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);
$w->watch($autoReload,$moveStatic,$noCacheBuster);
} else if ($command == "s") {
// run the snapshot command
$snapshotDir = $console->findCommandOptionValue("d|dir");
$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);
} 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;
}
} else {
2014-01-13 15:44:31 -05:00
// write the generic help
$console->writeHelp();
2014-01-13 15:44:31 -05:00
2013-06-21 16:02:07 -04:00
}