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 templates issues #409

Merged
merged 6 commits into from
Sep 21, 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
14 changes: 11 additions & 3 deletions packages/barrels/bin/barrels.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import {existsSync} from "node:fs";
import {readFile, writeFile} from "node:fs/promises";
import {join} from "node:path";
import {dirname, join} from "node:path";

import {globby} from "globby";

Expand Down Expand Up @@ -46,8 +46,16 @@ async function build() {

const excluded = exclude.map((path) => `!${path}`).concat(directory.map((path) => `!${path}/index.ts`));

const promises = directory.map(async (directory) => {
const baseIndex = join(process.cwd(), directory);
const directories = (
await globby(directory, {
cwd: process.cwd()
})
).reduce((set, file) => {
return set.add(dirname(file));
}, new Set());

const promises = [...directories.keys()].map(async (directory) => {
const baseIndex = join(process.cwd(), directory?.path ?? directory);

const files = await globby(["**/*.ts", "!index.ts", ...excluded], {
cwd: directory
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/src/utils/createTasksRunner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
import {isFunction} from "@tsed/core";
import {Listr, ListrTaskWrapper, Logger} from "listr2";
import {Listr, type ListrTaskWrapper, Logger} from "listr2";

import type {TaskOptions, Tasks} from "../interfaces/Tasks.js";
import {getLogger} from "./createInjector.js";
Expand Down
4 changes: 1 addition & 3 deletions packages/cli-core/src/utils/loadPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {fileURLToPath} from "node:url";

import {GlobalProviders, InjectorService} from "@tsed/di";
import chalk from "chalk";
// @ts-ignore
Expand All @@ -21,7 +19,7 @@ export async function loadPlugins(injector: InjectorService) {
.filter((mod) => mod.startsWith(`@${name}/cli-plugin`) || mod.includes(`${name}-cli-plugin`))
.map(async (mod) => {
try {
const {default: plugin} = await fs.importModule(mod, fileURLToPath(rootDir));
const {default: plugin} = await fs.importModule(mod, rootDir);

if (!injector.has(plugin)) {
const provider = GlobalProviders.get(plugin)?.clone();
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-core/src/utils/mapCommanderOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import commander from "commander";
import type {Command} from "commander";

export function mapCommanderOptions(commands: commander.Command[]) {
export function mapCommanderOptions(commands: Command[]) {
const options: any = {};
commands.forEach((command) => {
Object.entries(command.opts())
Expand Down
17 changes: 17 additions & 0 deletions packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ export class EslintInitHook {

await this.packageManagers.runScript("prepare");
}
},
{
title: "Run linter",
task: () => {
return this.packageManagers.runScript("test:lint:fix", {
ignoreError: true
});
}
}
];
}
Expand Down Expand Up @@ -115,6 +123,15 @@ export class EslintInitHook {
);
}

if (ctx.vitest) {
this.packageJson.addDevDependencies(
{
"eslint-plugin-vitest": "latest"
},
ctx
);
}

if (ctx.prettier) {
this.packageJson.addDevDependencies(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import typescriptParser from "@typescript-eslint/parser";
{{#if prettier}}import pluginPrettierRecommended from "eslint-plugin-prettier/recommended";
{{/if}}import pluginSimpleImportSort from "eslint-plugin-simple-import-sort";
{{#if vitest}}import vitest from "eslint-plugin-vitest";
i{{/if}}import globals from "globals";
{{/if}}import globals from "globals";

export default [
{
Expand Down Expand Up @@ -58,8 +58,7 @@ export default [
},
rules: {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"workspaces/no-absolute-imports": "error"
"simple-import-sort/exports": "error"
}
}{{#if prettier}},
pluginPrettierRecommended{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-vitest/src/CliPluginVitestModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class CliPluginVitestModule {
const runtime = this.runtimes.get();

this.packageJson.addScripts({
test: `${runtime.run("test:lint")} && ${runtime.run("test:coverage")} `,
test: `${runtime.run("test:lint")} && ${runtime.run("test:coverage")}`,
"test:unit": "cross-env NODE_ENV=test vitest run",
"test:watch": "cross-env NODE_ENV=test vitest",
"test:coverage": `cross-env NODE_ENV=test vitest run --coverage`
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/generate/GenerateCmd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("GenerateCmd", () => {
express: false,
koa: false,
platformSymbol: undefined,
barrels: '["./src/controllers/rest/index.js"]',
barrels: '["./src/controllers/rest"]',
imports: [
{from: "@tsed/ajv"},
{symbols: "{config}", from: "./config/index.js"},
Expand Down Expand Up @@ -169,7 +169,7 @@ describe("GenerateCmd", () => {
express: false,
koa: false,
platformSymbol: undefined,
barrels: '["./src/controllers/rest/index.js"]',
barrels: '["./src/controllers/rest"]',
imports: [
{from: "@tsed/ajv"},
{symbols: "{config}", from: "./config/index.js"},
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/utils/__snapshots__/fillImport.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`fillImports() > should return barrels and imports files for ('arc_default', oidc: false, graphql: false, swagger: true, passportjs: false, express: false, koa: false, mongoose: false) 1`] = `
{
"architecture": "arc_default",
"barrels": "["./src/controllers/rest/index.js","./src/controllers/pages/index.js"]",
"barrels": "["./src/controllers/rest","./src/controllers/pages"]",
"express": false,
"graphql": false,
"imports": [
Expand Down Expand Up @@ -37,7 +37,7 @@ exports[`fillImports() > should return barrels and imports files for ('arc_defau
exports[`fillImports() > should return barrels and imports files for ('arc_default', oidc: true, graphql: false, swagger: false, passportjs: false, express: false, koa: true, mongoose: false) 1`] = `
{
"architecture": "arc_default",
"barrels": "["./src/controllers/rest/index.js","./src/interactions/index.js"]",
"barrels": "["./src/controllers/rest","./src/interactions"]",
"express": false,
"graphql": false,
"imports": [
Expand Down Expand Up @@ -75,7 +75,7 @@ exports[`fillImports() > should return barrels and imports files for ('arc_defau
exports[`fillImports() > should return barrels and imports files for ('arc_default', oidc: true, graphql: true, swagger: true, passportjs: true, express: false, koa: true, mongoose: true) 1`] = `
{
"architecture": "arc_default",
"barrels": "["./src/controllers/rest/index.js","./src/controllers/pages/index.js","./src/interactions/index.js","./src/datasources/index.js","./src/resolvers/index.js"]",
"barrels": "["./src/controllers/rest","./src/controllers/pages","./src/interactions","./src/datasources","./src/resolvers"]",
"express": false,
"graphql": true,
"imports": [
Expand Down Expand Up @@ -131,7 +131,7 @@ exports[`fillImports() > should return barrels and imports files for ('arc_defau
exports[`fillImports() > should return barrels and imports files for ('feature', oidc: false, graphql: false, swagger: false, passportjs: false, express: false, koa: false, mongoose: false) 1`] = `
{
"architecture": "feature",
"barrels": "["./src/rest/index.js"]",
"barrels": "["./src/rest"]",
"express": false,
"graphql": false,
"imports": [
Expand All @@ -158,7 +158,7 @@ exports[`fillImports() > should return barrels and imports files for ('feature',
exports[`fillImports() > should return barrels and imports files for ('feature', oidc: false, graphql: false, swagger: true, passportjs: false, express: false, koa: false, mongoose: false) 1`] = `
{
"architecture": "feature",
"barrels": "["./src/rest/index.js","./src/pages/index.js"]",
"barrels": "["./src/rest","./src/pages"]",
"express": false,
"graphql": false,
"imports": [
Expand Down Expand Up @@ -192,7 +192,7 @@ exports[`fillImports() > should return barrels and imports files for ('feature',
exports[`fillImports() > should return barrels and imports files for ('feature', oidc: true, graphql: false, swagger: false, passportjs: false, express: true, koa: false, mongoose: false) 1`] = `
{
"architecture": "feature",
"barrels": "["./src/rest/index.js","./src/interactions/index.js"]",
"barrels": "["./src/rest","./src/interactions"]",
"express": false,
"graphql": false,
"imports": [
Expand Down Expand Up @@ -230,7 +230,7 @@ exports[`fillImports() > should return barrels and imports files for ('feature',
exports[`fillImports() > should return barrels and imports files for ('feature', oidc: true, graphql: true, swagger: true, passportjs: true, express: true, koa: false, mongoose: true) 1`] = `
{
"architecture": "feature",
"barrels": "["./src/rest/index.js","./src/pages/index.js","./src/interactions/index.js","./src/datasources/index.js","./src/resolvers/index.js"]",
"barrels": "["./src/rest","./src/pages","./src/interactions","./src/datasources","./src/resolvers"]",
"express": false,
"graphql": true,
"imports": [
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/utils/fillImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export function fillImports(ctx: any) {

ctx.barrels = JSON.stringify(
[
isFeature ? "./src/rest/index.js" : "./src/controllers/rest/index.js",
ctx.swagger && (isFeature ? "./src/pages/index.js" : "./src/controllers/pages/index.js"),
ctx.oidc && "./src/interactions/index.js",
ctx.graphql && "./src/datasources/index.js",
ctx.graphql && "./src/resolvers/index.js"
isFeature ? "./src/rest" : "./src/controllers/rest",
ctx.swagger && (isFeature ? "./src/pages" : "./src/controllers/pages"),
ctx.oidc && "./src/interactions",
ctx.graphql && "./src/datasources",
ctx.graphql && "./src/resolvers"
].filter(Boolean)
);

Expand Down
1 change: 1 addition & 0 deletions packages/cli/templates/init/.dockerignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
Dockerfile
.env.local
.env.development
**/*.spec.ts
2 changes: 1 addition & 1 deletion packages/cli/templates/init/.swcrc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"decorators": true,
"dynamicImport": true
},
"target": "es2023",
"target": "es2022",
"externalHelpers": true,
"keepClassNames": true,
"transform": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/init/docker/npm/Dockerfile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COPY ./src ./src

RUN npm run build

FROM node:${NODE_VERSION}-alpine as runtime
FROM node:${NODE_VERSION}-alpine AS runtime
ENV WORKDIR /opt
WORKDIR $WORKDIR

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/init/docker/pnpm/Dockerfile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COPY ./src ./src

RUN pnpm run build

FROM node:${NODE_VERSION}-alpine as runtime
FROM node:${NODE_VERSION}-alpine AS runtime
ENV WORKDIR /opt
WORKDIR $WORKDIR

Expand Down
Loading