Skip to content

Commit

Permalink
feat(init): write commitlint.config.js (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Sep 24, 2017
1 parent d2f6cd8 commit a1266b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'commitlint',
'coverage',
'release',
'init',
]],
},
}
17 changes: 14 additions & 3 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,31 @@ async function copyEditorConfig(baseDir) {
process.stdout.write(`${target} was updated.\n`)
}

async function writeConfigFile(baseDir, fileName, fileContent) {
const target = path.join(baseDir, fileName)
await fs.writeFile(target, fileContent)
process.stdout.write(`${target} was wrote.\n`)
}

async function writeESLintConfig(baseDir) {
const target = path.join(baseDir, '.eslintrc.js')
await fs.writeFile(target, `module.exports = {
writeConfigFile(baseDir, '.eslintrc.js', `module.exports = {
root: true,
extends: ['ybiquitous'],
}
`)
}

process.stdout.write(`${target} was updated.\n`)
async function writeCommitlintConfig(baseDir) {
writeConfigFile(baseDir, 'commitlint.config.js', `module.exports = {
extends: ['@commitlint/config-angular'],
}
`)
}

module.exports = async function init() {
const baseDir = process.cwd()
await updatePackageFile(baseDir)
await copyEditorConfig(baseDir)
await writeESLintConfig(baseDir)
await writeCommitlintConfig(baseDir)
}
10 changes: 10 additions & 0 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ suite('init', () => {
root: true,
extends: ['ybiquitous'],
}
`)
})

test('write commitlint.config.js', async () => {
await exec('init')

const wrote = await fs.readFile(path.join(workDir, 'commitlint.config.js'), 'utf8')
assert(wrote === `module.exports = {
extends: ['@commitlint/config-angular'],
}
`)
})
})

0 comments on commit a1266b8

Please sign in to comment.