-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.js
39 lines (32 loc) · 908 Bytes
/
dist.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
const fs = require("fs");
const VERSION = process.env.VERSION ? process.env.VERSION : "alpha.0.0.0";
const FILE_PATH = `dist/object-editor.${VERSION}.min.js`;
const BUILD_DIR = "build/static/js/";
console.log("Generating version:", VERSION);
generateFile(FILE_PATH)(eachFile(BUILD_DIR)(appendDist));
function generateFile(path) {
fs.open(path, "wx", err => {
if (err) {
if (err.code === "EEXIST")
return fs.unlink(path, () => generateFile(path));
throw err;
}
});
return fn => fn.apply();
}
function eachFile(dir) {
return callback => () => {
fs.readdir(dir, (err, files) => {
if (err) throw err;
files.forEach(file => callback(dir + file));
});
};
}
function appendDist(path) {
fs.readFile(path, "utf8", (err, data) => {
if (err) throw err;
fs.appendFile(FILE_PATH, "\r\n" + data, err => {
if (err) throw err;
});
});
}