From 8380084d00561a2b0dfb5bb925df3733c7507daa Mon Sep 17 00:00:00 2001 From: Dipendra Upreti Date: Thu, 29 Aug 2024 16:36:45 +0545 Subject: [PATCH] chore: add eslint prettier plugin --- commitlint.config.js | 2 +- eslint.config.js | 2 ++ generators/app/index.js | 20 +++++------ generators/fastify-plugin/index.js | 55 ++++++++++++++++-------------- 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index 3f5e287..fa584fb 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1 @@ -export default { extends: ['@commitlint/config-conventional'] }; +export default { extends: ["@commitlint/config-conventional"] }; diff --git a/eslint.config.js b/eslint.config.js index d477281..49dd16e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,9 +1,11 @@ import globals from "globals"; import tseslint from "typescript-eslint"; +import esLintPrettier from "eslint-plugin-prettier/recommended"; export default [ {languageOptions: { globals: globals.browser }}, ...tseslint.configs.recommended, + esLintPrettier, { ignores: [ "**/.gitignore", diff --git a/generators/app/index.js b/generators/app/index.js index 7088ee8..7f19def 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -44,9 +44,9 @@ export default class LibraryGenerator extends Generator { message: "Include fastify plugin?", name: "fastifyPlugin", type: "confirm", - } + }, ]); - }; + } async writing() { await this.fs.copyTplAsync( @@ -57,18 +57,18 @@ export default class LibraryGenerator extends Generator { ...this.options, }, {}, - { - globOptions: { + { + globOptions: { dot: true, - } + }, }, ); if (this.props.fastifyPlugin) { await this.composeWith( - { - Generator: FastifyPluginGenerator, - path: "../fastify-plugin/index.js" + { + Generator: FastifyPluginGenerator, + path: "../fastify-plugin/index.js", }, { authorEmail: this.props.authorEmail, @@ -80,8 +80,8 @@ export default class LibraryGenerator extends Generator { installationType: "library", scope: this.props.scope, version: this.props.version, - } + }, ); } } -}; +} diff --git a/generators/fastify-plugin/index.js b/generators/fastify-plugin/index.js index 8c4541f..7687aba 100644 --- a/generators/fastify-plugin/index.js +++ b/generators/fastify-plugin/index.js @@ -19,7 +19,9 @@ export default class FastifyPluginGenerator extends Generator { type: "input", }, { - default: this.options.baseName? `${this.options.baseName}-fastify`: "fastify", + default: this.options.baseName + ? `${this.options.baseName}-fastify` + : "fastify", message: "Fastify plugin name", name: "name", type: "input", @@ -46,7 +48,7 @@ export default class FastifyPluginGenerator extends Generator { } else { this.props.authorName = this.options.authorName; } - + if (!this.options.authorEmail) { prompts.push({ message: "Author email", @@ -75,15 +77,15 @@ export default class FastifyPluginGenerator extends Generator { choices: [ { name: "Generate this fastify plugin in library monorepo", - value: "library" + value: "library", }, { name: "Generate this fastify plugin in app monorepo", - value: "app" + value: "app", }, { name: "Standalone", - value: "standalone" + value: "standalone", }, ], }); @@ -99,17 +101,18 @@ export default class FastifyPluginGenerator extends Generator { type: "input", }); - this.props["baseName"] = baseName; + this.props["baseName"] = baseName; } else { this.props["baseName"] = this.options.baseName; } if (!this.options.destinationPath) { - const defaultPath = this.props.installationType === "library" - ? "./packages/fastify" - : this.props.installationType === "app" - ? "./libs/fastify" - : `./${this.props.name}`; + const defaultPath = + this.props.installationType === "library" + ? "./packages/fastify" + : this.props.installationType === "app" + ? "./libs/fastify" + : `./${this.props.name}`; const { destinationPath } = await this.prompt({ default: defaultPath, @@ -124,53 +127,53 @@ export default class FastifyPluginGenerator extends Generator { } const { description } = await this.prompt({ - default: this.options.description + default: this.options.description ? this.options.description : generateDescription( this.props.installationType, this.options.name || this.props.name, - this.props.baseName - ), + this.props.baseName, + ), message: "Enter fastify plugin description", name: "description", - type: "input" + type: "input", }); this.props["description"] = description; - this.props["displayName"] = - [this.props.scope, this.props.name] + this.props["displayName"] = [this.props.scope, this.props.name] .join("-") .split("-") - .map(token => token.charAt(0).toUpperCase() + token.slice(1)) + .map((token) => token.charAt(0).toUpperCase() + token.slice(1)) .join(""); - }; + } async writing() { await this.fs.copyTplAsync( this.templatePath(), - this.destinationPath(path.join(this.options.baseName || "", this.props.destinationPath )), + this.destinationPath( + path.join(this.options.baseName || "", this.props.destinationPath), + ), { ...this.props, ...this.options, }, {}, { - globOptions: { + globOptions: { dot: true, - } + }, }, ); } -}; +} const capitalize = (word) => { return word ? word.charAt(0).toUpperCase() + word.slice(1) : word; }; const generateDescription = (installationType, name, baseName) => { - let description, - capitalizedName; + let description, capitalizedName; switch (installationType) { case "library": @@ -186,4 +189,4 @@ const generateDescription = (installationType, name, baseName) => { } return description; -} +};