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

Clean up reporter #52

Merged
merged 3 commits into from
Apr 7, 2018
Merged
Show file tree
Hide file tree
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
547 changes: 523 additions & 24 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
"chalk": "^2.1.0",
"eth-ens-namehash": "^2.0.0",
"ethereum-ens": "https://github.com/Arachnid/ensjs.git",
"execa": "^0.10.0",
"figures": "^2.0.0",
"find-up": "^2.1.0",
"fs-extra": "^4.0.2",
"ganache-core": "~2.0.2",
"git-clone": "^0.1.0",
"homedir": "^0.6.0",
"ipfs-api": "^14.3.7",
"js-sha3": "^0.7.0",
"listr": "^0.13.0",
"multimatch": "^2.1.0",
"rimraf": "^2.6.2",
"semver": "^5.4.1",
Expand Down
35 changes: 12 additions & 23 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ const {
middlewaresDecorator
} = require('./decorators')
const {
reporterMiddleware,
manifestMiddleware,
moduleMiddleware
} = require('./middleware')
const {
findProjectRoot
} = require('./util')
const ConsoleReporter = require('./reporters/ConsoleReporter')

const MIDDLEWARES = [
reporterMiddleware,
manifestMiddleware,
moduleMiddleware
]
Expand All @@ -33,21 +32,6 @@ const cmd = require('yargs')
cmd
)

// Wrap command handler
const _handler = cmd.handler
cmd.handler = (argv) => {
// Handle errors
_handler(argv.reporter, argv)
.then((exitCode = 0) => {
process.exitCode = exitCode
})
.catch((err) => {
argv.reporter.error(err.message)
argv.reporter.debug(err.stack)
process.exitCode = 1
})
}

return cmd
}
})
Expand All @@ -71,7 +55,6 @@ cmd.option('cwd', {
}
})


// APM
cmd.option('apm.ens-registry', {
description: 'Address of the ENS registry',
Expand All @@ -92,24 +75,30 @@ cmd.group('apm.ipfs.rpc', 'APM providers:')
// Ethereum
cmd.option('eth-rpc', {
description: 'An URI to the Ethereum node used for RPC calls',
default: 'http://localhost:8545',
default: 'http://localhost:8545'
})

cmd.option('keyfile', {
description: 'Path to a local file containing a private key, rpc node and ENS. If provided it will overwrite eth-rpc (but not apm.ens-registry)',
default: require('homedir')()+'/.localkey.json',
default: require('homedir')() + '/.localkey.json',
coerce: (file) => {
try {
return require(require('path').resolve(file))
} catch (e) {
} catch (e) {
return {}
}
}
})


// Add epilogue
cmd.epilogue('For more information, check out https://wiki.aragon.one')

// Run
cmd.argv // eslint-disable-line
const reporter = new ConsoleReporter()
cmd.fail((msg, err, a) => {
reporter.error(err.message || msg || 'An error occurred')
reporter.debug(err.stack)
process.exit(1)
}).parse(process.argv.slice(2), {
reporter
})
9 changes: 4 additions & 5 deletions src/commands/grant.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const Web3 = require('web3')
const { MessageError } = require('../errors')
const EthereumTx = require('ethereumjs-tx')
const APM = require('../apm')
const ACL = require('../acl')
Expand All @@ -16,8 +15,9 @@ exports.builder = function (yargs) {
})
}

