Skip to content

Commit 371d992

Browse files
fentbcoe
authored andcommitted
feat: manifest.json support (#236)
1 parent 6dac27b commit 371d992

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ const commit = require('./lib/lifecycles/commit')
77
const tag = require('./lib/lifecycles/tag')
88

99
module.exports = function standardVersion (argv) {
10-
var pkgPath = path.resolve(process.cwd(), './package.json')
11-
var pkg = require(pkgPath)
10+
var pkg
11+
bump.pkgFiles.forEach((filename) => {
12+
if (pkg) return
13+
var pkgPath = path.resolve(process.cwd(), filename)
14+
try {
15+
pkg = require(pkgPath)
16+
} catch (err) {}
17+
})
18+
if (!pkg) {
19+
return Promise.reject(new Error('no package file found'))
20+
}
1221
var newVersion = pkg.version
1322
var defaults = require('./defaults')
1423
var args = Object.assign({}, defaults, argv)

lib/lifecycles/bump.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ Bump.getUpdatedConfigs = function () {
4646
return configsToUpdate
4747
}
4848

49+
Bump.pkgFiles = [
50+
'package.json',
51+
'bower.json',
52+
'manifest.json'
53+
]
54+
55+
Bump.lockFiles = [
56+
'package-lock.json',
57+
'npm-shrinkwrap.json'
58+
]
59+
4960
function getReleaseType (prerelease, expectedReleaseType, currentVersion) {
5061
if (isString(prerelease)) {
5162
if (isInPrerelease(currentVersion)) {
@@ -138,10 +149,9 @@ function bumpVersion (releaseAs, callback) {
138149
*/
139150
function updateConfigs (args, newVersion) {
140151
const dotgit = DotGitignore()
141-
configsToUpdate[path.resolve(process.cwd(), './package.json')] = false
142-
configsToUpdate[path.resolve(process.cwd(), './package-lock.json')] = false
143-
configsToUpdate[path.resolve(process.cwd(), './npm-shrinkwrap.json')] = false
144-
configsToUpdate[path.resolve(process.cwd(), './bower.json')] = false
152+
Bump.pkgFiles.concat(Bump.lockFiles).forEach((filename) => {
153+
configsToUpdate[path.resolve(process.cwd(), filename)] = false
154+
})
145155
Object.keys(configsToUpdate).forEach(function (configPath) {
146156
try {
147157
if (dotgit.ignore(configPath)) return

test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ function writeBowerJson (version, option) {
5454
fs.writeFileSync('bower.json', JSON.stringify(bower), 'utf-8')
5555
}
5656

57+
function writeManifestJson (version, option) {
58+
option = option || {}
59+
var manifest = Object.assign(option, {version: version})
60+
fs.writeFileSync('manifest.json', JSON.stringify(manifest), 'utf-8')
61+
}
62+
5763
function writeNpmShrinkwrapJson (version, option) {
5864
option = option || {}
5965
var shrinkwrap = Object.assign(option, { version: version })
@@ -693,6 +699,16 @@ describe('standard-version', function () {
693699
})
694700
})
695701

702+
describe('without a package file to bump', function () {
703+
it('should exit with error', function () {
704+
shell.rm('package.json')
705+
return require('./index')({silent: true})
706+
.catch((err) => {
707+
err.message.should.equal('no package file found')
708+
})
709+
})
710+
})
711+
696712
describe('bower.json support', function () {
697713
beforeEach(function () {
698714
writeBowerJson('1.0.0')
@@ -710,6 +726,23 @@ describe('standard-version', function () {
710726
})
711727
})
712728

729+
describe('manifest.json support', function () {
730+
beforeEach(function () {
731+
writeManifestJson('1.0.0')
732+
})
733+
734+
it('bumps version # in manifest.json', function () {
735+
commit('feat: first commit')
736+
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
737+
commit('feat: new feature!')
738+
return require('./index')({silent: true})
739+
.then(() => {
740+
JSON.parse(fs.readFileSync('manifest.json', 'utf-8')).version.should.equal('1.1.0')
741+
getPackageVersion().should.equal('1.1.0')
742+
})
743+
})
744+
})
745+
713746
describe('npm-shrinkwrap.json support', function () {
714747
beforeEach(function () {
715748
writeNpmShrinkwrapJson('1.0.0')

0 commit comments

Comments
 (0)