forked from ChapelR/custom-macros-for-sugarcube-2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
46 lines (32 loc) · 1.19 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
41
42
43
44
45
46
// jshint esversion: 6, node: true
const jetpack = require('fs-jetpack'),
Terser = require('terser');
const buildDate = new Date().toISOString().split('T')[0],
buildID = require('git-commit-id')();
function build () {
const jsFiles = jetpack.find('./scripts', {
matching : '*.js',
recursive : false
});
jsFiles.forEach( file => {
const source = jetpack.read(file);
let path = file.split(/[\\\/]/g);
const name = path.pop().split('.').join('.min.');
let version = source.match(/(v|version\s+)(\d+\.\d+.\d+)/);
if (version == null) {
version = '0.0.0';
console.log(`missing version info: ${file}`);
} else {
version = version[2];
}
const result = Terser.minify(source);
console.log(result.error);
path.unshift('.');
path.push('minified');
path.push(name);
path = path.join('/');
const ret = `// ${name}, for SugarCube 2, by Chapel\n// v${version}, ${buildDate}, ${buildID}\n;${result.code}\n// end ${name}`;
jetpack.write(path, ret, {atomic : true});
});
}
build();