diff --git a/lib/clean.js b/lib/clean.js index a734655..5807e76 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -1,5 +1,5 @@ -module.exports = function(Spike, args) { - const project = new Spike({ root: args.path }) +module.exports = function(Spike, { path }) { + const project = new Spike({ root: path }) process.nextTick(() => project.clean()) return project } diff --git a/lib/compile.js b/lib/compile.js index 0c14633..39c804a 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -1,5 +1,5 @@ -module.exports = function(Spike, args) { - const project = new Spike({ root: args.path, env: args.env }) +module.exports = function(Spike, { path, env }) { + const project = new Spike({ root: path, env }) process.nextTick(() => project.compile()) return project } diff --git a/lib/index.js b/lib/index.js index f19fd01..9dfebd4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,7 +6,7 @@ const EventEmitter = require('events') const GA = require('universal-analytics') const ArgumentParser = require('argparse').ArgumentParser const reduce = require('lodash.reduce') -const pkg = require('../package.json') +const { version, description } = require('../package.json') const path = require('path') const fs = require('fs') let analytics @@ -21,12 +21,7 @@ module.exports = class CLI extends EventEmitter { constructor() { super() - this.parser = new ArgumentParser({ - version: pkg.version, - description: pkg.description, - addHelp: true - }) - + this.parser = new ArgumentParser({ version, description, addHelp: true }) this.sub = this.parser.addSubparsers() this.addCompile() @@ -61,7 +56,7 @@ module.exports = class CLI extends EventEmitter { // try to load up a local spike instance first let spikePath = args.path && path.join(args.path, 'node_modules/spike-core') try { - fs.accessSync(spikePath) + fs.accessSync(spikePath, fs.constants.F_OK | fs.constants.R_OK) } catch (_) { spikePath = 'spike-core' } diff --git a/lib/new.js b/lib/new.js index 6e1d93b..980bcec 100644 --- a/lib/new.js +++ b/lib/new.js @@ -1,23 +1,23 @@ -const path = require('path') +const { resolve } = require('path') const EventEmitter = require('events').EventEmitter const inquirer = require('inquirer') -module.exports = function(Spike, args) { +module.exports = function(Spike, { path, overrides, template }) { const emitter = new EventEmitter() emitter.on('done', project => { emitter.emit( 'success', - `project created at ${path.resolve(project.config.context)}` + `project created at ${resolve(project.config.context)}` ) }) process.nextTick(() => Spike.new({ - root: args.path, - emitter: emitter, - locals: args.overrides, - template: args.template, + emitter, + template, + root: path, + locals: overrides, inquirer: inquirer.prompt.bind(inquirer) }) ) diff --git a/lib/template/add.js b/lib/template/add.js index ccdbcb9..88e1181 100644 --- a/lib/template/add.js +++ b/lib/template/add.js @@ -2,8 +2,6 @@ const EventEmitter = require('events') module.exports = function(Spike, args) { const emitter = new EventEmitter() - process.nextTick(() => { - Spike.template.add(Object.assign(args, { emitter: emitter })) - }) + process.nextTick(() => Spike.template.add(Object.assign(args, { emitter }))) return emitter } diff --git a/lib/template/default.js b/lib/template/default.js index 755d124..c09edf1 100644 --- a/lib/template/default.js +++ b/lib/template/default.js @@ -2,8 +2,8 @@ const EventEmitter = require('events') module.exports = function(Spike, args) { const emitter = new EventEmitter() - process.nextTick(() => { - Spike.template.default(Object.assign(args, { emitter: emitter })) - }) + process.nextTick(() => + Spike.template.default(Object.assign(args, { emitter })) + ) return emitter } diff --git a/lib/template/list.js b/lib/template/list.js index 8c24c72..ea71dbf 100644 --- a/lib/template/list.js +++ b/lib/template/list.js @@ -4,10 +4,10 @@ module.exports = function(Spike, args) { const emitter = new EventEmitter() const e2 = new EventEmitter() process.nextTick(() => { - emitter.on('success', res => { + emitter.on('success', res => e2.emit('success', 'Your Templates:\n- ' + Object.keys(res).join('\n- ')) - }) - Spike.template.list(Object.assign(args, { emitter: emitter })) + ) + Spike.template.list(Object.assign(args, { emitter })) }) return e2 } diff --git a/lib/template/remove.js b/lib/template/remove.js index f6b0ee7..d98d960 100644 --- a/lib/template/remove.js +++ b/lib/template/remove.js @@ -2,8 +2,8 @@ const EventEmitter = require('events') module.exports = function(Spike, args) { const emitter = new EventEmitter() - process.nextTick(() => { - Spike.template.remove(Object.assign(args, { emitter: emitter })) - }) + process.nextTick(() => + Spike.template.remove(Object.assign(args, { emitter })) + ) return emitter } diff --git a/lib/watch.js b/lib/watch.js index bd3bd7c..3f72d5e 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -1,9 +1,5 @@ -module.exports = function(Spike, args) { - const project = new Spike({ - root: args.path, - env: args.env, - server: { port: args.port } - }) +module.exports = function(Spike, { path, env, port }) { + const project = new Spike({ env, root: path, server: { port } }) process.nextTick(() => project.watch()) return project }