@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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/compose-app/copy-template.compose.js +1 -0
  4. package/dist/compose-app/replace-content-in-file.compose.js +1 -0
  5. package/dist/config/index.js +1 -0
  6. package/dist/index.js +2 -0
  7. package/dist/utils/logs.js +1 -0
  8. package/dist/utils/on-cancel.js +1 -0
  9. package/dist/utils/to-pascal-case.js +1 -0
  10. package/dist/validations/package-name.validation.js +1 -0
  11. package/package.json +71 -0
  12. package/templates/clean/.env.example +5 -0
  13. package/templates/clean/.eslintignore +2 -0
  14. package/templates/clean/.eslintrc.json +22 -0
  15. package/templates/clean/.husky/pre-commit +1 -0
  16. package/templates/clean/.lintstagedrc.json +4 -0
  17. package/templates/clean/.prettierignore +7 -0
  18. package/templates/clean/.prettierrc.json +6 -0
  19. package/templates/clean/.vscode/settings.json +8 -0
  20. package/templates/clean/build.config.ts +55 -0
  21. package/templates/clean/package.json +41 -0
  22. package/templates/clean/pnpm-lock.yaml +3929 -0
  23. package/templates/clean/src/env.ts +17 -0
  24. package/templates/clean/src/index.ts +1 -0
  25. package/templates/clean/tsconfig.json +15 -0
  26. package/templates/clean/vitest.config.mts +6 -0
  27. package/templates/fastify/.env.example +11 -0
  28. package/templates/fastify/.eslintignore +2 -0
  29. package/templates/fastify/.eslintrc.json +22 -0
  30. package/templates/fastify/.husky/pre-commit +1 -0
  31. package/templates/fastify/.lintstagedrc.json +4 -0
  32. package/templates/fastify/.prettierignore +7 -0
  33. package/templates/fastify/.prettierrc.json +6 -0
  34. package/templates/fastify/.vscode/settings.json +8 -0
  35. package/templates/fastify/build.config.ts +55 -0
  36. package/templates/fastify/package.json +57 -0
  37. package/templates/fastify/pnpm-lock.yaml +5353 -0
  38. package/templates/fastify/src/@types/fastify-zod-type-provider.ts +39 -0
  39. package/templates/fastify/src/@types/fastify.d.ts +16 -0
  40. package/templates/fastify/src/app.ts +45 -0
  41. package/templates/fastify/src/controllers/hello/hello-multipart.controller.e2e-spec.ts +32 -0
  42. package/templates/fastify/src/controllers/hello/hello-multipart.controller.ts +51 -0
  43. package/templates/fastify/src/controllers/hello/hello.controller.e2e-spec.ts +14 -0
  44. package/templates/fastify/src/controllers/hello/hello.controller.ts +36 -0
  45. package/templates/fastify/src/env.ts +19 -0
  46. package/templates/fastify/src/errors/exceptions.ts +87 -0
  47. package/templates/fastify/src/errors/http-error-handler.ts +111 -0
  48. package/templates/fastify/src/plugins/error-handler.plugin.ts +27 -0
  49. package/templates/fastify/src/plugins/handle-swagger-multipart.plugin.ts +96 -0
  50. package/templates/fastify/src/plugins/require-upload.plugin.ts +200 -0
  51. package/templates/fastify/src/routes/hello.routes.ts +8 -0
  52. package/templates/fastify/src/routes/index.ts +6 -0
  53. package/templates/fastify/src/server.ts +12 -0
  54. package/templates/fastify/src/utils/capitalize-word.ts +3 -0
  55. package/templates/fastify/test/e2e-setup.ts +10 -0
  56. package/templates/fastify/tsconfig.json +15 -0
  57. package/templates/fastify/vitest.config.e2e.mts +9 -0
  58. package/templates/fastify/vitest.config.mts +6 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Leonardo Henrique
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @leo-h/create-nodejs-app
2
+
3
+ ![example](https://github.com/Leo-Henrique/create-nodejs-app/assets/72027449/c1d21542-293b-483d-a94b-3fb885a9e43e)
4
+
5
+ Create a Node.js application with TypeScript with just one command and without worrying about environment or framework configurations. Dedicate your energy only to the business rules of your application.
6
+
7
+ ## Get started
8
+
9
+ With NPM:
10
+
11
+ ```bash
12
+ npm create @leo-h/nodejs-app
13
+ ```
14
+
15
+ With Yarn:
16
+
17
+ ```bash
18
+ yarn create @leo-h/nodejs-app
19
+ ```
20
+
21
+ With PNPM:
22
+
23
+ ```bash
24
+ pnpm create @leo-h/nodejs-app
25
+ ```
26
+
27
+ ## Features
28
+
29
+ - **Fast**: All templates use [tsx](https://tsx.is/) to run Node.js with TypeScript and [unbuild](https://github.com/unjs/unbuild) to build the application. Both tools use [esbuild](https://esbuild.github.io/), an extremely fast packager also used by tools like [Vite](https://vitejs.dev/).
30
+
31
+ - **Lint and code format**: All templates use [eslint](https://eslint.org/) to identify problems in the code and [prettier](https://prettier.io/) to ensure consistent code formatting. Both are integrated with [husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/lint-staged/lint-staged) to automatically run them before every commit you make with git.
@@ -0,0 +1 @@
1
+ const index=require("../config/index.js"),promises=require("fs/promises"),path=require("path");async function copyTemplateCompose(o,s){const n=(e,r)=>{for(const t of r)if(path.basename(e)===t)return!0;return!1};await promises.cp(path.resolve(index.TEMPLATES_PATH,s),o,{recursive:!0,filter:e=>!n(e,["node_modules","pnpm-lock.yaml",".env","dist",".eslintcache"])})}exports.copyTemplateCompose=copyTemplateCompose;
@@ -0,0 +1 @@
1
+ const promises=require("fs/promises");async function replaceContentInFileCompose(o,i){let e=await promises.readFile(o,"utf-8");for(const[t,n]of i)e=e.replaceAll(t,n);await promises.writeFile(o,e)}exports.replaceContentInFileCompose=replaceContentInFileCompose;
@@ -0,0 +1 @@
1
+ const path=require("path"),t=path.basename(path.resolve(__dirname,".."));t==="dist"?process.env.NODE_ENV="production":process.env.NODE_ENV="development";const o=path.resolve(__dirname,"../.."),GENERATED_APP_ROOT_PATH=process.env.NODE_ENV==="production"?process.cwd():path.resolve(o,"generated-apps"),TEMPLATES_PATH=path.resolve(o,"templates");path.resolve(TEMPLATES_PATH,"clean");exports.GENERATED_APP_ROOT_PATH=GENERATED_APP_ROOT_PATH;exports.TEMPLATES_PATH=TEMPLATES_PATH;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ const index=require("./config/index.js"),logs=require("./utils/logs.js"),onCancel=require("./utils/on-cancel.js"),fs=require("fs"),promises=require("fs/promises"),path=require("path"),picocolors=require("picocolors"),y=require("prompts"),copyTemplate_compose=require("./compose-app/copy-template.compose.js"),replaceContentInFile_compose=require("./compose-app/replace-content-in-file.compose.js"),packageName_validation=require("./validations/package-name.validation.js"),d=e=>(a,t)=>t.template==="api"?e:null,v=[{type:"text",name:"projectName",message:"What is your project name?",validate:async e=>(await promises.readdir(index.GENERATED_APP_ROOT_PATH)).includes(e)?"Already exists a folder with same name in current directory.":packageName_validation.packageNameValidation(e)},{type:"select",name:"packageManager",message:"What is your favorite package manager?",choices:[{title:"NPM",value:"npm"},{title:"Yarn",value:"yarn"},{title:"PNPM",value:"pnpm"}],initial:2},{type:"select",name:"template",message:"Select your template:",choices:[{title:"Clean",value:"clean"},{title:"API",value:"api"}]},{type:d("select"),name:"framework",message:"What is your favorite framework:",choices:[{title:"Fastify",value:"fastify"},{title:"Nest",value:"nest",disabled:!0},{title:"tRPC",value:"trpc",disabled:!0}],initial:0}];(async()=>{process.env.NODE_ENV==="development"&&!fs.existsSync(index.GENERATED_APP_ROOT_PATH)&&await promises.mkdir(index.GENERATED_APP_ROOT_PATH,{recursive:!0});const e=await y(v,{onCancel:onCancel.onCancelPrompt}),a=path.resolve(index.GENERATED_APP_ROOT_PATH,e.projectName);await copyTemplate_compose.copyTemplateCompose(a,e.framework?e.framework:"clean");const t=path.resolve(a,"package.json"),o=path.resolve(a,".env.example"),s=path.resolve(a,".husky/pre-commit");await Promise.all([replaceContentInFile_compose.replaceContentInFileCompose(t,[["app-name",e.projectName]]),replaceContentInFile_compose.replaceContentInFileCompose(o,[["app-name",e.projectName]]),replaceContentInFile_compose.replaceContentInFileCompose(s,[["pnpm",e.packageManager]])]),logs.successLog(`Success in creating new app ${picocolors.cyan(e.projectName)}!`,`> ${a}`)})();
@@ -0,0 +1 @@
1
+ const picocolors=require("picocolors");function successLog(o,...r){console.log(`${picocolors.green("\u2714")} ${o}`);for(const c of r)console.log(c)}function errorLog(o,...r){console.log(`${picocolors.red("\u2716")} ${o}`);for(const c of r)console.log(c)}exports.errorLog=errorLog;exports.successLog=successLog;
@@ -0,0 +1 @@
1
+ const logs=require("./logs.js");function onCancelPrompt(){logs.errorLog("Script canceled."),process.exit(1)}exports.onCancelPrompt=onCancelPrompt;
@@ -0,0 +1 @@
1
+ function toPascalCase(a){return a[0].toUpperCase()+a.slice(1)}exports.toPascalCase=toPascalCase;
@@ -0,0 +1 @@
1
+ const toPascalCase=require("../utils/to-pascal-case.js"),e=require("validate-npm-package-name");function packageNameValidation(s){const a=e(s);return a.validForNewPackages?!0:toPascalCase.toPascalCase(a.errors[0])}exports.packageNameValidation=packageNameValidation;
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@leo-h/create-nodejs-app",
3
+ "version": "1.0.0",
4
+ "packageManager": "pnpm@9.1.1",
5
+ "author": "Leonardo Henrique <leonardo0507.business@gmail.com>",
6
+ "description": "Create a modern Node.js app with TypeScript using one command.",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "node",
10
+ "node.js",
11
+ "typescript"
12
+ ],
13
+ "bin": {
14
+ "create-nodejs-app": "./dist/index.js"
15
+ },
16
+ "files": [
17
+ "./dist",
18
+ "./templates"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/Leo-Henrique/create-nodejs-app"
23
+ },
24
+ "scripts": {
25
+ "prepare": "husky",
26
+ "start": "node ./dist/index.js",
27
+ "start:dev": "tsx ./src/index.ts",
28
+ "start:dev:watch": "tsx watch ./src/index.ts",
29
+ "typecheck": "tsc --noEmit",
30
+ "lint": "eslint . --ext .ts --max-warnings 0 --cache",
31
+ "lint:fix": "pnpm lint --fix",
32
+ "format": "prettier . --write --cache",
33
+ "test:unit": "vitest run",
34
+ "test:unit:watch": "vitest",
35
+ "test:coverage": "vitest run --coverage.enabled=true --coverage.all=false",
36
+ "template:create": "tsx ./scripts/create-template.script.ts",
37
+ "template:open": "tsx ./scripts/open-template.script.ts",
38
+ "prebuild": "rimraf ./dist",
39
+ "build": "unbuild",
40
+ "prepublishOnly": "pnpm build"
41
+ },
42
+ "dependencies": {
43
+ "commander": "12.1.0",
44
+ "picocolors": "1.0.1",
45
+ "prompts": "2.4.2",
46
+ "validate-npm-package-name": "5.0.1",
47
+ "zod": "3.23.8"
48
+ },
49
+ "devDependencies": {
50
+ "@faker-js/faker": "8.4.1",
51
+ "@types/node": "20.12.12",
52
+ "@types/prompts": "2.4.9",
53
+ "@types/validate-npm-package-name": "4.0.2",
54
+ "@typescript-eslint/eslint-plugin": "7.10.0",
55
+ "@typescript-eslint/parser": "7.10.0",
56
+ "conventional-changelog-conventionalcommits": "8.0.0",
57
+ "eslint": "8.57.0",
58
+ "eslint-config-prettier": "9.1.0",
59
+ "eslint-plugin-vitest": "0.4.0",
60
+ "husky": "9.0.11",
61
+ "lint-staged": "15.2.2",
62
+ "npm-run-all": "4.1.5",
63
+ "prettier": "3.2.5",
64
+ "rimraf": "5.0.7",
65
+ "tsx": "4.10.5",
66
+ "typescript": "5.4.5",
67
+ "unbuild": "2.0.0",
68
+ "vite-tsconfig-paths": "4.3.2",
69
+ "vitest": "1.6.0"
70
+ }
71
+ }
@@ -0,0 +1,5 @@
1
+ # example: "development" ("development" | "test" | "production")
2
+ NODE_ENV=
3
+
4
+ # example: "app-name"
5
+ APP_NAME=
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ dist
@@ -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,4 @@
1
+ {
2
+ "*.{ts,json,yaml,yml,md}": "prettier --write --cache",
3
+ "*.ts": ["eslint --max-warnings 0 --fix --cache"]
4
+ }
@@ -0,0 +1,7 @@
1
+ node_modules
2
+ package-lock.json
3
+ yarn.lock
4
+ pnpm-lock.yaml
5
+ .husky
6
+ coverage
7
+ dist
@@ -0,0 +1,6 @@
1
+ {
2
+ "arrowParens": "avoid",
3
+ "semi": true,
4
+ "singleQuote": false,
5
+ "tabWidth": 2
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
4
+ "editor.codeActionsOnSave": {
5
+ "source.organizeImports": "explicit",
6
+ "source.fixAll.eslint": "explicit"
7
+ }
8
+ }
@@ -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/index.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,41 @@
1
+ {
2
+ "name": "app-name",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "prepare": "husky",
7
+ "start": "node ./dist/index.js",
8
+ "start:dev": "tsx watch ./src/index.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:coverage": "vitest run --coverage.enabled=true --coverage.all=false",
16
+ "prebuild": "rimraf ./dist",
17
+ "build": "unbuild"
18
+ },
19
+ "dependencies": {
20
+ "dotenv": "16.4.5",
21
+ "zod": "3.23.8"
22
+ },
23
+ "devDependencies": {
24
+ "@faker-js/faker": "8.4.1",
25
+ "@types/node": "20.12.12",
26
+ "@typescript-eslint/eslint-plugin": "7.10.0",
27
+ "@typescript-eslint/parser": "7.10.0",
28
+ "eslint": "8.57.0",
29
+ "eslint-config-prettier": "9.1.0",
30
+ "eslint-plugin-vitest": "0.4.0",
31
+ "husky": "9.0.11",
32
+ "lint-staged": "15.2.5",
33
+ "prettier": "3.2.5",
34
+ "rimraf": "5.0.7",
35
+ "tsx": "4.11.0",
36
+ "typescript": "5.4.5",
37
+ "unbuild": "2.0.0",
38
+ "vite-tsconfig-paths": "4.3.2",
39
+ "vitest": "1.6.0"
40
+ }
41
+ }