From 2b83a72356a2a657122ed287db0e47694656a9b4 Mon Sep 17 00:00:00 2001 From: jonatan-martinez <102022630+jonatan-martinez@users.noreply.github.com> Date: Thu, 18 May 2023 17:33:50 +0200 Subject: [PATCH 1/2] feat: add eslint and prompt for options --- .../@guidesmiths/cuckoojs-cli/package.json | 24 +++------ .../cuckoojs-cli/src/commands/new.command.ts | 6 ++- .../src/lib/runners/schematic.runner.ts | 3 +- .../src/eslint/eslint.factory.ts | 21 +++++--- .../src/eslint/files/eslintrc.js | 52 ++++++++++++------ .../src/eslint/schema.json | 54 ++++++++++++++++++- 6 files changed, 119 insertions(+), 41 deletions(-) diff --git a/packages/@guidesmiths/cuckoojs-cli/package.json b/packages/@guidesmiths/cuckoojs-cli/package.json index 42652bd1..57783945 100644 --- a/packages/@guidesmiths/cuckoojs-cli/package.json +++ b/packages/@guidesmiths/cuckoojs-cli/package.json @@ -24,22 +24,10 @@ }, "homepage": "https://github.com/guidesmiths/cuckoojs#readme", "contributors": [ - { - "name": "David Yusta", - "email": "david.yusta@one-beyond.com" - }, - { - "name": "Laura Corbí", - "email": "laura.corbi@one-beyond.com" - }, - { - "name": "Adrián Rodríguez", - "email": "adrian.rodriguez@one-beyond.com" - }, - { - "name": "Íñigo Marquínez", - "email": "inigo.marquinez@one-beyond.com" - } + "David Yusta ", + "Laura Corbí ", + "Adrián Rodríguez ", + "Íñigo Marquínez " ], "main": "dist/src/cli.js", "bin": { @@ -71,5 +59,7 @@ "jest": "^29.3.1", "ts-jest": "^29.0.3", "typescript": "^4.9.4" - } + }, + "types": "./dist/src/cli.d.ts", + "author": "" } diff --git a/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts b/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts index 2d524c9b..55b1d336 100644 --- a/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts +++ b/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts @@ -31,7 +31,7 @@ export class NewCommand extends AbstractCommand { } public async execute() { - const printer = new Printer({total: 8, step: 1}); + const printer = new Printer({total: 9, step: 1}); this.printSuccess(messages.banner); if (this.checkFileExists()) { @@ -75,6 +75,10 @@ export class NewCommand extends AbstractCommand { await this.bashRunnerHusky.addHuskyCommitMsg(this.name); printer.endStep(); + printer.startStep('Creating eslint configuration'); + printer.endStep(); + await this.schematicRunner.addESlint(this.name); + this.printSuccess(`\n 🐦 Your CuckooJS nest "${this.name}" is generated and ready to use 🐦`); } catch (error: unknown) { printer.load.fail(`Error generating new project: ${(error as Error).message}`); diff --git a/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts b/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts index 8e272d30..6f047f23 100644 --- a/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts +++ b/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts @@ -43,7 +43,8 @@ export class SchematicRunner extends GenericRunner { } public async addESlint(name: string) { + debugger const args = [`@guidesmiths/cuckoojs-schematics:eslint --directory=${name}`]; - await super.run({command: SchematicRunner.getSchematicsCliPath(), args, stdio: ['pipe', 'pipe', 'inherit']}); + await super.run({command: SchematicRunner.getSchematicsCliPath(), args, stdio: ['inherit', 'inherit', 'inherit']}); } } diff --git a/packages/@guidesmiths/cuckoojs-schematics/src/eslint/eslint.factory.ts b/packages/@guidesmiths/cuckoojs-schematics/src/eslint/eslint.factory.ts index 76d8a5a8..f5e1aee7 100644 --- a/packages/@guidesmiths/cuckoojs-schematics/src/eslint/eslint.factory.ts +++ b/packages/@guidesmiths/cuckoojs-schematics/src/eslint/eslint.factory.ts @@ -16,7 +16,11 @@ export const main = (options: any): Rule => (tree: Tree, context: SchematicConte const path = normalize(options.directory); const templateSource = apply(url('./files'), [ - template({...options}), + template( + { + ...options, + indentvalue: options.indent === 'tabs' ? '\'tabs\'' : 4, + }), move(path), renameFile(options), ]); @@ -26,7 +30,7 @@ export const main = (options: any): Rule => (tree: Tree, context: SchematicConte return chain([ merged, updatePackageJson(path), - ])(tree, context) + ])(tree, context); }; function renameFile(options: any): Rule { @@ -47,16 +51,21 @@ function updatePackageJson(directory: string): Rule { json.devDependencies = {}; } - json.devDependencies['eslint'] = '^8.29.0'; + json.devDependencies.eslint = '^8.40.0'; json.devDependencies['eslint-config-airbnb-base'] = '^15.0.0'; json.devDependencies['eslint-plugin-import'] = '^2.26.0'; json.devDependencies['eslint-plugin-jest'] = '^27.1.6'; + json.devDependencies['@typescript-eslint/eslint-plugin'] = '^5.59.6'; + json.devDependencies['@typescript-eslint/parser'] = '^5.59.6'; + json.devDependencies['eslint-plugin-promise'] = '^6.1.1'; + json.devDependencies['eslint-config-standard-with-typescript'] = '^34.0.1'; + json.devDependencies['eslint-plugin-n'] = '^15.7.0'; - if(!json.scripts) { - json.scripts = {} + if (!json.scripts) { + json.scripts = {}; } - json.scripts['lint'] = 'eslint .'; + json.scripts.lint = 'eslint .'; json.scripts['lint:fix'] = 'eslint . --fix'; tree.overwrite(path, JSON.stringify(json, null, 2)); diff --git a/packages/@guidesmiths/cuckoojs-schematics/src/eslint/files/eslintrc.js b/packages/@guidesmiths/cuckoojs-schematics/src/eslint/files/eslintrc.js index dd5ca4d0..10f66653 100644 --- a/packages/@guidesmiths/cuckoojs-schematics/src/eslint/files/eslintrc.js +++ b/packages/@guidesmiths/cuckoojs-schematics/src/eslint/files/eslintrc.js @@ -1,17 +1,39 @@ module.exports = { - env: { - commonjs: true, - es2021: true, - node: true, - 'jest/globals': true - }, - extends: 'airbnb-base', - overrides: [ - ], - parserOptions: { - ecmaVersion: 'latest', - }, - plugins: ['jest'], - rules: { - }, + env: { + commonjs: true, + es2021: true, + node: true, + 'jest/globals': true, + }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'airbnb-base', + ], + overrides: [ + ], + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + plugins: ['jest', '@typescript-eslint'], + rules: { + indent: [ + 'error', + <%= indentvalue %>, + ], + 'linebreak-style': [ + 'error', + '<%= linebreakStyle %>', + ], + quotes: [ + 'error', + '<%= quotes %>', + ], + semi: [ + 'error', + '<%= semicolon %>', + ], + }, }; diff --git a/packages/@guidesmiths/cuckoojs-schematics/src/eslint/schema.json b/packages/@guidesmiths/cuckoojs-schematics/src/eslint/schema.json index c3269564..37abdc22 100644 --- a/packages/@guidesmiths/cuckoojs-schematics/src/eslint/schema.json +++ b/packages/@guidesmiths/cuckoojs-schematics/src/eslint/schema.json @@ -9,7 +9,59 @@ "description": "eslint config directory", "default": ".", "x-prompt": "Where do you want to setup eslint?" + }, + "indent": { + "description": "identation style", + "type": "string", + "default": "tabs", + "x-prompt": { + "message": "What style of indentation do you use?", + "type": "list", + "items": [ + {"label": "Tabs", "value": "tabs"}, + {"label": "Spaces", "value": "spaces"} + ] + } + }, + "quotes": { + "description": "quote style", + "type": "string", + "default": "single", + "x-prompt": { + "message": "What quotes do you use for strings?", + "type": "list", + "items": [ + {"label": "Double", "value": "double"}, + {"label": "Single", "value": "single"} + ] + } + }, + "linebreakStyle": { + "description": "line-ending style", + "type": "string", + "default": "unix", + "x-prompt": { + "message": "What line endings do you use?", + "type": "list", + "items": [ + {"label": "Unix", "value": "unix"}, + {"label": "Windows", "value": "windows"} + ] + } + }, + "semicolon": { + "description": "semicolon yes or not", + "type": "string", + "default": "always", + "x-prompt": { + "message": "Do you require semicolons?", + "type": "list", + "items": [ + {"label": "Yes", "value": "always"}, + {"label": "No", "value": "never"} + ] + } } }, - "required": ["directory"] + "required": ["directory", "indent", "quotes", "linebreakStyle", "semicolon"] } From 9b14e1ff5dfe5199e36c7b1fe12e5ebba5a8aed4 Mon Sep 17 00:00:00 2001 From: jonatan-martinez <102022630+jonatan-martinez@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:32:32 +0200 Subject: [PATCH 2/2] fix: remove debugger statement --- .../cuckoojs-cli/src/lib/runners/schematic.runner.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts b/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts index 6f047f23..11ce8932 100644 --- a/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts +++ b/packages/@guidesmiths/cuckoojs-cli/src/lib/runners/schematic.runner.ts @@ -43,7 +43,6 @@ export class SchematicRunner extends GenericRunner { } public async addESlint(name: string) { - debugger const args = [`@guidesmiths/cuckoojs-schematics:eslint --directory=${name}`]; await super.run({command: SchematicRunner.getSchematicsCliPath(), args, stdio: ['inherit', 'inherit', 'inherit']}); }