0 ? date(' ') . $text . PHP_EOL : PHP_EOL; } function createDirIfNotExist(string $dir): void { if (!file_exists($dir) || !is_dir($dir)) { mkdir($dir); misuzu_log("Created '{$dir}'!"); } } function globDir(string $dir, string $pattern, int $flags = 0): array { return glob($dir . '/' . $pattern, $flags); } function deleteAllFilesInDir(string $dir, string $pattern): void { $files = globDir($dir, $pattern); foreach ($files as $file) { if (is_dir($file)) { misuzu_log("'{$file}' is a directory, entering..."); deleteAllFilesInDir($file, $pattern); rmdir($file); } else { unlink($file); misuzu_log("Deleted '{$file}'"); } } } misuzu_log('Cleanup'); createDirIfNotExist(CSS_DIR); createDirIfNotExist(JS_DIR); deleteAllFilesInDir(CSS_DIR, '*.css'); deleteAllFilesInDir(JS_DIR, '*.js'); deleteAllFilesInDir(TS_DIR, '*.d.ts'); misuzu_log(); misuzu_log('Compiling LESS'); if (!is_file(LESS_DIR . LESS_ENTRY_POINT)) { misuzu_log('==> ERR: Entry point for this style does not exist (' . basename(LESS_ENTRY_POINT) . ')'); } else { system(sprintf(LESS_CMD, escapeshellarg(LESS_DIR . LESS_ENTRY_POINT), LESS_DEST)); } // figure this out //misuzu_log(); //misuzu_log('Compiling TypeScript'); misuzu_log(); misuzu_log('Importing libraries'); define('IMPORT_SEQ', [ [ 'name' => 'CSS', 'files' => NODE_IMPORT_CSS, 'destination' => NODE_DEST_CSS, 'insert-semicolon' => false, ], [ 'name' => 'JavaScript', 'files' => NODE_IMPORT_JS, 'destination' => NODE_DEST_JS, 'insert-semicolon' => true, ], ]); foreach (IMPORT_SEQ as $sequence) { misuzu_log("=> {$sequence['name']}"); $contents = ''; foreach ($sequence['files'] as $file) { $realpath = realpath(NODE_MODULES_DIR . '/' . $file); misuzu_log("==> '{$file}'"); if (!file_exists($realpath)) { misuzu_log('===> File does not exist.'); continue; } $contents .= file_get_contents($realpath); if ($sequence['insert-semicolon']) { $contents .= ';'; } } file_put_contents($sequence['destination'], $contents); } // no need to do this in debug mode, auto reload is enabled and cache is disabled if (!file_exists(__DIR__ . '/.debug')) { // Clear Twig cache misuzu_log(); misuzu_log('Deleting template cache'); deleteAllFilesInDir(TWIG_DIRECTORY, '*'); }