Skip to content

Commit

Permalink
feat: manifest.json support (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
fent authored and bcoe committed May 21, 2018
1 parent 6dac27b commit 371d992
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 14 additions & 4 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 371d992

Please sign in to comment.