From 2eaea120f83d7e98ceb11bd176034d5ca4aa9ce8 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Thu, 13 Sep 2018 14:43:07 +0200 Subject: [PATCH] feat(commands/run): introduce --client-version and --client-port (#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 #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: https://github.com/aragon/aragon-cli/issues/198 Closes #182 --- package.json | 4 ++++ src/commands/run.js | 45 +++++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index e3942ee0b..cc092bc31 100644 --- a/package.json +++ b/package.json @@ -90,5 +90,9 @@ "require": [ "@babel/register" ] + }, + "aragon": { + "clientVersion": "fcebf55d1af6c574a92587e2a1d3ac8c00804d16", + "clientPort": "3000" } } diff --git a/src/commands/run.js b/src/commands/run.js index 9b1542f80..d4728e9f6 100644 --- a/src/commands/run.js +++ b/src/commands/run.js @@ -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, @@ -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' @@ -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 }) } @@ -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', @@ -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', @@ -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 } @@ -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() } @@ -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) {