From 7e0739fbebecdff3e24e93775457a531b5321ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20R=C3=A8gne?= Date: Fri, 2 Aug 2019 15:38:56 +0200 Subject: [PATCH] feat: makes the list of metadata files configurable --- command.js | 10 ++++++++++ defaults.js | 13 ++++++++++++- index.js | 2 +- lib/lifecycles/bump.js | 15 +-------------- test.js | 27 ++++++++++++++------------- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/command.js b/command.js index c03ce5604..8db41a8bb 100755 --- a/command.js +++ b/command.js @@ -96,6 +96,16 @@ const yargs = require('yargs') default: defaults.preset, describe: 'Commit message guideline preset' }) + .option('pkg-files', { + type: 'string', + default: defaults.pkgFiles, + describe: 'Configure metadata files' + }) + .option('lock-files', { + type: 'string', + default: defaults.lockFiles, + describe: 'Configure metadata-lock files' + }) .check((argv) => { if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) { throw Error('scripts must be an object') diff --git a/defaults.js b/defaults.js index 202b8f4d4..ee1b34f7c 100644 --- a/defaults.js +++ b/defaults.js @@ -12,7 +12,18 @@ const defaults = { skip: {}, dryRun: false, gitTagFallback: true, - preset: 'conventionalcommits' + preset: 'conventionalcommits', + pkgFiles: [ + 'package.json', + 'bower.json', + 'manifest.json', + 'composer.json' + ], + lockFiles: [ + 'package-lock.json', + 'npm-shrinkwrap.json', + 'composer.lock' + ] } /** diff --git a/index.js b/index.js index e40339887..d2e2d89b4 100755 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ module.exports = function standardVersion (argv) { } let pkg - bump.pkgFiles.forEach((filename) => { + argv.pkgFiles.forEach((filename) => { if (pkg) return let pkgPath = path.resolve(process.cwd(), filename) try { diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js index a2a5335ac..23d5b1cad 100644 --- a/lib/lifecycles/bump.js +++ b/lib/lifecycles/bump.js @@ -51,19 +51,6 @@ Bump.getUpdatedConfigs = function () { return configsToUpdate } -Bump.pkgFiles = [ - 'package.json', - 'bower.json', - 'manifest.json', - 'composer.json' -] - -Bump.lockFiles = [ - 'package-lock.json', - 'npm-shrinkwrap.json', - 'composer.lock' -] - function getReleaseType (prerelease, expectedReleaseType, currentVersion) { if (isString(prerelease)) { if (isInPrerelease(currentVersion)) { @@ -163,7 +150,7 @@ function bumpVersion (releaseAs, currentVersion, args) { */ function updateConfigs (args, newVersion) { const dotgit = DotGitignore() - Bump.pkgFiles.concat(Bump.lockFiles).forEach(function (filename) { + args.pkgFiles.concat(args.lockFiles).forEach(function (filename) { let configPath = path.resolve(process.cwd(), filename) try { if (dotgit.ignore(configPath)) return diff --git a/test.js b/test.js index 55a11bd8c..2975568b3 100644 --- a/test.js +++ b/test.js @@ -12,6 +12,7 @@ const semver = require('semver') const formatCommitMessage = require('./lib/format-commit-message') const cli = require('./command') const standardVersion = require('./index') +const defaults = require('./defaults') require('chai').should() @@ -822,7 +823,7 @@ describe('standard-version', function () { shell.exec('git tag -a v1.0.0 -m "my awesome first release"') commit('feat: new feature!') - require('./index')({ silent: true }) + require('./index')(Object.assign({}, defaults, { silent: true })) .catch((err) => { err.message.should.match(/bump err/) done() @@ -852,7 +853,7 @@ describe('standard-version', function () { shell.exec('git tag -a v1.0.0 -m "my awesome first release"') commit('feat: new feature!') - require('./index')({ silent: true }) + require('./index')(Object.assign({}, defaults, { silent: true })) .catch((err) => { err.message.should.match(/changelog err/) return done() @@ -865,7 +866,7 @@ describe('standard-version', function () { shell.exec('git tag -a v1.0.0 -m "my awesome first release"') commit('feat: new feature!') - require('./index')({ silent: true }) + require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { // check last commit message shell.exec('git log --oneline -n1').stdout.should.match(/chore\(release\): 1\.1\.0/) @@ -878,10 +879,10 @@ 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')({ + return require('./index')(Object.assign({}, defaults, { silent: true, gitTagFallback: false - }) + })) .catch((err) => { err.message.should.equal('no package file found') }) @@ -897,7 +898,7 @@ describe('standard-version', 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 }) + return require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.1.0') getPackageVersion().should.equal('1.1.0') @@ -914,7 +915,7 @@ describe('standard-version', 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 }) + return require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { JSON.parse(fs.readFileSync('manifest.json', 'utf-8')).version.should.equal('1.1.0') getPackageVersion().should.equal('1.1.0') @@ -931,7 +932,7 @@ describe('standard-version', function () { commit('feat: first commit') shell.exec('git tag -a v1.0.0 -m "my awesome first release"') commit('feat: new feature!') - require('./index')({ silent: true }) + require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { JSON.parse(fs.readFileSync('npm-shrinkwrap.json', 'utf-8')).version.should.equal('1.1.0') getPackageVersion().should.equal('1.1.0') @@ -950,7 +951,7 @@ describe('standard-version', 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 }) + return require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { JSON.parse(fs.readFileSync('package-lock.json', 'utf-8')).version.should.equal('1.1.0') getPackageVersion().should.equal('1.1.0') @@ -1014,7 +1015,7 @@ describe('standard-version', 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 }) + return require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.0.0') getPackageVersion().should.equal('1.1.0') @@ -1033,7 +1034,7 @@ describe('standard-version', 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 }) + return require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.0.0') getPackageVersion().should.equal('1.1.0') @@ -1045,7 +1046,7 @@ describe('standard-version', function () { it('defaults to 1.0.0 if no tags in git history', () => { shell.rm('package.json') commit('feat: first commit') - return require('./index')({ silent: true }) + return require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { const output = shell.exec('git tag') output.stdout.should.include('v1.1.0') @@ -1057,7 +1058,7 @@ describe('standard-version', function () { shell.exec('git tag -a v5.0.0 -m "a release"') shell.exec('git tag -a v3.0.0 -m "another release"') commit('feat: another commit') - return require('./index')({ silent: true }) + return require('./index')(Object.assign({}, defaults, { silent: true })) .then(() => { const output = shell.exec('git tag') output.stdout.should.include('v5.1.0')