forked from nidorx/matcaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
48 lines (42 loc) · 1.43 KB
/
release.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
const fs = require('fs');
const JSZip = require('jszip');
/**
* Padronizar a geração dos artefatos da release
*
* Cada diretório .zip
* Extrair os zmt de seus compactados e incluir no zmt.zip
*/
function todo() {
new Promise((resolve, reject) => {
let basename = path.basename(this.name, '.png');
const zippath = path.join('zip', basename + '.zip');
if (fs.existsSync(zippath)) {
return resolve();
}
var zip = new JSZip();
[
{folder: '64', ext: '.png'},
{folder: '128', ext: '.png'},
{folder: '256', ext: '.png'},
{folder: '512', ext: '.png'},
{folder: '1024', ext: '.png'},
{folder: 'palette', ext: '.png'},
{folder: 'preview', ext: '.jpg'},
{folder: 'zmt', ext: '.zmt'},
].forEach(item => {
let folder = item.folder;
let ext = item.ext;
let filename = basename + ext;
const filepath = path.join(folder, filename);
if (fs.existsSync(filepath)) {
var zfolder = zip.folder(folder);
zfolder.file(filename, fs.createReadStream(filepath));
}
});
// Save zip content
zip.generateNodeStream({type: 'nodebuffer', streamFiles: true})
.pipe(fs.createWriteStream(zippath))
.on('error', reject)
.on('finish', resolve);
});
}