Skip to content

Commit 4fd3bc2

Browse files
authored
feat: do not update/commit files in .gitignore (#230)
1 parent c5e1ee2 commit 4fd3bc2

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ npm-debug.log
1414

1515
# coverage
1616
coverage
17+
package-lock.json

lib/lifecycles/bump.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
'use strict'
2+
13
const chalk = require('chalk')
24
const checkpoint = require('../checkpoint')
35
const conventionalRecommendedBump = require('conventional-recommended-bump')
46
const figures = require('figures')
57
const fs = require('fs')
8+
const DotGitignore = require('dotgitignore')
69
const path = require('path')
710
const runLifecycleScript = require('../run-lifecycle-script')
811
const semver = require('semver')
@@ -134,12 +137,14 @@ function bumpVersion (releaseAs, callback) {
134137
* @return {string}
135138
*/
136139
function updateConfigs (args, newVersion) {
140+
const dotgit = DotGitignore()
137141
configsToUpdate[path.resolve(process.cwd(), './package.json')] = false
138142
configsToUpdate[path.resolve(process.cwd(), './package-lock.json')] = false
139143
configsToUpdate[path.resolve(process.cwd(), './npm-shrinkwrap.json')] = false
140144
configsToUpdate[path.resolve(process.cwd(), './bower.json')] = false
141145
Object.keys(configsToUpdate).forEach(function (configPath) {
142146
try {
147+
if (dotgit.ignore(configPath)) return
143148
var stat = fs.lstatSync(configPath)
144149
if (stat.isFile()) {
145150
var config = require(configPath)

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"chalk": "^1.1.3",
4242
"conventional-changelog": "^1.1.0",
4343
"conventional-recommended-bump": "^1.0.0",
44+
"dotgitignore": "^1.0.3",
4445
"figures": "^1.5.0",
4546
"fs-access": "^1.0.0",
4647
"semver": "^5.1.0",

test.js

+50-6
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,32 @@ describe('cli', function () {
590590
var pkgJson = fs.readFileSync('package.json', 'utf-8')
591591
pkgJson.should.equal(['{', ' "version": "1.1.0"', '}', ''].join('\n'))
592592
})
593+
594+
it('exits with error code if "scripts" is not an object', () => {
595+
writePackageJson('1.0.0', {
596+
'standard-version': {
597+
scripts: 'echo hello'
598+
}
599+
})
600+
601+
commit('feat: first commit')
602+
var result = execCli()
603+
result.code.should.equal(1)
604+
result.stderr.should.match(/scripts must be an object/)
605+
})
606+
607+
it('exits with error code if "skip" is not an object', () => {
608+
writePackageJson('1.0.0', {
609+
'standard-version': {
610+
skip: true
611+
}
612+
})
613+
614+
commit('feat: first commit')
615+
var result = execCli()
616+
result.code.should.equal(1)
617+
result.stderr.should.match(/skip must be an object/)
618+
})
593619
})
594620

595621
describe('standard-version', function () {
@@ -672,15 +698,14 @@ describe('standard-version', function () {
672698
writeBowerJson('1.0.0')
673699
})
674700

675-
it('bumps version # in bower.json', function (done) {
701+
it('bumps version # in bower.json', function () {
676702
commit('feat: first commit')
677703
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
678704
commit('feat: new feature!')
679-
require('./index')({silent: true})
705+
return require('./index')({silent: true})
680706
.then(() => {
681707
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.1.0')
682708
getPackageVersion().should.equal('1.1.0')
683-
return done()
684709
})
685710
})
686711
})
@@ -706,17 +731,17 @@ describe('standard-version', function () {
706731
describe('package-lock.json support', function () {
707732
beforeEach(function () {
708733
writePackageLockJson('1.0.0')
734+
fs.writeFileSync('.gitignore', '', 'utf-8')
709735
})
710736

711-
it('bumps version # in package-lock.json', function (done) {
737+
it('bumps version # in package-lock.json', function () {
712738
commit('feat: first commit')
713739
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
714740
commit('feat: new feature!')
715-
require('./index')({silent: true})
741+
return require('./index')({silent: true})
716742
.then(() => {
717743
JSON.parse(fs.readFileSync('package-lock.json', 'utf-8')).version.should.equal('1.1.0')
718744
getPackageVersion().should.equal('1.1.0')
719-
return done()
720745
})
721746
})
722747
})
@@ -765,4 +790,23 @@ describe('standard-version', function () {
765790
})
766791
})
767792
})
793+
794+
describe('.gitignore', () => {
795+
beforeEach(function () {
796+
writeBowerJson('1.0.0')
797+
})
798+
799+
it('does not update files present in .gitignore', () => {
800+
fs.writeFileSync('.gitignore', 'bower.json', 'utf-8')
801+
802+
commit('feat: first commit')
803+
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
804+
commit('feat: new feature!')
805+
return require('./index')({silent: true})
806+
.then(() => {
807+
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.0.0')
808+
getPackageVersion().should.equal('1.1.0')
809+
})
810+
})
811+
})
768812
})

0 commit comments

Comments
 (0)