create-origo-app 0.0.0-stage → 0.1.1
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/README.md +314 -2
- package/dist/base/backend/express/.env +3 -0
- package/dist/base/backend/express/javascript/src/app.js +25 -0
- package/dist/base/backend/express/javascript/src/config/env.js +10 -0
- package/dist/base/backend/express/javascript/src/routes/index.js +18 -0
- package/dist/base/backend/express/javascript/src/server.js +28 -0
- package/dist/base/backend/express/manifest.js +61 -0
- package/dist/base/backend/express/typescript/src/app.ts +25 -0
- package/dist/base/backend/express/typescript/src/config/env.ts +10 -0
- package/dist/base/backend/express/typescript/src/routes/index.ts +18 -0
- package/dist/base/backend/express/typescript/src/server.ts +28 -0
- package/dist/base/backend/express/typescript/tsconfig.server.json +16 -0
- package/dist/base/backend/fastify/javascript/src/app.js +16 -0
- package/dist/base/backend/fastify/javascript/src/routes/index.js +18 -0
- package/dist/base/backend/fastify/javascript/src/server.js +27 -0
- package/dist/base/backend/fastify/manifest.js +61 -0
- package/dist/base/backend/fastify/typescript/src/app.ts +16 -0
- package/dist/base/backend/fastify/typescript/src/routes/index.ts +20 -0
- package/dist/base/backend/fastify/typescript/src/server.ts +27 -0
- package/dist/base/frontend/react/app/App.css +308 -0
- package/dist/base/frontend/react/app/App.tsx +59 -0
- package/dist/base/frontend/react/app/assets/react.svg +1 -0
- package/dist/base/frontend/react/app/assets/vite.svg +1 -0
- package/dist/base/frontend/react/app/components/Counter.tsx +16 -0
- package/dist/base/frontend/react/app/components/OrigoLogo.tsx +32 -0
- package/dist/base/frontend/react/app/components/PingButton.tsx +45 -0
- package/dist/base/frontend/react/app/index.css +27 -0
- package/dist/base/frontend/react/app/main.tsx +17 -0
- package/dist/base/frontend/react/app/vite-env.d.ts +2 -0
- package/dist/base/frontend/react/html/index.html +23 -0
- package/dist/base/frontend/react/manifest.js +180 -0
- package/dist/base/frontend/react/styles/bootstrap/App.tsx +61 -0
- package/dist/base/frontend/react/styles/bootstrap/Counter.tsx +16 -0
- package/dist/base/frontend/react/styles/bootstrap/PingButton.tsx +52 -0
- package/dist/base/frontend/react/styles/bootstrap/index.css +174 -0
- package/dist/base/frontend/react/styles/sass/App.scss +231 -0
- package/dist/base/frontend/react/styles/sass/App.tsx +59 -0
- package/dist/base/frontend/react/styles/sass/PingButton.scss +33 -0
- package/dist/base/frontend/react/styles/sass/PingButton.tsx +47 -0
- package/dist/base/frontend/react/styles/sass/index.scss +30 -0
- package/dist/base/frontend/react/styles/sass/main.tsx +17 -0
- package/dist/base/frontend/react/styles/tailwind/App.tsx +66 -0
- package/dist/base/frontend/react/styles/tailwind/Counter.tsx +16 -0
- package/dist/base/frontend/react/styles/tailwind/PingButton.tsx +52 -0
- package/dist/base/frontend/shared/favicon.ico +0 -0
- package/dist/base/frontend/shared/origo-logo.svg +6 -0
- package/dist/commands/create.js +196 -0
- package/dist/commands/index.js +11 -0
- package/dist/composer/ast/arrays.js +12 -0
- package/dist/composer/ast/config.js +13 -0
- package/dist/composer/ast/context.js +73 -0
- package/dist/composer/ast/expressions.js +6 -0
- package/dist/composer/ast/imports.js +33 -0
- package/dist/composer/ast/index.js +6 -0
- package/dist/composer/ast/objects.js +32 -0
- package/dist/config/architectures.js +5 -0
- package/dist/config/backend.js +9 -0
- package/dist/config/frontend.js +17 -0
- package/dist/config/fullstack.js +30 -0
- package/dist/constants/app.js +3 -0
- package/dist/core/copy-template.js +57 -0
- package/dist/core/dependency-resolver.js +43 -0
- package/dist/core/install-dependencies.js +10 -0
- package/dist/core/path-safety.js +22 -0
- package/dist/core/project-target.js +40 -0
- package/dist/core/version-resolver.js +137 -0
- package/dist/features/frontend/styling/tailwind/dependencies.js +10 -0
- package/dist/features/frontend/styling/tailwind/feature.js +11 -0
- package/dist/features/frontend/styling/tailwind/generator.js +13 -0
- package/dist/features/frontend/styling/tailwind/index.js +3 -0
- package/dist/features/frontend/styling/tailwind/integrations/index.js +11 -0
- package/dist/features/frontend/styling/tailwind/integrations/rsbuild.js +3 -0
- package/dist/features/frontend/styling/tailwind/integrations/vite.js +17 -0
- package/dist/features/frontend/styling/tailwind/integrations/webpack.js +3 -0
- package/dist/features/frontend/styling/tailwind/templates/tailwind-css.js +1 -0
- package/dist/features/frontend/styling/tailwind/templates/theme.js +39 -0
- package/dist/features/frontend/styling/tailwind/versions/v3.js +19 -0
- package/dist/features/frontend/styling/tailwind/versions/v4.js +11 -0
- package/dist/features/frontend/ui/shadcn/dependencies.js +8 -0
- package/dist/features/frontend/ui/shadcn/feature.js +11 -0
- package/dist/features/frontend/ui/shadcn/generator.js +13 -0
- package/dist/features/frontend/ui/shadcn/index.js +3 -0
- package/dist/features/frontend/ui/shadcn/patches/tsconfig.js +22 -0
- package/dist/features/frontend/ui/shadcn/patches/vite-config.js +35 -0
- package/dist/features/frontend/ui/shadcn/templates/components-json.js +23 -0
- package/dist/features/frontend/ui/shadcn/templates/lib-utils.js +14 -0
- package/dist/features/index.js +29 -0
- package/dist/generators/backend/base-loader.js +33 -0
- package/dist/generators/backend/context.js +54 -0
- package/dist/generators/backend/generate.js +72 -0
- package/dist/generators/backend/index.js +4 -0
- package/dist/generators/backend/resolvers/database.js +1277 -0
- package/dist/generators/frontend/base-loader.js +23 -0
- package/dist/generators/frontend/context.js +118 -0
- package/dist/generators/frontend/css.js +34 -0
- package/dist/generators/frontend/file-writer.js +37 -0
- package/dist/generators/frontend/generate.js +46 -0
- package/dist/generators/frontend/index.js +4 -0
- package/dist/generators/frontend/resolvers/base.js +24 -0
- package/dist/generators/frontend/resolvers/bundler.js +13 -0
- package/dist/generators/frontend/resolvers/index.js +5 -0
- package/dist/generators/frontend/resolvers/language.js +55 -0
- package/dist/generators/frontend/resolvers/profile.js +41 -0
- package/dist/generators/frontend/resolvers/typescript.js +29 -0
- package/dist/generators/frontend/template.js +3 -0
- package/dist/generators/frontend/validate.js +31 -0
- package/dist/generators/package-json/build-package-json.js +33 -0
- package/dist/generators/package-json/index.js +2 -0
- package/dist/generators/package-json/types.js +1 -0
- package/dist/generators/package-json/write-package-json.js +9 -0
- package/dist/index.js +6 -0
- package/dist/prompts/architecture.js +5 -0
- package/dist/prompts/compatibility.js +18 -0
- package/dist/prompts/custom-fullstack.js +10 -0
- package/dist/prompts/custom-stack.js +12 -0
- package/dist/prompts/database-package.js +15 -0
- package/dist/prompts/project-name.js +25 -0
- package/dist/prompts/tech-stack.js +54 -0
- package/dist/registry/bundlers.js +4 -0
- package/dist/registry/databases.js +36 -0
- package/dist/registry/features/development.js +40 -0
- package/dist/registry/features/quality.js +33 -0
- package/dist/registry/features/testing.js +36 -0
- package/dist/registry/features/ui.js +37 -0
- package/dist/registry/frameworks.js +9 -0
- package/dist/registry/packages.js +231 -0
- package/dist/registry/routing.js +12 -0
- package/dist/registry/runtimes.js +7 -0
- package/dist/registry/styling.js +7 -0
- package/dist/types/project.js +1 -0
- package/dist/ui/banner.js +9 -0
- package/dist/ui/checkbox.js +51 -0
- package/dist/ui/logger.js +15 -0
- package/package.json +62 -4
package/README.md
CHANGED
|
@@ -1,3 +1,315 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Create Origo App
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`create-origo-app` is an interactive CLI for generating ready-to-run React and Node.js projects. It creates files in memory, applies stack-specific transformations, and writes a clean project layout with resolved dependencies and automatic installs.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js `>=20`
|
|
8
|
+
- npm
|
|
9
|
+
- Internet access when generating a project, because dependency versions are resolved from the npm registry and generated dependencies are installed automatically
|
|
10
|
+
|
|
11
|
+
## Install and use
|
|
12
|
+
|
|
13
|
+
Install globally from npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm i -g create-origo-app@latest
|
|
17
|
+
create-origo-app my-app
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
You can also run it without a global install:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx create-origo-app my-app
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or use the npm create shortcut:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm create origo-app@latest my-app
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The CLI accepts:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
create-origo-app <project-name> [project-path]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Examples:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
create-origo-app my-app
|
|
42
|
+
create-origo-app my-app ./workspace
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The legacy `origo` binary alias is also installed for backward compatibility:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
origo my-app
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Local development setup
|
|
52
|
+
|
|
53
|
+
From the repository root:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install
|
|
57
|
+
npm run typecheck
|
|
58
|
+
npm test
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Useful scripts:
|
|
62
|
+
|
|
63
|
+
| Script | Purpose |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `npm run build` | Compile TypeScript and copy canonical base files into `dist/base` |
|
|
66
|
+
| `npm run dev` | Watch TypeScript and restart the built CLI |
|
|
67
|
+
| `npm run typecheck` | Type-check source without emitting files |
|
|
68
|
+
| `npm test` | Build and run all tests in `tests/*.test.mjs` |
|
|
69
|
+
| `npm run try:cli` | Build and start the local interactive CLI |
|
|
70
|
+
| `npm run preview` | Build and preview the npm tarball contents with `npm pack --dry-run` |
|
|
71
|
+
| `npm run pack:local` | Build and create a local `.tgz` package for install testing |
|
|
72
|
+
| `npm run publish:npm` | Publish the unscoped package to npmjs |
|
|
73
|
+
|
|
74
|
+
## Preview the package before publishing
|
|
75
|
+
|
|
76
|
+
### Preview tarball contents
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm run preview
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This runs `npm pack --dry-run`, so you can confirm that only the intended files, mainly `dist`, `README.md`, and `package.json`, will be published.
|
|
83
|
+
|
|
84
|
+
### Install a local tarball in another folder
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm run pack:local
|
|
88
|
+
cd /tmp
|
|
89
|
+
npx /absolute/path/to/origo/source-code/create-origo-app-0.1.1.tgz demo-app
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The exact `.tgz` name depends on the package version. You can also install it globally from the tarball:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm i -g /absolute/path/to/create-origo-app-0.1.1.tgz
|
|
96
|
+
create-origo-app demo-app
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Link the local package
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm run build
|
|
103
|
+
npm link
|
|
104
|
+
cd /tmp
|
|
105
|
+
create-origo-app linked-app
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Clean up with:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm unlink -g create-origo-app
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Features
|
|
115
|
+
|
|
116
|
+
### Architecture selection
|
|
117
|
+
|
|
118
|
+
- Frontend projects
|
|
119
|
+
- Backend projects
|
|
120
|
+
- Full-stack projects
|
|
121
|
+
|
|
122
|
+
### Presets
|
|
123
|
+
|
|
124
|
+
- MERN: MongoDB, Express, React, Node.js
|
|
125
|
+
- PERN: PostgreSQL, Express, React, Node.js
|
|
126
|
+
- Custom full-stack: choose frontend, backend, and database interactively
|
|
127
|
+
|
|
128
|
+
### Frontend generation
|
|
129
|
+
|
|
130
|
+
- React with Vite
|
|
131
|
+
- TypeScript or JavaScript output
|
|
132
|
+
- Canonical in-source React base files transformed in memory
|
|
133
|
+
- Styling support:
|
|
134
|
+
- Vanilla CSS
|
|
135
|
+
- Tailwind CSS v3/v4
|
|
136
|
+
- Bootstrap
|
|
137
|
+
- Sass/SCSS
|
|
138
|
+
- shadcn/ui integrations for Tailwind projects
|
|
139
|
+
- Generated `vite-env.d.ts` for Vite client and CSS module typings
|
|
140
|
+
- Full-stack projects include a `PingButton` that calls the backend `/api/health` endpoint
|
|
141
|
+
|
|
142
|
+
### Backend generation
|
|
143
|
+
|
|
144
|
+
- Express or Fastify
|
|
145
|
+
- TypeScript or JavaScript output
|
|
146
|
+
- CORS configured from `CLIENT_URL`
|
|
147
|
+
- dotenv loaded from `../.env` for both `src` and `dist`
|
|
148
|
+
- Health endpoint
|
|
149
|
+
- Automatic dependency version resolution from npm
|
|
150
|
+
- Automatic `npm install` in the generated project
|
|
151
|
+
|
|
152
|
+
### Database support
|
|
153
|
+
|
|
154
|
+
Choose one database package during generation:
|
|
155
|
+
|
|
156
|
+
| Database | Package options |
|
|
157
|
+
| --- | --- |
|
|
158
|
+
| MongoDB | Official MongoDB driver, Mongoose |
|
|
159
|
+
| PostgreSQL | `pg`, Prisma, Sequelize |
|
|
160
|
+
|
|
161
|
+
Every database setup generates environment variables, connection/config files, and Todo CRUD:
|
|
162
|
+
|
|
163
|
+
- `src/models/todo.*`
|
|
164
|
+
- `src/services/todos.*`
|
|
165
|
+
- `src/routes/todos.*`
|
|
166
|
+
- `GET /api/todos`
|
|
167
|
+
- `GET /api/todos/:id`
|
|
168
|
+
- `POST /api/todos`
|
|
169
|
+
- `PUT /api/todos/:id`
|
|
170
|
+
- `DELETE /api/todos/:id`
|
|
171
|
+
|
|
172
|
+
Prisma generation also creates:
|
|
173
|
+
|
|
174
|
+
- `prisma/schema.prisma` with a `Todo` model
|
|
175
|
+
- `prisma.config.ts`
|
|
176
|
+
- `db:generate` and `db:push` scripts
|
|
177
|
+
|
|
178
|
+
### Full-stack layout
|
|
179
|
+
|
|
180
|
+
Full-stack projects deliberately create separate packages:
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
my-app/
|
|
184
|
+
├── package.json # root orchestrator
|
|
185
|
+
├── client/
|
|
186
|
+
│ ├── package.json
|
|
187
|
+
│ ├── package-lock.json
|
|
188
|
+
│ ├── node_modules/
|
|
189
|
+
│ ├── .env
|
|
190
|
+
│ └── src/
|
|
191
|
+
└── server/
|
|
192
|
+
├── package.json
|
|
193
|
+
├── package-lock.json
|
|
194
|
+
├── node_modules/
|
|
195
|
+
├── .env
|
|
196
|
+
└── src/
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Root scripts orchestrate both packages:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npm run dev
|
|
203
|
+
npm run build
|
|
204
|
+
npm run dev:client
|
|
205
|
+
npm run dev:server
|
|
206
|
+
npm run build:client
|
|
207
|
+
npm run build:server
|
|
208
|
+
npm run start
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Client environment:
|
|
212
|
+
|
|
213
|
+
```env
|
|
214
|
+
VITE_API_URL=http://localhost:3000/api
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Server environment includes:
|
|
218
|
+
|
|
219
|
+
```env
|
|
220
|
+
PORT=3000
|
|
221
|
+
NODE_ENV=development
|
|
222
|
+
CLIENT_URL=http://localhost:5173
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Database-specific variables are appended when a database is selected.
|
|
226
|
+
|
|
227
|
+
## How the generator works
|
|
228
|
+
|
|
229
|
+
- Canonical base files live under `src/base`.
|
|
230
|
+
- Code and config transformations use `ts-morph` through `src/composer/ast`.
|
|
231
|
+
- Frontend and backend generators build file lists in memory before writing anything.
|
|
232
|
+
- `src/generators/frontend/file-writer.ts` prevents writes outside the project root and refuses symlink escapes.
|
|
233
|
+
- `scripts/build.js` compiles TypeScript and copies base files to `dist/base`.
|
|
234
|
+
- Published packages include only `dist`, plus npm's standard `README.md` and `package.json`.
|
|
235
|
+
|
|
236
|
+
## Current support and roadmap
|
|
237
|
+
|
|
238
|
+
Currently implemented:
|
|
239
|
+
|
|
240
|
+
- React + Vite frontend generation
|
|
241
|
+
- Express and Fastify backend generation
|
|
242
|
+
- MongoDB and PostgreSQL packages listed above
|
|
243
|
+
- Tailwind, Bootstrap, Sass, and vanilla styles
|
|
244
|
+
- shadcn/ui integration
|
|
245
|
+
- Todo CRUD for all database packages
|
|
246
|
+
- Full-stack split packages with root orchestration
|
|
247
|
+
|
|
248
|
+
Currently limited or planned:
|
|
249
|
+
|
|
250
|
+
- Webpack and Rsbuild generation currently throw a clear “not implemented” error.
|
|
251
|
+
- Frontend framework options beyond React are not fully generated yet.
|
|
252
|
+
- React Router and TanStack Router prompts exist but routing generation is still planned.
|
|
253
|
+
- CSS Modules prompt option is listed but has no dedicated feature generator yet.
|
|
254
|
+
|
|
255
|
+
## Contributing
|
|
256
|
+
|
|
257
|
+
1. Fork the repository and create a branch:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
git checkout -b feat/my-change
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
2. Install dependencies:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npm install
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
3. Make changes in `src`.
|
|
270
|
+
4. Add or update tests under `tests/*.test.mjs`.
|
|
271
|
+
5. Do not edit generated `dist` files; they are rebuilt from `src`.
|
|
272
|
+
6. Run checks:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
npm run typecheck
|
|
276
|
+
npm test
|
|
277
|
+
npm run preview
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
7. Commit with a concise message and open a pull request.
|
|
281
|
+
|
|
282
|
+
### Where to make changes
|
|
283
|
+
|
|
284
|
+
| Change | Location |
|
|
285
|
+
| --- | --- |
|
|
286
|
+
| Canonical generated files | `src/base` |
|
|
287
|
+
| Frontend generation | `src/generators/frontend` |
|
|
288
|
+
| Backend generation | `src/generators/backend` |
|
|
289
|
+
| AST transformations | `src/composer/ast` |
|
|
290
|
+
| Optional frontend features | `src/features` |
|
|
291
|
+
| Stack choices and prompts | `src/config`, `src/prompts`, `src/registry` |
|
|
292
|
+
| Dependency mappings | `src/registry/packages.ts` |
|
|
293
|
+
| CLI flow | `src/commands` |
|
|
294
|
+
| Build behavior | `scripts/build.js` |
|
|
295
|
+
| Tests | `tests` |
|
|
296
|
+
|
|
297
|
+
### Pull request checklist
|
|
298
|
+
|
|
299
|
+
- `npm run typecheck` passes
|
|
300
|
+
- `npm test` passes
|
|
301
|
+
- `npm run preview` shows the expected package contents
|
|
302
|
+
- Generated projects still build for affected stacks
|
|
303
|
+
- README updated when behavior or usage changes
|
|
304
|
+
- No secrets, local paths, or generated `dist` files committed
|
|
305
|
+
|
|
306
|
+
## Maintainer publishing
|
|
307
|
+
|
|
308
|
+
Publishing is configured for npmjs through `publishConfig`, and the package is public:
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
npm version patch
|
|
312
|
+
npm run publish:npm
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
If npm asks for two-factor authentication, use the OTP from your npm account authenticator app. Use `npm run preview` before publishing to confirm the tarball contents.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import cors from "cors";
|
|
2
|
+
import express from "express";
|
|
3
|
+
|
|
4
|
+
import { env } from "./config/env.js";
|
|
5
|
+
import { apiRouter } from "./routes/index.js";
|
|
6
|
+
{{DB_ROUTE_IMPORT}}
|
|
7
|
+
|
|
8
|
+
export function createApp() {
|
|
9
|
+
const app = express();
|
|
10
|
+
|
|
11
|
+
app.use(cors({ origin: env.clientUrl }));
|
|
12
|
+
app.use(express.json());
|
|
13
|
+
|
|
14
|
+
app.get("/", (_request, response) => {
|
|
15
|
+
response.json({
|
|
16
|
+
name: "{{PROJECT_NAME}}",
|
|
17
|
+
message: "Origo Express API is running",
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app.use("/api", apiRouter);
|
|
22
|
+
{{DB_ROUTE_REGISTER}}
|
|
23
|
+
|
|
24
|
+
return app;
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function parsePort(value) {
|
|
2
|
+
const port = Number(value ?? 3000);
|
|
3
|
+
return Number.isInteger(port) && port > 0 ? port : 3000;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const env = {
|
|
7
|
+
port: parsePort(process.env.PORT),
|
|
8
|
+
nodeEnv: process.env.NODE_ENV ?? "development",
|
|
9
|
+
clientUrl: process.env.CLIENT_URL ?? "http://localhost:5173",
|
|
10
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
|
|
3
|
+
export const apiRouter = Router();
|
|
4
|
+
|
|
5
|
+
apiRouter.get("/health", (_request, response) => {
|
|
6
|
+
response.status(200).json({
|
|
7
|
+
status: "ok",
|
|
8
|
+
uptime: process.uptime(),
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
apiRouter.get("/hello", (request, response) => {
|
|
13
|
+
const name = typeof request.query.name === "string" ? request.query.name : "Origo";
|
|
14
|
+
|
|
15
|
+
response.json({
|
|
16
|
+
message: `Hello, ${name}!`,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
import dotenv from "dotenv";
|
|
5
|
+
|
|
6
|
+
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
dotenv.config({ path: path.resolve(currentDirectory, "../.env") });
|
|
8
|
+
{{DB_IMPORT}}
|
|
9
|
+
|
|
10
|
+
const { createApp } = await import("./app.js");
|
|
11
|
+
const { env } = await import("./config/env.js");
|
|
12
|
+
{{DB_CONNECT}}
|
|
13
|
+
|
|
14
|
+
const app = createApp();
|
|
15
|
+
|
|
16
|
+
const server = app.listen(env.port, () => {
|
|
17
|
+
console.log(`Server listening on http://localhost:${env.port}`);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function shutdown() {
|
|
21
|
+
server.close(() => {
|
|
22
|
+
console.log("Server closed");
|
|
23
|
+
process.exit(0);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
process.on("SIGINT", shutdown);
|
|
28
|
+
process.on("SIGTERM", shutdown);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const commonFiles = [
|
|
2
|
+
{
|
|
3
|
+
source: "backend/express/.env",
|
|
4
|
+
destination: ".env",
|
|
5
|
+
kind: "text",
|
|
6
|
+
},
|
|
7
|
+
];
|
|
8
|
+
const languageFiles = {
|
|
9
|
+
typescript: [
|
|
10
|
+
{
|
|
11
|
+
source: "backend/express/typescript/src/app.ts",
|
|
12
|
+
destination: "src/app.ts",
|
|
13
|
+
kind: "text",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
source: "backend/express/typescript/src/server.ts",
|
|
17
|
+
destination: "src/server.ts",
|
|
18
|
+
kind: "text",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
source: "backend/express/typescript/src/config/env.ts",
|
|
22
|
+
destination: "src/config/env.ts",
|
|
23
|
+
kind: "text",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
source: "backend/express/typescript/src/routes/index.ts",
|
|
27
|
+
destination: "src/routes/index.ts",
|
|
28
|
+
kind: "text",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
source: "backend/express/typescript/tsconfig.server.json",
|
|
32
|
+
destination: "tsconfig.json",
|
|
33
|
+
kind: "text",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
javascript: [
|
|
37
|
+
{
|
|
38
|
+
source: "backend/express/javascript/src/app.js",
|
|
39
|
+
destination: "src/app.js",
|
|
40
|
+
kind: "text",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
source: "backend/express/javascript/src/server.js",
|
|
44
|
+
destination: "src/server.js",
|
|
45
|
+
kind: "text",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
source: "backend/express/javascript/src/config/env.js",
|
|
49
|
+
destination: "src/config/env.js",
|
|
50
|
+
kind: "text",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
source: "backend/express/javascript/src/routes/index.js",
|
|
54
|
+
destination: "src/routes/index.js",
|
|
55
|
+
kind: "text",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
export function getExpressBaseFiles(language) {
|
|
60
|
+
return [...commonFiles, ...languageFiles[language]];
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import cors from "cors";
|
|
2
|
+
import express, { type Express } from "express";
|
|
3
|
+
|
|
4
|
+
import { env } from "./config/env.js";
|
|
5
|
+
import { apiRouter } from "./routes/index.js";
|
|
6
|
+
{{DB_ROUTE_IMPORT}}
|
|
7
|
+
|
|
8
|
+
export function createApp(): Express {
|
|
9
|
+
const app = express();
|
|
10
|
+
|
|
11
|
+
app.use(cors({ origin: env.clientUrl }));
|
|
12
|
+
app.use(express.json());
|
|
13
|
+
|
|
14
|
+
app.get("/", (_request, response) => {
|
|
15
|
+
response.json({
|
|
16
|
+
name: "{{PROJECT_NAME}}",
|
|
17
|
+
message: "Origo Express API is running",
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app.use("/api", apiRouter);
|
|
22
|
+
{{DB_ROUTE_REGISTER}}
|
|
23
|
+
|
|
24
|
+
return app;
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function parsePort(value: string | undefined): number {
|
|
2
|
+
const port = Number(value ?? 3000);
|
|
3
|
+
return Number.isInteger(port) && port > 0 ? port : 3000;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const env = {
|
|
7
|
+
port: parsePort(process.env.PORT),
|
|
8
|
+
nodeEnv: process.env.NODE_ENV ?? "development",
|
|
9
|
+
clientUrl: process.env.CLIENT_URL ?? "http://localhost:5173",
|
|
10
|
+
} as const;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Router, type Request, type Response } from "express";
|
|
2
|
+
|
|
3
|
+
export const apiRouter = Router();
|
|
4
|
+
|
|
5
|
+
apiRouter.get("/health", (_request: Request, response: Response) => {
|
|
6
|
+
response.status(200).json({
|
|
7
|
+
status: "ok",
|
|
8
|
+
uptime: process.uptime(),
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
apiRouter.get("/hello", (request: Request, response: Response) => {
|
|
13
|
+
const name = typeof request.query.name === "string" ? request.query.name : "Origo";
|
|
14
|
+
|
|
15
|
+
response.json({
|
|
16
|
+
message: `Hello, ${name}!`,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
import dotenv from "dotenv";
|
|
5
|
+
|
|
6
|
+
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
dotenv.config({ path: path.resolve(currentDirectory, "../.env") });
|
|
8
|
+
{{DB_IMPORT}}
|
|
9
|
+
|
|
10
|
+
const { createApp } = await import("./app.js");
|
|
11
|
+
const { env } = await import("./config/env.js");
|
|
12
|
+
{{DB_CONNECT}}
|
|
13
|
+
|
|
14
|
+
const app = createApp();
|
|
15
|
+
|
|
16
|
+
const server = app.listen(env.port, () => {
|
|
17
|
+
console.log(`Server listening on http://localhost:${env.port}`);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function shutdown(): void {
|
|
21
|
+
server.close(() => {
|
|
22
|
+
console.log("Server closed");
|
|
23
|
+
process.exit(0);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
process.on("SIGINT", shutdown);
|
|
28
|
+
process.on("SIGTERM", shutdown);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"noEmitOnError": true,
|
|
13
|
+
"types": ["node"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import cors from "@fastify/cors";
|
|
2
|
+
import Fastify from "fastify";
|
|
3
|
+
|
|
4
|
+
import { env } from "./config/env.js";
|
|
5
|
+
import { registerRoutes } from "./routes/index.js";
|
|
6
|
+
{{DB_ROUTE_IMPORT}}
|
|
7
|
+
|
|
8
|
+
export async function createApp() {
|
|
9
|
+
const app = Fastify({ logger: true });
|
|
10
|
+
|
|
11
|
+
await app.register(cors, { origin: env.clientUrl });
|
|
12
|
+
await app.register(registerRoutes);
|
|
13
|
+
{{DB_ROUTE_REGISTER}}
|
|
14
|
+
|
|
15
|
+
return app;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export async function registerRoutes(app) {
|
|
2
|
+
app.get("/", async () => ({
|
|
3
|
+
name: "{{PROJECT_NAME}}",
|
|
4
|
+
message: "Origo Fastify API is running",
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
app.get("/api/health", async () => ({
|
|
8
|
+
status: "ok",
|
|
9
|
+
service: "{{PROJECT_NAME}}",
|
|
10
|
+
uptime: process.uptime(),
|
|
11
|
+
timestamp: new Date().toISOString(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
app.get("/api/hello", async (request) => {
|
|
15
|
+
const { name } = request.query ?? {};
|
|
16
|
+
return { message: `Hello, ${name ?? "world"}!` };
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
import dotenv from "dotenv";
|
|
5
|
+
|
|
6
|
+
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
dotenv.config({ path: path.resolve(currentDirectory, "../.env") });
|
|
8
|
+
{{DB_IMPORT}}
|
|
9
|
+
|
|
10
|
+
const { createApp } = await import("./app.js");
|
|
11
|
+
const { env } = await import("./config/env.js");
|
|
12
|
+
{{DB_CONNECT}}
|
|
13
|
+
|
|
14
|
+
const app = await createApp();
|
|
15
|
+
const address = await app.listen({ host: "0.0.0.0", port: env.port });
|
|
16
|
+
|
|
17
|
+
console.log(`Server listening on ${address}`);
|
|
18
|
+
|
|
19
|
+
function shutdown() {
|
|
20
|
+
app.close().then(() => {
|
|
21
|
+
console.log("Server closed");
|
|
22
|
+
process.exit(0);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
process.on("SIGINT", shutdown);
|
|
27
|
+
process.on("SIGTERM", shutdown);
|