1
0
mirror of https://github.com/pattern-lab/patternlab-php.git synced 2025-01-18 06:38:20 +01:00
patternlab-php/core/builder.php

118 lines
3.4 KiB
PHP
Raw Normal View History

2013-06-21 16:02:07 -04:00
<?php
/*!
2014-02-04 21:44:07 -05:00
* Pattern Lab Builder CLI - v0.7.2
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
*
* Usage:
*
* php builder.php -g
* Iterates over the 'source' directories & files and generates the entire site a single time.
* It also cleans the 'public' directory.
2013-06-21 16:02:07 -04:00
*
* php builder/builder.php -gc
* In addition to the -g flag features it will also generate CSS for each pattern. Resource instensive.
*
2013-06-21 16:02:07 -04:00
* php builder.php -w
* Generates the site like the -g flag and then watches for changes in the 'source' directories &
* files. Will re-generate files if they've changed.
*
* php builder.php -wr
* In addition to the -w flag features it will also automatically start the auto-reload server.
2013-06-21 16:02:07 -04:00
*
* php builder.php -v
* Prints out the current version of Pattern Lab.
*
2013-06-21 16:02:07 -04:00
*/
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
require(__DIR__."/lib/SplClassLoader.php");
2013-06-21 16:02:07 -04:00
2014-01-13 15:44:31 -05:00
$loader = new SplClassLoader('PatternLab', __DIR__.'/lib');
$loader->register();
2014-01-13 15:44:31 -05:00
$loader = new SplClassLoader('Mustache', __DIR__.'/lib');
$loader->setNamespaceSeparator("_");
$loader->register();
2013-06-21 16:02:07 -04:00
// make sure this script is being accessed from the command line
2014-01-13 15:44:31 -05:00
if (php_sapi_name() != 'cli') {
2014-01-20 09:41:53 -05:00
print "The builder script can only be run from the command line.\n";
2014-01-13 15:44:31 -05:00
exit;
}
2014-01-20 09:41:53 -05:00
// grab the arguments from the command line
$args = getopt("gwcrv");
// load Pattern Lab's config, if first time set-up move files appropriately too
$co = new PatternLab\Configurer;
$config = $co->getConfig();
// show the version of Pattern Lab
if (isset($args["v"])) {
print "You're running v".$config["v"]." of the PHP version of Pattern Lab.\n";
exit;
}
2014-01-20 09:41:53 -05:00
// generate the pattern lab site if appropriate
2014-01-13 15:44:31 -05:00
if (isset($args["g"]) || isset($args["w"])) {
2014-01-20 19:03:19 -05:00
$g = new PatternLab\Generator($config);
2014-01-13 15:44:31 -05:00
$c = false;
// check to see if CSS for patterns should be parsed & outputted
if (isset($args["c"]) && !isset($args["w"])) {
$c = true;
}
$g->generate($c);
// have some fun
if (!isset($args["w"])) {
$g->printSaying();
}
2014-01-13 15:44:31 -05:00
}
2013-06-21 16:02:07 -04:00
2014-01-20 09:41:53 -05:00
// watch the source directory and regenerate any changed files
2014-01-13 15:44:31 -05:00
if (isset($args["w"])) {
$w = new PatternLab\Watcher($config);
2014-01-13 15:44:31 -05:00
$a = false;
if (isset($args["r"])) {
$a = true;
}
$w->watch($a);
}
2014-01-20 09:41:53 -05:00
// when in doubt write out the usage
if (!isset($args["g"]) && !isset($args["w"]) && !isset($args["v"])) {
2014-01-13 15:44:31 -05:00
print "\n";
print "Usage:\n\n";
print " php ".$_SERVER["PHP_SELF"]." -g\n";
print " Iterates over the 'source' directories & files and generates the entire site a single time.\n";
print " It also cleans the 'public' directory.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -gc\n";
print " In addition to the -g flag features it will also generate CSS for each pattern. Resource instensive.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -w\n";
print " Generates the site like the -g flag and then watches for changes in the 'source' directories &\n";
print " files. Will re-generate files if they've changed.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -wr\n";
print " In addition to the -w flag features it will also automatically start the auto-reload server.\n\n";
print " php ".$_SERVER["PHP_SELF"]." -v\n";
print " Prints out the current version of Pattern Lab.\n\n";
2014-01-13 15:44:31 -05:00
2013-06-21 16:02:07 -04:00
}