forked from aspectron/kdx
-
Notifications
You must be signed in to change notification settings - Fork 7
/
.emanate
171 lines (142 loc) · 5.3 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
"use strict";
const KARLSEN_DEFAULT_BRANCH = 'master';
const E = new Emanator(__dirname, {
type : argv.includes('build') || flags.innosetup ? 'NODE+NWJS' : 'UTIL',
guid : '8d51c029-f5dc-44d8-b453-f93629fee7b7',
group : 'Karlsen',
ident : 'karlsen-desktop',
suffix : flags.full ? '-dev' : '',
title : 'Karlsen Desktop',
banner : 'Karlsen Desktop',
git : 'https://github.com/karlsen-network/karlsen-desktop',
author : "Karlsen Developers",
url : "https://karlsencoin.com",
// archive : true,
folder : true,
standalone : true,
production: true,
// DMG: true,
nwjs : { version : '0.78.1' },
resources : 'resources/setup',
manifest : (manifest) => {
if(E.flags['with-perfmon'] && !E.flags['no-perfmon']) {
if(E.PLATFORM != 'macos') {
Object.assign(manifest.dependencies,{
"@karlsen/process-list": "*",
})
}
}
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.21.6');
const git = await E.modules.git();
const gcc = await E.modules.gcc();
const npm = await E.modules.npm({ production : true });
const karlsend = E.task('karlsend', ['origin'], async () => {
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/karlsen-network/');
if((E.flags.reset || E.flags.clean) && fs.existsSync(dest))
await E.emptyDir(dest);
const branch = E.flags['branch'] || KARLSEN_DEFAULT_BRANCH || 'master';
console.log('branch:',branch);
const repos = [`karlsend:${branch}`];
console.log("REPOS:".brightMagenta,repos);
for(const repo of repos) {
let [name, git_branch] = repo.split(':');
console.log(`git clone https://github.com/karlsen-network/${name} branch: ${git_branch || 'master'}`.brightYellow);
await git.clone(`https://github.com/karlsen-network/${name}`,dest, {branch : git_branch || 'master'});
}
let targets = [
'karlsend',
...fs.readdirSync(path.join(dest,'karlsend/cmd')).filter(f => f !== 'karlsenminer').map(f => `karlsend/cmd/${f}`),
];
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.task('remote', ['origin'], async () => {
let files = (E.manifest.files||[]).map(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`);
})
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',`karlsen-desktop:latest`,'.');
const ts0 = Date.now();
await E.utils.spawn('sudo', args, { cwd : __dirname, stdio: 'inherit' });
await E.utils.spawn('sudo',['docker','tag','karlsen-desktop:latest',`karlsen-desktop:${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.i18n){
E.task('i18n', null, async () => {
E.utils.sortAndSaveI18nFiles();
E.utils.mergeI18nEntries2Data();
})
}
if(E.flags['local-binaries'] || E.flags['karlsen']) {
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.i18n) {
E.runTask('i18n');
}else if(E.flags['karlsen']) {
await karlsend();
}
else if(E.flags['local-binaries']) {
E.runTask('karlsend');
E.runTask('aptitude');
}
else
E.run();