-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.js
86 lines (68 loc) · 1.82 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
#!/usr/bin/env node
'use strict';
const path = require('path');
const fs = require('fs');
const pkg = require('pkg');
const archiver = require('archiver');
const config = require('./package.json');
// Build Paths
const configPath = path.dirname(require.resolve('./package.json'));
const binPath = path.normalize(configPath + '/' + config.pkg.out);
clean();
build()
.then(pack);
/**
* Clean the Bin Directory
*/
function clean() {
console.log();
console.log("CLEANING...");
let files = fs.readdirSync(binPath);
for ( let file of files ) {
fs.unlinkSync(path.normalize(binPath + '/' + file));
}
}
/**
* Build Binaries using PKG
* @returns Promise
*/
function build() {
console.log();
console.log("BUILDING...");
return pkg.exec(['./package.json', '--targets', config.pkg.targets, '--out-dir', binPath]);
}
/**
* Pack the Binaries into separate zip files
*/
function pack() {
console.log();
console.log("PACKAGING...");
let bins = fs.readdirSync(binPath);
for ( let bin of bins ) {
if ( bin.includes('rtm-cli-') ) {
let parts = bin.split('-');
let os = parts[2];
let arch = parts[3];
let name = 'rtm';
let version = config.version;
let zipName = name + '-' + os + '.' + arch + '-' + version + '.zip';
let zipFile = path.normalize(binPath + '/' + zipName);
let binFile = path.normalize(binPath + '/' + bin);
let zip = fs.createWriteStream(zipFile);
let archive = archiver('zip', {zib: {level: 9}});
zip.on('close', function() {
fs.unlinkSync(binFile);
console.log("..." + bin);
});
zip.on('error', function(err) {
throw err;
});
if ( os === 'win' ) {
name = name + '.exe';
}
archive.pipe(zip);
archive.file(binFile, {name: name});
archive.finalize();
}
}
}