Skip to content

Commit

Permalink
fix: check the private field in package.json(#102) (#103)
Browse files Browse the repository at this point in the history
It should not suggest `npm publish` if the package.json
has `private: true`.
  • Loading branch information
watilde authored and stevemao committed Sep 12, 2016
1 parent 1ad772a commit 2ce4160
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ function tag (newVersion, argv) {
}
checkpoint('tagging release %s', [newVersion])
exec('git tag ' + tagOption + 'v' + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
var message = 'git push --follow-tags origin master'
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr
if (pkg.private !== true) message += '; npm publish'
if (errMessage) {
console.log(chalk.red(errMessage))
process.exit(1)
} else {
checkpoint('Run `%s` to publish', [
'git push --follow-tags origin master; npm publish'
], chalk.blue(figures.info))
checkpoint('Run `%s` to publish', [message], chalk.blue(figures.info))
}
})
}
Expand Down
17 changes: 13 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

'use strict'

var extend = Object.assign || require('util')._extend
var shell = require('shelljs')
var fs = require('fs')
var path = require('path')
Expand All @@ -18,10 +19,10 @@ function execCli (argString) {
return shell.exec('node ' + cliPath + (argString != null ? ' ' + argString : ''))
}

function writePackageJson (version) {
fs.writeFileSync('package.json', JSON.stringify({
version: version
}), 'utf-8')
function writePackageJson (version, option) {
option = option || {}
var pkg = extend(option, {version: version})
fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8')
}

function writeGitPreCommitHook () {
Expand Down Expand Up @@ -197,4 +198,12 @@ describe('cli', function () {
commit('feat: second commit')
execCli('-n').code.should.equal(0)
})

it('does not display `npm publish` if the package is private', function () {
writePackageJson('1.0.0', {private: true})

var result = execCli()
result.code.should.equal(0)
result.stdout.should.not.match(/npm publish/)
})
})

0 comments on commit 2ce4160

Please sign in to comment.