split-command
Advanced tools
Comparing version 0.0.3 to 0.0.4
27
index.js
@@ -9,3 +9,2 @@ 'use strict'; | ||
var yargs = require('yargs'); | ||
var exec = require('child_process').exec; | ||
@@ -43,11 +42,21 @@ var spawn = require('child_process').spawn; | ||
module.exports = function (execCmd, installCmd) { | ||
module.exports = function (projectPackageJson, execCmd, installCmd) { | ||
if (!projectPackageJson || !projectPackageJson.splitCommands) { | ||
console.info("Please check your SplitCommand congifuration"); | ||
return false; | ||
} | ||
var args, cmd, splitCmds; | ||
args = process.argv; | ||
if (!execCmd || !installCmd) { | ||
var argv = yargs.argv; | ||
var cmd = argv._[0]; | ||
var splitCmds = require('../../package.json').splitCommands; | ||
if (args.length > 2) { | ||
cmd = args[2]; | ||
splitCmds = projectPackageJson.splitCommands; | ||
} else { | ||
return false; | ||
} | ||
if (!splitCmds[cmd]) { | ||
return; | ||
return false; | ||
} | ||
@@ -64,8 +73,8 @@ | ||
console.error("can't read split command configuration in your package.json"); | ||
process.exit(); | ||
return false; | ||
} | ||
} | ||
checkCmdExists(execCmd).then(function () { | ||
forkRun(execCmd, argv._.slice(1)); | ||
return !!checkCmdExists(execCmd).then(function () { | ||
forkRun(execCmd, args.slice(3)); | ||
}).catch(function () { | ||
@@ -72,0 +81,0 @@ console.log('please run:\n ' + installCmd + '\nto install this command first'); |
{ | ||
"name": "split-command", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "a framework for write separable command line application", | ||
@@ -19,3 +19,2 @@ "scripts": { | ||
"dependencies": { | ||
"yargs": "^6.0.0", | ||
"babel-plugin-transform-runtime": "^6.12.0", | ||
@@ -22,0 +21,0 @@ "babel-runtime": "^6.11.6" |
@@ -52,4 +52,5 @@ # SplitCommand | ||
```javascript | ||
var splitCommand = require('split-command'); | ||
splitCommand(); | ||
var projectPackageJSON = require('../package.json'); // configuration file of your project | ||
require('split-command')(projectPackageJSON); | ||
``` | ||
@@ -76,5 +77,6 @@ | ||
if (argv._[0] === 'coreCommand') { | ||
console.log("coreCommand running....") // any awesome logic of your normal sub command | ||
console.log("coreCommand running....") // any awesome logic of your normal sub command | ||
} | ||
splitCommand(); // let's split command do the rest | ||
var projectPackageJSON = require('../package.json'); // configuration file of your project | ||
var isSplitCommandMatched = splitCommand(projectPackageJSON); // let's split command do the rest | ||
})() | ||
@@ -94,3 +96,4 @@ ``` | ||
## Release History | ||
* 161101(0.0.4): remove dependence of yargs | ||
* 161027(0.0.3): first version | ||
42145
2
64
97
- Removedyargs@^6.0.0
- Removedansi-regex@2.1.1(transitive)
- Removedcamelcase@3.0.0(transitive)
- Removedcliui@3.2.0(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-caller-file@1.0.3(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.16.1(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedlcid@1.0.0(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedrequire-main-filename@1.0.1(transitive)
- Removedresolve@1.22.10(transitive)
- Removedsemver@5.7.2(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.21(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedwhich-module@1.0.0(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@6.6.0(transitive)
- Removedyargs-parser@4.2.1(transitive)