#!/usr/bin/env node "use strict"; const fs = require("fs"); const browserify = require("browserify"); // Handle home page const b = browserify(); b.add(`${process.cwd()}/src/main.js`) .bundle() .pipe(fs.createWriteStream(`${process.cwd()}/public/main.js`)); // Handle subpages function getPageHtml(pagename) { return ` <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Kuadrado Software - ${pagename}</title> <link href="../../style/style.css" rel="stylesheet" /> </head> <body> <main></main> </body> <script type="text/javascript" src="./${pagename}.js"></script> </html> `; } const files = fs.readdirSync(`${process.cwd()}/src/pages`); for (const f of files) { const fPath = `${process.cwd()}/src/pages/${f}`; const targetDirPath = `${process.cwd()}/public/${f}`; if (!fs.existsSync(targetDirPath)) { fs.mkdirSync(targetDirPath); } const b = browserify(); b.add(fPath) .bundle() .pipe(fs.createWriteStream(`${targetDirPath}/${f}.js`)); const page = fs.createWriteStream(`${targetDirPath}/index.html`); page.write(getPageHtml(f)); }