@leo-h/create-nodejs-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/compose-app/copy-template.compose.js +1 -0
- package/dist/compose-app/replace-content-in-file.compose.js +1 -0
- package/dist/config/index.js +1 -0
- package/dist/index.js +2 -0
- package/dist/utils/logs.js +1 -0
- package/dist/utils/on-cancel.js +1 -0
- package/dist/utils/to-pascal-case.js +1 -0
- package/dist/validations/package-name.validation.js +1 -0
- package/package.json +71 -0
- package/templates/clean/.env.example +5 -0
- package/templates/clean/.eslintignore +2 -0
- package/templates/clean/.eslintrc.json +22 -0
- package/templates/clean/.husky/pre-commit +1 -0
- package/templates/clean/.lintstagedrc.json +4 -0
- package/templates/clean/.prettierignore +7 -0
- package/templates/clean/.prettierrc.json +6 -0
- package/templates/clean/.vscode/settings.json +8 -0
- package/templates/clean/build.config.ts +55 -0
- package/templates/clean/package.json +41 -0
- package/templates/clean/pnpm-lock.yaml +3929 -0
- package/templates/clean/src/env.ts +17 -0
- package/templates/clean/src/index.ts +1 -0
- package/templates/clean/tsconfig.json +15 -0
- package/templates/clean/vitest.config.mts +6 -0
- package/templates/fastify/.env.example +11 -0
- package/templates/fastify/.eslintignore +2 -0
- package/templates/fastify/.eslintrc.json +22 -0
- package/templates/fastify/.husky/pre-commit +1 -0
- package/templates/fastify/.lintstagedrc.json +4 -0
- package/templates/fastify/.prettierignore +7 -0
- package/templates/fastify/.prettierrc.json +6 -0
- package/templates/fastify/.vscode/settings.json +8 -0
- package/templates/fastify/build.config.ts +55 -0
- package/templates/fastify/package.json +57 -0
- package/templates/fastify/pnpm-lock.yaml +5353 -0
- package/templates/fastify/src/@types/fastify-zod-type-provider.ts +39 -0
- package/templates/fastify/src/@types/fastify.d.ts +16 -0
- package/templates/fastify/src/app.ts +45 -0
- package/templates/fastify/src/controllers/hello/hello-multipart.controller.e2e-spec.ts +32 -0
- package/templates/fastify/src/controllers/hello/hello-multipart.controller.ts +51 -0
- package/templates/fastify/src/controllers/hello/hello.controller.e2e-spec.ts +14 -0
- package/templates/fastify/src/controllers/hello/hello.controller.ts +36 -0
- package/templates/fastify/src/env.ts +19 -0
- package/templates/fastify/src/errors/exceptions.ts +87 -0
- package/templates/fastify/src/errors/http-error-handler.ts +111 -0
- package/templates/fastify/src/plugins/error-handler.plugin.ts +27 -0
- package/templates/fastify/src/plugins/handle-swagger-multipart.plugin.ts +96 -0
- package/templates/fastify/src/plugins/require-upload.plugin.ts +200 -0
- package/templates/fastify/src/routes/hello.routes.ts +8 -0
- package/templates/fastify/src/routes/index.ts +6 -0
- package/templates/fastify/src/server.ts +12 -0
- package/templates/fastify/src/utils/capitalize-word.ts +3 -0
- package/templates/fastify/test/e2e-setup.ts +10 -0
- package/templates/fastify/tsconfig.json +15 -0
- package/templates/fastify/vitest.config.e2e.mts +9 -0
- package/templates/fastify/vitest.config.mts +6 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
import "dotenv/config";
|
2
|
+
import { z } from "zod";
|
3
|
+
|
4
|
+
const schema = z.object({
|
5
|
+
NODE_ENV: z.enum(["test", "development", "production"]),
|
6
|
+
APP_NAME: z.string(),
|
7
|
+
});
|
8
|
+
|
9
|
+
const parsedEnv = schema.safeParse(process.env);
|
10
|
+
|
11
|
+
if (!parsedEnv.success) {
|
12
|
+
console.error(parsedEnv.error.flatten().fieldErrors);
|
13
|
+
|
14
|
+
throw new Error("Invalid environment variables.");
|
15
|
+
}
|
16
|
+
|
17
|
+
export const env = parsedEnv.data;
|
@@ -0,0 +1 @@
|
|
1
|
+
console.log("Hello world!");
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "ESNext",
|
4
|
+
"module": "Commonjs",
|
5
|
+
"esModuleInterop": true,
|
6
|
+
"resolveJsonModule": true,
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
8
|
+
"strict": true,
|
9
|
+
"skipLibCheck": true,
|
10
|
+
"baseUrl": ".",
|
11
|
+
"paths": {
|
12
|
+
"@/*": ["./src/*"]
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# example: "development" ("development" | "test" | "production")
|
2
|
+
NODE_ENV=
|
3
|
+
|
4
|
+
# example: "app-name"
|
5
|
+
API_NAME=
|
6
|
+
|
7
|
+
# example: "3333"
|
8
|
+
API_PORT=
|
9
|
+
|
10
|
+
# example: "https://my-client-app.com" (url - only constraint | regex - specific constraint | "*" - not constraint)
|
11
|
+
API_ACCESS_PERMISSION_CLIENT_SIDE=
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"root": true,
|
3
|
+
"env": {
|
4
|
+
"es2021": true,
|
5
|
+
"node": true
|
6
|
+
},
|
7
|
+
"extends": [
|
8
|
+
"eslint:recommended",
|
9
|
+
"plugin:@typescript-eslint/recommended",
|
10
|
+
"prettier",
|
11
|
+
"plugin:vitest/recommended"
|
12
|
+
],
|
13
|
+
"parser": "@typescript-eslint/parser",
|
14
|
+
"parserOptions": {
|
15
|
+
"ecmaVersion": "latest",
|
16
|
+
"sourceType": "module"
|
17
|
+
},
|
18
|
+
"plugins": ["@typescript-eslint"],
|
19
|
+
"rules": {
|
20
|
+
"@typescript-eslint/no-unused-vars": "warn"
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
pnpm lint-staged
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { readdirSync } from "fs";
|
2
|
+
import { resolve } from "path";
|
3
|
+
import { BuildOptions, defineBuildConfig } from "unbuild";
|
4
|
+
import packageJson from "./package.json";
|
5
|
+
import { compilerOptions } from "./tsconfig.json";
|
6
|
+
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
8
|
+
const getAllFiles = (path: string) => {
|
9
|
+
return readdirSync(path, {
|
10
|
+
recursive: true,
|
11
|
+
encoding: "utf-8",
|
12
|
+
})
|
13
|
+
.filter(reading => reading.endsWith(".ts"))
|
14
|
+
.map(filename => `${path}/${filename}`);
|
15
|
+
};
|
16
|
+
|
17
|
+
const pathAliases = Object.keys(compilerOptions.paths).reduce(
|
18
|
+
(resolvedAliases, alias) => {
|
19
|
+
const unbuildAlias = alias.replace("/*", "");
|
20
|
+
const unbuildPath = compilerOptions.paths[
|
21
|
+
alias as keyof typeof compilerOptions.paths
|
22
|
+
][0].replace("/*", "");
|
23
|
+
|
24
|
+
resolvedAliases[unbuildAlias] = resolve(
|
25
|
+
compilerOptions.baseUrl,
|
26
|
+
unbuildPath,
|
27
|
+
);
|
28
|
+
|
29
|
+
return resolvedAliases;
|
30
|
+
},
|
31
|
+
{} as BuildOptions["alias"],
|
32
|
+
);
|
33
|
+
|
34
|
+
export default defineBuildConfig({
|
35
|
+
outDir: "./dist",
|
36
|
+
entries: ["./src/server.ts"],
|
37
|
+
clean: true,
|
38
|
+
alias: pathAliases,
|
39
|
+
externals: Object.keys(packageJson.dependencies),
|
40
|
+
rollup: {
|
41
|
+
emitCJS: true,
|
42
|
+
cjsBridge: true,
|
43
|
+
inlineDependencies: true,
|
44
|
+
output: {
|
45
|
+
format: "cjs",
|
46
|
+
entryFileNames: "[name].js",
|
47
|
+
preserveModules: true,
|
48
|
+
strict: false,
|
49
|
+
},
|
50
|
+
esbuild: {
|
51
|
+
minifySyntax: true,
|
52
|
+
treeShaking: true,
|
53
|
+
},
|
54
|
+
},
|
55
|
+
});
|
@@ -0,0 +1,57 @@
|
|
1
|
+
{
|
2
|
+
"name": "app-name",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"private": true,
|
5
|
+
"scripts": {
|
6
|
+
"prepare": "husky",
|
7
|
+
"start": "node ./dist/server.js",
|
8
|
+
"start:dev": "tsx watch ./src/server.ts",
|
9
|
+
"typecheck": "tsc --noEmit",
|
10
|
+
"lint": "eslint . --ext .ts --max-warnings 0 --cache",
|
11
|
+
"lint:fix": "pnpm lint --fix",
|
12
|
+
"format": "prettier . --write --cache",
|
13
|
+
"test:unit": "vitest run",
|
14
|
+
"test:unit:watch": "vitest",
|
15
|
+
"test:e2e": "vitest run --config ./vitest.config.e2e.mts",
|
16
|
+
"test:e2e:watch": "vitest --config ./vitest.config.e2e.mts",
|
17
|
+
"test:coverage": "vitest run --coverage.enabled=true --coverage.all=false",
|
18
|
+
"prebuild": "rimraf ./dist",
|
19
|
+
"build": "unbuild"
|
20
|
+
},
|
21
|
+
"dependencies": {
|
22
|
+
"@fastify/cookie": "9.3.1",
|
23
|
+
"@fastify/cors": "9.0.1",
|
24
|
+
"@fastify/swagger": "8.14.0",
|
25
|
+
"@fastify/swagger-ui": "3.0.0",
|
26
|
+
"dotenv": "16.4.5",
|
27
|
+
"fastify": "4.27.0",
|
28
|
+
"fastify-multer": "2.0.3",
|
29
|
+
"fastify-type-provider-zod": "1.2.0",
|
30
|
+
"mime-types": "2.1.35",
|
31
|
+
"pretty-bytes": "5.6.0",
|
32
|
+
"zod": "3.23.8",
|
33
|
+
"zod-validation-error": "3.3.0"
|
34
|
+
},
|
35
|
+
"devDependencies": {
|
36
|
+
"@faker-js/faker": "8.4.1",
|
37
|
+
"@types/mime-types": "2.1.4",
|
38
|
+
"@types/node": "20.12.12",
|
39
|
+
"@types/supertest": "6.0.2",
|
40
|
+
"@typescript-eslint/eslint-plugin": "7.10.0",
|
41
|
+
"@typescript-eslint/parser": "7.10.0",
|
42
|
+
"eslint": "8.57.0",
|
43
|
+
"eslint-config-prettier": "9.1.0",
|
44
|
+
"eslint-plugin-vitest": "0.4.0",
|
45
|
+
"husky": "9.0.11",
|
46
|
+
"lint-staged": "15.2.5",
|
47
|
+
"prettier": "3.2.5",
|
48
|
+
"rimraf": "5.0.7",
|
49
|
+
"supertest": "7.0.0",
|
50
|
+
"tsx": "4.11.0",
|
51
|
+
"type-fest": "4.20.0",
|
52
|
+
"typescript": "5.4.5",
|
53
|
+
"unbuild": "2.0.0",
|
54
|
+
"vite-tsconfig-paths": "4.3.2",
|
55
|
+
"vitest": "1.6.0"
|
56
|
+
}
|
57
|
+
}
|