-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-nestjs-from-scratch.sh
executable file
·136 lines (114 loc) · 2.96 KB
/
create-nestjs-from-scratch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
#
# (c) https://dev.to/micalevisk/5-steps-to-create-a-bare-minimum-nestjs-app-from-scratch-5c3b
#
app_dir=${1:-"nestjs-app"}
[ -z "$app_dir" ] && exit 1
mkdir $app_dir
cd $app_dir
## Using NPM as the default package manager if we didn't succeeded on inferring the invoked one
package_manager="npm"
case "$0" in
*pnpm*)
package_manager="pnpm"
;;
*npm*)
package_manager="npm"
;;
*yarn*)
package_manager="yarn"
;;
esac
echo "Using $package_manager as the package manager!"
case "$package_manager" in
*pnpm*)
pnpm init
pnpm install reflect-metadata@0.1 @nestjs/common@latest @nestjs/core@latest @nestjs/platform-express@latest
pnpm install --save-dev typescript@^5 @types/node @nestjs/cli@latest
;;
*npm*)
npm init --yes
npm install reflect-metadata@0.1 @nestjs/common@latest @nestjs/core@latest @nestjs/platform-express@latest
npm install --save-dev typescript@^5 @types/node @nestjs/cli@latest
;;
*yarn*)
yarn init --yes
yarn add reflect-metadata@0.1 @nestjs/common@latest @nestjs/core@latest @nestjs/platform-express@latest
yarn add --save-dev typescript@^5 @types/node @nestjs/cli@latest
;;
esac
npm pkg delete scripts.test
npm pkg set main="dist/src/main"
npm pkg set scripts.build="nest build"
npm pkg set scripts.start:dev="nest start --watch"
npm pkg set scripts.start:prod="node ."
mkdir src
cat <<EOF > tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"strictNullChecks": true,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./",
"baseUrl": "./",
"skipLibCheck": true,
"incremental": true
}
}
EOF
cat <<EOF > tsconfig.build.json
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
EOF
cat <<EOF > nest-cli.json
{
"\$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"monorepo": false,
"sourceRoot": "src",
"entryFile": "main",
"language": "ts",
"generateOptions": {
"spec": false
},
"compilerOptions": {
"manualRestart": true,
"tsConfigPath": "./tsconfig.build.json",
"webpack": false,
"deleteOutDir": true,
"assets": [],
"watchAssets": false,
"plugins": []
}
}
EOF
npx nest generate module app --flat
cat <<EOF > src/main.ts
import { NestFactory } from '@nestjs/core';
import type { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
await app.listen(process.env.PORT || 3000);
}
bootstrap();
EOF
cat <<EOF > .gitignore
dist/
node_modules/
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
EOF
echo -e "\nApp created at '$app_dir' directory!"