Compare commits

...
5 Commits
4 changed files with 41 additions and 13 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ For maximum comfort you can automate this inside your `package.json`:
```json
"scripts": {
"prepublish": "semantic-release pre"
"prepublish": "semantic-release pre",
"postpublish": "semantic-release post"
}
```
+23 -10
View File
@@ -1,9 +1,11 @@
#!/usr/bin/env node
'use strict'
var abbrev = require('abbrev')
var confirm = require('confirm-simple')
var minimist = require('minimist')
var argv = require('minimist')(process.argv.slice(2), {
var argv = minimist(process.argv.slice(2), {
alias: {
d: 'debug',
dry: 'debug',
@@ -14,20 +16,21 @@ var argv = require('minimist')(process.argv.slice(2), {
}
})
var npmArgv = process.env.npm_config_argv
npmArgv = npmArgv ? JSON.parse(npmArgv).cooked : []
var npmArgv = process.env.npm_config_argv ?
minimist(JSON.parse(process.env.npm_config_argv).cooked) :
{_: []}
if (~argv._.indexOf('pre')) {
var publish = false
// see src/restart.js
if (~npmArgv.indexOf('--semantic-release-rerun')) process.exit(0)
if (npmArgv['semantic-release-rerun']) process.exit(0)
// 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 (isAbbrev(npmArgv, 'install')) process.exit(0)
return confirmCI(function () {
if (~npmArgv.indexOf('publish')) publish = true
if (isAbbrev(npmArgv, 'publish')) publish = true
console.log('Determining new version')
@@ -43,7 +46,14 @@ if (~argv._.indexOf('pre')) {
}
console.log('Publishing v' + result)
if (publish) require('../src/restart')()
if (publish) require('../src/restart')(function (err) {
if (err) {
console.log('Something went wrong.')
throw err
}
process.exit(1)
})
})
})
}
@@ -57,19 +67,22 @@ if (~argv._.indexOf('post')) {
}
// see src/restart.js
if (~npmArgv.indexOf('--semantic-release-rerun')) {
if (npmArgv['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)
if (process.env.CI || argv.ci === false) 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)
})
}
function isAbbrev (argv, command) {
return argv._.some(Object.prototype.hasOwnProperty.bind(abbrev(command)))
}
+2 -1
View File
@@ -1,13 +1,14 @@
{
"name": "semantic-release",
"description": "semantic semver compliant package publishing",
"version": "0.0.3",
"version": "0.0.5",
"author": "Stephan Bönnemann <stephan@boennemann.me>",
"bin": "./bin/semantic-release",
"bugs": {
"url": "https://github.com/boennemann/semantic-release/issues"
},
"dependencies": {
"abbrev": "^1.0.5",
"confirm-simple": "^1.0.3",
"conventional-changelog": "0.0.11",
"github": "^0.2.3",
+15 -1
View File
@@ -2,7 +2,7 @@
var spawn = require('child_process').spawn
module.exports = function () {
var exports = module.exports = function (cb) {
// npm loads package.json data before running the `prepublish` hook
// changing the version on `prepublish` has no effect
// see https://github.com/npm/npm/issues/7118
@@ -10,7 +10,21 @@ module.exports = function () {
// the package.json is then loaded again and the correct version will be published
var child = spawn('npm', ['publish', '--semantic-release-rerun'])
var handler = exports.handleCloseAndExit.bind(null, cb)
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.on('close', handler)
child.on('exit', handler)
child.on('error', cb)
}
exports.handleCloseAndExit = function (cb, code, signal) {
if (code === 0) return cb(null)
cb({
code: code,
signal: signal,
message: 'npm publish failed'
})
}