-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
40 lines (33 loc) · 1.28 KB
/
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
34
35
36
37
38
39
40
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const EXTENSIONS_DIR = path.join(__dirname, 'extensions');
const TEMPLATES_DIR = path.join(__dirname, 'templates');
const extensions = fs.readdirSync(EXTENSIONS_DIR).map(readExtension);
const templates = fs.readdirSync(TEMPLATES_DIR);
for (const template of templates) {
fs.writeFileSync(template, renderTemplate(path.join(TEMPLATES_DIR, template), { extensions }));
}
// ------------------------------------------
function readExtension(name) {
const dirpath = path.join(EXTENSIONS_DIR, name);
const settings = JSON.parse(fs.readFileSync(path.join(dirpath, 'extension.json'), 'utf8'));
const description = settings['description'];
let linkUrl = "";
let scriptUrl = `https://extensions.netsblox.org/extensions/${name}/index.js`;
if (!settings['useDev']) {
linkUrl = `https://editor.netsblox.org/?extensions=[%22${scriptUrl}%22]#`;
} else {
linkUrl = `https://dev.netsblox.org/?extensions=[%22${scriptUrl}%22]#`;
}
return {
name,
displayName : settings['customName'] ?? name,
description,
linkUrl,
scriptUrl,
};
}
function renderTemplate(name, data) {
return _.template(fs.readFileSync(name, 'utf8'))(data).trim();
}