$autoload = (require getcwd() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'); require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'sauce.php'; require __DIR__ . DIRECTORY_SEPARATOR . 'functions.php'; \Sauce\Base::bind(function ($bootstrap) { die($bootstrap()); }); run(function () { \Sauce\Shell\CLI::initialize(); $xargs = \Sauce\Shell\CLI::values(); $command = array_shift($xargs); $paths = array(); $paths[] = path(__DIR__, 'tasks'); is_dir($app_tasks = path(APP_PATH, 'tasks')) && ($paths[] = $app_tasks); \IO\Dir::open($paths, function ($file) { if (is_dir($file)) { require path($file, 'initialize.php'); } else { require $file; } }); if (!$command) { help(arg('help')); } else { try { \Sauce\Shell\Task::exec($command, $xargs); } catch (\Exception $e) { \Sauce\Shell\CLI::error("\n \\cred,black({$e->getMessage()})\\c\n"); } } });
function error($text) { \Sauce\Shell\CLI::error("\\cred,black({$text})\\c"); }
say("\n {$prefix}Press \\bwhite(CTRL+C)\\b to exit\n"); $cache = array(); if ($readline = function_exists('readline')) { readline_completion_function(function () { return array(); }); } $callback = $readline ? 'readline' : '\\Sauce\\Shell\\CLI::readln'; \Sauce\Shell\CLI::main(function () use($callback, $readline, &$cache, $warn) { $_ = trim(call_user_func($callback, colorize(' > '))); if (!$_) { return; } elseif ($readline && $_ && !in_array($_, $cache)) { readline_add_history($_); $cache[] = $_; } $code = "extract(__set());return __set({$_},get_defined_vars());"; $out = $warn ? (array) @eval($code) : @assert($_); if (is_array($out)) { foreach ($out as $key => $one) { $prefix = ''; if (is_string($key)) { $prefix = "\\clight_gray({$key} )\\c"; } $one = preg_replace('/^/m', colorize(" \\cgreen(>)\\c {$prefix}"), trim(inspect($one))); writeln($one); } } else { writeln(colorize(sprintf(' \\c%s(> %s)\\c', $out ? 'green' : 'red', $_))); } });
\Tailor\Config::set('styles_dir', path($assets_dir, 'css')); \Tailor\Config::set('scripts_dir', path($assets_dir, 'js')); if (arg('b build')) { say("\n \\cwhite,blue(**COMPILING**)\\c"); } else { say("\n \\cwhite,magenta(**WATCHING**)\\c\n Press \\bwhite(CTRL+C)\\b to exit"); } say("\n *From*: {$source_dir}\n *To*: {$output_dir}\n"); $cache_file = path($target_dir, '.cache'); $cache = explode("\n", read($cache_file)) ?: array(); $timeout = (int) arg('t to') ?: 3; if ($recreate) { require path(__DIR__, 'create_skeleton.php'); } elseif (arg('r reset')) { $cache = array(); \IO\Dir::unfile($output_dir, '*', TRUE); is_dir($output_dir) or mkdir($output_dir, 0755, TRUE); status('reset'); } if (arg('b build')) { $a = microtime(TRUE); $cache = array(); $timeout = 0; require path(__DIR__, 'do_compile.php'); $diff = round(microtime(TRUE) - $a, 4); say("\n *Done*: {$diff}s\n"); } else { \Sauce\Shell\CLI::main(function () use(&$cache, $target_dir, $assets_dir, $source_dir, $output_dir, $timeout) { require path(__DIR__, 'do_compile.php'); }); }
private static function search($q = '') { \Sauce\Shell\CLI::printf("\n \\ccyan(Available tasks:)\\c\n\n"); $max = 0; foreach (static::$tasks as $ns => $set) { foreach (array_keys($set) as $k) { $cmd = $k != 'default' ? "{$ns}:{$k}" : $ns; $max = ($test = strlen($cmd)) > $max ? $test : $max; } } foreach (static::$tasks as $ns => $set) { if (!$q or strpos($ns, $q) === 0) { foreach ($set as $key => $val) { $cmd = $key != 'default' ? "{$ns}:{$key}" : $ns; $pad = str_repeat(' ', $max + 2 - strlen($cmd)); if (!empty($val['desc'])) { \Sauce\Shell\CLI::printf(" \\cbrown(%s)\\c{$pad}\\cdark_gray(#)\\c \\clight_gray(%s)\\c\n", $cmd, $val['desc']); } else { \Sauce\Shell\CLI::printf(" \\cbrown(%s)\\c\n", $cmd); } } } } \Sauce\Shell\CLI::writeln(); }