-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
33 lines (28 loc) · 954 Bytes
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from 'fs-extra';
const parseBundle = async (template, bundle) => {
let scripts = [...new Set(bundle.scripts)];
scripts = await Promise.all(scripts.map(async(script) => {
const scriptImport = fs.readFileSync(`./templates/${template}/${script}.js`, 'utf-8');
return {
file: `${script}.js`,
code: scriptImport
}
}));
const arrayToObject = {};
scripts.forEach(({file, code}) => {
arrayToObject[file] = {
file,
code
}
});
return {
...bundle,
scripts: arrayToObject
}
}
const templates = fs.readdirSync('./templates');
await Promise.all(templates.map(async (template) => {
const bundle = fs.readFileSync(`./templates/${template}/bundle.json`);
const parsedBundle = await parseBundle(template, JSON.parse(bundle));
fs.writeFile(`./src/templates/${template}.json`, JSON.stringify(parsedBundle));
}))