-
Notifications
You must be signed in to change notification settings - Fork 16
/
makezip.js
executable file
·63 lines (54 loc) · 1.5 KB
/
makezip.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
#!/usr/bin/env node
const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const spawn = require('child_process').spawnSync;
const copy = require('recursive-copy');
const rimraf = require('rimraf');
const which = require('which');
const pkginfo = require('./package.json');
const plugininfo = require('./src/plugin.json');
try {
which.sync('zip');
} catch (err) {
console.log('zip executable not found');
process.exit(1);
}
const topdir = process.cwd();
const version = pkginfo.version;
const pkgname = pkginfo.name;
const pkgid = plugininfo.id;
const srcdir = path.join(topdir, 'dist');
const tmpdir = path.join(topdir, 'tmp');
const workdir = path.join(tmpdir, pkgid);
const packagedir = path.join(topdir, 'artifacts');
const zipfile = path.join(packagedir, `${pkgname}-${version}.zip`);
rimraf.sync(workdir);
rimraf.sync(zipfile);
fs.mkdirsSync(workdir);
fs.mkdirsSync(packagedir);
return copy(path.join(srcdir), workdir, {
dot: true,
filter: [
'**/*',
'!packages',
'!packages/*',
],
junk: false,
}).then((results) => {
console.info(results.length + ' files copied to ' + workdir);
console.info('* running zip');
const ret = spawn('zip', ['-r', zipfile, pkgid], { // NOSONAR
cwd: path.join(tmpdir),
stdio: ['inherit', 'inherit', 'inherit'],
});
if (ret.error) {
console.log('zip failed');
process.exit(1);
}
rimraf.sync(workdir);
process.exit(0);
}).catch((error) => {
console.log('Copy failed: ' + error);
process.exit(1);
});