-
Notifications
You must be signed in to change notification settings - Fork 221
/
pack.js
58 lines (50 loc) · 1.7 KB
/
pack.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
const fs = require('fs');
const path = require('path');
const archiver = require('archiver');
const manifest = require('./manifest.json');
const dir = `./release/${manifest.meta.version}`;
fs.rmdirSync(dir, {
recursive: true
});
fs.mkdirSync(dir);
fs.mkdirSync(`${dir}/app`);
fs.mkdirSync(`${dir}/app/plugins`);
copyRecursiveSync('./store', `${dir}/store`)
fs.copyFileSync('./CHANGELOG.md', `${dir}/CHANGELOG.md`);
fs.copyFileSync('./manifest.json', `${dir}/app/manifest.json`);
copyRecursiveSync('./assets', `${dir}/app/assets`);
copyRecursiveSync('./dist', `${dir}/app/dist`);
copyRecursiveSync('./plugins/dist', `${dir}/app/plugins/dist`);
zipDirectory(dir, `./release/poe-overlay-overwolf ${manifest.meta.version}.zip`).then(() => {
fs.rmdirSync(dir, {
recursive: true
});
}, error => {
console.error('could not create zip.', error);
});
function copyRecursiveSync(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest);
fs.readdirSync(src).forEach(function (childItemName) {
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
function zipDirectory(source, out) {
const archive = archiver('zip', { zlib: { level: 9 } });
const stream = fs.createWriteStream(out);
return new Promise((resolve, reject) => {
archive
.directory(source, false)
.on('error', err => reject(err))
.pipe(stream);
stream.on('close', () => resolve());
archive.finalize();
});
}