-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
91 lines (82 loc) · 1.96 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const AdmZip = require('adm-zip');
const fs = require('fs');
const path = require('path');
const minimatch = require("minimatch")
const pjson = require('./package.json');
const scriptName = path.basename(__filename);
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 = 'anvil_of_destiny';
const version = pjson.version;
const root_folder = __dirname;
const ignore_list = [
'node_modules',
'dist',
'gimp',
'.*',
'*.zip',
'anvil_preview.gif',
'idea.lua',
'LICENSE',
'README.md',
'TODO.md',
'package*.json',
'rune_alphabet.png',
'rune_alphabet_sprites.png',
'rune_alphabet_typer.htm',
'rune_texts.txt',
'Modworkshop Readme.txt',
'recipe_description_image.html',
'recipe_description_image.png',
'steam description.txt',
'fmod',
'workshop.xml',
'workshop_id.txt',
'workshop_preview_image.png',
'mod_id.txt',
];
// Config end
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 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}`);
}
}
}
};
const zip = new AdmZip();
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`);
}