-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
77 lines (69 loc) · 1.64 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('fs');
const AdmZip = require('adm-zip');
const path = require('path');
const minimatch = require("minimatch");
const pjson = require('./package.json');
let preview = false;
const args = process.argv.slice(2);
args.forEach(val => {
if(val == '--preview') {
preview = true;
}
});
// Config
const out_dir = __dirname + '/dist';
const name = path.basename(__dirname);
const version = pjson.version;
const root_folder = __dirname;
const ignore_list = [
'**/node_modules',
'**/.*',
'www/*',
'*.json',
'*.js',
'dist',
'env.lua',
'*.md',
'unit_test.lua',
'unit_tests.lua',
'xxx.lua',
];
// Config end
const scriptName = path.basename(__filename);
ignore_list.push(scriptName);
function is_dir(path) {
try {
var stat = fs.lstatSync(path);
return stat.isDirectory();
} catch (e) {
// lstatSync throws an error if path doesn't exist
return false;
}
}
const zip = new AdmZip();
const addFiles = item => {
if(ignore_list.every(ignore_entry => !minimatch(item, ignore_entry))) {
if(is_dir(__dirname + '/' + item)) {
fs.readdirSync(__dirname + '/' + item).forEach(entry => {
const child_item = `${item}/${entry}`;
addFiles(child_item);
});
} else {
const folderName = item.substr(0, item.lastIndexOf('/'));
if(preview) {
console.log(item);
} else {
zip.addLocalFile(`${__dirname}/${item}`, `${name}/${folderName}`);
}
}
}
};
fs.readdirSync(root_folder).forEach(entry => {
addFiles(entry);
});
if(!preview) {
if (!fs.existsSync(out_dir)) {
fs.mkdirSync(out_dir);
}
zip.writeZip(`${out_dir}/${name}_v${version}.zip`);
}