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 read access check to fs.accessSync & use es6 destructuring #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lib/clean.js
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions lib/compile.js
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 3 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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'
}
Expand Down
14 changes: 7 additions & 7 deletions lib/new.js
Original file line number Diff line number Diff line change
@@ -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)
})
)
Expand Down
4 changes: 1 addition & 3 deletions lib/template/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions lib/template/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions lib/template/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions lib/template/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 2 additions & 6 deletions lib/watch.js
Original file line number Diff line number Diff line change
@@ -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
}