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

Add husky for pre-commit: lint-stage & pre-push: test #279

Merged
merged 9 commits into from
Dec 4, 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
20 changes: 20 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"es6": true,
"node": true
},
"extends": [
"standard",
"plugin:prettier/recommended",
"plugin:ava/recommended"
],
"parser": "babel-eslint",
"rules": {
"valid-jsdoc": "error",
"no-console": "off",
"linebreak-style": [
"error",
"unix"
]
}
}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"semi": false,
"trailingComma": "es5",
"bracketSpacing": true
}
2,847 changes: 1,850 additions & 997 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 29 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "npm run extract-roles && babel -d dist src --copy-files",
"prepare": "npm run build",
"test": "ava",
"lint": "standard && documentation lint src test",
"lint": "eslint src test && documentation lint src test",
"extract-roles": "scripts/extract-roles"
},
"repository": {
Expand Down Expand Up @@ -61,9 +61,9 @@
"js-sha3": "^0.7.0",
"listr": "^0.13.0",
"listr-input": "0.1.3",
"listr-verbose-renderer": "^0.4.1",
"listr-silent-renderer": "^1.1.1",
"listr-update-renderer": "^0.4.0",
"listr-verbose-renderer": "^0.4.1",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"opn": "^5.3.0",
Expand All @@ -90,7 +90,18 @@
"babel-eslint": "^10.0.1",
"coveralls": "^3.0.0",
"documentation": "^9.0.0-alpha.0",
"standard": "^10.0.3"
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-ava": "^5.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^1.2.0",
"lint-staged": "^8.1.0",
"prettier": "^1.15.3"
},
"engines": {
"node": ">=8.0.0"
Expand All @@ -104,12 +115,6 @@
"test/**/*.js"
]
},
"standard": {
"parser": "babel-eslint",
"ignore": [
"dist"
]
},
"aragon": {
"clientVersion": "2d79d2b9373d8b89bb28a7ecd613fb6373ac2d43",
"clientPort": "3000",
Expand All @@ -121,5 +126,20 @@
"dot-notation": true,
"parse-numbers": false,
"boolean-negation": true
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run lint && npm run test"
}
},
"lint-staged": {
"linters": {
"*.js": [
"eslint --fix",
"documentation lint",
"git add"
]
}
}
}
28 changes: 20 additions & 8 deletions src/acl/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
const DEFAULT_GAS_PRICE = require('../../package.json').aragon.defaultGasPrice

module.exports = ({ web3, network }) => {
const getACL = async (repoAddr) => {
const repo = new web3.eth.Contract(require('@aragon/os/build/contracts/AragonApp').abi, repoAddr)
const getACL = async repoAddr => {
const repo = new web3.eth.Contract(
require('@aragon/os/build/contracts/AragonApp').abi,
repoAddr
)
const daoAddr = await repo.methods.kernel().call()
const dao = new web3.eth.Contract(require('@aragon/os/build/contracts/Kernel').abi, daoAddr)
const dao = new web3.eth.Contract(
require('@aragon/os/build/contracts/Kernel').abi,
daoAddr
)
const aclAddr = await dao.methods.acl().call()

return new web3.eth.Contract(require('@aragon/os/build/contracts/ACL').abi, aclAddr)
return new web3.eth.Contract(
require('@aragon/os/build/contracts/ACL').abi,
aclAddr
)
}

const getRoleId = async (repoAddr) => {
const repo = new web3.eth.Contract(require('@aragon/os/build/contracts/Repo').abi, repoAddr)
const getRoleId = async repoAddr => {
const repo = new web3.eth.Contract(
require('@aragon/os/build/contracts/Repo').abi,
repoAddr
)
return repo.methods.CREATE_VERSION_ROLE().call()
}

Expand All @@ -26,8 +38,8 @@ module.exports = ({ web3, network }) => {
to: acl.options.address,
data: call.encodeABI(),
gas: web3.utils.toHex(5e5),
gasPrice: network.gasPrice || DEFAULT_GAS_PRICE
gasPrice: network.gasPrice || DEFAULT_GAS_PRICE,
}
}
},
}
}
79 changes: 44 additions & 35 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/usr/bin/env node
require('@babel/polyfill')
const { environmentMiddleware, manifestMiddleware, moduleMiddleware } = require('./middleware')
const {
environmentMiddleware,
manifestMiddleware,
moduleMiddleware,
} = require('./middleware')
const { findProjectRoot } = require('./util')
const ConsoleReporter = require('./reporters/ConsoleReporter')
const url = require('url')

const MIDDLEWARES = [
manifestMiddleware,
moduleMiddleware,
environmentMiddleware
environmentMiddleware,
]

