Skip to content

Commit

Permalink
convert to prettier linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Aug 23, 2017
1 parent 8a55228 commit 489a791
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 657 deletions.
2 changes: 1 addition & 1 deletion lib/clean.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (Spike, args) {
module.exports = function(Spike, args) {
const project = new Spike({ root: args.path })
process.nextTick(() => project.clean())
return project
Expand Down
2 changes: 1 addition & 1 deletion lib/compile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (Spike, args) {
module.exports = function(Spike, args) {
const project = new Spike({ root: args.path, env: args.env })
process.nextTick(() => project.compile())
return project
Expand Down
49 changes: 31 additions & 18 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let Spike
* @extends EventEmitter
*/
module.exports = class CLI extends EventEmitter {
constructor () {
constructor() {
super()

this.parser = new ArgumentParser({
Expand All @@ -41,13 +41,22 @@ module.exports = class CLI extends EventEmitter {
* @param {Array|String} args - a string or array representing a command
* @return {CLI} returns itself, which is an event emitter
*/
run (args) {
if (typeof args === 'string') { args = args.split(' ') }
run(args) {
if (typeof args === 'string') {
args = args.split(' ')
}
args = this.parser.parseArgs(args)

// argparse uses `null` which doesn't get along with joi, so we remove
// null values here
args = reduce(args, (m, v, k) => { if (v) m[k] = v; return m }, {})
args = reduce(
args,
(m, v, k) => {
if (v) m[k] = v
return m
},
{}
)

// try to load up a local spike instance first
let spikePath = args.path && path.join(args.path, 'node_modules/spike-core')
Expand All @@ -57,7 +66,9 @@ module.exports = class CLI extends EventEmitter {
spikePath = 'spike-core'
}

if (!Spike) { Spike = require(spikePath) }
if (!Spike) {
Spike = require(spikePath)
}

// set up analytics
const uid = Spike.globalConfig().id // mocked in tests
Expand All @@ -80,7 +91,7 @@ module.exports = class CLI extends EventEmitter {
emitter.on('info', this.emit.bind(this, 'info'))

// instance-method-specific
emitter.on('compile', (res) => {
emitter.on('compile', res => {
analytics.event({ ec: 'core', ea: 'compile' }).send()
this.emit('compile', res)
})
Expand All @@ -89,7 +100,7 @@ module.exports = class CLI extends EventEmitter {
return this
}

addCompile () {
addCompile() {
const s = this.sub.addParser('compile', {
help: 'Compile a spike project'
})
Expand All @@ -101,15 +112,16 @@ module.exports = class CLI extends EventEmitter {
})

s.addArgument(['--env', '-e'], {
help: 'Name of the environment you\'d like to use'
help: "Name of the environment you'd like to use"
})

s.setDefaults({ fn: 'compile' })
}

addWatch () {
addWatch() {
const s = this.sub.addParser('watch', {
help: 'Watch a spike project and compile any time there are changes to a file'
help:
'Watch a spike project and compile any time there are changes to a file'
})

s.addArgument(['path'], {
Expand All @@ -124,13 +136,13 @@ module.exports = class CLI extends EventEmitter {
})

s.addArgument(['--env', '-e'], {
help: 'Name of the environment you\'d like to use'
help: "Name of the environment you'd like to use"
})

s.setDefaults({ fn: 'watch' })
}

addClean () {
addClean() {
const s = this.sub.addParser('clean', {
help: 'Removes the output directory of a spike project'
})
Expand All @@ -144,7 +156,7 @@ module.exports = class CLI extends EventEmitter {
s.setDefaults({ fn: 'clean' })
}

addNew () {
addNew() {
const s = this.sub.addParser('new', {
help: 'Creates a new spike project from a template'
})
Expand All @@ -159,13 +171,14 @@ module.exports = class CLI extends EventEmitter {

s.addArgument(['--overrides', '-o'], {
type: keyVal,
help: "Pass information directly to the template without answering questions. Accepts a quoted comma-separated key-value list, like 'a: b, c: d'"
help:
"Pass information directly to the template without answering questions. Accepts a quoted comma-separated key-value list, like 'a: b, c: d'"
})

s.setDefaults({ fn: 'new' })
}

addTemplate () {
addTemplate() {
const main = this.sub.addParser('template', {
aliases: ['tpl'],
help: 'Manage spike project templates'
Expand All @@ -185,7 +198,7 @@ module.exports = class CLI extends EventEmitter {
})

s.addArgument(['src'], {
help: 'Url that can be git-clone\'d to download the template'
help: "Url that can be git-clone'd to download the template"
})

s.setDefaults({ fn: 'template/add' })
Expand Down Expand Up @@ -238,9 +251,9 @@ module.exports = class CLI extends EventEmitter {
* @param {String} str - input string
* @return {Object} javascript object output
*/
function keyVal (str) {
function keyVal(str) {
return str.split(',').reduce((m, i) => {
const s = i.split(':').map((i) => i.trim())
const s = i.split(':').map(i => i.trim())
m[s[0]] = s[1]
return m
}, {})
Expand Down
25 changes: 15 additions & 10 deletions lib/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ const path = require('path')
const EventEmitter = require('events').EventEmitter
const inquirer = require('inquirer')

module.exports = function (Spike, args) {
module.exports = function(Spike, args) {
const emitter = new EventEmitter()

emitter.on('done', (project) => {
emitter.emit('success', `project created at ${path.resolve(project.config.context)}`)
emitter.on('done', project => {
emitter.emit(
'success',
`project created at ${path.resolve(project.config.context)}`
)
})

process.nextTick(() => Spike.new({
root: args.path,
emitter: emitter,
locals: args.overrides,
template: args.template,
inquirer: inquirer.prompt.bind(inquirer)
}))
process.nextTick(() =>
Spike.new({
root: args.path,
emitter: emitter,
locals: args.overrides,
template: args.template,
inquirer: inquirer.prompt.bind(inquirer)
})
)

return emitter
}
2 changes: 1 addition & 1 deletion lib/template/add.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const EventEmitter = require('events')

module.exports = function (Spike, args) {
module.exports = function(Spike, args) {
const emitter = new EventEmitter()
process.nextTick(() => {
Spike.template.add(Object.assign(args, { emitter: emitter }))
Expand Down
2 changes: 1 addition & 1 deletion lib/template/default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const EventEmitter = require('events')

module.exports = function (Spike, args) {
module.exports = function(Spike, args) {
const emitter = new EventEmitter()
process.nextTick(() => {
Spike.template.default(Object.assign(args, { emitter: emitter }))
Expand Down
2 changes: 1 addition & 1 deletion lib/template/remove.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const EventEmitter = require('events')

module.exports = function (Spike, args) {
module.exports = function(Spike, args) {
const emitter = new EventEmitter()
process.nextTick(() => {
Spike.template.remove(Object.assign(args, { emitter: emitter }))
Expand Down
2 changes: 1 addition & 1 deletion lib/template/reset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const EventEmitter = require('events')

module.exports = function (Spike, args) {
module.exports = function(Spike, args) {
const emitter = new EventEmitter()
process.nextTick(() => {
Spike.template.reset()
Expand Down
8 changes: 6 additions & 2 deletions lib/watch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = function (Spike, args) {
const project = new Spike({ root: args.path, env: args.env, server: { port: args.port } })
module.exports = function(Spike, args) {
const project = new Spike({
root: args.path,
env: args.env,
server: { port: args.port }
})
process.nextTick(() => project.watch())
return project
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"devDependencies": {
"ava": "^0.21.0",
"coveralls": "^2.13.1",
"husky": "^0.14.3",
"nyc": "^11.0.3",
"rewire": "^2.5.1",
"snazzy": "^7.0.0",
"standard": "^10.0.2"
"prettier": "^1.5.3",
"rewire": "^2.5.1"
},
"engines": {
"node": ">=6.0.0",
Expand All @@ -43,9 +43,8 @@
"scripts": {
"coverage": "nyc --reporter=html ava && open coverage/index.html",
"coveralls": "nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls",
"lint": "standard --verbose | snazzy",
"precommit": "npm run lint -s",
"pretest": "npm run lint -s",
"lint": "prettier --no-semi --single-quote --write '**/*.js'",
"precommit": "npm run lint",
"test": "ava "
}
}
Loading

0 comments on commit 489a791

Please sign in to comment.