Browse Source

REFA,IMPRO: local custom bundler generates vainlla and module

dev-feat-component_preview
chris 2 months ago
parent
commit
e65c2f96cd
  1. 16
      generate_single_file.js

16
generate_single_file.js

@ -85,9 +85,7 @@ async function appendContent(srcFile, targetFile, contentModifications = [], lin
try {
let content = await fs.readFile(srcFile, 'utf8');
console.log(`Processing '${srcFile}'`);
console.log(` READ: successfully!`);
console.log(` Adding Copyright disclaimer!`);
console.log(` Attepting to append to default script variant`);
console.log(` READ: successfully!`, `Attepting to append file`);
/* Apply modifications */
content = contentModifications
@ -122,8 +120,12 @@ async function bundleWithSpecifiedMode(targetFile, fileList, modulize = true) {
let lineModifications = [
function (line) {
let starters = ["function", "const", "let", "class"];
return (starters.some(s => line.startsWith(s)) ? "export " : "") + line;
if (starters.some(s => line.startsWith(s))) {
return "export " + line;
}
return line;
}
];
@ -161,7 +163,7 @@ async function bundleWithSpecifiedMode(targetFile, fileList, modulize = true) {
* @param {string|path} bundleFile path to the bundleFile if there is some
* - preparation for jpclw-bundler
*/
function bundle(targetFile = "./jpc-like-websites.js", modulize = true, bundleFile = './jpclw-bundle.json') {
function bundle(modulize = false, targetFile = "./jpc-like-websites.js", bundleFile = './jpclw-bundle.json') {
let fileOrder = require(bundleFile);
console.log("(Re-) Creating target file: '" + targetFile + "'");
@ -169,7 +171,7 @@ function bundle(targetFile = "./jpc-like-websites.js", modulize = true, bundleFi
fs.writeFile(targetFile, "", err => { });
if (modulize) {
let targetModule = path.basename(targetFile).split('.', 1)[0] + 'mjs';
let targetModule = path.basename(targetFile).split('.', 1)[0] + '.mjs';
fs.writeFile(targetModule, "", err => { });
}
@ -187,5 +189,5 @@ function bundle(targetFile = "./jpc-like-websites.js", modulize = true, bundleFi
}
let args = process.argv.slice(2);
bundle(args[0], args[1], args[2]);
bundle(Boolean(args[0]), args[1], args[2]);

Loading…
Cancel
Save