-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildplugin.js
40 lines (31 loc) · 961 Bytes
/
buildplugin.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 fs = require("fs");
const { EOL } = require("os");
const path = require("path");
function build() {
console.info("Build script starting");
let modules = 0;
const buffer = [
"// auto-generated file", "",
];
const emitModule = file => {
const moduleName = file.replace(".js", "");
modules += 1;
buffer.push(`exports.${moduleName} = require("./snippets/${moduleName}");`);
};
const files = fs.readdirSync(__dirname + "/src/snippets");
files
.filter(fname => fname !== "index.js" && !fname.startsWith("."))
.forEach(f => {
const stats = fs.statSync(path.join(__dirname, "src/snippets", f));
if (stats.isFile()) {
emitModule(f);
}
});
fs.writeFileSync(path.join(__dirname, "src/index.js"), buffer.join(EOL)+EOL);
console.info(`Build script done. 'src/index.js' emitted with ${modules} modules`);
}
module.exports = function () {
this.plugin("watch-run", function () {
build();
})
};