Skip to content

Commit

Permalink
fix(init): no update lint:js command (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Oct 10, 2017
1 parent ed0df68 commit 6f0acc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const path = require('path')
const fs = require('fs-extra')
const originalPackage = require('../package.json')

const targetProps = ['scripts', 'lint-staged']

function stdout(str) {
process.stdout.write(`${str}\n`)
}
Expand All @@ -30,11 +28,18 @@ class Init {
async updatePackageFile() {
const packageInfo = JSON.parse(await this.readFile('package.json'))

targetProps.forEach((prop) => {
packageInfo[prop] = { ...originalPackage[prop], ...packageInfo[prop] }
const { scripts } = packageInfo
Object.assign(scripts, {
'test:watch': `${scripts.test} --watch`,
'test:coverage': 'echo "unsupported." && exit 1',
})
packageInfo.scripts['test:watch'] = `${packageInfo.scripts.test} --watch`
packageInfo.scripts['test:coverage'] = 'echo "unsupported." && exit 1'
Object.keys(originalPackage.scripts)
.filter(key => !(key === 'test' || key.startsWith('test:')))
.forEach((key) => {
scripts[key] = originalPackage.scripts[key]
})

Object.assign(packageInfo['lint-staged'], originalPackage['lint-staged'])

await this.writeFile('package.json', JSON.stringify(packageInfo, null, 2))
}
Expand Down
4 changes: 2 additions & 2 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ suite('init', () => {
setup('package.json', async () => {
packageJson = path.join(workDir, 'package.json')
await fs.writeJson(packageJson, {
scripts: { test: 'abc' },
scripts: { test: 'abc', 'lint:js': 'eslint .' },
'lint-staged': { '*.css': 'xyz' },
})
})
Expand All @@ -36,6 +36,7 @@ suite('init', () => {
const pkg = await fs.readJson(packageJson)

assert.deepStrictEqual(pkg.scripts, {
build: 'babel src/ -d lib/',
commitmsg: 'commitlint -e',
'lint:js': 'eslint --max-warnings=-1 --ignore-path=.gitignore --ext=.js --ext=.jsx .',
'lint:js:fix': 'npm run lint:js -- --fix',
Expand All @@ -47,7 +48,6 @@ suite('init', () => {
test: 'abc',
'test:watch': 'abc --watch',
'test:coverage': 'echo "unsupported." && exit 1',
build: 'babel src/ -d lib/',
})

assert.deepStrictEqual(pkg['lint-staged'], {
Expand Down

0 comments on commit 6f0acc9

Please sign in to comment.