Skip to content

Commit

Permalink
feat: do not update/commit files in .gitignore (conventional-changelo…
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Jan 3, 2018
1 parent c5e1ee2 commit 4fd3bc2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ npm-debug.log

# coverage
coverage
package-lock.json
5 changes: 5 additions & 0 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict'

const chalk = require('chalk')
const checkpoint = require('../checkpoint')
const conventionalRecommendedBump = require('conventional-recommended-bump')
const figures = require('figures')
const fs = require('fs')
const DotGitignore = require('dotgitignore')
const path = require('path')
const runLifecycleScript = require('../run-lifecycle-script')
const semver = require('semver')
Expand Down Expand Up @@ -134,12 +137,14 @@ function bumpVersion (releaseAs, callback) {
* @return {string}
*/
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
Object.keys(configsToUpdate).forEach(function (configPath) {
try {
if (dotgit.ignore(configPath)) return
var stat = fs.lstatSync(configPath)
if (stat.isFile()) {
var config = require(configPath)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"chalk": "^1.1.3",
"conventional-changelog": "^1.1.0",
"conventional-recommended-bump": "^1.0.0",
"dotgitignore": "^1.0.3",
"figures": "^1.5.0",
"fs-access": "^1.0.0",
"semver": "^5.1.0",
Expand Down
56 changes: 50 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,32 @@ describe('cli', function () {
var pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal(['{', ' "version": "1.1.0"', '}', ''].join('\n'))
})

it('exits with error code if "scripts" is not an object', () => {
writePackageJson('1.0.0', {
'standard-version': {
scripts: 'echo hello'
}
})

commit('feat: first commit')
var result = execCli()
result.code.should.equal(1)
result.stderr.should.match(/scripts must be an object/)
})

it('exits with error code if "skip" is not an object', () => {
writePackageJson('1.0.0', {
'standard-version': {
skip: true
}
})

commit('feat: first commit')
var result = execCli()
result.code.should.equal(1)
result.stderr.should.match(/skip must be an object/)
})
})

describe('standard-version', function () {
Expand Down Expand Up @@ -672,15 +698,14 @@ describe('standard-version', function () {
writeBowerJson('1.0.0')
})

it('bumps version # in bower.json', function (done) {
it('bumps version # in bower.json', 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})
return require('./index')({silent: true})
.then(() => {
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
return done()
})
})
})
Expand All @@ -706,17 +731,17 @@ describe('standard-version', function () {
describe('package-lock.json support', function () {
beforeEach(function () {
writePackageLockJson('1.0.0')
fs.writeFileSync('.gitignore', '', 'utf-8')
})

it('bumps version # in package-lock.json', function (done) {
it('bumps version # in package-lock.json', 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})
return require('./index')({silent: true})
.then(() => {
JSON.parse(fs.readFileSync('package-lock.json', 'utf-8')).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
return done()
})
})
})
Expand Down Expand Up @@ -765,4 +790,23 @@ describe('standard-version', function () {
})
})
})

describe('.gitignore', () => {
beforeEach(function () {
writeBowerJson('1.0.0')
})

it('does not update files present in .gitignore', () => {
fs.writeFileSync('.gitignore', 'bower.json', 'utf-8')

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('bower.json', 'utf-8')).version.should.equal('1.0.0')
getPackageVersion().should.equal('1.1.0')
})
})
})
})

0 comments on commit 4fd3bc2

Please sign in to comment.