Skip to content
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
27 changes: 21 additions & 6 deletions bin/node-dev
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#!/usr/bin/env node

var dev = require('..')
, args = process.argv.slice(2)
var program = require('commander')
var resolveMain = require('../lib/resolveMain')


program
.version(require('../package.json').version)
.option('--all-deps', 'watch the whole dependency tree')
.option('--no-deps', 'watch only the project’s own files and linked modules' +
' (via `npm link`)')
.option('--dedupe', 'dedupe modules dynamically')
.arguments('<script> [arguments...]')
.action(function (script, scriptArgs) {
var wrapper = resolveMain(__dirname + '/../lib/wrap.js')

if (!args.length) {
console.log('Usage: node-dev [options] script [arguments]\n')
process.exit(1)
}
dev(wrapper, script, scriptArgs || [], {
allDeps: program.allDeps || false,
noDeps: program.noDeps || false,
dedupe: program.dedupe || false,
})
})

dev(args)
program.parse(process.argv)
40 changes: 0 additions & 40 deletions lib/cli.js

This file was deleted.

26 changes: 17 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ var fork = require('child_process').fork
var path = require('path')
var filewatcher = require('filewatcher')
var ipc = require('./ipc')
var cli = require('./cli')
var resolveMain = require('./resolveMain')

module.exports = function(args) {

// The child_process
var child
module.exports = function(wrapper, script, scriptArgs, opts) {
if (typeof wrapper !== 'string' || wrapper.length === 0) {
throw new TypeError('`wrapper` must be a string')
}

if (typeof script !== 'string' || script.length === 0) {
throw new TypeError('`script` must be a string')
}

// Parse command line options
var opts = cli.parseOpts(args)
if (!Array.isArray(scriptArgs)) {
throw new TypeError('`scriptArgs` must be an array')
}

// Inject wrap.js into the args array
var main = cli.injectScript(args, __dirname + '/wrap.js')
// The child_process
var child

var main = resolveMain(script)
var cfg = require('./cfg')(main, opts)
var log = require('./log')(cfg)
var notify = require('./notify')(cfg, log)
Expand Down Expand Up @@ -50,7 +57,8 @@ module.exports = function(args) {
* Run the wrapped script.
*/
function start() {
child = fork(args[0], args.slice(1), {
var wrapperArgs = [script].concat(scriptArgs)
child = fork(wrapper, wrapperArgs, {
cwd: process.cwd(),
env: process.env
})
Expand Down
9 changes: 9 additions & 0 deletions lib/resolveMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var resolve = require('resolve').sync


module.exports = function(main) {
return resolve(main, {
basedir: process.cwd(),
paths: [process.cwd()]
})
}
4 changes: 2 additions & 2 deletions lib/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ var resolve = require('resolve').sync
var hook = require('./hook')
var ipc = require('./ipc')
var cfg = require('./cfg')
var cli = require('./cli')
var resolveMain = require('./resolveMain')

// Remove wrap.js from the argv array
process.argv.splice(1, 1)

// Resolve the location of the main script relative to cwd
var main = cli.resolveMain(process.argv[1])
var main = resolveMain(process.argv[1])

var cfg = require('./cfg')(main)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test": "node test"
},
"dependencies": {
"commander": "^2.8.1",
"dateformat": "~1.0.4-1.2.3",
"dynamic-dedupe": "^0.2.0",
"filewatcher": "~1.1.1",
Expand Down