commit-message-install
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -5,8 +5,4 @@ #!/usr/bin/env node | ||
const args = require('minimist')(process.argv.slice(2), { | ||
alias: { | ||
file: 'f' | ||
}, | ||
string: 'file' | ||
}) | ||
const debug = require('debug')('commit-message-install') | ||
const execa = require('execa') | ||
@@ -23,26 +19,54 @@ const api = require('..') | ||
let start | ||
if (args.file) { | ||
console.log('loading message from file', args.file) | ||
const fs = require('fs') | ||
const message = fs.readFileSync(args.file, 'utf8') | ||
start = Promise.resolve(message) | ||
} else { | ||
start = getMessage() | ||
function commitMessageInstall (cliArguments) { | ||
if (!cliArguments) { | ||
cliArguments = process.argv.slice(2) | ||
} | ||
const args = require('minimist')(cliArguments, { | ||
alias: { | ||
file: 'f' | ||
}, | ||
string: ['file', 'else'] | ||
}) | ||
let start | ||
if (args.file) { | ||
console.log('loading message from file', args.file) | ||
const fs = require('fs') | ||
const message = fs.readFileSync(args.file, 'utf8') | ||
start = Promise.resolve(message) | ||
} else { | ||
start = getMessage() | ||
} | ||
return start | ||
.then(getJsonBlock) | ||
.then(json => { | ||
if (!json) { | ||
debug('nothing to do from the commit message') | ||
if (args.else) { | ||
debug('have --else command') | ||
debug(args.else) | ||
const options = { | ||
stdio: 'inherit' | ||
} | ||
return execa.shell(args.else, options) | ||
} | ||
return | ||
} | ||
// alias for API simplicity | ||
json.packages = json.packages || json.package | ||
if (json.package) { | ||
delete json.package | ||
} | ||
console.log('got json block from the git commit message') | ||
console.log(JSON.stringify(json, null, 2)) | ||
return npmInstall(json) | ||
}) | ||
.catch(onError) | ||
} | ||
start | ||
.then(getJsonBlock) | ||
.then(json => { | ||
if (!json) { | ||
return | ||
} | ||
// alias for API simplicity | ||
json.packages = json.packages || json.package | ||
if (json.package) { | ||
delete json.package | ||
} | ||
console.log('got json block from the git commit message') | ||
console.log(JSON.stringify(json, null, 2)) | ||
return npmInstall(json) | ||
}) | ||
.catch(onError) | ||
if (!module.parent) { | ||
commitMessageInstall() | ||
} | ||
module.exports = commitMessageInstall |
@@ -1,1 +0,1 @@ | ||
{"name":"commit-message-install","description":"NPM install a package by name taken from the last commit message","version":"1.5.0","author":"Gleb Bahmutov <gleb.bahmutov@gmail.com>","bugs":"https://github.com/bahmutov/commit-message-install/issues","bin":{"commit-message-install":"bin/commit-message-install.js","cmi":"bin/commit-message-install.js","run-if":"bin/commit-message-run.js"},"config":{"pre-git":{"commit-msg":"simple","pre-commit":["npm prune","npm run deps","npm test","git add src/*.js bin/*.js","npm run ban"],"pre-push":["npm run secure","npm run license","npm run ban -- --all","npm run size"],"post-commit":[],"post-merge":[]}},"engines":{"node":">=6"},"files":["bin","src/*.js","!src/*-spec.js"],"homepage":"https://github.com/bahmutov/commit-message-install#readme","keywords":["ci","commit","git","install","npm","utility"],"license":"MIT","main":"src/","publishConfig":{"registry":"http://registry.npmjs.org/"},"repository":{"type":"git","url":"https://github.com/bahmutov/commit-message-install.git"},"scripts":{"ban":"ban","deps":"deps-ok && dependency-check --no-dev .","issues":"git-issues","license":"license-checker --production --onlyunknown --csv","lint":"standard --verbose --fix src/*.js bin/*.js","prelint":"npm run pretty","pretest":"npm run lint","pretty":"echo ⚠️ disable prettier-standard 'src/*.js' 'bin/*.js'","secure":"echo disabled nsp check","size":"t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";","test":"npm run unit","unit":"mocha src/*-spec.js","semantic-release":"semantic-release pre && npm publish && semantic-release post","demo":"node bin/commit-message-run.js -f test/run-if.txt echo Foo is \\$FOO"},"release":{"verifyConditions":{"path":"condition-node-version","node":"8"},"analyzeCommits":"simple-commit-message","generateNotes":"github-post-release","verifyRelease":{"path":"dont-crack","test-against":[]}},"devDependencies":{"ban-sensitive-files":"1.9.0","common-tags":"1.5.1","condition-node-version":"1.3.0","dependency-check":"2.9.1","deps-ok":"1.2.1","dont-crack":"1.2.1","git-issues":"1.3.1","github-post-release":"1.13.1","if-node-version":"1.1.1","license-checker":"15.0.0","mocha":"4.0.1","nsp":"2.8.1","pre-git":"3.15.3","prettier-standard":"7.0.3","schema-shot":"1.9.0","semantic-release":"8.2.0","simple-commit-message":"3.3.1","snap-shot-it":"4.0.1","standard":"10.0.3","stub-spawn-once":"2.3.0"},"dependencies":{"chalk":"2.3.0","check-more-types":"2.24.0","debug":"3.1.0","execa":"0.8.0","lazy-ass":"1.6.0","minimist":"1.2.0"}} | ||
{"name":"commit-message-install","description":"NPM install a package by name taken from the last commit message","version":"1.6.0","author":"Gleb Bahmutov <gleb.bahmutov@gmail.com>","bugs":"https://github.com/bahmutov/commit-message-install/issues","bin":{"commit-message-install":"bin/commit-message-install.js","cmi":"bin/commit-message-install.js","run-if":"bin/commit-message-run.js"},"config":{"pre-git":{"commit-msg":"simple","pre-commit":["npm prune","npm run deps","npm test","git add src/*.js bin/*.js","npm run ban"],"pre-push":["npm run secure","npm run license","npm run ban -- --all","npm run size"],"post-commit":[],"post-merge":[]}},"engines":{"node":">=6"},"files":["bin","src/*.js","!src/*-spec.js"],"homepage":"https://github.com/bahmutov/commit-message-install#readme","keywords":["ci","commit","git","install","npm","utility"],"license":"MIT","main":"src/","publishConfig":{"registry":"http://registry.npmjs.org/"},"repository":{"type":"git","url":"https://github.com/bahmutov/commit-message-install.git"},"scripts":{"ban":"ban","deps":"deps-ok && dependency-check --no-dev .","issues":"git-issues","license":"license-checker --production --onlyunknown --csv","lint":"standard --verbose --fix src/*.js bin/*.js","prelint":"npm run pretty","pretest":"npm run lint","pretty":"echo ⚠️ disable prettier-standard 'src/*.js' 'bin/*.js'","secure":"echo disabled nsp check","size":"t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";","test":"npm run unit","unit":"mocha src/*-spec.js","semantic-release":"semantic-release pre && npm publish && semantic-release post","demo":"node bin/commit-message-run.js -f test/run-if.txt echo Foo is \\$FOO"},"release":{"verifyConditions":{"path":"condition-node-version","node":"8"},"analyzeCommits":"simple-commit-message","generateNotes":"github-post-release","verifyRelease":{"path":"dont-crack","test-against":[]}},"devDependencies":{"ban-sensitive-files":"1.9.0","common-tags":"1.5.1","condition-node-version":"1.3.0","dependency-check":"2.9.1","deps-ok":"1.2.1","dont-crack":"1.2.1","git-issues":"1.3.1","github-post-release":"1.13.1","if-node-version":"1.1.1","license-checker":"15.0.0","mocha":"4.0.1","nsp":"2.8.1","pre-git":"3.15.3","prettier-standard":"7.0.3","schema-shot":"1.9.0","semantic-release":"8.2.0","simple-commit-message":"3.3.1","snap-shot-it":"4.0.1","standard":"10.0.3","stub-spawn-once":"2.3.0"},"dependencies":{"chalk":"2.3.0","check-more-types":"2.24.0","debug":"3.1.0","execa":"0.8.0","lazy-ass":"1.6.0","minimist":"1.2.0"}} |
@@ -55,2 +55,11 @@ # commit-message-install | ||
### Alternative command | ||
You can specify a command to run *if commit message has no JSON block*. For example you can | ||
install default dependency | ||
```bash | ||
$ $(npm bin)/commit-message-install --else "npm install foo-bar" | ||
``` | ||
### Run or skip command based on platform | ||
@@ -57,0 +66,0 @@ |
16013
299
165