Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/misc 20240829 #21

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
export default { extends: ["@commitlint/config-conventional"] };
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 10 additions & 10 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default class LibraryGenerator extends Generator {
message: "Include fastify plugin?",
name: "fastifyPlugin",
type: "confirm",
}
},
]);
};
}

async writing() {
await this.fs.copyTplAsync(
Expand All @@ -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,
Expand All @@ -80,8 +80,8 @@ export default class LibraryGenerator extends Generator {
installationType: "library",
scope: this.props.scope,
version: this.props.version,
}
},
);
}
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ jobs:
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
- name: Install pnpm
- name: Setup pnpm and install dependencies
uses: pnpm/action-setup@v4
with:
run_install: |
- version: 8
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
- run:
pnpm -r install
- run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
Expand Down
22 changes: 9 additions & 13 deletions generators/app/templates/.github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ jobs:
matrix:
node-version: [20, 21]
steps:
- uses: actions/checkout@v4
name: Use node ${{ matrix.node-version }}

- uses: actions/setup-node@v4
- name: Checkout
uses: actions/checkout@v4
- name: Use node ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- uses: pnpm/action-setup@v2
name: Install pnpm
- name: Setup pnpm and install dependencies
uses: pnpm/action-setup@v4
with:
version: 8

- name: Install Dependencies
run: pnpm install --frozen-lockfile

run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
- name: Build packages
run: pnpm build

- name: Run tests
run: pnpm test
55 changes: 32 additions & 23 deletions generators/fastify-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
},
],
});
Expand All @@ -99,14 +101,21 @@ 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 { destinationPath } = await this.prompt({
default: `${this.props.name}`,
default: defaultPath,
message: "Destination path",
name: "destinationPath",
type: "input",
Expand All @@ -118,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":
Expand All @@ -180,4 +189,4 @@ const generateDescription = (installationType, name, baseName) => {
}

return description;
}
};