UNPKG

axcora

Version:

Modern and Super Light Static Site Generator

115 lines (114 loc) 5.54 kB
import fs from "fs"; import path from "path"; import chalk from "chalk"; // Banner function showBanner() { console.log(chalk.cyan(` ╔═════════════════════════════════════════════════════╗ ║ ${chalk.magenta('█████')} ${chalk.blue('██╗ ██╗')} ${chalk.cyan('██████')} ${chalk.green('██████')} ${chalk.red('█████████')} ${chalk.yellow('█████')} ║ ║ ${chalk.magenta('██╔══██╗')}${chalk.blue('╚██╗██╔╝')}${chalk.cyan('██╔════╝')}${chalk.green('██╔═══██╗')}${chalk.red('██ ██')} ${chalk.yellow('██╔══██╗')} ║ ║ ${chalk.magenta('███████║')} ${chalk.blue('╚███╔╝')} ${chalk.cyan('██║ ')}${chalk.green('██║ ██║')}${chalk.red('█████████')} ${chalk.yellow('███████║')} ║ ║ ${chalk.magenta('██╔══██║')} ${chalk.blue('██╔██╗')} ${chalk.cyan('██║ ')}${chalk.green('██║ ██║')}${chalk.red('██ ██ ')} ${chalk.yellow('██╔══██║')} ║ ║ ${chalk.magenta('██║ ██║')}${chalk.blue('██╔╝ ██╗')}${chalk.cyan('╚██████╗')}${chalk.green('╚██████╔╝')}${chalk.red('██ ██████╗')}${chalk.yellow('██║ ██║')} ║ ╚═════════════════════════════════════════════════════╝ `)); console.log(chalk.bold.cyan(" Modern and Super Light Static Site Generator")); console.log(chalk.gray(" ════════════════════════════════════════════════")); } // Direktori const nodeModules = path.resolve("node_modules"); const componentsDir = path.resolve("src/components"); const cssComponentsDir = path.resolve("static/css/components"); const jsComponentsDir = path.resolve("static/js/components"); // Tambahan untuk folder dist const cssDistDir = path.resolve("static/css/dist"); const jsDistDir = path.resolve("static/js/dist"); // Buat folder yang diperlukan ["static", "static/css", "static/js", cssComponentsDir, jsComponentsDir, cssDistDir, jsDistDir ].forEach(dir => { fs.mkdirSync(dir, { recursive: true }); }); const copied = []; const skipped = []; let totalCopied = 0; const baseCssSrc = path.join(nodeModules, "axcora-css", "axcora-base.css"); const baseCssDst = path.join("static/css", "axcora-base.css"); if (fs.existsSync(baseCssSrc)) { fs.mkdirSync(path.dirname(baseCssDst), { recursive: true }); fs.copyFileSync(baseCssSrc, baseCssDst); } // Helper copy + counter function copyFileCount(src, dst) { if (fs.existsSync(src)) { fs.mkdirSync(path.dirname(dst), { recursive: true }); fs.copyFileSync(src, dst); totalCopied++; } } // Patch khusus flat partial function patchSpecialFlatPartial() { const special = "axcora-seo"; const srcAxc = path.join(componentsDir, special, `${special}.axc`); const dstFlat = path.join(componentsDir, `${special}.axc`); if (fs.existsSync(srcAxc)) { fs.copyFileSync(srcAxc, dstFlat); totalCopied++; } } showBanner(); fs.readdirSync(nodeModules).forEach(pkg => { if (pkg.startsWith("axcora-")) { const fullPkg = path.join(nodeModules, pkg); if (fs.existsSync(fullPkg)) { // All .axc fs.readdirSync(fullPkg) .filter(f => f.endsWith(".axc")) .forEach(axc => { const compName = axc.replace(/\.axc$/, ""); const destDir = path.join(componentsDir, compName); const src = path.join(fullPkg, axc); const dst = path.join(destDir, axc); copyFileCount(src, dst); }); // All .css fs.readdirSync(fullPkg) .filter(f => f.endsWith(".css")) .forEach(css => { const src = path.join(fullPkg, css); const dst = path.join(cssComponentsDir, css); copyFileCount(src, dst); }); // All .js fs.readdirSync(fullPkg) .filter(f => f.endsWith(".js")) .forEach(js => { const src = path.join(fullPkg, js); const dst = path.join(jsComponentsDir, js); copyFileCount(src, dst); }); } } }); fs.readdirSync(nodeModules).forEach(pkg => { if (pkg.startsWith("axcora-theme-")) { const themeName = pkg.replace("axcora-theme-", ""); const themeDir = path.join(nodeModules, pkg); const themeCss = path.join(themeDir, "theme.css"); const dstDir = path.join("static/css/themes", themeName); const dstCss = path.join(dstDir, "theme.css"); if (fs.existsSync(themeCss)) { fs.mkdirSync(dstDir, { recursive: true }); fs.copyFileSync(themeCss, dstCss); totalCopied++; // console.log(chalk.green(`[THEME] Copied: ${themeCss} → ${dstCss}`)); } } }); patchSpecialFlatPartial(); console.log(chalk.green.bold(`[AXCORA] Copied (${totalCopied}) components themes css js and axc`));