if ($this->config['show-server-output'] === false) { $cmd_docs_server .= " > /dev/null 2>&1"; } $cmd_watcher = "php ./bin/watcher.php"; $cmd_logs = "tail -n 0 -f ./debug.log | cut -c 76-10000"; $this->config['proc-server'] = popen($cmd_server, 'w'); $this->config['proc-docs-server'] = popen($cmd_docs_server, 'w'); $this->config['proc-watcher'] = popen($cmd_watcher, 'w'); $this->config['proc-logs'] = popen($cmd_logs, 'w'); register_shutdown_function([$this, 'shutdown']); while (!feof($this->config['proc-logs'])) { echo fread($this->config['proc-logs'], 4096); @flush(); usleep(1000000); } } public function shutdown() { pclose($this->config['proc-server']); pclose($this->config['proc-docs-server']); pclose($this->config['proc-watcher']); pclose($this->config['proc-logs']); proc_terminate($this->config['proc-server']); proc_terminate($this->config['proc-docs-server']); proc_terminate($this->config['proc-watcher']); proc_terminate($this->config['proc-logs']); exit; } } Container::addTask(new Server());
$dictionaryKeys['model:' . $this->config['table']] = ucwords($this->config['table']); } foreach ($this->config['columns'] as $column) { if (isset($dictionaryKeys['model:' . $this->config['table'] . ':' . $column['name']]) === false) { $dictionaryKeys['model:' . $this->config['table'] . ':' . $column['name']] = ucwords(str_replace('_', ' ', $column['name'])); } } ksort($dictionaryKeys); file_put_contents($modelDictPath, json_encode($dictionaryKeys, JSON_PRETTY_PRINT)); $navigationDictPath = getcwd() . '/app/dictionary/en__navigation.json'; if (file_exists($modelDictPath)) { $dictionaryKeys = json_decode(file_get_contents($navigationDictPath), true); } else { $dictionaryKeys = []; } if (isset($dictionaryKeys['navigation:' . $this->config['table'] . '.view.table']) === false) { $dictionaryKeys['navigation:' . $this->config['table'] . '.view.table'] = ucwords(str_replace('_', ' ', $this->config['table'])); } ksort($dictionaryKeys); file_put_contents($navigationDictPath, json_encode($dictionaryKeys, JSON_PRETTY_PRINT)); } public function testBuildKeys() { } public function testBuildFiles() { $this->buildFromTemplate('test', getcwd() . '/tests/' . $this->config['name'] . '_Test.php'); } } Container::addTask(new Generate());
<?php namespace Lucid\Task; class Test extends Task implements TaskInterface { public static $trigger = 'test'; public function run() { echo "Running tests...\n"; echo shell_exec('phpunit --bootstrap ./bootstrap.php tests/'); } } Container::addTask(new Test());
$this->formatter($ok, 'Version Control', implode(', ', $availableVcs), 'This only checks for subversion, git, and mercurial as they are the most common. I recommend git. You may safely ignore this check if you\'re using somethign else, but you *should* be using something.'); } public function checkKernel() { $availableVcs = []; $kernel = strtolower(php_uname('s')); $ok = $kernel == 'darwin' || $kernel == 'linux'; $this->formatter($ok, 'Kernel', $kernel, 'If you are not running on linux or osx, you\'re in uncharted territory. If on windows, you should probably look into cygwin or setting up some kind of unix-like environment on your machine.'); } public function checkCaseSensitive() { $ok = !(file_exists(strtoupper(__FILE__)) && file_exists(strtolower(__FILE__))); $caseSensitive = true; $this->formatter($ok, 'FS Case Sensitive', $ok ? 'Sensitive' : 'Insensitive', 'Your current filesystem appears to be case-insensitive, which may lead to problems if you deploy your code to a case-sensitive production server.'); } } Container::addTask(new SystemReport()); # load additional tasks from the project directories, if we're in a valid project Container::findTasks(); # Determine what the task we're trying to run is # the first element of the array is simply this filename, so get rid of it right away array_shift($argv); # Determine if a task is being passed. If not, default to 'usage' if (count($argv) > 0) { $task = array_shift($argv); } else { $task = 'usage'; } # run the task and exit. Container::run($task, $argv); exit;
echo "Setting import paths...\n"; foreach ($config['importPaths'] as $path) { echo " {$path}\n"; $importPaths[] = getcwd() . '/' . $path; } $scss = new \Leafo\ScssPhp\Compiler(); $scss->setImportPaths($importPaths); # build a compressed version first echo "Writing production.css...\n"; $scss->setFormatter('Leafo\\ScssPhp\\Formatter\\Crunched'); $result = $scss->compile($source); $prodOutput = getcwd() . '/' . $config['outputPath'] . '/production.css'; if (file_exists($prodOutput) === true) { unlink($prodOutput); } file_put_contents($prodOutput, $result); # now build a debug version echo "Writing debug.css...\n"; $scss->setFormatter('Leafo\\ScssPhp\\Formatter\\Expanded'); $scss->setLineNumberStyle(\Leafo\ScssPhp\Compiler::LINE_COMMENTS); $result = $scss->compile($source); $debugOutput = getcwd() . '/' . $config['outputPath'] . '/debug.css'; if (file_exists($debugOutput) === true) { unlink($debugOutput); } file_put_contents($debugOutput, $result); echo "Complete.\n"; } } Container::addTask(new CompileSass());
$pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetFont('helvetica', '', 20); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->AddPage(); $pdf->writeHTML($html, true, 0, true, 0); $pdf->lastPage(); echo "Writing PDF...\n"; $pdf->Output($this->config['output'], 'F'); echo "Complete.\n"; } public function findMarkdown($links) { $markdown = ''; foreach ($links as $link) { $lucidPath = '../vendor/dev-lucid/lucid/docs/'; $file = $link['file']; $file = str_replace('lucid/', $lucidPath, $file); $filePath = $this->config['doc-root'] . $file . '.md'; echo " {$filePath}...\n"; $markdown .= file_get_contents($filePath) . "\n"; if (isset($link['children']) === true && count($link['children']) > 0) { $markdown .= $this->findMarkdown($link['children']); } } return $markdown; } } Container::addTask(new BuildDocs());
class PhinxStatus extends Task implements TaskInterface { public static $trigger = 'status'; public function isAvailable() { return file_exists(getcwd() . '/config/phinx.php') === true; } public function run() { include getcwd() . '/bootstrap.php'; $cmd = 'bin/phinx status -c config/phinx.php -p php -e ' . app('config')->stage() . ' -vvv'; echo $cmd . "\n\n"; $result = shell_exec($cmd); exit($result); /* $result = explode("\n", $result); while (strpos($result[0], 'using environment ') === false) { array_shift($result); } array_shift($result); $result = implode("\n", $result); $result = str_replace('using the create command.', 'using the lucid migration command.', $result); echo($result); */ } } Container::addTask(new PhinxStatus());
class PhinxMigration extends Task implements TaskInterface { public static $trigger = 'migration'; public function __construct() { $this->parameters[] = new \Lucid\Task\Parameter('name', 'unlabeled', false, null); } public function isAvailable() { return file_exists(getcwd() . '/config/phinx.php') === true; } public function run() { include getcwd() . '/bootstrap.php'; $cmd = 'php bin/phinx create ' . $this->config['name'] . ' -c ./config/phinx.php -p php -vvv'; echo $cmd . "\n\n"; $result = shell_exec($cmd); exit($result); /* $result = explode("\n", $result); while (count($result) > 0 && strpos($result[0], 'using default template') === false) { array_shift($result); } array_shift($result); echo(implode("\n", $result)); */ } } Container::addTask(new PhinxMigration());
<?php namespace Lucid\Task; class VCS extends Task implements TaskInterface { public static $trigger = 'vcs'; public function parseArguments(array $arguments) { $this->config = $arguments; } public function isAvailable() { return file_exists(getcwd() . '/.git') === true || file_exists(getcwd() . '/.hg') === true || file_exists(getcwd() . '/.svn') === true; } public function run() { $vcs = ''; $vcs = file_exists(getcwd() . '/.git') === true ? 'git' : $vcs; $vcs = file_exists(getcwd() . '/.hg') === true ? 'hg' : $vcs; $vcs = file_exists(getcwd() . '/.svn') === true ? 'svn' : $vcs; $cmd = $vcs . ' ' . implode(' ', $this->config); echo '> ' . $cmd . "\n\n"; $result = shell_exec($cmd); exit($result); } } Container::addTask(new VCS());
namespace Lucid\Task; class CompileJavascript extends Task implements TaskInterface { public static $trigger = 'compile-javascript'; public function run() { $config = (include getcwd() . '/config/javascript.php'); $files = []; foreach ($config['include'] as $path => $pathFiles) { foreach ($pathFiles as $pathFile) { $files[] = getcwd() . '/' . $path . '/' . $pathFile; } } $source = ''; echo "Loading script files...\n"; foreach ($files as $file) { echo " {$file}\n"; $source .= file_get_contents($file); } echo "Writing debug.js\n"; file_put_contents(getcwd() . '/' . $config['outputPath'] . '/debug.js', $source); #$source = \JSMin::minify($source); #$source = \JShrink\Minifier::minify($source); echo "Writing production.js\n"; file_put_contents(getcwd() . '/' . $config['outputPath'] . '/production.js', $source); echo "Complete.\n"; } } Container::addTask(new CompileJavascript());