Skip to content

Commit

Permalink
feat(commands/run): introduce --client-version and --client-port (ara…
Browse files Browse the repository at this point in the history
…gon#194)

* refactor: move aragon client version into package.json property

NPM's package files support custom properties for library specific usages.
This commit moves the aragon client version into a newly introduced
`aragon` properties section.

* refactor: rename WRAPPER_PATH, WRAPPER_PORT to CLIENT_PATH, CLIENT_PORT

* feat(commands/run): introduce --client-version and --client-port

This commit introduces a new option `--client-version` that can be used to
specify the Aragon client version to be used as discussed in aragon#182. A version
can be any commit-ish values (hashes, branches, tags).

Example:

```
$ aragon run --client-version=fa2025232330bc3e4d3b792cab4bf44d754d33e6
```
Or

```
$ aragon run --client-version=dev
```

It also offers a new option `--client-port` to configure the port on which
the client is being served from.

Notice that this option is being ignored at the moment, which will be addressed
in a future commit. For more info: aragon#198

Closes aragon#182
  • Loading branch information
0x-r4bbit authored and izqui committed Sep 13, 2018
1 parent b1ef6cc commit 2eaea12
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,9 @@
"require": [
"@babel/register"
]
},
"aragon": {
"clientVersion": "fcebf55d1af6c574a92587e2a1d3ac8c00804d16",
"clientPort": "3000"
}
}
45 changes: 29 additions & 16 deletions src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const os = require('os')
const fs = require('fs-extra')
const opn = require('opn')
const execa = require('execa')
const pkg = require('../../package.json')

const {
findProjectRoot,
Expand All @@ -32,9 +33,9 @@ const { Writable } = require('stream')
const url = require('url')

const TX_MIN_GAS = 10e6
const WRAPPER_PORT = 3000

const WRAPPER_COMMIT = 'fcebf55d1af6c574a92587e2a1d3ac8c00804d16'
const DEFAULT_CLIENT_VERSION = pkg.aragon.clientVersion;
const DEFAULT_CLIENT_PORT = pkg.aragon.clientPort

exports.command = 'run'

Expand Down Expand Up @@ -85,6 +86,12 @@ exports.builder = function (yargs) {
description: 'Arguments for calling the app init function',
array: true,
default: [],
}).option('client-version', {
description: 'Version of Aragon client used to run your sandboxed app',
default: DEFAULT_CLIENT_VERSION
}).option('client-port', {
description: 'Port being used by Aragon client',
default: DEFAULT_CLIENT_PORT
})
}

Expand Down Expand Up @@ -123,9 +130,16 @@ exports.handler = function ({
httpServedFrom,
appInit,
appInitArgs,
clientVersion,
clientPort
}) {

apmOptions.ensRegistryAddress = apmOptions['ens-registry']

clientPort = clientPort || DEFAULT_CLIENT_PORT

const showAccounts = accounts

const tasks = new TaskList([
{
title: 'Start a local Ethereum network',
Expand Down Expand Up @@ -231,26 +245,25 @@ exports.handler = function ({
{
title: 'Download wrapper',
task: (ctx, task) => {
const WRAPPER_PATH = `${os.homedir()}/.aragon/wrapper-${WRAPPER_COMMIT}`
ctx.wrapperPath = WRAPPER_PATH
clientVersion = clientVersion || DEFAULT_CLIENT_VERSION
const CLIENT_PATH = `${os.homedir()}/.aragon/wrapper-${clientVersion}`
ctx.wrapperPath = CLIENT_PATH

// Make sure we haven't already downloaded the wrapper
if (fs.existsSync(path.resolve(WRAPPER_PATH))) {
if (fs.existsSync(path.resolve(CLIENT_PATH))) {
task.skip('Wrapper already downloaded')
ctx.wrapperAvailable = true
return
}

// Ensure folder exists
fs.ensureDirSync(WRAPPER_PATH)
fs.ensureDirSync(CLIENT_PATH)

// Clone wrapper
return clone(
'https://github.com/aragon/aragon',
WRAPPER_PATH,
{ checkout: WRAPPER_COMMIT }
)
},
return clone('https://github.com/aragon/aragon', CLIENT_PATH, {
checkout: clientVersion
})
}
},
{
title: 'Install wrapper dependencies',
Expand All @@ -260,7 +273,7 @@ exports.handler = function ({
{
title: 'Start Aragon client',
task: async (ctx, task) => {
if (await isPortTaken(WRAPPER_PORT)) {
if (await isPortTaken(clientPort)) {
ctx.portOpen = true
return
}
Expand All @@ -281,9 +294,9 @@ exports.handler = function ({
// Check until the wrapper is served
const checkWrapperReady = () => {
setTimeout(async () => {
const portTaken = await isPortTaken(WRAPPER_PORT)
const portTaken = await isPortTaken(clientPort)
if (portTaken) {
opn(`http://localhost:${WRAPPER_PORT}/#/${ctx.daoAddress}`)
opn(`http://localhost:${clientPort}/#/${ctx.daoAddress}`)
} else {
checkWrapperReady()
}
Expand All @@ -305,7 +318,7 @@ exports.handler = function ({

return tasks.run({ ens: apmOptions['ens-registry'] }).then(async (ctx) => {
if (ctx.portOpen) {
reporter.warning(`Server already listening at port ${WRAPPER_PORT}, skipped starting Aragon`)
reporter.warning(`Server already listening at port ${clientPort}, skipped starting Aragon`)
}

if (ctx.notInitialized) {
Expand Down

0 comments on commit 2eaea12

Please sign in to comment.