Skip to content

Commit 230e923

Browse files
author
Jeff Escalante
committed
api return object consistency, closes #148
1 parent 6530f1c commit 230e923

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

lib/index.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ class Spike extends EventEmitter {
3333
* @fires Spike#error
3434
* @fires Spike#warning
3535
* @fires Spike#compile
36-
* @return {Array} a unique compile id, and webpack compiler instance
36+
* @return {Object} compile id, webpack compiler
3737
*/
3838
compile () {
3939
const id = this._id()
4040
const compiler = webpack(this.config)
41-
4241
compiler.run(compileCallback.bind(this, id))
43-
44-
// Returns the compilation's ID synchronously, this can be checked against
45-
// events emitted from the project instance.
46-
return [id, compiler]
42+
return {id, compiler}
4743
}
4844

4945
/**
@@ -52,13 +48,14 @@ class Spike extends EventEmitter {
5248
* @fires Spike#error
5349
* @fires Spike#warning
5450
* @fires Spike#compile
55-
* @return {Watcher} webpack watcher instance
51+
* @return {Object} watch id, webpack watcher
5652
*/
5753
watch (opts = {}) {
5854
const id = this._id()
5955
this.compiler = webpack(this.config)
60-
this.watcher = this.compiler.watch(opts, compileCallback.bind(this, id))
61-
return this.watcher
56+
const watcher = this.compiler.watch(opts, compileCallback.bind(this, id))
57+
this.watcher = watcher
58+
return {id, watcher}
6259
}
6360

6461
/**
@@ -76,10 +73,10 @@ class Spike extends EventEmitter {
7673
* @static
7774
* @param {Object} options - options for new project
7875
* @param {String} options.root - path ro the root of the project
79-
* @param {String} [options.template='base'] - name of the template to use
80-
* @param {String} [options.src=https://github.com/static-dev/spike-tpl-base.git] - path to the template source
81-
* @param {Object} [options.overrides] - locals provided to the sprout template
76+
* @param {String} [options.template] - name of the template to use
77+
* @param {Object} [options.locals] - locals provided to the sprout template
8278
* @param {EventEmitter} [options.emitter] - an event emitter for feedback
79+
* @param {Inquirer} [options.inquirer] - inquirer instance for CLI
8380
* @fires Spike#info
8481
* @fires Spike#error
8582
* @fires Spike#done
@@ -127,11 +124,11 @@ class Spike extends EventEmitter {
127124

128125
// run it
129126
promise
130-
.tap(() => { emit('info', 'initializing template') })
127+
.tap(() => emit('info', 'initializing template'))
131128
.then(sprout.init.bind(sprout, opts.template, opts.root, sproutOptions))
132-
.tap(() => { emit('info', 'installing production dependencies') })
129+
.tap(() => emit('info', 'installing production dependencies'))
133130
.then(npmInstall.bind(null, opts))
134-
.then(() => { return new Spike({ root: opts.root }) })
131+
.then(() => new Spike({ root: opts.root }))
135132
.done(
136133
(instance) => { emit('done', instance) },
137134
(err) => { emit('error', err) }
@@ -181,7 +178,7 @@ function compileCallback (id, err, stats) {
181178
this.emit('warning', new Warning({ id: id, message: jsonStats.warnings }))
182179
}
183180

184-
this.emit('compile', { id: id, stats: stats })
181+
this.emit('compile', {id, stats})
185182
}
186183

187184
/**
@@ -195,7 +192,7 @@ Spike.template = {
195192
* @param {String} src - url from which the template can be `git clone`d
196193
* @param {EventEmitter} emitter - will return events to report progress
197194
* @fires emitter#info
198-
* @fires emitter#done
195+
* @fires emitter#success
199196
* @fires emitter#error
200197
*/
201198
add: function (options = {}) {
@@ -278,7 +275,6 @@ Spike.template = {
278275
},
279276
/**
280277
* Removes the primary spike config and all templates, like a clean install
281-
* @private
282278
*/
283279
reset: function () {
284280
try {

test/watch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test.cb('watches the project, reloads on modification', (t) => {
2424
}
2525
})
2626

27-
const watcher = project.watch()
27+
const {watcher} = project.watch()
2828
// make sure the watcher is returned
2929
t.truthy((typeof watcher.startTime) === 'number')
3030
})
@@ -53,5 +53,5 @@ test.cb('incorporates new file when added while watching', (t) => {
5353
}
5454
})
5555

56-
const watcher = project.watch()
56+
const {watcher} = project.watch()
5757
})

0 commit comments

Comments
 (0)