-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
85 lines (73 loc) · 3.24 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
const shell = require('shelljs');
const moment = require('moment');
const path = require('path');
const console = require('console');
const os = require('os');
const fs = require('fs');
const buildTime = moment().format('HH:mm:ss DD/MM/YYYY');
const serverUrls = {
localnet: 'http://localhost:4096',
testnet: 'http://test.asch.io',
mainnet: 'http://mainnet.asch.io'
};
const build = (osVersion, netVersion) => {
// Check node.js version
// if (shell.exec('node -v | cut -b 2-3').stdout.trim() !== 10) {
// console.log('Exited. Please use node.js version 10');
// process.exit(1)
// }
// Install dependencies
shell.exec('sudo apt-get install curl sqlite3 ntp wget git libssl-dev openssl make gcc g++ autoconf automake python build-essential libtool libtool-bin -y');
const fullPath = path.join(__dirname, 'build');
shell.mkdir('-p', fullPath);
shell.cd(fullPath);
console.log('Packaging backend...')
const backendRepo = 'https://github.com/AschPlatform/asch.git';
shell.exec(`git clone --single-branch -b master ${backendRepo}`);
shell.cd('asch');
shell.pwd();
shell.mkdir('-p', 'public/dist', 'chains', 'tmp', 'logs', 'bin', 'data');
const version = JSON.parse(fs.readFileSync('./package.json', 'utf-8')).version;
if (netVersion !== 'localnet') {
shell.sed('-i', 'testnet', netVersion, `aschd`);
shell.sed('-i', 'testnet', netVersion, `app.js`);
shell.cp(`config-${netVersion}.json`, `config.json`);
}
if (osVersion === 'linux') {
shell.cp(shell.exec('which node'), `bin/`)
}
shell.sed('-i', 'DEFAULT_BUILD_TIME', buildTime, `app.js`);
shell.exec('npm install --production');
console.log('Packaging frontend...');
shell.cd(fullPath);
if (shell.exec('which yarn').code !== 0) {
console.log('yarn not found, installing')
shell.exec('npm install -g yarn')
}
const frontendRepo = 'https://github.com/AschPlatform/asch-frontend-2.git';
shell.exec(`git clone --single-branch -b develop ${frontendRepo}`);
shell.cd('asch-frontend-2');
shell.exec('yarn install');
shell.exec('node_modules/.bin/quasar build');
shell.exec('cp -r dist/spa-mat/* ../asch/public/dist');
shell.cd(fullPath);
shell.exec(`tar zcf asch-linux-latest-${netVersion}.tar.gz asch`);
shell.exec(`rm -rf asch`);
shell.exec('rm -rf asch-frontend-2');
// Generate metadata file
if (netVersion !== 'localnet') {
shell.exec(`touch metadata_upgrade_${netVersion}.txt`);
shell.exec(`echo asch-linux-latest-${netVersion}.tar.gz >> metadata_upgrade_${netVersion}.txt`);
shell.exec(`md5sum asch-linux-latest-${netVersion}.tar.gz | cut -d ' ' -f 1 >> metadata_upgrade_${netVersion}.txt`);
shell.exec(`echo ${buildTime} >> metadata_upgrade_${netVersion}.txt`);
shell.exec(`echo ${version} >> metadata_upgrade_${netVersion}.txt`);
shell.exec(`ls -l asch-linux-latest-${netVersion}.tar.gz | cut -d ' ' -f 5 >> metadata_upgrade_${netVersion}.txt`)
}
}
if (process.argv.length < 3) {
console.log('Usage: `node build.js all` or `node build.js os net`.\nSo far only host build, no cross building support yet. Net can be localnet, testnet or mainnet.')
} else if (process.argv[2] === 'all') {
['localnet', 'testnet', 'mainnet'].forEach(net => build(os.platform(), net))
} else {
build(process.argv[2], process.argv[3])
}