-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.js
More file actions
126 lines (101 loc) · 5.55 KB
/
build.js
File metadata and controls
126 lines (101 loc) · 5.55 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const fs = require('fs-extra');
const util = require('util');
const zipper = require('zip-local');
const node_rfc_build = require('./node-rfc/windows/build.js');
const NODE_RFC_BUILD = 'build/node-rfc';
const KRPA_RFC_BUILD = 'build/krpa-rfc';
const KRPA_RFC_BUILD_WINDOWS = KRPA_RFC_BUILD + '/windows';
const KRPA_RFC_BUILD_LINUX = KRPA_RFC_BUILD + '/linux';
const KRPA_RFC_BUILD_ALL = KRPA_RFC_BUILD + '/all';
const KRPA_RFC_DIST = 'dist';
const WINDOWS_BUILD = true;
const WINDOWS_BUILD_FROM_SOURCE = false;
const LINUX_BUILD = true;
// Uncomment this line if you want to use another version of node-rfc
//const NODE_RFC_VERSION = "1.0.6";
// Uncomment this line if you want to build the master branch of node-rfc
//const NODE_RFC_BRANCH = "master";
(async function(){
var krpaRfcVersion = require('./package.json').version;
var nodeRfcVersion = (typeof NODE_RFC_VERSION === 'undefined' || NODE_RFC_VERSION === null) ? krpaRfcVersion : NODE_RFC_VERSION;
var nodeRfcBranch = (typeof NODE_RFC_BRANCH === 'undefined' || NODE_RFC_BRANCH === null) ? "v" + nodeRfcVersion : NODE_RFC_BRANCH;
function npmInstall(directory, command) {
console.log ('npm install ' + command + '\n');
var cwd = process.cwd();
process.chdir(directory);
require('child_process').execSync('npm install ' + command + ' && npm prune --production', {stdio:[0,1,2]});
fs.unlinkSync('package-lock.json');
process.chdir(cwd);
}
console.log("Building connector version " + krpaRfcVersion + " using node-rfc version " + nodeRfcVersion + " (branch " + nodeRfcBranch +")\n");
// Clean the build directory
await fs.remove('build');
if (WINDOWS_BUILD) {
console.log("Building Windows release\n");
fs.mkdirSync(KRPA_RFC_BUILD_WINDOWS + '/node_modules', {recursive : true});
if (WINDOWS_BUILD_FROM_SOURCE) {
// Build the win32 ia32 node-rfc module from source using Docker Windows
console.log("Build the node-rfc module from source");
fs.mkdirSync(NODE_RFC_BUILD, {recursive : true});
await node_rfc_build.run(nodeRfcBranch, NODE_RFC_BUILD);
// Install node-rfc package dependencies + deasync module
console.log("Install node-rfc package dependencies + deasync module\n");
npmInstall(KRPA_RFC_BUILD_WINDOWS, '--ignore-scripts --platform=win32 --arch=ia32 deasync "' + require('path').resolve(NODE_RFC_BUILD + '/node-rfc-'+ nodeRfcBranch +'.tgz') + '"');
}
else {
// Install node-rfc + deasync modules
console.log("Install node-rfc + deasync modules\n");
npmInstall(KRPA_RFC_BUILD_WINDOWS, '--platform=win32 --arch=ia32 deasync node-rfc@' + nodeRfcVersion);
}
console.log("Copy connector manifest and source file\n");
fs.copyFileSync('src/manifest.json', KRPA_RFC_BUILD_WINDOWS + '/manifest.json');
fs.copyFileSync('src/krpa-rfc.js', KRPA_RFC_BUILD_WINDOWS + '/node_modules/krpa-rfc.js');
console.log("Create connector archive\n");
fs.mkdirSync(KRPA_RFC_DIST, {recursive : true});
var connectorArchive = KRPA_RFC_DIST + '/krpa-rfc-windows-' + krpaRfcVersion.replace(/\./g, "_") + '.connector';
await fs.remove(connectorArchive);
zipper.sync.zip(KRPA_RFC_BUILD_WINDOWS).compress().save(connectorArchive);
}
if (LINUX_BUILD) {
console.log("Building Linux release\n");
// Install node-rfc + deasync modules
console.log("Install node-rfc + deasync modules\n");
fs.mkdirSync(KRPA_RFC_BUILD_LINUX + '/node_modules', {recursive : true});
npmInstall(KRPA_RFC_BUILD_LINUX, '--platform=linux --arch=x64 deasync node-rfc@' + nodeRfcVersion);
console.log("Copy connector manifest and source file\n");
fs.copyFileSync('src/manifest.json', KRPA_RFC_BUILD_LINUX + '/manifest.json');
fs.copyFileSync('src/krpa-rfc.js', KRPA_RFC_BUILD_LINUX + '/node_modules/krpa-rfc.js');
console.log("Create connector archive\n");
fs.mkdirSync(KRPA_RFC_DIST, {recursive : true});
var connectorArchive = KRPA_RFC_DIST + '/krpa-rfc-linux-' + krpaRfcVersion.replace(/\./g, "_") + '.connector';
await fs.remove(connectorArchive);
zipper.sync.zip(KRPA_RFC_BUILD_LINUX).compress().save(connectorArchive);
}
if ((WINDOWS_BUILD) && (LINUX_BUILD)) {
console.log("Building All release\n");
fs.mkdirSync(KRPA_RFC_BUILD_ALL + '/node_modules', {recursive : true});
// Install node-rfc + deasync modules
console.log("Install node-rfc + deasync modules for Linux\n");
npmInstall(KRPA_RFC_BUILD_ALL, '--platform=linux --arch=x64 deasync node-rfc-linux@npm:node-rfc@' + nodeRfcVersion);
if (WINDOWS_BUILD_FROM_SOURCE) {
// Install node-rfc package dependencies + deasync module
console.log("Install node-rfc package dependencies + deasync module for Windows\n");
npmInstall(KRPA_RFC_BUILD_ALL, '--ignore-scripts --platform=win32 --arch=ia32 deasync "node-rfc-win32@' + require('path').resolve(NODE_RFC_BUILD + '/node-rfc-'+ nodeRfcBranch +'.tgz') +'"');
}
else {
// Install node-rfc + deasync modules
console.log("Install node-rfc + deasync modules for Windows\n");
npmInstall(KRPA_RFC_BUILD_ALL, '--platform=win32 --arch=ia32 deasync node-rfc-win32@npm:node-rfc@' + nodeRfcVersion);
}
console.log("Copy connector manifest and source files\n");
fs.copyFileSync('src/manifest.json', KRPA_RFC_BUILD_ALL + '/manifest.json');
fs.copyFileSync('src/krpa-rfc.js', KRPA_RFC_BUILD_ALL + '/node_modules/krpa-rfc.js');
fs.copyFileSync('src/node-rfc.js', KRPA_RFC_BUILD_ALL + '/node_modules/node-rfc.js');
console.log("Create connector archive\n");
fs.mkdirSync(KRPA_RFC_DIST, {recursive : true});
var connectorArchive = KRPA_RFC_DIST + '/krpa-rfc-all-' + krpaRfcVersion.replace(/\./g, "_") + '.connector';
await fs.remove(connectorArchive);
zipper.sync.zip(KRPA_RFC_BUILD_ALL).compress().save(connectorArchive);
}
console.log("Build completed");
})();