From bd909369271c84b33af8f0970f3aee0a56f38831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Mon, 2 Feb 2015 15:39:33 +0100 Subject: [PATCH] feat(semantic-release): let the user confirm if they run hooks outside of CI --- bin/semantic-release | 62 ++++++++++++++++++++++++++++---------------- package.json | 1 + 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/bin/semantic-release b/bin/semantic-release index 13bc9c90..ea84a8a4 100755 --- a/bin/semantic-release +++ b/bin/semantic-release @@ -1,6 +1,8 @@ #!/usr/bin/env node 'use strict' +var confirm = require('confirm-simple') + var argv = require('minimist')(process.argv.slice(2), { alias: { d: 'debug', @@ -23,37 +25,51 @@ if (~argv._.indexOf('pre')) { // the `prepublish` hook is also executed when the package is installed // in this case we abort the command and do nothing. 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) { - if (err) { - console.log('Something went wrong.') - throw err - } + console.log('Determining new version') - if (!result) { - console.log('Nothing changed. Not publishing.') - process.exit(1) - } + require('../src/pre')(argv, function (err, result) { + if (err) { + console.log('Something went wrong.') + throw err + } - console.log('Publishing v' + result) - if (publish) require('../src/restart')() + if (!result) { + console.log('Nothing changed. Not publishing.') + process.exit(1) + } + + console.log('Publishing v' + result) + if (publish) require('../src/restart')() + }) }) } if (~argv._.indexOf('post')) { - return require('../src/post')(argv, function (err) { - if (err) { - console.log('Something went wrong.') - throw err - } + return confirmCI(function () { + require('../src/post')(argv, function (err) { + if (err) { + console.log('Something went wrong.') + throw err + } - // see src/restart.js - if (~npmArgv.indexOf('--semantic-release-rerun')) { - console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') - process.exit(1) - } + // see src/restart.js + if (~npmArgv.indexOf('--semantic-release-rerun')) { + console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') + 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) }) } diff --git a/package.json b/package.json index 173c3c7e..5db5137a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "url": "https://github.com/boennemann/semantic-release/issues" }, "dependencies": { + "confirm-simple": "^1.0.3", "conventional-changelog": "0.0.11", "github": "^0.2.3", "minimist": "^1.1.0",