-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateExtensionSrc.cjs
32 lines (27 loc) · 1.16 KB
/
updateExtensionSrc.cjs
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
/* eslint-disable */
const fs = require('fs');
const buildDir = __dirname + '/build';
fs.readdir(buildDir, function (err, buildFilenames) {
buildFilenames.forEach((path) => {
if (path.endsWith('.html')) {
const htmlFilePath = buildDir + '/' + path;
const content = fs.readFile(htmlFilePath, function (_, content) {
if (content.indexOf('<!--__EXTENSION_SRC_PATHS_PLACEHOLDER__-->') > -1) {
const extDir = buildDir + '/extension-js';
fs.readdir(extDir, function (err, filenames) {
const fNames = filenames?.filter((f) => f.endsWith('.js'));
if (fNames?.length) {
const scripts = fNames.sort((a,b)=>parseInt(a)-parseInt(b)).reduce((state, fName) => {
return state += "<script src='./extension-js/" + fName + "'></script>";
}, '');
const replacedContent = content.toString().replace('<!--__EXTENSION_SRC_PATHS_PLACEHOLDER__-->', scripts);
fs.writeFile(htmlFilePath, replacedContent, (err) => {
err ? console.log('ERR Writing file=', err) : null;
});
}
});
}
});
}
});
});