Skip to content

Commit

Permalink
add CLI usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Jun 22, 2014
1 parent 4c3dc15 commit cb46347
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ But who knows when that's going to happen.
This uses [`child_process.execFileSync()`](http://nodejs.org/docs/v0.11.13/api/child_process.html#child_process_child_process_execfilesync_command_args_options),
so is only supported in node `>= v0.11.13`ish.

## Usage
## CLI Usage

You can install `autoinstall` globally:

```bash
npm i -g autoinstall
```

Then use `autoinstall(1)` like `node(1)`:

```bash
autoinstall index.js
```

## API Usage

```bash
npm i autoinstall
Expand Down
35 changes: 35 additions & 0 deletions bin/autoinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node

var autoinstall = require.resolve('..')

var args = process.argv.slice(2)

var options = []
args = args.filter(function (arg) {
if (arg[0] === '-') {
options.push(arg)
return false
}
return true
})

if (args.length > 1) {
throw new Error('more than 1 argument supplied')
}

var path = require('path')
var file = path.resolve(args[0])

options.push('-e',
"require('" + autoinstall + "');" +
"require('" + file + "');"
)

var spawn = require('child_process').spawn
var proc = spawn('node', options, {
customFds: [0, 1, 2]
})

proc.on('exit', function (code) {
process.exit(code)
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
},
"engines": {
"node": ">= 0.11.13"
}
},
"bin": "bin/autoinstall"
}
3 changes: 3 additions & 0 deletions test/koa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

require('koa')
console.log('koa passed!')
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ assert(require('debug'))
assert(require('mocha'))
assert(require('should'))
assert('function', typeof require('type-is'))

console.log('tests pass!!!')

0 comments on commit cb46347

Please sign in to comment.