// Set up commands
const cmd = require('yargs')
.commandDir('./commands', {
visit: (cmd) => {
// Add middlewares
cmd.middlewares = MIDDLEWARES
return cmd
}
}) // .strict()
const cmd = require('yargs').commandDir('./commands', {
visit: cmd => {
// Add middlewares
cmd.middlewares = MIDDLEWARES
return cmd
},
}) // .strict()

cmd.alias('h', 'help')
cmd.alias('v', 'version')
Expand All @@ -30,18 +33,18 @@ cmd.demandCommand(1, 'You need to specify a command')
// Set global options
cmd.option('silent', {
description: 'Silence output to terminal',
default: false
default: false,
})

cmd.option('debug', {
description: 'Show more output to terminal',
default: false,
coerce: (debug) => {
coerce: debug => {
if (debug || process.env.DEBUG) {
global.DEBUG_MODE = true
return true
}
}
},
})

cmd.option('cwd', {
Expand All @@ -52,63 +55,67 @@ cmd.option('cwd', {
} catch (_) {
return process.cwd()
}
}
},
})

cmd.option('use-frame', {
description: 'Use frame as a signing provider and web3 provider',
boolean: true,
default: false
default: false,
})

// network coerce is called multiple times, only warn once
let warnedDeprecatedNetwork = false

// Ethereum
cmd.option('network', {
description: '(deprecated) The network in your truffle.js that you want to use. Deprecated in favor of `--environment`',
coerce: (network) => {
description:
'(deprecated) The network in your truffle.js that you want to use. Deprecated in favor of `--environment`',
coerce: network => {
if (warnedDeprecatedNetwork) {
return network
}
warnedDeprecatedNetwork = true
reporter.info('Use of `--network` is deprecated and has been replaced with `--environment`. You may need to update your arapp.json')
}
reporter.info(
'Use of `--network` is deprecated and has been replaced with `--environment`. You may need to update your arapp.json'
)
},
})

cmd.option('environment', {
description: 'The environment in your arapp.json that you want to use'
description: 'The environment in your arapp.json that you want to use',
// default: 'default'
})

// APM
cmd.option('apm.ens-registry', {
description: 'Address of the ENS registry. This will be overwritten if the selected \'--environment\' from your arapp.json includes a `registry` property',
default: require('@aragon/aragen').ens
description:
"Address of the ENS registry. This will be overwritten if the selected '--environment' from your arapp.json includes a `registry` property",
default: require('@aragon/aragen').ens,
})
cmd.group(['apm.ens-registry', 'eth-rpc'], 'APM:')

cmd.option('apm.ipfs.rpc', {
description: 'An URI to the IPFS node used to publish files',
default: 'http://localhost:5001#default'
default: 'http://localhost:5001#default',
})
cmd.group('apm.ipfs.rpc', 'APM providers:')

cmd.option('apm', {
coerce: (apm) => {
coerce: apm => {
if (apm.ipfs && apm.ipfs.rpc) {
const uri = url.parse(apm.ipfs.rpc)
const uri = new url.URL(apm.ipfs.rpc)
apm.ipfs.rpc = {
protocol: uri.protocol.replace(':', ''),
host: uri.hostname,
port: parseInt(uri.port)
port: parseInt(uri.port),
}
if (uri.hash === '#default') {
apm.ipfs.rpc.default = true
}
}
return apm
}
},
})

// Add epilogue
Expand All @@ -117,11 +124,13 @@ cmd.epilogue('For more information, check out https://hack.aragon.one')
// Run
const reporter = new ConsoleReporter()
reporter.debug(JSON.stringify(process.argv))
cmd.fail((msg, err, yargs) => {
if (!err) yargs.showHelp()
reporter.error(msg || err.message || 'An error occurred')
reporter.debug(err && err.stack)
process.exit(1)
}).parse(process.argv.slice(2), {
reporter
})
cmd
.fail((msg, err, yargs) => {
if (!err) yargs.showHelp()
reporter.error(msg || err.message || 'An error occurred')
reporter.debug(err && err.stack)
process.exit(1)
})
.parse(process.argv.slice(2), {
reporter,
})
10 changes: 5 additions & 5 deletions src/commands/apm.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const {
manifestMiddleware,
moduleMiddleware,
environmentMiddleware
environmentMiddleware,
} = require('../middleware')

const MIDDLEWARES = [
manifestMiddleware,
moduleMiddleware,
environmentMiddleware
environmentMiddleware,
]

exports.command = 'apm <command>'
Expand All @@ -16,13 +16,13 @@ exports.describe = 'Publish and manage your APM package'

exports.aliases = ['package']

exports.builder = function (yargs) {
exports.builder = function(yargs) {
const cmd = yargs.commandDir('apm_cmds', {
visit: (cmd) => {
visit: cmd => {
// Add middlewares
cmd.middlewares = MIDDLEWARES
return cmd
}
},
})
cmd.demandCommand(1, 'You need to specify a command')

Expand Down
Loading