diff --git a/package.json b/package.json index 2401c950..d0e57ef8 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "lint-staged": "^4.2.3", "markdownlint-cli": "^0.3.1", "npm-run-all": "^4.1.1", + "prepend-file-cli": "^1.0.6", "semver": "^5.4.1", "standard-version": "^4.2.0", "yargs": "^9.0.1" @@ -51,8 +52,7 @@ "babel-register": "^6.26.0", "codecov": "^2.3.0", "mocha": "^4.0.1", - "nyc": "^11.2.1", - "prepend-file-cli": "^1.0.6" + "nyc": "^11.2.1" }, "scripts": { "build": "babel src/ -d lib/", diff --git a/src/init.js b/src/init.js index 32dd6b82..94e973f4 100644 --- a/src/init.js +++ b/src/init.js @@ -28,6 +28,7 @@ class Init { async updatePackageFile() { const packageInfo = JSON.parse(await this.readFile('package.json')) + // update 'scripts' const { scripts } = packageInfo Object.assign(scripts, { 'test:watch': `${scripts.test} --watch`, @@ -39,7 +40,14 @@ class Init { scripts[key] = originalPackage.scripts[key] }) - Object.assign(packageInfo['lint-staged'], originalPackage['lint-staged']) + // update other keys + const keys = ['lint-staged', 'standard-version'] + keys.forEach((key) => { + if (!(key in packageInfo)) { + packageInfo[key] = {} + } + Object.assign(packageInfo[key], originalPackage[key]) + }) await this.writeFile('package.json', JSON.stringify(packageInfo, null, 2)) } diff --git a/test/init.test.js b/test/init.test.js index 377d501b..027ab53b 100644 --- a/test/init.test.js +++ b/test/init.test.js @@ -58,6 +58,12 @@ suite('init', () => { '*.md': 'markdownlint', '*.css': 'xyz', }) + + assert.deepStrictEqual(pkg['standard-version'], { + scripts: { + postchangelog: 'prepend CHANGELOG.md "\n"', + }, + }) }) test('copy .editorconfig', async () => {