From fd526a59a0382cc7a834c545e208e13d372e33f5 Mon Sep 17 00:00:00 2001 From: Wu Yang Date: Sat, 15 Sep 2018 20:47:15 +0800 Subject: [PATCH 1/2] make build.js working on macOS and a little easier to use --- build.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/build.js b/build.js index 602349b..b524556 100644 --- a/build.js +++ b/build.js @@ -4,10 +4,16 @@ const shell = require('shelljs') const moment = require('moment') const path = require('path') const pkg = require('./package') +const console = require('console') +const os = require('os') const buildTime = moment().format('HH:mm:ss DD/MM/YYYY') +const arch = os.platform() + function build(osVersion, netVersion) { + console.log(`Building ${netVersion}`) + const dir = `asch-${osVersion}-${pkg.version}-${netVersion}` const fullPath = path.join(__dirname, 'build', dir) shell.mkdir('-p', fullPath) @@ -26,16 +32,25 @@ function build(osVersion, netVersion) { shell.cp('genesisBlock.json', fullPath) - if (osVersion === 'linux') { + if (osVersion === 'linux' || osVersion === 'darwin') { shell.cp(shell.exec('which node'), `${fullPath}/bin/`) } shell.cp('-r', 'app.js', 'src', fullPath) - shell.exec(`find ${fullPath}/src -type f -print0 | xargs -0 sed -i 's/localnet/${netVersion}/g'`) + shell.exec(`find ${fullPath}/src -type f -print0 | xargs -0 sed -i '' 's/localnet/${netVersion}/g'`) shell.sed('-i', 'testnet', netVersion, `${fullPath}/app.js`) shell.sed('-i', 'DEFAULT_BUILD_TIME', buildTime, `${fullPath}/app.js`) shell.exec(`cd ${fullPath} && npm install --production`) + // TODO: checkout and build frontend from its git project, copy release files and cleanup. + shell.exec(`cd ${fullPath}/public/dist && wget -q https://downloads.asch.cn/package/frontend-mainnet-5f5b3cf5.zip && unzip -qq -o frontend-mainnet-5f5b3cf5.zip`) shell.exec(`cd ${fullPath}/.. && tar zcf ${dir}.tar.gz ${dir}`) + shell.exec(`ls -lh ${fullPath}.tar.gz`) } -build(process.argv[2], process.argv[3]) +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(arch, net)) +} else { + build(process.argv[2], process.argv[3]) +} From a5953351bc3d22cde358be803766fa68f0ce17fc Mon Sep 17 00:00:00 2001 From: Wu Yang Date: Tue, 18 Sep 2018 16:57:56 +0800 Subject: [PATCH 2/2] install frontend from its source project --- build.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/build.js b/build.js index b524556..517eee3 100644 --- a/build.js +++ b/build.js @@ -41,8 +41,19 @@ function build(osVersion, netVersion) { shell.sed('-i', 'testnet', netVersion, `${fullPath}/app.js`) shell.sed('-i', 'DEFAULT_BUILD_TIME', buildTime, `${fullPath}/app.js`) shell.exec(`cd ${fullPath} && npm install --production`) - // TODO: checkout and build frontend from its git project, copy release files and cleanup. - shell.exec(`cd ${fullPath}/public/dist && wget -q https://downloads.asch.cn/package/frontend-mainnet-5f5b3cf5.zip && unzip -qq -o frontend-mainnet-5f5b3cf5.zip`) + + console.log('installing front-end') + const magic = shell.exec('grep magic config.json | awk \'{print $2}\' | sed -e \'s/[",]//g\'', { silent: true }).stdout.trim() + const branch = shell.exec('git branch | grep \\* | cut -d \' \' -f2', { silent: true }).stdout.trim() + // It is quite possible that last build stop before cleanup frontend files + if (shell.test('-e', `${fullPath}/tmp/asch-frontend-2`)) { + shell.rm('-rf', `${fullPath}/tmp/asch-frontend-2`, { silent: true }) + } + shell.exec(`cd ${fullPath}/tmp && pwd && git clone --single-branch -b ${branch} https://github.com/AschPlatform/asch-frontend-2.git \ + && cd asch-frontend-2 && yarn install && pwd && sed -i '' 's/5f5b3cf5/${magic}/g' src/utils/constants.js \ + && quasar build && cp -r dist/spa-mat/* ../../public/dist/ && rm -rf asch-frontend-2`, { silent: true }) + + // done, create tarball shell.exec(`cd ${fullPath}/.. && tar zcf ${dir}.tar.gz ${dir}`) shell.exec(`ls -lh ${fullPath}.tar.gz`) }