Skip to content

Commit

Permalink
feat: makes the list of metadata files configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Aug 2, 2019
1 parent f34e39b commit 7e0739f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
10 changes: 10 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 12 additions & 1 deletion defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}

/**
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 1 addition & 14 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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/)
Expand All @@ -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')
})
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 7e0739f

Please sign in to comment.