diff --git a/README.md b/README.md index 101c458..66d7916 100644 --- a/README.md +++ b/README.md @@ -199,45 +199,30 @@ publish.standard(); - versionCmd + publishDevCmd - The CLI to execute which sets the dev version to release under. - + The CLI to execute which publishes a development release to NPM. + Uses the value specified by the `devTag` option. - "npm version --no-git-tag-version ${version}" -
-
-

- NOTE: This command will update the version in the package.json file, but will not commit the change. -

+ "npm publish --tag ${devTag}" - distTagCmd + versionCmd - The CLI to execute which tags an NPM release. + The CLI to execute which sets the dev version to release under. - "npm dist-tag add ${packageName}@${version} ${tag}" + "npm version --no-git-tag-version ${version}"

@@ -372,13 +357,13 @@ publish.standard(); - distTagHint + publishDevHint - A hint for addressing an issue where applying a distribution tag fails. + A hint for addressing an issue where publishing to the registry fails. - "If the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n" + "Ensure that you have access to publish to the registry and that the current version does not already exist.\nIf the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n" diff --git a/package.json b/package.json index 0a9800c..d25cb19 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,8 @@ "revisionCmd": "git rev-parse --verify --short HEAD", "packCmd": "npm pack", "publishCmd": "npm publish", + "publishDevCmd": "npm publish --tag ${devTag}", "versionCmd": "npm version --no-git-tag-version ${version}", - "distTagCmd": "npm dist-tag add ${packageName}@${version} ${tag}", "cleanCmd": "git checkout -- package.json", "vcTagCmd": "git tag -a v${version} -m 'Tagging the ${version} release'", "pushVCTagCmd": "git push ${remote} v${version}", @@ -58,7 +58,7 @@ "changesHint": "Address uncommitted changes: Commit \"git commit -a\", Stash \"git stash\" or Clean \"git reset --hard\"\n", "checkRemoteHint": "Run \"git remote -v\" for a list of available remote repositories.\n", "publishHint": "Ensure that you have access to publish to the registry and that the current version does not already exist.\n", - "distTagHint": "If the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n", + "publishDevHint": "Ensure that you have access to publish to the registry and that the current version does not already exist.\nIf the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n", "vcTagHint": "If the tag already exists, run \"git tag -d v${version}\" to remove the existing tag.\n", "pushVCTagHint": "If the tag already exists, run \"git push ${remote} :refs/tags/v${version} to remove the existing tag.\n" } diff --git a/publish.js b/publish.js index c76236b..2d33160 100644 --- a/publish.js +++ b/publish.js @@ -223,35 +223,20 @@ publish.getDevVersion = function (moduleVersion, options) { * If isTest is specified, it will instead create a tarball in the local directory. * * @param isTest {Boolean} - indicates if this is a test run or not - * @param options {Object} - e.g. {"packCmd": "npm pack", "publishCmd": "npm publish", "publishHint": "publish hint"} + * @param isDev {Boolean} - indicates if this is a development (true) or standard (false) release + * @param options {Object} - e.g. {"packCmd": "npm pack", "publishCmd": "npm publish", "publishDevCmd": "npm publish --tag", "publishHint": "publish hint", "publishDevHint": "publish dev hint", devTag: "dev"} */ -publish.pubImpl = function (isTest, options) { +publish.pubImpl = function (isTest, isDev, options) { if (isTest) { // create a local tarball publish.execSyncFromTemplate(options.packCmd); } else { // publish to npm - publish.execSyncFromTemplate(options.publishCmd, {}, options.publishHint); + var pubCmd = isDev ? options.publishDevCmd : options.publishCmd; + publish.execSyncFromTemplate(pubCmd, options, options.publishHint); } }; -/** - * Tags the specified version with the specified dist-tag - * If it is a test run, the tag command will be output to the console. - * - * @param isTest {Boolean} - indicates if this is a test run or not - * @param version {String} - a string indicating which version to tag - * @param tag {String} - the dist-tag to apply - * @param options {Object} - e.g. {"distTagCmd": "npm dist-tag add ${packageName}@${version} ${tag}", "distTagHint": "dist tag hint"} - */ -publish.tag = function (isTest, packageName, version, tag, options) { - publish.execSyncFromTemplate(options.distTagCmd, { - packageName: packageName, - version: version, - tag: tag - }, options.distTagHint, isTest); -}; - /** * Applies a version control tag to the latest commit * @@ -328,8 +313,7 @@ publish.dev = function (isTest, options) { try { // publish - publish.pubImpl(isTest, opts); - publish.tag(isTest, modulePkg.name, devVersion, opts.devTag, opts); + publish.pubImpl(isTest, true, opts); } finally { // cleanup changes publish.clean(opts.moduleRoot, opts); @@ -365,7 +349,7 @@ publish.standard = function (isTest, options) { publish.tagVC (isTest, modulePkg.version, opts); // publish - publish.pubImpl(isTest, opts); + publish.pubImpl(isTest, false, opts); }; module.exports = publish; diff --git a/tests/publishTests.js b/tests/publishTests.js index 4a5d26c..76e840d 100644 --- a/tests/publishTests.js +++ b/tests/publishTests.js @@ -318,24 +318,61 @@ console.log("\n*** publish.pubImpl ***"); var pubImplFixture = [{ isTest: true, + isDev: false, packCmd: "pack", - publishCmd: "shouldn't publish" + publishCmd: "shouldn't publish", + publishDevCmd: "shouldn't publish dev" }, { isTest: false, + isDev: false, packCmd: "shouldn't pack", - publishCmd: "publish" + publishCmd: "publish", + publishDevCmd: "shouldn't publish dev" }, { + isDev: false, packCmd: "shouldn't pack", - publishCmd: "publish" + publishCmd: "publish", + publishDevCmd: "shouldn't publish dev" +}, { + isDev: true, + packCmd: "shouldn't pack", + publishCmd: "shouldn't publish", + publishDevCmd: "publish dev" +}, { + isTest: false, + isDev: true, + packCmd: "pack", + publishCmd: "shouldn't publish", + publishDevCmd: "publish dev" +}, { + isTest: true, + isDev: true, + packCmd: "pack", + publishCmd: "shouldn't publish", + publishDevCmd: "shouldn't publish dev" +}, { + isTest: false, + packCmd: "shouldn't pack", + publishCmd: "publish", + publishDevCmd: "shouldn't publish dev" +}, { + isTest: true, + packCmd: "pack", + publishCmd: "shouldn't publish", + publishDevCmd: "shouldn't publish dev" +}, { + packCmd: "shouldn't pack", + publishCmd: "publish", + publishDevCmd: "shouldn't publish dev" }]; pubImplFixture.forEach(function (fixture) { - console.log("pubImpl test - isTest: " + fixture.isTest + " packCmd: " + fixture.packCmd + " publishCmd: " + fixture.publishCmd); + console.log("pubImpl test - isTest: " + fixture.isTest + "isDev: " + fixture.isDev + " packCmd: " + fixture.packCmd + " publishCmd: " + fixture.publishCmd + " publishDevCmd: " + fixture.publishDevCmd); var exec = sinon.stub(publish, "execSync"); - var expected = fixture[fixture.isTest ? "packCmd" : "publishCmd"]; + var expected = fixture.isTest ? fixture.packCmd : fixture[fixture.isDev ? "publishDevCmd" : "publishCmd"]; - publish.pubImpl(fixture.isTest, fixture); + publish.pubImpl(fixture.isTest, fixture.isDev, fixture); assert(exec.calledOnce, "execSync should have been called"); assert(exec.calledWith(expected), "execSync should have been called with: " + expected); @@ -343,56 +380,6 @@ pubImplFixture.forEach(function (fixture) { publish.execSync.restore(); }); -/*************** - * publish.tag * - ***************/ -console.log("\n*** publish.tag ***"); - -var tagFixture = [{ - isTest: true, - packageName: "test1", - version: "1.0.0", - tag: "tag", - distTagCmd: "add tag ${tag} to ${packageName} at ${version}", - expected: "add tag tag to test1 at 1.0.0" -}, { - isTest: false, - packageName: "test2", - version: "2.0.0", - tag: "tag2", - distTagCmd: "add tag ${tag} to ${packageName} at ${version}", - expected: "add tag tag2 to test2 at 2.0.0" -}, { - version: "3.0.0", - packageName: "test3", - tag: "tag3", - distTagCmd: "add tag ${tag} to ${packageName} at ${version}", - expected: "add tag tag3 to test3 at 3.0.0" -}]; - -tagFixture.forEach(function (fixture) { - console.log("tag test - isTest: " + fixture.isTest + " packageName: " + fixture.packageName + " version: " + fixture.version + " tag: " + fixture.tag + " distTagCmd: " + fixture.distTagCmd); - - var toStub = ["execSync", "log"]; - var stub = createStubs(publish, toStub); - var expectedLog = "Executing Command: " + fixture.expected; - - publish.tag(fixture.isTest, fixture.packageName, fixture.version, fixture.tag, fixture); - - assert(stub.log.calledOnce, "console.log should have been called"); - assert(stub.log.calledWith(expectedLog), "console.log should have been called with: " + expectedLog); - - if (fixture.isTest) { - assert(!stub.execSync.called, "execSync should not have been called"); - } else { - assert(stub.execSync.calledOnce, "execSync should have been called"); - assert(stub.execSync.calledWith(fixture.expected), "execSync should have been called with: " + fixture.expected); - } - - // remove stubs - removeStubs(publish, toStub); -}); - /***************** * publish.clean * *****************/ @@ -461,8 +448,8 @@ var publishFixture = [{ "revisionCmd": "dry run get revision", "packCmd": "dry run pack", "publishCmd": "dry run publish", + "publishDevCmd": "dry run npm publish dev", "versionCmd": "dry run version", - "distTagCmd": "dry run set tag", "cleanCmd": "dry run clean", "vcTagCmd": "dry run vc tag", "pushVCTagCmd": "dry run push vc tag", @@ -473,7 +460,7 @@ var publishFixture = [{ "changesHint": "dry run changes hint\n", "checkRemoteHint": "dry run check remote hint\n", "publishHint": "dry run publish hint\n", - "distTagHint": "dry run dist tag hint\n", + "publishDevHint": "dry run publish dev hint\n", "vcTagHint": "dry run vc tag hint\n", "pushVCTagHint": "dry run push vc tag hint\n" } @@ -486,8 +473,8 @@ var publishFixture = [{ "revisionCmd": "get revision", "packCmd": "pack", "publishCmd": "publish", + "publishDevCmd": "publish dev", "versionCmd": "version", - "distTagCmd": "set tag", "cleanCmd": "clean", "vcTagCmd": "vc tag", "pushVCTagCmd": "push vc tag", @@ -498,7 +485,7 @@ var publishFixture = [{ "changesHint": "changes hint\n", "checkRemoteHint": "check remote hint\n", "publishHint": "publish hint\n", - "distTagHint": "dist tag hint\n", + "publishDevHint": "publish dev hint\n", "vcTagHint": "vc tag hint\n", "pushVCTagHint": "push vc tag hint\n" } @@ -515,7 +502,7 @@ publishFixture.forEach(function (fixture) { var optsString = JSON.stringify(fixture.options || {}); console.log("dev test - isTest: " + fixture.isTest, " options: " + optsString + "\n"); - var toStub = ["checkChanges", "getDevVersion", "setVersion", "pubImpl", "tag", "clean"]; + var toStub = ["checkChanges", "getDevVersion", "setVersion", "pubImpl", "clean"]; var stub = createStubs(publish, toStub); var moduleVersion = modulePackage.version; var devVersion = moduleVersion + "-testVersion"; @@ -530,11 +517,9 @@ publishFixture.forEach(function (fixture) { assert(stub.setVersion.calledOnce, "setVersion should have been called"); assert(stub.setVersion.calledWith(devVersion, fixture.options), "setVersion should have been called with: " + devVersion + ", " + optsString); assert(stub.pubImpl.calledOnce, "pubImpl should have been called"); - assert(stub.pubImpl.calledWith(fixture.isTest, fixture.options), modulePackage); - assert(stub.tag.calledOnce, "tag should have been called"); - assert(stub.tag.calledWith(fixture.isTest, modulePackage.name, devVersion, fixture.options.devTag, fixture.options), "tag should have been called with: " + fixture.isTest + ", " + modulePackage.name + ", " + devVersion + ", " + fixture.options.devTag + ", " + optsString); + assert(stub.pubImpl.calledWith(fixture.isTest, true, fixture.options), modulePackage); assert(stub.clean.calledOnce, "clean should have been called"); - assert(stub.clean.calledWith(fixture.options.moduleRoot, fixture.options), "clean should have been called with: " + fixture.options.moduleRoot + ", " + optsString); + assert(stub.clean.calledWith(fixture.options.moduleRoot, fixture.options), "clean should have been called with: " + fixture.options.moduleRoot + ", true, " + optsString); removeStubs(publish, toStub); }); @@ -561,7 +546,7 @@ publishFixture.forEach(function (fixture) { assert(stub.tagVC.calledOnce, "tagVC should have been called"); assert(stub.tagVC.calledWith(fixture.isTest, modulePackage.version, fixture.options), "tagVC should have been called with: " + fixture.isTest + " ," + modulePackage.version + " ," + optsString); assert(stub.pubImpl.calledOnce, "pubImpl should have been called"); - assert(stub.pubImpl.calledWith(fixture.isTest, fixture.options), "pubImpl should have been called with: " + fixture.isTest + ", " + optsString); + assert(stub.pubImpl.calledWith(fixture.isTest, false, fixture.options), "pubImpl should have been called with: " + fixture.isTest + ", false, " + optsString); removeStubs(publish, toStub); });