diff --git a/packages/eslint-config/cypress.js b/packages/eslint-config/cypress.js index 56aba59916..796566c23c 100644 --- a/packages/eslint-config/cypress.js +++ b/packages/eslint-config/cypress.js @@ -1,5 +1,4 @@ module.exports = { - extends: ['.index.js'], plugins: ['cypress'], env: { 'cypress/globals': true, diff --git a/packages/eslint-config/jest.js b/packages/eslint-config/jest.js index b4b504cb15..de5b91ed6a 100644 --- a/packages/eslint-config/jest.js +++ b/packages/eslint-config/jest.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['plugin:jest/recommended', './index.js'], + extends: ['plugin:jest/recommended'], rules: { 'jest/expect-expect': 'off', }, diff --git a/packages/eslint-config/react.js b/packages/eslint-config/react.js index 73101bd646..271def1043 100644 --- a/packages/eslint-config/react.js +++ b/packages/eslint-config/react.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['prettier/react', './index.js'], + extends: ['prettier/react'], rules: { 'react/jsx-filename-extension': 'off', 'import/extensions': [ diff --git a/packages/eslint-config/typescript.js b/packages/eslint-config/typescript.js index 445d4a0787..c5c695d2d0 100644 --- a/packages/eslint-config/typescript.js +++ b/packages/eslint-config/typescript.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['prettier/@typescript', './index.js'], + extends: ['prettier/@typescript'], overrides: [ { files: ['**/*.ts?(x)'], diff --git a/packages/eslint-config/vue.js b/packages/eslint-config/vue.js index 74567d5783..c2988ac90a 100644 --- a/packages/eslint-config/vue.js +++ b/packages/eslint-config/vue.js @@ -1,3 +1,3 @@ module.exports = { - extends: ['plugin:vue/recommended', 'prettier/vue', './index.js'], + extends: ['plugin:vue/recommended', 'prettier/vue'], } diff --git a/packages/generator-particle-base/src/generators/app/index.ts b/packages/generator-particle-base/src/generators/app/index.ts index c3479636dc..2d98aa33b9 100644 --- a/packages/generator-particle-base/src/generators/app/index.ts +++ b/packages/generator-particle-base/src/generators/app/index.ts @@ -1,6 +1,7 @@ import Generator from 'yeoman-generator' import merge from 'lodash.merge' import fs from 'fs' +import _ from 'lodash'; import { Answers, @@ -88,6 +89,40 @@ module.exports = class extends Generator { ) } + /** + * Create eslintrc file + **/ + + _eslintCompile(configuration: Answers ) { + const { frontendFramework, testingLibraries, hasTypescript } = configuration.options + + // Array of all valid eslint-config sub-modules listed in CLI. + const validPackages: string[] = ['react', 'vue', 'cypress', 'jest', 'typescript'] + + // Array of users CLI selections. + const extend: string[] = [ + ...frontendFramework, + ...testingLibraries, + hasTypescript ? 'typescript' : '' + ] + + // Filter for valid packages and construct extends array elements. + const elements: string[] = _.filter( + extend, (el)=> validPackages + .includes(el)) + .map(el => `\n'@phase2/eslint-config/${el}'` + ) + + const esModule = `module.exports = { + extends: [ + '@phase2/eslint-config', ${elements} + ] + }` + + fs.writeFileSync(`${process.cwd()}/.eslintrc.js`, esModule) + + } + async _promptUser() { // Initialize storybook const results: ConfigurationAnswers = await this.prompt(configurationPrompt) @@ -115,6 +150,9 @@ module.exports = class extends Generator { async initializing() { await this._promptUser() + // Compile eslintrc.js file from user input. + this._eslintCompile(this.configuration) + // All composed generators must be imported following this syntax https://yeoman.io/authoring/composability.html if ( this.configuration.options.frontendFramework.includes(