File tree Expand file tree Collapse file tree 6 files changed +50
-9
lines changed
Expand file tree Collapse file tree 6 files changed +50
-9
lines changed Original file line number Diff line number Diff line change 44
55## install
66
7- > npm install -g node-fire
8- > fire ./test.js
7+ ```
8+ $ npm install -g node-fire
9+ ```
10+
11+ ## How to use
12+ ```
13+ $ fire ./test.js
14+ ```
15+
16+ ## LICENSE
17+ Released under MIT license
Original file line number Diff line number Diff line change @@ -30,10 +30,14 @@ module.exports = function (...argv) {
3030
3131 debug ( ' > loopup script:' , script ) ;
3232 script = patternRequire ( script ) ;
33+
3334 if ( script == null ) {
34- console . error ( 'Not find a valid js file' ) ;
35+ console . error ( 'Not find a valid js/json file' ) ;
3536 return ;
3637 }
38+
39+ debug ( `> RUN ${ script } \n` ) ;
40+
3741 debug ( ' > ha, got it' , script ) ;
3842
3943 let fn = require ( script ) ;
Original file line number Diff line number Diff line change 11const requireg = require ( './requireg/index' ) ;
2+ const { existsSync } = require ( 'fs' ) ;
23const {
3- resolve,
44 extname,
55 join
66} = require ( 'path' ) ;
7+ const resolve = require ( 'resolve' ) . sync ;
8+ const cwd = process . cwd ( ) ;
79
810const PKG_PREFIX = '' ;
911
@@ -13,11 +15,12 @@ exports.isObject = function(obj) {
1315
1416exports . patternRequire = function patternRequire ( filepath = '.' ) {
1517 filepath = String ( filepath ) ;
16- let fullpath = filepath ;
17- if ( / ^ [ \. \\ \/ ] / . test ( filepath ) ) {
18+ let fullpath = resolve ( filepath , { basedir : cwd } ) ;
19+
20+ if ( / ^ [ \. \\ \/ ] / . test ( filepath ) && existsSync ( fullpath ) ) {
1821 return fullpath ;
1922 } else if ( ! ( fullpath = requireg . resolve ( PKG_PREFIX + filepath ) ) ) {
20- return resolve ( filepath ) ;
23+ return ;
2124 }
2225 return fullpath ;
2326}
Original file line number Diff line number Diff line change 11{
22 "name" : " node-fire" ,
3- "version" : " 0.0.1 " ,
3+ "version" : " 0.0.2 " ,
44 "description" : " A library for automatically generating command line CLIs from any nodejs project." ,
55 "bin" : {
66 "fire" : " ./bin/index.js"
Original file line number Diff line number Diff line change 1+ const { exec } = require ( 'shelljs' ) ;
2+ module . exports = function ( script ) {
3+ return exec ( 'node ./bin/index ' + script ) ;
4+ }
Original file line number Diff line number Diff line change 11const test = require ( 'ava' ) ;
2- test ( 'todo' , ( t ) => {
2+ const exec = require ( './_exec' ) ;
3+ test ( 'exec' , ( t ) => {
4+ exec ( './test/fixtures/test.js' ) ;
35 t . pass ( ) ;
6+ } ) ;
7+
8+ test ( 'path autocomplete' , ( t ) => {
9+ exec ( './test/fixtures/test' ) ;
10+ t . pass ( ) ;
11+ } ) ;
12+
13+
14+ test ( 'json & multi params' , ( t ) => {
15+ exec ( './test/fixtures/test.json name' ) ;
16+ t . pass ( ) ;
17+ } ) ;
18+
19+ test ( 'test2' , ( t ) => {
20+ exec ( './test/fixtures/test2.js' ) ;
21+ } ) ;
22+
23+ test ( 'test2 with second param' , ( t ) => {
24+ exec ( './test/fixtures/test2.js a' ) ;
425} ) ;
You can’t perform that action at this time.
0 commit comments