Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make build.js working on macOS and a little easier to use #266

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -26,16 +32,36 @@ 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`)

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`)
}

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])
}