exports.handler = async function (reporter, {
exports.handler = async function ({
// Globals
reporter,
cwd,
ethRpc,
keyfile,
Expand All @@ -38,14 +38,13 @@ exports.handler = async function (reporter, {
const acl = ACL(web3)

if (!module || !Object.keys(module).length) {
throw new MessageError('This directory is not an Aragon project',
'ERR_NOT_A_PROJECT')
throw new Error('This directory is not an Aragon project')
}

const repo = await apm.getRepository(module.appName)
.catch(() => null)
if (repo === null) {
throw new MessageError(`Repository ${module.appName} does not exist and it's registry does not exist`)
throw new Error(`Repository ${module.appName} does not exist and it's registry does not exist`)
}

reporter.info(`Granting permission to publish on ${module.appName} for ${address}`)
Expand Down
7 changes: 3 additions & 4 deletions src/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { MessageError } = require('../errors')
const { promisify } = require('util')
const clone = promisify(require('git-clone'))

Expand Down Expand Up @@ -29,7 +28,7 @@ exports.builder = (yargs) => {

if (!tmpl.includes('/')) {
if (!aliases[tmpl]) {
throw new MessageError(`No template named ${tmpl} exists`)
throw new Error(`No template named ${tmpl} exists`)
}
tmpl = aliases[tmpl]
}
Expand All @@ -40,14 +39,14 @@ exports.builder = (yargs) => {
.check(function validateApplicationName ({ name }) {
const isValidAppName = name.split('.').length >= 2
if (!isValidAppName) {
throw new MessageError(`${name} is not a valid application name (should be e.g. "foo.aragonpm.eth")`, 'ERR_INVALID_APP_NAME')
throw new Error(`${name} is not a valid application name (should be e.g. "foo.aragonpm.eth")`)
}

return true
})
}

exports.handler = function (reporter, { name, template }) {
exports.handler = function ({ reporter, name, template }) {
// Clone the template into the directory
// TODO: Somehow write name to `manifest.json` in template?
// TODO: Write human-readable app name to `arapp.json`
Expand Down
13 changes: 6 additions & 7 deletions src/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ const tmp = require('tmp-promise')
const path = require('path')
const { promisify } = require('util')
const { copy, readJson, writeJson } = require('fs-extra')
const { MessageError } = require('../errors')
const extract = require('../helpers/solidity-extractor')
const APM = require('../apm')
const semver = require('semver')
const EthereumTx = require('ethereumjs-tx')
const namehash = require('eth-ens-namehash')
const multimatch = require('multimatch')
const { keccak256 } = require('js-sha3')
const { keccak256 } = require('js-sha3')

exports.command = 'publish [contract]'

Expand Down Expand Up @@ -127,7 +126,9 @@ async function prepareFilesForPublishing (files = [], ignorePatterns = null) {
return tmpDir
}

exports.handler = async function (reporter, {
exports.handler = async function ({
reporter,

// Globals
cwd,
ethRpc,
Expand All @@ -153,14 +154,12 @@ exports.handler = async function (reporter, {
const apm = await APM(web3, apmOptions)

if (!module || !Object.keys(module).length) {
throw new MessageError('This directory is not an Aragon project',
'ERR_NOT_A_PROJECT')
throw new Error('This directory is not an Aragon project')
}

// Validate version
if (!semver.valid(module.version)) {
throw new MessageError(`${module.version} is not a valid semantic version`,
'ERR_INVALID_VERSION')
throw new Error(`${module.version} is not a valid semantic version`)
}

if (!onlyArtifacts) {
Expand Down
6 changes: 2 additions & 4 deletions src/commands/version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('fs')
const findUp = require('find-up')
const semver = require('semver')
const { MessageError } = require('../errors')

exports.command = 'version <bump>'

Expand All @@ -13,11 +12,10 @@ exports.builder = function (yargs) {
})
}

exports.handler = async function (reporter, { bump, cwd }) {
exports.handler = async function ({ reporter, bump, cwd }) {
const manifestLocation = await findUp('arapp.json', { cwd })
if (!manifestLocation) {
throw new MessageError('This directory is not an Aragon project',
'ERR_NOT_A_PROJECT')
throw new Error('This directory is not an Aragon project')
}

let manifest = JSON.parse(fs.readFileSync(manifestLocation))
Expand Down
6 changes: 2 additions & 4 deletions src/commands/versions.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
const Web3 = require('web3')
const findUp = require('find-up')
const { MessageError } = require('../errors')
const apm = require('../apm')

exports.command = 'versions'

exports.describe = 'List all versions of the package'

exports.handler = async function (reporter, { module, bump, cwd, keyfile, ethRpc, apm: apmOptions }) {
exports.handler = async function ({ reporter, module, bump, cwd, keyfile, ethRpc, apm: apmOptions }) {
const web3 = new Web3(keyfile.rpc ? keyfile.rpc : ethRpc)

apmOptions.ensRegistry = !apmOptions.ensRegistry ? keyfile.ens : apmOptions.ensRegistry

const moduleLocation = await findUp('arapp.json', { cwd })
if (!moduleLocation) {
throw new MessageError('This directory is not an Aragon project',
'ERR_NOT_A_PROJECT')
throw new Error('This directory is not an Aragon project')
}

return apm(web3, apmOptions).getAllVersions(module.appName)
Expand Down
8 changes: 0 additions & 8 deletions src/errors.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const reporterMiddleware = require('./reporter')
const manifestMiddleware = require('./manifest')
const moduleMiddleware = require('./module')

module.exports = {
reporterMiddleware,
manifestMiddleware,
moduleMiddleware
}
9 changes: 0 additions & 9 deletions src/middleware/reporter.js

This file was deleted.

15 changes: 12 additions & 3 deletions src/reporters/ConsoleReporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const chalk = require('chalk')
const figures = require('figures')

module.exports = class ConsoleReporter {
constructor (opts = { silent: false }) {
Expand All @@ -8,14 +9,22 @@ module.exports = class ConsoleReporter {
message (category = 'info', message) {
if (this.silent) return

const colors = {
const color = {
debug: 'magenta',
info: 'blue',
warning: 'yellow',
error: 'red',
success: 'green'
}
console.log(`${chalk[colors[category]](category)}: ${message}`)
}[category]
const symbol = {
debug: figures.pointer,
info: figures.info,
warning: figures.warning,
error: figures.cross,
success: figures.tick
}[category]
const icon = chalk[color](symbol)
console.log(` ${icon} ${message}`)
}

debug (message) {
Expand Down