Skip to content

Commit 2ce4160

Browse files
watildestevemao
authored andcommitted
fix: check the private field in package.json(#102) (#103)
It should not suggest `npm publish` if the package.json has `private: true`.
1 parent 1ad772a commit 2ce4160

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ function tag (newVersion, argv) {
148148
}
149149
checkpoint('tagging release %s', [newVersion])
150150
exec('git tag ' + tagOption + 'v' + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
151+
var message = 'git push --follow-tags origin master'
151152
var errMessage = null
152153
if (err) errMessage = err.message
153154
if (stderr) errMessage = stderr
155+
if (pkg.private !== true) message += '; npm publish'
154156
if (errMessage) {
155157
console.log(chalk.red(errMessage))
156158
process.exit(1)
157159
} else {
158-
checkpoint('Run `%s` to publish', [
159-
'git push --follow-tags origin master; npm publish'
160-
], chalk.blue(figures.info))
160+
checkpoint('Run `%s` to publish', [message], chalk.blue(figures.info))
161161
}
162162
})
163163
}

test.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
'use strict'
44

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

21-
function writePackageJson (version) {
22-
fs.writeFileSync('package.json', JSON.stringify({
23-
version: version
24-
}), 'utf-8')
22+
function writePackageJson (version, option) {
23+
option = option || {}
24+
var pkg = extend(option, {version: version})
25+
fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8')
2526
}
2627

2728
function writeGitPreCommitHook () {
@@ -197,4 +198,12 @@ describe('cli', function () {
197198
commit('feat: second commit')
198199
execCli('-n').code.should.equal(0)
199200
})
201+
202+
it('does not display `npm publish` if the package is private', function () {
203+
writePackageJson('1.0.0', {private: true})
204+
205+
var result = execCli()
206+
result.code.should.equal(0)
207+
result.stdout.should.not.match(/npm publish/)
208+
})
200209
})

0 commit comments

Comments
 (0)