From e35110d3cc9cacebcb0521d9faabd32e798fd36e Mon Sep 17 00:00:00 2001 From: ybiquitous Date: Thu, 31 Aug 2017 03:47:29 +0900 Subject: [PATCH] feat: write `.eslintrc.js` on `init` command --- src/init.js | 13 ++++++++++++- src/init.test.js | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/init.js b/src/init.js index 1ebeb299..6c597eca 100644 --- a/src/init.js +++ b/src/init.js @@ -26,8 +26,19 @@ async function copyEditorConfig(baseDir) { process.stdout.write(`${target} was updated.\n`) } +async function writeESLintConfig(baseDir) { + const target = path.join(baseDir, '.eslintrc.js') + await fs.writeFile(target, `module.exports = { + root: true, + extends: ['ybiquitous'], +} +`) + + process.stdout.write(`${target} was updated.\n`) +} + module.exports = async function init(baseDir = process.cwd()) { await updatePackageFile(baseDir) - await copyEditorConfig(baseDir) + await writeESLintConfig(baseDir) } diff --git a/src/init.test.js b/src/init.test.js index cec84ccc..9de4ede2 100644 --- a/src/init.test.js +++ b/src/init.test.js @@ -52,11 +52,22 @@ suite('init', () => { }) }) - test('write .editorconfig', async () => { + test('copy .editorconfig', async () => { await init(workDir) const original = await fs.readFile(path.join(__dirname, '..', '.editorconfig'), 'utf8') - const wrote = await fs.readFile(path.join(workDir, '.editorconfig'), 'utf8') - assert(original === wrote) + const copy = await fs.readFile(path.join(workDir, '.editorconfig'), 'utf8') + assert(original === copy) + }) + + test('write .eslintrc.js', async () => { + await init(workDir) + + const wrote = await fs.readFile(path.join(workDir, '.eslintrc.js'), 'utf8') + assert(wrote === `module.exports = { + root: true, + extends: ['ybiquitous'], +} +`) }) })