From 2ce4160fcf4cb2c7b9338adf9d800c9d68128b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daijir=C5=8D=20Wachi?= Date: Tue, 13 Sep 2016 01:20:13 +0200 Subject: [PATCH] fix: check the private field in package.json(#102) (#103) It should not suggest `npm publish` if the package.json has `private: true`. --- index.js | 6 +++--- test.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 8faf1e343..9361ac226 100755 --- a/index.js +++ b/index.js @@ -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)) } }) } diff --git a/test.js b/test.js index 19316a139..b3f04f892 100644 --- a/test.js +++ b/test.js @@ -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') @@ -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 () { @@ -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/) + }) })