@buenojs/bueno 0.8.4 → 0.8.6
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 +264 -17
- package/dist/cli/{index.js → bin.js} +413 -332
- package/dist/container/index.js +273 -0
- package/dist/context/index.js +219 -0
- package/dist/database/index.js +493 -0
- package/dist/frontend/index.js +7697 -0
- package/dist/graphql/index.js +2156 -0
- package/dist/health/index.js +364 -0
- package/dist/i18n/index.js +345 -0
- package/dist/index.js +9694 -5047
- package/dist/jobs/index.js +819 -0
- package/dist/lock/index.js +367 -0
- package/dist/logger/index.js +281 -0
- package/dist/metrics/index.js +289 -0
- package/dist/middleware/index.js +77 -0
- package/dist/migrations/index.js +571 -0
- package/dist/modules/index.js +3411 -0
- package/dist/notification/index.js +484 -0
- package/dist/observability/index.js +331 -0
- package/dist/openapi/index.js +795 -0
- package/dist/orm/index.js +1356 -0
- package/dist/router/index.js +886 -0
- package/dist/rpc/index.js +691 -0
- package/dist/schema/index.js +400 -0
- package/dist/telemetry/index.js +595 -0
- package/dist/template/index.js +640 -0
- package/dist/templates/index.js +640 -0
- package/dist/testing/index.js +1111 -0
- package/dist/types/index.js +60 -0
- package/llms.txt +231 -0
- package/package.json +125 -27
- package/src/cache/index.ts +2 -1
- package/src/cli/ARCHITECTURE.md +3 -3
- package/src/cli/bin.ts +2 -2
- package/src/cli/commands/build.ts +183 -165
- package/src/cli/commands/dev.ts +96 -89
- package/src/cli/commands/generate.ts +142 -111
- package/src/cli/commands/help.ts +20 -16
- package/src/cli/commands/index.ts +3 -6
- package/src/cli/commands/migration.ts +124 -105
- package/src/cli/commands/new.ts +294 -232
- package/src/cli/commands/start.ts +81 -79
- package/src/cli/core/args.ts +68 -50
- package/src/cli/core/console.ts +89 -95
- package/src/cli/core/index.ts +4 -4
- package/src/cli/core/prompt.ts +65 -62
- package/src/cli/core/spinner.ts +23 -20
- package/src/cli/index.ts +46 -38
- package/src/cli/templates/database/index.ts +37 -18
- package/src/cli/templates/database/mysql.ts +3 -3
- package/src/cli/templates/database/none.ts +2 -2
- package/src/cli/templates/database/postgresql.ts +3 -3
- package/src/cli/templates/database/sqlite.ts +3 -3
- package/src/cli/templates/deploy.ts +29 -26
- package/src/cli/templates/docker.ts +41 -30
- package/src/cli/templates/frontend/index.ts +33 -15
- package/src/cli/templates/frontend/none.ts +2 -2
- package/src/cli/templates/frontend/react.ts +18 -18
- package/src/cli/templates/frontend/solid.ts +15 -15
- package/src/cli/templates/frontend/svelte.ts +17 -17
- package/src/cli/templates/frontend/vue.ts +15 -15
- package/src/cli/templates/generators/index.ts +29 -29
- package/src/cli/templates/generators/types.ts +21 -21
- package/src/cli/templates/index.ts +6 -6
- package/src/cli/templates/project/api.ts +37 -36
- package/src/cli/templates/project/default.ts +25 -25
- package/src/cli/templates/project/fullstack.ts +28 -26
- package/src/cli/templates/project/index.ts +55 -16
- package/src/cli/templates/project/minimal.ts +17 -12
- package/src/cli/templates/project/types.ts +10 -5
- package/src/cli/templates/project/website.ts +15 -15
- package/src/cli/utils/fs.ts +55 -41
- package/src/cli/utils/index.ts +3 -3
- package/src/cli/utils/strings.ts +47 -33
- package/src/cli/utils/version.ts +14 -8
- package/src/config/env-validation.ts +100 -0
- package/src/config/env.ts +169 -41
- package/src/config/index.ts +28 -20
- package/src/config/loader.ts +25 -16
- package/src/config/merge.ts +21 -10
- package/src/config/types.ts +566 -25
- package/src/config/validation.ts +215 -7
- package/src/container/forward-ref.ts +22 -22
- package/src/container/index.ts +34 -12
- package/src/context/index.ts +11 -1
- package/src/database/index.ts +7 -190
- package/src/database/orm/builder.ts +457 -0
- package/src/database/orm/casts/index.ts +130 -0
- package/src/database/orm/casts/types.ts +25 -0
- package/src/database/orm/compiler.ts +304 -0
- package/src/database/orm/hooks/index.ts +114 -0
- package/src/database/orm/index.ts +61 -0
- package/src/database/orm/model-registry.ts +59 -0
- package/src/database/orm/model.ts +821 -0
- package/src/database/orm/relationships/base.ts +146 -0
- package/src/database/orm/relationships/belongs-to-many.ts +179 -0
- package/src/database/orm/relationships/belongs-to.ts +56 -0
- package/src/database/orm/relationships/has-many.ts +45 -0
- package/src/database/orm/relationships/has-one.ts +41 -0
- package/src/database/orm/relationships/index.ts +11 -0
- package/src/database/orm/scopes/index.ts +55 -0
- package/src/events/__tests__/event-system.test.ts +235 -0
- package/src/events/config.ts +238 -0
- package/src/events/example-usage.ts +185 -0
- package/src/events/index.ts +278 -0
- package/src/events/manager.ts +385 -0
- package/src/events/registry.ts +182 -0
- package/src/events/types.ts +124 -0
- package/src/frontend/api-routes.ts +65 -23
- package/src/frontend/bundler.ts +76 -34
- package/src/frontend/console-client.ts +2 -2
- package/src/frontend/console-stream.ts +94 -38
- package/src/frontend/dev-server.ts +94 -46
- package/src/frontend/file-router.ts +61 -19
- package/src/frontend/frameworks/index.ts +37 -10
- package/src/frontend/frameworks/react.ts +10 -8
- package/src/frontend/frameworks/solid.ts +11 -9
- package/src/frontend/frameworks/svelte.ts +15 -9
- package/src/frontend/frameworks/vue.ts +13 -11
- package/src/frontend/hmr-client.ts +12 -10
- package/src/frontend/hmr.ts +146 -103
- package/src/frontend/index.ts +14 -5
- package/src/frontend/islands.ts +41 -22
- package/src/frontend/isr.ts +59 -37
- package/src/frontend/layout.ts +36 -21
- package/src/frontend/ssr/react.ts +74 -27
- package/src/frontend/ssr/solid.ts +54 -20
- package/src/frontend/ssr/svelte.ts +48 -14
- package/src/frontend/ssr/vue.ts +50 -18
- package/src/frontend/ssr.ts +83 -39
- package/src/frontend/types.ts +91 -56
- package/src/graphql/built-in-engine.ts +598 -0
- package/src/graphql/context-builder.ts +110 -0
- package/src/graphql/decorators.ts +358 -0
- package/src/graphql/execution-pipeline.ts +227 -0
- package/src/graphql/graphql-module.ts +563 -0
- package/src/graphql/index.ts +101 -0
- package/src/graphql/metadata.ts +237 -0
- package/src/graphql/schema-builder.ts +319 -0
- package/src/graphql/subscription-handler.ts +283 -0
- package/src/graphql/types.ts +324 -0
- package/src/health/index.ts +21 -9
- package/src/i18n/engine.ts +305 -0
- package/src/i18n/index.ts +38 -0
- package/src/i18n/loader.ts +218 -0
- package/src/i18n/middleware.ts +164 -0
- package/src/i18n/negotiator.ts +162 -0
- package/src/i18n/types.ts +158 -0
- package/src/index.ts +182 -27
- package/src/jobs/drivers/memory.ts +315 -0
- package/src/jobs/drivers/redis.ts +459 -0
- package/src/jobs/index.ts +30 -0
- package/src/jobs/queue.ts +281 -0
- package/src/jobs/types.ts +295 -0
- package/src/jobs/worker.ts +380 -0
- package/src/logger/index.ts +1 -3
- package/src/logger/transports/index.ts +62 -22
- package/src/metrics/index.ts +25 -16
- package/src/migrations/index.ts +9 -0
- package/src/modules/filters.ts +13 -17
- package/src/modules/guards.ts +49 -26
- package/src/modules/index.ts +457 -299
- package/src/modules/interceptors.ts +58 -20
- package/src/modules/lazy.ts +11 -19
- package/src/modules/lifecycle.ts +15 -7
- package/src/modules/metadata.ts +15 -5
- package/src/modules/pipes.ts +94 -72
- package/src/notification/channels/base.ts +68 -0
- package/src/notification/channels/email.ts +105 -0
- package/src/notification/channels/push.ts +104 -0
- package/src/notification/channels/sms.ts +105 -0
- package/src/notification/channels/whatsapp.ts +104 -0
- package/src/notification/index.ts +48 -0
- package/src/notification/service.ts +354 -0
- package/src/notification/types.ts +344 -0
- package/src/observability/__tests__/observability.test.ts +483 -0
- package/src/observability/breadcrumbs.ts +114 -0
- package/src/observability/index.ts +136 -0
- package/src/observability/interceptor.ts +85 -0
- package/src/observability/service.ts +303 -0
- package/src/observability/trace.ts +37 -0
- package/src/observability/types.ts +196 -0
- package/src/openapi/__tests__/decorators.test.ts +335 -0
- package/src/openapi/__tests__/document-builder.test.ts +285 -0
- package/src/openapi/__tests__/route-scanner.test.ts +334 -0
- package/src/openapi/__tests__/schema-generator.test.ts +275 -0
- package/src/openapi/decorators.ts +328 -0
- package/src/openapi/document-builder.ts +274 -0
- package/src/openapi/index.ts +112 -0
- package/src/openapi/metadata.ts +112 -0
- package/src/openapi/route-scanner.ts +289 -0
- package/src/openapi/schema-generator.ts +256 -0
- package/src/openapi/swagger-module.ts +166 -0
- package/src/openapi/types.ts +398 -0
- package/src/orm/index.ts +10 -0
- package/src/rpc/index.ts +3 -1
- package/src/schema/index.ts +9 -0
- package/src/security/index.ts +15 -6
- package/src/ssg/index.ts +9 -8
- package/src/telemetry/index.ts +76 -22
- package/src/template/index.ts +7 -0
- package/src/templates/engine.ts +224 -0
- package/src/templates/index.ts +9 -0
- package/src/templates/loader.ts +331 -0
- package/src/templates/renderers/markdown.ts +212 -0
- package/src/templates/renderers/simple.ts +269 -0
- package/src/templates/types.ts +154 -0
- package/src/testing/index.ts +100 -27
- package/src/types/optional-deps.d.ts +347 -187
- package/src/validation/index.ts +92 -2
- package/src/validation/schemas.ts +536 -0
- package/tests/integration/cli.test.ts +19 -19
- package/tests/integration/fullstack.test.ts +4 -4
- package/tests/unit/cli.test.ts +1 -1
- package/tests/unit/database.test.ts +2 -72
- package/tests/unit/env-validation.test.ts +166 -0
- package/tests/unit/events.test.ts +910 -0
- package/tests/unit/graphql.test.ts +991 -0
- package/tests/unit/i18n.test.ts +455 -0
- package/tests/unit/jobs.test.ts +493 -0
- package/tests/unit/notification.test.ts +988 -0
- package/tests/unit/observability.test.ts +453 -0
- package/tests/unit/orm/builder.test.ts +323 -0
- package/tests/unit/orm/casts.test.ts +179 -0
- package/tests/unit/orm/compiler.test.ts +220 -0
- package/tests/unit/orm/eager-loading.test.ts +285 -0
- package/tests/unit/orm/hooks.test.ts +191 -0
- package/tests/unit/orm/model.test.ts +373 -0
- package/tests/unit/orm/relationships.test.ts +303 -0
- package/tests/unit/orm/scopes.test.ts +74 -0
- package/tests/unit/templates-simple.test.ts +53 -0
- package/tests/unit/templates.test.ts +454 -0
- package/tests/unit/validation.test.ts +18 -24
- package/tsconfig.json +11 -3
|
@@ -4,52 +4,56 @@
|
|
|
4
4
|
* Generate code artifacts (controllers, services, modules, etc.)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
7
|
+
import { type ParsedArgs, getOption, hasFlag } from "../core/args";
|
|
8
|
+
import { cliConsole, colors } from "../core/console";
|
|
9
|
+
import { confirm, isInteractive } from "../core/prompt";
|
|
10
|
+
import { spinner } from "../core/spinner";
|
|
11
|
+
import { CLIError, CLIErrorType } from "../index";
|
|
12
12
|
import {
|
|
13
13
|
fileExists,
|
|
14
|
-
writeFile,
|
|
15
|
-
readFile,
|
|
16
14
|
getProjectRoot,
|
|
17
15
|
isBuenoProject,
|
|
18
16
|
joinPaths,
|
|
19
17
|
processTemplate,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
readFile,
|
|
19
|
+
writeFile,
|
|
20
|
+
} from "../utils/fs";
|
|
21
|
+
import { camelCase, kebabCase, pascalCase } from "../utils/strings";
|
|
22
|
+
import { defineCommand } from "./index";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Generator types
|
|
26
26
|
*/
|
|
27
27
|
type GeneratorType =
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
28
|
+
| "controller"
|
|
29
|
+
| "service"
|
|
30
|
+
| "module"
|
|
31
|
+
| "guard"
|
|
32
|
+
| "interceptor"
|
|
33
|
+
| "pipe"
|
|
34
|
+
| "filter"
|
|
35
|
+
| "dto"
|
|
36
|
+
| "middleware"
|
|
37
|
+
| "migration"
|
|
38
|
+
| "job"
|
|
39
|
+
| "job-handler";
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* Generator aliases
|
|
41
43
|
*/
|
|
42
44
|
const GENERATOR_ALIASES: Record<string, GeneratorType> = {
|
|
43
|
-
c:
|
|
44
|
-
s:
|
|
45
|
-
m:
|
|
46
|
-
gu:
|
|
47
|
-
i:
|
|
48
|
-
p:
|
|
49
|
-
f:
|
|
50
|
-
d:
|
|
51
|
-
mw:
|
|
52
|
-
mi:
|
|
45
|
+
c: "controller",
|
|
46
|
+
s: "service",
|
|
47
|
+
m: "module",
|
|
48
|
+
gu: "guard",
|
|
49
|
+
i: "interceptor",
|
|
50
|
+
p: "pipe",
|
|
51
|
+
f: "filter",
|
|
52
|
+
d: "dto",
|
|
53
|
+
mw: "middleware",
|
|
54
|
+
mi: "migration",
|
|
55
|
+
j: "job",
|
|
56
|
+
jh: "job-handler",
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
/**
|
|
@@ -259,7 +263,7 @@ export const {{camelCase name}}Middleware: Middleware = async (
|
|
|
259
263
|
return result;
|
|
260
264
|
};
|
|
261
265
|
`,
|
|
262
|
-
migration: `import { createMigration, type MigrationRunner } from '@buenojs/bueno';
|
|
266
|
+
migration: `import { createMigration, type MigrationRunner } from '@buenojs/bueno/migrations';
|
|
263
267
|
|
|
264
268
|
export default createMigration('{{migrationId}}', '{{migrationName}}')
|
|
265
269
|
.up(async (db: MigrationRunner) => {
|
|
@@ -278,6 +282,23 @@ export default createMigration('{{migrationId}}', '{{migrationName}}')
|
|
|
278
282
|
// Example:
|
|
279
283
|
// await db.dropTable('{{tableName}}');
|
|
280
284
|
});
|
|
285
|
+
`,
|
|
286
|
+
job: `export interface {{pascalCase name}}JobData {
|
|
287
|
+
// TODO: Define job data properties
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export const {{camelCase name}} = (data: {{pascalCase name}}JobData) => ({
|
|
291
|
+
name: '{{camelCase name}}',
|
|
292
|
+
data,
|
|
293
|
+
});
|
|
294
|
+
`,
|
|
295
|
+
"job-handler": `import { type JobHandler } from '@buenojs/bueno/jobs';
|
|
296
|
+
import type { {{pascalCase name}}JobData } from './{{kebabCase name}}.job';
|
|
297
|
+
|
|
298
|
+
export const handle{{pascalCase name}}: JobHandler<{{pascalCase name}}JobData> = async (job) => {
|
|
299
|
+
const { data } = job;
|
|
300
|
+
// TODO: Implement job logic
|
|
301
|
+
};
|
|
281
302
|
`,
|
|
282
303
|
};
|
|
283
304
|
|
|
@@ -288,7 +309,10 @@ export default createMigration('{{migrationId}}', '{{migrationName}}')
|
|
|
288
309
|
* Get file extension for generator type
|
|
289
310
|
*/
|
|
290
311
|
function getFileExtension(type: GeneratorType): string {
|
|
291
|
-
|
|
312
|
+
if (type === "dto") return ".dto.ts";
|
|
313
|
+
if (type === "job") return ".job.ts";
|
|
314
|
+
if (type === "job-handler") return ".handler.ts";
|
|
315
|
+
return ".ts";
|
|
292
316
|
}
|
|
293
317
|
|
|
294
318
|
/**
|
|
@@ -296,25 +320,29 @@ function getFileExtension(type: GeneratorType): string {
|
|
|
296
320
|
*/
|
|
297
321
|
function getDefaultDirectory(type: GeneratorType): string {
|
|
298
322
|
switch (type) {
|
|
299
|
-
case
|
|
300
|
-
case
|
|
301
|
-
case
|
|
302
|
-
case
|
|
303
|
-
return
|
|
304
|
-
case
|
|
305
|
-
return
|
|
306
|
-
case
|
|
307
|
-
return
|
|
308
|
-
case
|
|
309
|
-
return
|
|
310
|
-
case
|
|
311
|
-
return
|
|
312
|
-
case
|
|
313
|
-
return
|
|
314
|
-
case
|
|
315
|
-
return
|
|
323
|
+
case "controller":
|
|
324
|
+
case "service":
|
|
325
|
+
case "module":
|
|
326
|
+
case "dto":
|
|
327
|
+
return "modules";
|
|
328
|
+
case "guard":
|
|
329
|
+
return "common/guards";
|
|
330
|
+
case "interceptor":
|
|
331
|
+
return "common/interceptors";
|
|
332
|
+
case "pipe":
|
|
333
|
+
return "common/pipes";
|
|
334
|
+
case "filter":
|
|
335
|
+
return "common/filters";
|
|
336
|
+
case "middleware":
|
|
337
|
+
return "common/middleware";
|
|
338
|
+
case "migration":
|
|
339
|
+
return "database/migrations";
|
|
340
|
+
case "job":
|
|
341
|
+
return "modules/jobs";
|
|
342
|
+
case "job-handler":
|
|
343
|
+
return "modules/jobs/handlers";
|
|
316
344
|
default:
|
|
317
|
-
return
|
|
345
|
+
return "";
|
|
318
346
|
}
|
|
319
347
|
}
|
|
320
348
|
|
|
@@ -328,7 +356,7 @@ async function generateFile(config: GeneratorConfig): Promise<string> {
|
|
|
328
356
|
const projectRoot = await getProjectRoot();
|
|
329
357
|
if (!projectRoot) {
|
|
330
358
|
throw new CLIError(
|
|
331
|
-
|
|
359
|
+
"Not in a Bueno project directory",
|
|
332
360
|
CLIErrorType.NOT_FOUND,
|
|
333
361
|
);
|
|
334
362
|
}
|
|
@@ -341,20 +369,21 @@ async function generateFile(config: GeneratorConfig): Promise<string> {
|
|
|
341
369
|
if (customPath) {
|
|
342
370
|
targetDir = joinPaths(projectRoot, customPath);
|
|
343
371
|
} else if (module) {
|
|
344
|
-
targetDir = joinPaths(projectRoot,
|
|
345
|
-
} else if (type ===
|
|
346
|
-
targetDir = joinPaths(projectRoot,
|
|
372
|
+
targetDir = joinPaths(projectRoot, "server", defaultDir, kebabCase(module));
|
|
373
|
+
} else if (type === "migration") {
|
|
374
|
+
targetDir = joinPaths(projectRoot, "server", defaultDir);
|
|
347
375
|
} else {
|
|
348
|
-
targetDir = joinPaths(projectRoot,
|
|
376
|
+
targetDir = joinPaths(projectRoot, "server", defaultDir, kebabName);
|
|
349
377
|
}
|
|
350
378
|
|
|
351
|
-
const fileName =
|
|
352
|
-
|
|
353
|
-
|
|
379
|
+
const fileName =
|
|
380
|
+
type === "migration"
|
|
381
|
+
? `${generateMigrationId()}_${kebabName}${getFileExtension(type)}`
|
|
382
|
+
: `${kebabName}${getFileExtension(type)}`;
|
|
354
383
|
const filePath = joinPaths(targetDir, fileName);
|
|
355
384
|
|
|
356
385
|
// Check if file exists
|
|
357
|
-
if (!force && await fileExists(filePath)) {
|
|
386
|
+
if (!force && (await fileExists(filePath))) {
|
|
358
387
|
if (isInteractive()) {
|
|
359
388
|
const shouldOverwrite = await confirm(
|
|
360
389
|
`File ${colors.cyan(filePath)} already exists. Overwrite?`,
|
|
@@ -362,7 +391,7 @@ async function generateFile(config: GeneratorConfig): Promise<string> {
|
|
|
362
391
|
);
|
|
363
392
|
if (!shouldOverwrite) {
|
|
364
393
|
throw new CLIError(
|
|
365
|
-
|
|
394
|
+
"File already exists. Use --force to overwrite.",
|
|
366
395
|
CLIErrorType.FILE_EXISTS,
|
|
367
396
|
);
|
|
368
397
|
}
|
|
@@ -378,9 +407,9 @@ async function generateFile(config: GeneratorConfig): Promise<string> {
|
|
|
378
407
|
const template = getTemplate(type);
|
|
379
408
|
const content = processTemplate(template, {
|
|
380
409
|
name,
|
|
381
|
-
module: module ??
|
|
410
|
+
module: module ?? "",
|
|
382
411
|
path: customPath ?? kebabName,
|
|
383
|
-
service: type ===
|
|
412
|
+
service: type === "controller" ? name : "",
|
|
384
413
|
migrationId: generateMigrationId(),
|
|
385
414
|
migrationName: name,
|
|
386
415
|
tableName: kebabName,
|
|
@@ -388,10 +417,10 @@ async function generateFile(config: GeneratorConfig): Promise<string> {
|
|
|
388
417
|
|
|
389
418
|
// Write file or show dry run
|
|
390
419
|
if (dryRun) {
|
|
391
|
-
cliConsole.log(`\n${colors.bold(
|
|
392
|
-
cliConsole.log(colors.bold(
|
|
420
|
+
cliConsole.log(`\n${colors.bold("File:")} ${filePath}`);
|
|
421
|
+
cliConsole.log(colors.bold("Content:"));
|
|
393
422
|
cliConsole.log(content);
|
|
394
|
-
cliConsole.log(
|
|
423
|
+
cliConsole.log("");
|
|
395
424
|
} else {
|
|
396
425
|
await writeFile(filePath, content);
|
|
397
426
|
}
|
|
@@ -405,11 +434,11 @@ async function generateFile(config: GeneratorConfig): Promise<string> {
|
|
|
405
434
|
function generateMigrationId(): string {
|
|
406
435
|
const now = new Date();
|
|
407
436
|
const year = now.getFullYear();
|
|
408
|
-
const month = String(now.getMonth() + 1).padStart(2,
|
|
409
|
-
const day = String(now.getDate()).padStart(2,
|
|
410
|
-
const hour = String(now.getHours()).padStart(2,
|
|
411
|
-
const minute = String(now.getMinutes()).padStart(2,
|
|
412
|
-
const second = String(now.getSeconds()).padStart(2,
|
|
437
|
+
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
438
|
+
const day = String(now.getDate()).padStart(2, "0");
|
|
439
|
+
const hour = String(now.getHours()).padStart(2, "0");
|
|
440
|
+
const minute = String(now.getMinutes()).padStart(2, "0");
|
|
441
|
+
const second = String(now.getSeconds()).padStart(2, "0");
|
|
413
442
|
return `${year}${month}${day}${hour}${minute}${second}`;
|
|
414
443
|
}
|
|
415
444
|
|
|
@@ -421,12 +450,12 @@ async function handleGenerate(args: ParsedArgs): Promise<void> {
|
|
|
421
450
|
const typeArg = args.positionals[0];
|
|
422
451
|
if (!typeArg) {
|
|
423
452
|
throw new CLIError(
|
|
424
|
-
|
|
453
|
+
"Generator type is required. Usage: bueno generate <type> <name>",
|
|
425
454
|
CLIErrorType.INVALID_ARGS,
|
|
426
455
|
);
|
|
427
456
|
}
|
|
428
457
|
|
|
429
|
-
const type = GENERATOR_ALIASES[typeArg] ?? typeArg as GeneratorType;
|
|
458
|
+
const type = GENERATOR_ALIASES[typeArg] ?? (typeArg as GeneratorType);
|
|
430
459
|
if (!getTemplate(type)) {
|
|
431
460
|
throw new CLIError(
|
|
432
461
|
`Unknown generator type: ${typeArg}. Available types: controller, service, module, guard, interceptor, pipe, filter, dto, middleware, migration`,
|
|
@@ -438,7 +467,7 @@ async function handleGenerate(args: ParsedArgs): Promise<void> {
|
|
|
438
467
|
const name = args.positionals[1];
|
|
439
468
|
if (!name) {
|
|
440
469
|
throw new CLIError(
|
|
441
|
-
|
|
470
|
+
"Name is required. Usage: bueno generate <type> <name>",
|
|
442
471
|
CLIErrorType.INVALID_ARGS,
|
|
443
472
|
);
|
|
444
473
|
}
|
|
@@ -447,24 +476,24 @@ async function handleGenerate(args: ParsedArgs): Promise<void> {
|
|
|
447
476
|
const config: GeneratorConfig = {
|
|
448
477
|
type,
|
|
449
478
|
name,
|
|
450
|
-
module: getOption<string>(args,
|
|
451
|
-
name:
|
|
452
|
-
type:
|
|
453
|
-
description:
|
|
479
|
+
module: getOption<string>(args, "module", {
|
|
480
|
+
name: "module",
|
|
481
|
+
type: "string",
|
|
482
|
+
description: "",
|
|
454
483
|
}),
|
|
455
|
-
path: getOption<string>(args,
|
|
456
|
-
name:
|
|
457
|
-
type:
|
|
458
|
-
description:
|
|
484
|
+
path: getOption<string>(args, "path", {
|
|
485
|
+
name: "path",
|
|
486
|
+
type: "string",
|
|
487
|
+
description: "",
|
|
459
488
|
}),
|
|
460
|
-
dryRun: hasFlag(args,
|
|
461
|
-
force: hasFlag(args,
|
|
489
|
+
dryRun: hasFlag(args, "dry-run"),
|
|
490
|
+
force: hasFlag(args, "force"),
|
|
462
491
|
};
|
|
463
492
|
|
|
464
493
|
// Check if in a Bueno project
|
|
465
494
|
if (!config.dryRun && !(await isBuenoProject())) {
|
|
466
495
|
throw new CLIError(
|
|
467
|
-
|
|
496
|
+
"Not in a Bueno project directory. Run this command from a Bueno project.",
|
|
468
497
|
CLIErrorType.NOT_FOUND,
|
|
469
498
|
);
|
|
470
499
|
}
|
|
@@ -476,7 +505,7 @@ async function handleGenerate(args: ParsedArgs): Promise<void> {
|
|
|
476
505
|
const filePath = await generateFile(config);
|
|
477
506
|
|
|
478
507
|
if (config.dryRun) {
|
|
479
|
-
s.info(
|
|
508
|
+
s.info("Dry run complete");
|
|
480
509
|
} else {
|
|
481
510
|
s.success(`Created ${colors.green(filePath)}`);
|
|
482
511
|
}
|
|
@@ -489,53 +518,55 @@ async function handleGenerate(args: ParsedArgs): Promise<void> {
|
|
|
489
518
|
// Register the command
|
|
490
519
|
defineCommand(
|
|
491
520
|
{
|
|
492
|
-
name:
|
|
493
|
-
alias:
|
|
494
|
-
description:
|
|
521
|
+
name: "generate",
|
|
522
|
+
alias: "g",
|
|
523
|
+
description:
|
|
524
|
+
"Generate code artifacts (controllers, services, modules, etc.)",
|
|
495
525
|
positionals: [
|
|
496
526
|
{
|
|
497
|
-
name:
|
|
527
|
+
name: "type",
|
|
498
528
|
required: true,
|
|
499
|
-
description:
|
|
529
|
+
description:
|
|
530
|
+
"Type of artifact to generate (controller, service, module, guard, interceptor, pipe, filter, dto, middleware, migration)",
|
|
500
531
|
},
|
|
501
532
|
{
|
|
502
|
-
name:
|
|
533
|
+
name: "name",
|
|
503
534
|
required: true,
|
|
504
|
-
description:
|
|
535
|
+
description: "Name of the artifact",
|
|
505
536
|
},
|
|
506
537
|
],
|
|
507
538
|
options: [
|
|
508
539
|
{
|
|
509
|
-
name:
|
|
510
|
-
alias:
|
|
511
|
-
type:
|
|
512
|
-
description:
|
|
540
|
+
name: "module",
|
|
541
|
+
alias: "m",
|
|
542
|
+
type: "string",
|
|
543
|
+
description: "Parent module to register with",
|
|
513
544
|
},
|
|
514
545
|
{
|
|
515
|
-
name:
|
|
516
|
-
type:
|
|
517
|
-
description:
|
|
546
|
+
name: "path",
|
|
547
|
+
type: "string",
|
|
548
|
+
description: "Custom path for controller routes",
|
|
518
549
|
},
|
|
519
550
|
{
|
|
520
|
-
name:
|
|
521
|
-
type:
|
|
551
|
+
name: "dry-run",
|
|
552
|
+
type: "boolean",
|
|
522
553
|
default: false,
|
|
523
|
-
description:
|
|
554
|
+
description: "Show what would be created without writing",
|
|
524
555
|
},
|
|
525
556
|
{
|
|
526
|
-
name:
|
|
527
|
-
type:
|
|
557
|
+
name: "force",
|
|
558
|
+
type: "boolean",
|
|
528
559
|
default: false,
|
|
529
|
-
description:
|
|
560
|
+
description: "Overwrite existing files",
|
|
530
561
|
},
|
|
531
562
|
],
|
|
532
563
|
examples: [
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
564
|
+
"bueno generate controller users",
|
|
565
|
+
"bueno g service auth",
|
|
566
|
+
"bueno g module posts",
|
|
567
|
+
"bueno g guard auth-guard --module auth",
|
|
568
|
+
"bueno g dto create-user --module users",
|
|
538
569
|
],
|
|
539
570
|
},
|
|
540
571
|
handleGenerate,
|
|
541
|
-
);
|
|
572
|
+
);
|
package/src/cli/commands/help.ts
CHANGED
|
@@ -4,29 +4,33 @@
|
|
|
4
4
|
* Display help information for commands
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import {
|
|
8
|
+
generateGlobalHelpText,
|
|
9
|
+
generateHelpText,
|
|
10
|
+
hasFlag,
|
|
11
|
+
} from "../core/args";
|
|
12
|
+
import { cliConsole } from "../core/console";
|
|
13
|
+
import { defineCommand } from "./index";
|
|
14
|
+
import { registry } from "./index";
|
|
11
15
|
|
|
12
16
|
defineCommand(
|
|
13
17
|
{
|
|
14
|
-
name:
|
|
15
|
-
description:
|
|
18
|
+
name: "help",
|
|
19
|
+
description: "Show help information for commands",
|
|
16
20
|
positionals: [
|
|
17
21
|
{
|
|
18
|
-
name:
|
|
22
|
+
name: "command",
|
|
19
23
|
required: false,
|
|
20
|
-
description:
|
|
24
|
+
description: "Command to show help for",
|
|
21
25
|
},
|
|
22
26
|
],
|
|
23
27
|
options: [
|
|
24
28
|
{
|
|
25
|
-
name:
|
|
26
|
-
alias:
|
|
27
|
-
type:
|
|
29
|
+
name: "all",
|
|
30
|
+
alias: "a",
|
|
31
|
+
type: "boolean",
|
|
28
32
|
default: false,
|
|
29
|
-
description:
|
|
33
|
+
description: "Show help for all commands",
|
|
30
34
|
},
|
|
31
35
|
],
|
|
32
36
|
},
|
|
@@ -39,17 +43,17 @@ defineCommand(
|
|
|
39
43
|
if (cmd) {
|
|
40
44
|
cliConsole.log(generateHelpText(cmd.definition));
|
|
41
45
|
}
|
|
42
|
-
} else if (hasFlag(args,
|
|
46
|
+
} else if (hasFlag(args, "all")) {
|
|
43
47
|
// Show detailed help for all commands
|
|
44
|
-
cliConsole.log(
|
|
48
|
+
cliConsole.log("\nBueno CLI - Available Commands\n");
|
|
45
49
|
|
|
46
50
|
for (const cmd of registry.getAll()) {
|
|
47
51
|
cliConsole.log(generateHelpText(cmd));
|
|
48
|
-
cliConsole.log(
|
|
52
|
+
cliConsole.log("---");
|
|
49
53
|
}
|
|
50
54
|
} else {
|
|
51
55
|
// Show global help
|
|
52
56
|
cliConsole.log(generateGlobalHelpText(registry.getAll()));
|
|
53
57
|
}
|
|
54
58
|
},
|
|
55
|
-
);
|
|
59
|
+
);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Manages command registration and execution
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { CommandDefinition, ParsedArgs } from
|
|
7
|
+
import type { CommandDefinition, ParsedArgs } from "../core/args";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Command handler function type
|
|
@@ -29,10 +29,7 @@ class CommandRegistry {
|
|
|
29
29
|
/**
|
|
30
30
|
* Register a command
|
|
31
31
|
*/
|
|
32
|
-
register(
|
|
33
|
-
definition: CommandDefinition,
|
|
34
|
-
handler: CommandHandler,
|
|
35
|
-
): void {
|
|
32
|
+
register(definition: CommandDefinition, handler: CommandHandler): void {
|
|
36
33
|
this.commands.set(definition.name, {
|
|
37
34
|
definition,
|
|
38
35
|
handler,
|
|
@@ -109,4 +106,4 @@ export function defineCommand(
|
|
|
109
106
|
handler: CommandHandler,
|
|
110
107
|
): void {
|
|
111
108
|
registry.register(definition, handler);
|
|
112
|
-
}
|
|
109
|
+
}
|