@vertz/create-vertz-app 0.1.0 → 0.2.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/dist/scaffold.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,WAAW,EAAE,MAAM;CAIhC;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzF"}
|
package/dist/scaffold.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { appTemplate, denoConfigTemplate, envExampleTemplate, envSrcTemplate, envTemplate, gitignoreTemplate,
|
|
3
|
+
import { appTemplate, denoConfigTemplate, envExampleTemplate, envSrcTemplate, envTemplate, gitignoreTemplate, healthModuleDefTemplate, healthModuleTemplate, healthRouterTemplate, healthServiceTemplate, mainTemplate, packageJsonTemplate, tsconfigTemplate, vertzConfigTemplate, } from './templates/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Error thrown when the project directory already exists
|
|
6
6
|
*/
|
|
@@ -34,10 +34,8 @@ export async function scaffold(parentDir, options) {
|
|
|
34
34
|
// Create subdirectories
|
|
35
35
|
const srcDir = path.join(projectDir, 'src');
|
|
36
36
|
const modulesDir = path.join(srcDir, 'modules');
|
|
37
|
-
const middlewaresDir = path.join(srcDir, 'middlewares');
|
|
38
37
|
await fs.mkdir(srcDir, { recursive: true });
|
|
39
38
|
await fs.mkdir(modulesDir, { recursive: true });
|
|
40
|
-
await fs.mkdir(middlewaresDir, { recursive: true });
|
|
41
39
|
// Generate and write core config files
|
|
42
40
|
await writeFile(projectDir, 'package.json', packageJsonTemplate({ projectName, runtime, includeExample }));
|
|
43
41
|
await writeFile(projectDir, 'tsconfig.json', tsconfigTemplate(runtime));
|
|
@@ -51,18 +49,14 @@ export async function scaffold(parentDir, options) {
|
|
|
51
49
|
}
|
|
52
50
|
// Generate source files
|
|
53
51
|
await writeFile(srcDir, 'env.ts', envSrcTemplate());
|
|
54
|
-
await writeFile(srcDir, 'app.ts', appTemplate());
|
|
52
|
+
await writeFile(srcDir, 'app.ts', appTemplate(includeExample));
|
|
55
53
|
await writeFile(srcDir, 'main.ts', mainTemplate());
|
|
56
|
-
await writeFile(middlewaresDir, 'request-id.middleware.ts', requestIdMiddlewareTemplate());
|
|
57
54
|
// Generate example health module if requested
|
|
58
55
|
if (includeExample) {
|
|
59
|
-
const schemasDir = path.join(modulesDir, 'schemas');
|
|
60
|
-
await fs.mkdir(schemasDir, { recursive: true });
|
|
61
56
|
await writeFile(modulesDir, 'health.module-def.ts', healthModuleDefTemplate());
|
|
62
|
-
await writeFile(modulesDir, 'health.module.ts', healthModuleTemplate());
|
|
63
57
|
await writeFile(modulesDir, 'health.service.ts', healthServiceTemplate());
|
|
64
58
|
await writeFile(modulesDir, 'health.router.ts', healthRouterTemplate());
|
|
65
|
-
await writeFile(
|
|
59
|
+
await writeFile(modulesDir, 'health.module.ts', healthModuleTemplate());
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
/**
|
|
@@ -148,11 +148,11 @@ describe('templates', () => {
|
|
|
148
148
|
});
|
|
149
149
|
describe('appTemplate', () => {
|
|
150
150
|
it('returns non-empty string', () => {
|
|
151
|
-
const result = appTemplate();
|
|
151
|
+
const result = appTemplate(true);
|
|
152
152
|
expect(result.length).toBeGreaterThan(0);
|
|
153
153
|
});
|
|
154
154
|
it('exports createServer', () => {
|
|
155
|
-
const result = appTemplate();
|
|
155
|
+
const result = appTemplate(false);
|
|
156
156
|
expect(result).toContain('createServer');
|
|
157
157
|
});
|
|
158
158
|
});
|
|
@@ -223,7 +223,7 @@ describe('templates', () => {
|
|
|
223
223
|
envExampleTemplate,
|
|
224
224
|
gitignoreTemplate,
|
|
225
225
|
envSrcTemplate,
|
|
226
|
-
appTemplate,
|
|
226
|
+
() => appTemplate(true),
|
|
227
227
|
mainTemplate,
|
|
228
228
|
requestIdMiddlewareTemplate,
|
|
229
229
|
healthModuleDefTemplate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,WAAW,EACX,OAAO,GACR,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,WAAW,EACX,OAAO,GACR,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GAAG,MAAM,CAkDT;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CA+BzD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAO5C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAMpC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAM3C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAgC1C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAavC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,cAAc,EAAE,OAAO,GAAG,MAAM,CAkB3D;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAQrC;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAmBpD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAKhD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAW7C;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAY9C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAqB7C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAQlD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAgB3C"}
|
package/dist/templates/index.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export function packageJsonTemplate({ projectName, runtime, }) {
|
|
5
5
|
const deps = {
|
|
6
|
-
'@vertz/
|
|
6
|
+
'@vertz/core': '^0.1.0',
|
|
7
|
+
'@vertz/schema': '^0.1.0',
|
|
8
|
+
envsafe: '^2.0.3',
|
|
7
9
|
};
|
|
8
10
|
const devDeps = {
|
|
9
11
|
'@vertz/cli': '^0.1.0',
|
|
@@ -20,20 +22,21 @@ export function packageJsonTemplate({ projectName, runtime, }) {
|
|
|
20
22
|
const scripts = {};
|
|
21
23
|
if (runtime === 'bun') {
|
|
22
24
|
scripts.dev = 'bun run src/main.ts';
|
|
23
|
-
scripts.build = '
|
|
24
|
-
scripts.check = '
|
|
25
|
+
scripts.build = 'vertz build';
|
|
26
|
+
scripts.check = 'vertz check';
|
|
25
27
|
}
|
|
26
28
|
else if (runtime === 'node') {
|
|
27
29
|
deps.tsx = '^4.19.0';
|
|
28
30
|
scripts.dev = 'tsx watch src/main.ts';
|
|
29
|
-
scripts.build = '
|
|
30
|
-
scripts.check = '
|
|
31
|
+
scripts.build = 'vertz build';
|
|
32
|
+
scripts.check = 'vertz check';
|
|
31
33
|
}
|
|
32
34
|
else if (runtime === 'deno') {
|
|
33
|
-
scripts.dev = 'deno run src/main.ts';
|
|
35
|
+
scripts.dev = 'deno run --watch src/main.ts';
|
|
36
|
+
scripts.build = 'vertz build';
|
|
34
37
|
scripts.check = 'deno check src/main.ts';
|
|
35
38
|
}
|
|
36
|
-
scripts.start =
|
|
39
|
+
scripts.start = scripts.dev;
|
|
37
40
|
const pkg = {
|
|
38
41
|
name: projectName,
|
|
39
42
|
version: '0.1.0',
|
|
@@ -82,11 +85,10 @@ export function tsconfigTemplate(runtime) {
|
|
|
82
85
|
* vertz.config.ts template
|
|
83
86
|
*/
|
|
84
87
|
export function vertzConfigTemplate() {
|
|
85
|
-
return `import { defineConfig } from '@vertz/
|
|
88
|
+
return `import { defineConfig } from '@vertz/core';
|
|
86
89
|
|
|
87
90
|
export default defineConfig({
|
|
88
|
-
|
|
89
|
-
middlewares: [],
|
|
91
|
+
entry: './src/app.ts',
|
|
90
92
|
});
|
|
91
93
|
`;
|
|
92
94
|
}
|
|
@@ -166,16 +168,21 @@ export const env = envsafe({
|
|
|
166
168
|
/**
|
|
167
169
|
* src/app.ts template
|
|
168
170
|
*/
|
|
169
|
-
export function appTemplate() {
|
|
170
|
-
|
|
171
|
+
export function appTemplate(includeExample) {
|
|
172
|
+
const imports = includeExample
|
|
173
|
+
? `import { vertz } from '@vertz/core';
|
|
174
|
+
import { healthModule } from './modules/health.module.js';`
|
|
175
|
+
: `import { vertz } from '@vertz/core';`;
|
|
176
|
+
const registerModules = includeExample
|
|
177
|
+
? `
|
|
178
|
+
.register(healthModule)`
|
|
179
|
+
: '';
|
|
180
|
+
return `${imports}
|
|
171
181
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
attribute: 'requestId',
|
|
177
|
-
},
|
|
178
|
-
});
|
|
182
|
+
const app = vertz
|
|
183
|
+
.app({ basePath: '/api' })${registerModules};
|
|
184
|
+
|
|
185
|
+
export { app };
|
|
179
186
|
`;
|
|
180
187
|
}
|
|
181
188
|
/**
|
|
@@ -185,14 +192,9 @@ export function mainTemplate() {
|
|
|
185
192
|
return `import { app } from './app.js';
|
|
186
193
|
import { env } from './env.js';
|
|
187
194
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
await app.start({ port: PORT });
|
|
192
|
-
console.log(\`Server running at http://localhost:\${PORT}\`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
main();
|
|
195
|
+
app.listen(env.PORT).then((handle) => {
|
|
196
|
+
console.log(\`✓ Server running at http://localhost:\${handle.port}/api\`);
|
|
197
|
+
});
|
|
196
198
|
`;
|
|
197
199
|
}
|
|
198
200
|
/**
|
|
@@ -222,75 +224,65 @@ export const requestIdMiddleware: Middleware = {
|
|
|
222
224
|
* src/modules/health.module-def.ts template
|
|
223
225
|
*/
|
|
224
226
|
export function healthModuleDefTemplate() {
|
|
225
|
-
return `import
|
|
227
|
+
return `import { vertz } from '@vertz/core';
|
|
226
228
|
|
|
227
|
-
export const
|
|
228
|
-
name: 'health',
|
|
229
|
-
imports: [],
|
|
230
|
-
} satisfies ModuleDefinition;
|
|
229
|
+
export const healthDef = vertz.moduleDef({ name: 'health' });
|
|
231
230
|
`;
|
|
232
231
|
}
|
|
233
232
|
/**
|
|
234
233
|
* src/modules/health.module.ts template
|
|
235
234
|
*/
|
|
236
235
|
export function healthModuleTemplate() {
|
|
237
|
-
return `import
|
|
238
|
-
import {
|
|
236
|
+
return `import { vertz } from '@vertz/core';
|
|
237
|
+
import { healthDef } from './health.module-def.js';
|
|
239
238
|
import { healthRouter } from './health.router.js';
|
|
240
|
-
import {
|
|
239
|
+
import { healthService } from './health.service.js';
|
|
241
240
|
|
|
242
|
-
export const healthModule = {
|
|
243
|
-
|
|
241
|
+
export const healthModule = vertz.module(healthDef, {
|
|
242
|
+
services: [healthService],
|
|
244
243
|
routers: [healthRouter],
|
|
245
|
-
|
|
246
|
-
} satisfies Module;
|
|
244
|
+
});
|
|
247
245
|
`;
|
|
248
246
|
}
|
|
249
247
|
/**
|
|
250
248
|
* src/modules/health.service.ts template
|
|
251
249
|
*/
|
|
252
250
|
export function healthServiceTemplate() {
|
|
253
|
-
return `import
|
|
254
|
-
import { HealthCheckSchema } from './schemas/health-check.schema.js';
|
|
251
|
+
return `import { healthDef } from './health.module-def.js';
|
|
255
252
|
|
|
256
|
-
export
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
async check() {
|
|
260
|
-
// In a real app, check database, external services, etc.
|
|
261
|
-
return {
|
|
253
|
+
export const healthService = healthDef.service({
|
|
254
|
+
methods: () => ({
|
|
255
|
+
check: () => ({
|
|
262
256
|
status: 'ok',
|
|
263
257
|
timestamp: new Date().toISOString(),
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export const healthService = new HealthService();
|
|
258
|
+
}),
|
|
259
|
+
}),
|
|
260
|
+
});
|
|
269
261
|
`;
|
|
270
262
|
}
|
|
271
263
|
/**
|
|
272
264
|
* src/modules/health.router.ts template
|
|
273
265
|
*/
|
|
274
266
|
export function healthRouterTemplate() {
|
|
275
|
-
return `import
|
|
267
|
+
return `import { s } from '@vertz/schema';
|
|
268
|
+
import { healthDef } from './health.module-def.js';
|
|
276
269
|
import { healthService } from './health.service.js';
|
|
277
270
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
},
|
|
292
|
-
}
|
|
293
|
-
};
|
|
271
|
+
const HealthResponseSchema = s.object({
|
|
272
|
+
status: s.string(),
|
|
273
|
+
timestamp: s.string(),
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
export const healthRouter = healthDef
|
|
277
|
+
.router({ prefix: '/health', inject: { healthService } })
|
|
278
|
+
.get('/', {
|
|
279
|
+
response: HealthResponseSchema,
|
|
280
|
+
handler: (ctx) => ctx.healthService.check(),
|
|
281
|
+
})
|
|
282
|
+
.get('/ready', {
|
|
283
|
+
response: s.object({ ready: s.boolean() }),
|
|
284
|
+
handler: () => ({ ready: true }),
|
|
285
|
+
});
|
|
294
286
|
`;
|
|
295
287
|
}
|
|
296
288
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertz/create-vertz-app",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Create a new Vertz application",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"commander": "^14.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "^25.
|
|
38
|
+
"@types/node": "^25.3.1",
|
|
39
39
|
"typescript": "^5.9.3"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|