Repository: conventional-changelog/standard-version
Pull request #236 (2018-03-04 06:03:09)

feat: manifest.json support
Hi there,

I've added support for updating a `manifest.json` file, which is used in Google Chrome extensions. 
There's potential in standard-release to be used for software packages that are not node.js related or don't use npm. And I think this is a good start towards that.

Thank you for this tool btw, it's helped me a lot!

stevemao: I guess we could merge this before we come up with a plugin strategy?
fent: Just noticed I left the `.only` on the test. But now some other tests fail.

Will try to figure out why.
MAGALY956: Y<a class="twitter-timeline" href="https://twitter.com/ThePSF?ref_src=twsrc%5Etfw">Tweets by ThePSF</a> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
coveralls: 
[![Coverage Status](https://coveralls.io/builds/15912456/badge)](https://coveralls.io/builds/15912456)

Coverage decreased (-0.1%) to 99.853% when pulling **4a030cd26bdd451b67a77a98481641beaa16f85e on fent:manifest** into **9a996072433935f79060ed252361a7707e988bf2 on conventional-changelog:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/15912456/badge)](https://coveralls.io/builds/15912456)

Coverage decreased (-0.1%) to 99.853% when pulling **4a030cd26bdd451b67a77a98481641beaa16f85e on fent:manifest** into **9a996072433935f79060ed252361a7707e988bf2 on conventional-changelog:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/15912456/badge)](https://coveralls.io/builds/15912456)

Coverage decreased (-0.1%) to 99.853% when pulling **4a030cd26bdd451b67a77a98481641beaa16f85e on fent:manifest** into **9a996072433935f79060ed252361a7707e988bf2 on conventional-changelog:master**.


Patch:
diff --git a/LICENSE.txt b/LICENSE.txt
index 836440b..5606e87 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,3 +1,5 @@
+ISC License
+
 Copyright (c) 2016, Contributors
 
 Permission to use, copy, modify, and/or distribute this software
diff --git a/index.js b/index.js
index b5936ee..0c685e0 100755
--- a/index.js
+++ b/index.js
@@ -7,8 +7,17 @@ const commit = require('./lib/lifecycles/commit')
 const tag = require('./lib/lifecycles/tag')
 
 module.exports = function standardVersion (argv) {
-  var pkgPath = path.resolve(process.cwd(), './package.json')
-  var pkg = require(pkgPath)
+  var pkg
+  bump.pkgFiles.forEach((filename) => {
+    if (pkg) return
+    var pkgPath = path.resolve(process.cwd(), filename)
+    try {
+      pkg = require(pkgPath)
+    } catch (err) {}
+  })
+  if (!pkg) {
+    return Promise.reject(new Error('no package file found'))
+  }
   var newVersion = pkg.version
   var defaults = require('./defaults')
   var args = Object.assign({}, defaults, argv)
diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js
index 4ab091c..5021a80 100644
--- a/lib/lifecycles/bump.js
+++ b/lib/lifecycles/bump.js
@@ -46,6 +46,17 @@ Bump.getUpdatedConfigs = function () {
   return configsToUpdate
 }
 
+Bump.pkgFiles = [
+  'package.json',
+  'bower.json',
+  'manifest.json'
+]
+
+Bump.lockFiles = [
+  'package-lock.json',
+  'npm-shrinkwrap.json'
+]
+
 function getReleaseType (prerelease, expectedReleaseType, currentVersion) {
   if (isString(prerelease)) {
     if (isInPrerelease(currentVersion)) {
@@ -138,10 +149,9 @@ function bumpVersion (releaseAs, callback) {
  */
 function updateConfigs (args, newVersion) {
   const dotgit = DotGitignore()
-  configsToUpdate[path.resolve(process.cwd(), './package.json')] = false
-  configsToUpdate[path.resolve(process.cwd(), './package-lock.json')] = false
-  configsToUpdate[path.resolve(process.cwd(), './npm-shrinkwrap.json')] = false
-  configsToUpdate[path.resolve(process.cwd(), './bower.json')] = false
+  Bump.pkgFiles.concat(Bump.lockFiles).forEach((filename) => {
+    configsToUpdate[path.resolve(process.cwd(), filename)] = false
+  })
   Object.keys(configsToUpdate).forEach(function (configPath) {
     try {
       if (dotgit.ignore(configPath)) return
diff --git a/lib/lifecycles/changelog.js b/lib/lifecycles/changelog.js
index 1eb1617..136f830 100644
--- a/lib/lifecycles/changelog.js
+++ b/lib/lifecycles/changelog.js
@@ -30,7 +30,8 @@ function outputChangelog (args, newVersion) {
     var context
     if (args.dryRun) context = {version: newVersion}
     var changelogStream = conventionalChangelog({
-      preset: 'angular'
+      preset: 'angular',
+      tagPrefix: args.tagPrefix
     }, context, {merges: null})
       .on('error', function (err) {
         return reject(err)


Test patch:
diff --git a/test.js b/test.js
index a2e0450..8895603 100644
--- a/test.js
+++ b/test.js
@@ -54,6 +54,12 @@ function writeBowerJson (version, option) {
   fs.writeFileSync('bower.json', JSON.stringify(bower), 'utf-8')
 }
 
+function writeManifestJson (version, option) {
+  option = option || {}
+  var manifest = Object.assign(option, {version: version})
+  fs.writeFileSync('manifest.json', JSON.stringify(manifest), 'utf-8')
+}
+
 function writeNpmShrinkwrapJson (version, option) {
   option = option || {}
   var shrinkwrap = Object.assign(option, { version: version })
@@ -693,6 +699,16 @@ describe('standard-version', function () {
       })
   })
 
+  describe('without a package file to bump', function () {
+    it('should exit with error', function () {
+      shell.rm('package.json')
+      return require('./index')({silent: true})
+        .catch((err) => {
+          err.message.should.equal('no package file found')
+        })
+    })
+  })
+
   describe('bower.json support', function () {
     beforeEach(function () {
       writeBowerJson('1.0.0')
@@ -710,6 +726,23 @@ describe('standard-version', function () {
     })
   })
 
+  describe('manifest.json support', function () {
+    beforeEach(function () {
+      writeManifestJson('1.0.0')
+    })
+
+    it('bumps version # in manifest.json', function () {
+      commit('feat: first commit')
+      shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
+      commit('feat: new feature!')
+      return require('./index')({silent: true})
+        .then(() => {
+          JSON.parse(fs.readFileSync('manifest.json', 'utf-8')).version.should.equal('1.1.0')
+          getPackageVersion().should.equal('1.1.0')
+        })
+    })
+  })
+
   describe('npm-shrinkwrap.json support', function () {
     beforeEach(function () {
       writeNpmShrinkwrapJson('1.0.0')