Skip to content

Commit

Permalink
chore: fix description issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dipendraupreti committed Aug 23, 2024
1 parent 6d6e6db commit f186e2a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
42 changes: 34 additions & 8 deletions generators/fastify-plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "node:path";
import Generator from "yeoman-generator";

export default class FastifyPluginGenerator extends Generator {
Expand All @@ -10,7 +11,7 @@ export default class FastifyPluginGenerator extends Generator {
}

async prompting() {
const prompts= [
const prompts = [
{
default: this.options.scope,
message: "Fastify plugin scope",
Expand All @@ -30,16 +31,16 @@ export default class FastifyPluginGenerator extends Generator {
type: "input",
},
];
if (!this.options.destinationPath && !this.args[0]) {

if (!this.options.destinationPath) {
prompts.push({
default: this.args[0] || ".",
default: ".",
message: "Destination path",
name: "destinationPath",
type: "input",
});
}

if (!this.options.monorepo) {
prompts.push({
default: false,
Expand All @@ -50,21 +51,42 @@ export default class FastifyPluginGenerator extends Generator {
}

this.props = await this.prompt(prompts);

if (!this.options.baseName) {
this.props["baseName"] = false;
}


if (this.props.monorepo) {
const { baseName } = await this.prompts({
default: "",
message: "Enter the monorepo name",
name: "baseName",
type: "confirm",
});

this.props["baseName"] = baseName;
}

if (!this.props["destinationPath"]) {
this.props["destinationPath"] = this.options.destinationPath || this.args[0] || ".";
this.props["destinationPath"] = this.options.destinationPath? path.join(baseName, this.options.destinationPath) : ".";
}

const { description } = await this.prompt({
default: capitalizeFirstLetter(`${this.props.name ?? "A"} plugin for fastify`),
message: "Enter description",
name: description,
type: input
})

this.props["description"] = description;

this.props["displayName"] =
[this.props.scope, this.props.name]
.join("-")
.split("-")
.map(token => token.charAt(0).toUpperCase() + token.slice(1))
.join("");

};

async writing() {
Expand All @@ -84,3 +106,7 @@ export default class FastifyPluginGenerator extends Generator {
);
}
};

const capitalizeFirstLetter = (sentence) => {
return sentence ? sentence.charAt(0).toUpperCase() + sentence.slice(1) : sentence;
};
4 changes: 1 addition & 3 deletions generators/fastify-plugin/templates/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# @<%= scope %>/<%= name %>

<%_ if (monorepo) { _%>
A [Fastify](https://github.com/fastify/fastify) plugin for <%= baseName %>.
<%_ } _%>
<%= description %>

## Installation

Expand Down
2 changes: 1 addition & 1 deletion generators/fastify-plugin/templates/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@<%= scope %>/<%= name %>",
"version": "<%= version %>",
"description": "<%= description %>",
<%_ if (monorepo) { _%>
"description": "<%= name %> plugin for fastify",
"homepage": "https://github.com/<%= scope %>/<%= baseName %>/tree/main/packages/fastify#readme",
"repository": {
"type": "git",
Expand Down

0 comments on commit f186e2a

Please sign in to comment.