Skip to content

Commit

Permalink
Merge pull request #150 from cosmos/fabo/136-build-works
Browse files Browse the repository at this point in the history
Fabo/136 build works
  • Loading branch information
faboweb authored Dec 4, 2017
2 parents a4928a3 + 1ade020 commit 585eac8
Show file tree
Hide file tree
Showing 10 changed files with 562 additions and 30 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ npm run pack && npm run build:darwin
open builds/cosmos-ui-darwin-x64/cosmos-ui.app
```

When you are testing the build system you can skip the repackaging of the JS files with:
```bash
$ npm run build -- --skip-pack
```

## Testing

To test you need to first package the web content of the app, as this content can only be used bundled by the electron instance.
Expand All @@ -82,6 +87,14 @@ i.e.:
```bash
$ npm i -g http-server
$ http-server test/unit/coverage/lcov-report
```

To test the running application e2e:

```bash
$ npm run pack
$ npm run test:e2e
```

## Debug

Expand All @@ -98,6 +111,24 @@ To debug the electron view, set the environment variable `COSMOS_DEVTOOLS` to so

To see the console output of the view in your terminal, set the environment variable `ELECTRON_ENABLE_LOGGING` to something truthy like `1`.

## Flags

A list of all environment variables and their purpose:

|Variable|Values|default|Purpose|
|--|--|--|--|
|NODE_ENV|'production', 'development'|||
|LOGGING|'true', 'false'|'true'|Disable logging|
|MOCK|'true', 'false'|'true' in development|Mock data to receive from the chain|
|COSMOS_TEST|'true', 'false'|'false'|Disable code that influences unit tests, like logging to files|
|COSMOS_NETWORK|{path to network configuration folder}|'../networks/gaia-1'|Network to connect to|
|COSMOS_UI_ONLY|'true', 'false'|'false'|Ignore spinning up the tendermint binaries|
|COSMOS_HOME|{path to config persistence folder}|'$HOME/cosmos-ui[-dev]'||
|PLATFORM_TARGET|'all', 'win32', 'darwin', 'linux', 'mas'|'all'|Which platform to build for|
|COSMOS_DEVTOOLS|'true', 'false'|'false'|Open the debug panel in the electron view|
|ELECTRON_ENABLE_LOGGING|'true', 'false'|'false'|Redirect the browser view console output to the console|


## FAQ

- If tendermint crashes and the log shows "Tendermint state.AppHash does not match AppHash after replay." delete the config folders at $HOME/.cosmos-ui[-dev].
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = async function (nodeIP) {
const RestClient = require('cosmos-sdk')
const RpcClient = require('tendermint')

let rest = RestClient(MOCK ? 'http://localhost:8999' : null)
let rest = RestClient(MOCK ? 'http://localhost:8999' : undefined)
let rpc = RpcClient(`ws://${nodeIP}`)
// TODO: handle disconnect, try to reconnect
// TODO: eventually, get all data from light-client connection instead of RPC
Expand Down
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ let config = {
ignore: /^\/(src|index\.ejs|icons)/,
out: path.join(__dirname, 'builds'),
overwrite: true,
platform: process.env.PLATFORM_TARGET || 'all'
platform: process.env.PLATFORM_TARGET || 'darwin,linux',
packageManager: 'yarn'
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter app test",
"lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix app test",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config webpack.renderer.config.js",
"pack:main": "cross-env NODE_ENV=production webpack --colors --config webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --colors --config webpack.renderer.config.js",
"test": "npm run test:unit",
"test:unit": "cross-env LOGGING=false MOCK=false jest",
"test:e2e": "tape \"test/e2e/!(main)*.js\"",
Expand Down Expand Up @@ -53,7 +53,7 @@
"electron-debug": "^1.4.0",
"electron-devtools-installer": "^2.1.0",
"electron-installer-dmg": "^0.2.1",
"electron-packager": "^8.5.0",
"electron-packager": "^10.1.0",
"electron-rebuild": "^1.5.7",
"eslint": "^3.13.1",
"eslint-config-standard": "^6.2.1",
Expand Down
50 changes: 47 additions & 3 deletions tasks/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@
const { exec } = require('child_process')
const path = require('path')
const packager = require('electron-packager')
const rebuild = require('electron-rebuild').default
const mkdirp = require('mkdirp').sync
const fs = require('fs-extra')

let skipPack = false
let binaryPath = null
process.argv.forEach(function (val) {
if (val === '--skip-pack') {
skipPack = true
}
if (val.startsWith('--binary')) {
binaryPath = val.replace('--binary=', '')
}
})

if (process.env.PLATFORM_TARGET === 'clean') {
require('del').sync(['builds/*', '!.gitkeep'])
console.log('\x1b[33m`builds` directory cleaned.\n\x1b[0m')
} else {
pack()
if (skipPack) {
build()
} else {
pack()
}
}

/**
Expand All @@ -21,7 +38,11 @@ function pack () {

pack.stdout.on('data', data => console.log(data))
pack.stderr.on('data', data => console.error(data))
pack.on('exit', code => build())
pack.on('exit', code => {
if (code === null || code <= 0) {
build()
}
})
}

/**
Expand All @@ -31,7 +52,18 @@ function build () {
let options = require('../config').building

options.afterCopy = [
goBuild(`github.com/cosmos/gaia/cmd/gaia`)
binaryPath
? copyBinary('gaia', binaryPath)
: goBuild(`github.com/cosmos/gaia/cmd/gaia`)
]
// prune installs the packages
options.afterPrune = [
// we need to rebuild some native packages for the electron environment
function rebuildNodeModules (buildPath, electronVersion, platform, arch, callback) {
rebuild({ buildPath, electronVersion, arch })
.then(callback)
.catch(callback)
}
]

console.log('\x1b[34mBuilding electron app(s)...\n\x1b[0m')
Expand All @@ -48,6 +80,17 @@ function build () {
})
}

function copyBinary (name, binaryLocation) {
return function (buildPath, electronVersion, platform, arch, cb) {
let binPath = path.join(buildPath, 'bin', name)
if (platform === 'win32') {
binPath = binPath + '.exe'
}
fs.copySync(binaryLocation, binPath)
cb()
}
}

const GOARCH = {
'x64': 'amd64',
'ia32': '386'
Expand All @@ -56,6 +99,7 @@ const GOARCH = {
function goBuild (pkg) {
return function (buildPath, electronVersion, platform, arch, cb) {
if (platform === 'win32') platform = 'windows'
if (platform === 'mas') platform = 'darwin'
if (GOARCH[arch]) arch = GOARCH[arch]

let name = path.basename(pkg)
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/gaia-1/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml

proxy_app = "tcp://127.0.0.1:46658"
moniker = "46.101.170.77"
fast_sync = true

db_backend = "leveldb"
log_level = "state:info,*:error"
#log_level = "*:debug"


[rpc]
laddr = "tcp://0.0.0.0:46657"


[consensus]
create_empty_blocks_interval = 60


[p2p]
laddr = "tcp://0.0.0.0:46656"
seeds = "159.203.14.24:46656,178.62.54.176:46656,138.197.10.42:46656,188.166.186.94:46656,165.227.28.93:46656,146.185.183.200:46656"
Loading

0 comments on commit 585eac8

Please sign in to comment.