forked from aspectron/kdx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.emanate
249 lines (203 loc) · 8.28 KB
/
.emanate
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
"use strict";
//const KASPA_DEFAULT_BRANCH = 'v0.11.7-dev'; //'master';
const KASPA_DEFAULT_BRANCH = 'master';
const E = new Emanator(__dirname, {
type : argv.includes('build') || flags.innosetup ? 'NODE+NWJS' : 'UTIL',
guid : 'c1072045-6d98-44d8-9aa5-e9be6c79bd01',
group : 'Kaspa',
ident : 'kdx',
suffix : flags.full ? '-dev' : '',
title : 'KDX',
banner : 'KDX',
git : '[email protected]:aspectron/kdx',
author : "ASPECTRON Inc.",
url : "http://aspectron.com",
//archive : true,
folder : true,
standalone : true,
production: true,
//DMG: true,
nwjs : { version : '0.55.0' },
resources : 'resources/setup',
manifest : (manifest) => {
if(E.flags['with-perfmon'] && !E.flags['no-perfmon']) {
if(E.PLATFORM != 'darwin') {
Object.assign(manifest.dependencies,{
"@aspectron/process-list": "*",
})
}
}
// if(E.PLATFORM == 'darwin')
// manifest.files.push('apps');
return manifest;
},
})
E.flags['with-perfmon'] = true;
E.aux_dmg_files = async (root) => {
if(fs.existsSync(path.join(E.BUILD,'apps')))
await E.copy(path.join(E.BUILD,'apps'),path.join(root,'apps'));
// E.copy(process.argv[0], root);
}
const go = await E.modules.go('go1.16.0');
const git = await E.modules.git();
const gcc = await E.modules.gcc();
const npm = await E.modules.npm({ production : true });
if(E.flags.full || E.flags.all) {
E.flags['with-dagviz'] = true;
E.flags['with-kmetrics'] = true;
E.flags['with-perfmon'] = true;
E.flags['with-extras'] = true;
}
E.flags['with-dagviz'] && E.task('dagviz', ['remote'], async () => {
const dest = path.join(E.BUILD,'apps');
mkdirp.sync(dest);
const dagvizFolder = path.join(dest,'dagviz');
await E.remove(dagvizFolder);
await git.clone('[email protected]:kaspanet/dagviz', dest, { branch : E.flags['dagviz-branch'] || 'master' });
await E.remove(path.join(dagvizFolder,'.git'));
await npm.install({ cwd : dagvizFolder});
//await E.spawn('emanate', ['--local-binaries'], { cwd : dagvizFolder, stdio: 'inherit' });
execSync('emanate --local-binaries', { cwd : dagvizFolder, stdio : 'inherit' });
await E.copy(process.argv[0],path.join(dagvizFolder,path.basename(process.argv[0])));
//await E.spawn('emanate', ['--local-binaries'], { cwd : dagvizFolder, stdio: 'inherit' });
// sine dagviz carries a lot of modules already included with kdx
// scan for duplicates and remove them from dagviz as require() will
// scan parent folders (kdx) for node_module
// --- this doesn't work properly - breaks dependency resolution in the deployment
// let dagvizModules = fs.readdirSync(path.join(dagvizFolder,'node_modules'));
// let kdxModules = fs.readdirSync(path.join(E.BUILD,'node_modules'));
// let duplicates = dagvizModules.filter(f => kdxModules.includes(f) && !/^\.\.?$/.test(f));
// let jobs = duplicates.map(f => E.remove(path.join(dagvizFolder,'node_modules',f)));
// await Promise.all(jobs);
});
/*
E.flags['with-ksandbox'] && E.task('ksandbox', ['remote'], async () => {
const dest = path.join(E.BUILD,'apps')
mkdirp.sync(dest);
const ksandboxFolder = path.join(dest,'ksandbox');
return Promise.resolve();
});
*/
E.flags['with-kmetrics'] && E.task('kmetrics', ['remote'], async () => {
const dest = path.join(E.BUILD,'apps')
mkdirp.sync(dest);
const kmetricsFolder = path.join(dest,'kmetrics');
await E.remove(kmetricsFolder);
await git.clone('[email protected]:aspectron/kmetrics', dest, { branch : E.flags['kmetrics-branch'] || 'master' });
await E.remove(path.join(kmetricsFolder,'.git'));
return Promise.resolve();
});
const kaspad = E.task('kaspad', ['origin'], async () => {
//return true;
if(E.PLATFORM == 'windows') {
process.env.PATH = ['C:\\TDM-GCC-64\\bin', ...process.env.PATH.split(';')].join(';');
}
let dest = path.join(go.SRC,'github.com/kaspanet/');
if((E.flags.reset || E.flags.clean) && fs.existsSync(dest))
await E.emptyDir(dest);
const branch = E.flags['branch'] || KASPA_DEFAULT_BRANCH || 'master';
console.log('branch:',branch);
//const repos = { };
const repos = [`kaspad:${branch}`];
if(E.flags['with-extras']) {
repos.push(`txgen:${branch}`,`kasparov:${KASPA_DEFAULT_BRANCH}`);
}
else if(E.flags['with-kmetrics'] || E.flags['with-txgen']) {
repos.push(`txgen:${branch}`);
}
console.log("REPOS:".brightMagenta,repos);
for(const repo of repos) {
let [name, git_branch] = repo.split(':');
console.log(`git clone https://github.com/kaspanet/${name} branch: ${git_branch || 'master'}`.brightYellow);
await git.clone(`https://github.com/kaspanet/${name}`,dest, {branch : git_branch || 'master'});
}
let targets = [
'kaspad',
...fs.readdirSync(path.join(dest,'kaspad/cmd')).map(f => `kaspad/cmd/${f}`),
];
if(E.flags['with-extras'] || E.flags['with-txgen']) {
targets = [
...targets,
// 'miningsimulator',
'txgen',
];
}
let rename = {}
console.log('Starting target processing...')
let folders = []
for(let target of targets) {
let folder = path.join(dest,target);
console.log('builing',folder);
await go.build(folder);
console.log('done',folder);
folders.push(folder);
}
folders.forEach((folder) => {
let file = path.basename(folder);
let name = `${E.title} ${file}`;
let dest = rename[file] || file;
file += E.PLATFORM_BINARY_EXTENSION;
dest += E.PLATFORM_BINARY_EXTENSION;
if(!fs.existsSync(path.join(folder,file))) {
console.log(`Unable to locate source file: ${path.join(folder,file)}`);
console.log(`...giving up`);
process.exit(1);
}
console.log("E.copy:", path.join(folder,file)," -> ",path.join(E.BIN,dest))
E.copy(path.join(folder,file),path.join(E.BIN,dest));
E.registerFirewallRule({ name, file : dest, binary : true });
})
//E.copy(path.join(dest,'kasparov','database','migrations'),path.join(E.BIN,'database','migrations'));
});
E.task('remote', ['origin'], async () => {
let files = (E.manifest.files||[]).map(f=>{
// console.log(E.REPO,'->',E.BUILD, f);
return E.copy(path.join(E.REPO,f), path.join(E.BUILD, f));
})
E.log(`copying ${files.length} items...`);
await Promise.all(files);
fs.writeFileSync(path.join(E.BUILD,'i18n.lock'),'');
console.log(`i18n.lock`);
})
const aux_deps = E.flags.auxiliary ? ['kaspad','remote'] : ['kaspad']
E.task('done', aux_deps, async () => {
})
E.task('aptitude', null, async () => {
if(E.PLATFORM != 'linux')
return;
})
E.flags.docker && E.task('docker', null, async () => {
E.manifest_read();
const relay = ['no-cache'];
const args = ['-s','docker','build'].concat(relay.map(k=>E.flags[k]?`--${k}`:null)).filter(v=>v);
args.push('-t',`kdx:latest`,'.');
const ts0 = Date.now();
await E.utils.spawn('sudo', args, { cwd : __dirname, stdio: 'inherit' });
await E.utils.spawn('sudo',['docker','tag','kdx:latest',`kdx:${E.manifest.version}`], { cwd : __dirname, stdio: 'inherit' });
console.log('Docker build complete at',new Date());
const ts1 = Date.now();
console.log('Docker build took'.brightBlue,`${((ts1-ts0)/1000/60).toFixed(1)}`.brightWhite,'minutes'.brightBlue)
});
if(E.flags['local-binaries'] || E.flags['kaspa']) {
E.BIN = path.join(E.appFolder,'bin', E.PLATFORM_ARCH);
mkdirp.sync(E.BIN);
}
if(E.flags.link) {
let list = ['flow-ux','flow-app','flow-utils','flow-rpc','flow-async'];
while(list.length) {
let ident = list.shift();
await npm.link(`@aspectron/${ident}`, { cwd : __dirname, stdio : 'inherit' });
}
}
else
if(E.flags.docker) {
E.runTask('docker');
}
else if(E.flags['kaspa'])
await kaspad();
else if(E.flags['local-binaries']) {
E.runTask('kaspad');
E.runTask('aptitude');
}
else
E.run();