From 661755b2574cefe5973f5ed9f37341a28e1e6d58 Mon Sep 17 00:00:00 2001 From: Rakan Nimer Date: Thu, 14 Nov 2019 09:01:23 +0200 Subject: [PATCH] feat(docz-core): copy eslint config to .docz (#1254) --- .../machine/services/create-resources.ts | 22 ++++++++++++++----- .../machine/services/exec-dev-command.ts | 12 ++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/core/docz-core/src/bundler/machine/services/create-resources.ts b/core/docz-core/src/bundler/machine/services/create-resources.ts index 8a1f8ad83..e3c8462eb 100644 --- a/core/docz-core/src/bundler/machine/services/create-resources.ts +++ b/core/docz-core/src/bundler/machine/services/create-resources.ts @@ -43,10 +43,22 @@ const copyAndModifyPkgJson = async (ctx: ServerMachineCtx) => { await fs.outputJSON(movePath, newPkg, { spaces: 2 }) } -const writeEslintRc = async ({ isDoczRepo }: ServerMachineCtx) => { - if (!isDoczRepo) return - const filepath = path.join(paths.docz, '.eslintrc') - await fs.outputJSON(filepath, { extends: 'react-app' }) +const writeEslintRc = async () => { + const possibleFilenames = [ + '.eslintrc.js', + '.eslintrc.yaml', + '.eslintrc.yml', + '.eslintrc.json', + '.eslintrc', + ] + for (const filename of possibleFilenames) { + const filepath = path.join(paths.root, filename) + const dest = path.join(paths.docz, filename) + if (fs.pathExistsSync(filepath)) { + await fs.copy(filepath, dest) + return + } + } } const copyEslintIgnore = async () => { @@ -108,7 +120,7 @@ export const createResources = async (ctx: ServerMachineCtx) => { try { copyDoczRc(ctx.args.config) await copyAndModifyPkgJson(ctx) - await writeEslintRc(ctx) + await writeEslintRc() await copyEslintIgnore() await writeNotFound() await writeGatsbyConfig(ctx) diff --git a/core/docz-core/src/bundler/machine/services/exec-dev-command.ts b/core/docz-core/src/bundler/machine/services/exec-dev-command.ts index 2409c5989..be50438da 100644 --- a/core/docz-core/src/bundler/machine/services/exec-dev-command.ts +++ b/core/docz-core/src/bundler/machine/services/exec-dev-command.ts @@ -35,10 +35,14 @@ export const execDevCommand = async ({ args }: ServerMachineCtx) => { // For monorepos that install dependencies higher in the fs tree const repoRootPath = get(args, 'repoRootPath', await findRootPath()) const gatsbyPath = path.join(repoRootPath, 'node_modules/.bin/gatsby') - spawn(gatsbyPath, ['develop', '--host', `${args.host}`, '--port', `${args.port}`], { - stdio: 'inherit', - cwd: paths.docz, - }) + spawn( + gatsbyPath, + ['develop', '--host', `${args.host}`, '--port', `${args.port}`], + { + stdio: 'inherit', + cwd: paths.docz, + } + ) const url = `http://${args.host}:${args.port}` console.log() console.log('Building app')