feat(semantic-release): let the user confirm if they run hooks outside of CI

This commit is contained in:
Stephan Bönnemann 2015-02-02 15:39:33 +01:00
parent c0aebd9873
commit bd90936927
2 changed files with 40 additions and 23 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict' 'use strict'
var confirm = require('confirm-simple')
var argv = require('minimist')(process.argv.slice(2), { var argv = require('minimist')(process.argv.slice(2), {
alias: { alias: {
d: 'debug', d: 'debug',
@ -23,37 +25,51 @@ if (~argv._.indexOf('pre')) {
// the `prepublish` hook is also executed when the package is installed // the `prepublish` hook is also executed when the package is installed
// in this case we abort the command and do nothing. // in this case we abort the command and do nothing.
if (~npmArgv.indexOf('install')) process.exit(0) if (~npmArgv.indexOf('install')) process.exit(0)
if (~npmArgv.indexOf('publish')) publish = true
console.log('Determining new version') return confirmCI(function () {
if (~npmArgv.indexOf('publish')) publish = true
return require('../src/pre')(argv, function (err, result) { console.log('Determining new version')
if (err) {
console.log('Something went wrong.')
throw err
}
if (!result) { require('../src/pre')(argv, function (err, result) {
console.log('Nothing changed. Not publishing.') if (err) {
process.exit(1) console.log('Something went wrong.')
} throw err
}
console.log('Publishing v' + result) if (!result) {
if (publish) require('../src/restart')() console.log('Nothing changed. Not publishing.')
process.exit(1)
}
console.log('Publishing v' + result)
if (publish) require('../src/restart')()
})
}) })
} }
if (~argv._.indexOf('post')) { if (~argv._.indexOf('post')) {
return require('../src/post')(argv, function (err) { return confirmCI(function () {
if (err) { require('../src/post')(argv, function (err) {
console.log('Something went wrong.') if (err) {
throw err console.log('Something went wrong.')
} throw err
}
// see src/restart.js // see src/restart.js
if (~npmArgv.indexOf('--semantic-release-rerun')) { if (~npmArgv.indexOf('--semantic-release-rerun')) {
console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') console.log('Everything is alright :) npm will now print an error message that you can safely ignore.')
process.exit(1) process.exit(1)
} }
})
})
}
function confirmCI (cb) {
if (process.env.CI) return cb(null, true)
confirm('Not running in a CI enviroment. Are you sure you want to run this hook?', function (ok) {
if (!ok) process.exit(1)
cb(null, ok)
}) })
} }

View File

@ -8,6 +8,7 @@
"url": "https://github.com/boennemann/semantic-release/issues" "url": "https://github.com/boennemann/semantic-release/issues"
}, },
"dependencies": { "dependencies": {
"confirm-simple": "^1.0.3",
"conventional-changelog": "0.0.11", "conventional-changelog": "0.0.11",
"github": "^0.2.3", "github": "^0.2.3",
"minimist": "^1.1.0", "minimist": "^1.1.0",