fragment-ts 1.0.0 ā 1.0.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 +401 -0
- package/USAGE.md +1439 -0
- package/bin/fragment.js +2 -0
- package/dist/ai/ai.module.d.ts +27 -0
- package/dist/ai/ai.module.d.ts.map +1 -0
- package/dist/ai/ai.module.js +77 -0
- package/dist/ai/ai.module.js.map +1 -0
- package/dist/auth/auth.module.d.ts +18 -0
- package/dist/auth/auth.module.d.ts.map +1 -0
- package/dist/auth/auth.module.js +89 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/cli/commands/build.command.d.ts +6 -1
- package/dist/cli/commands/build.command.d.ts.map +1 -0
- package/dist/cli/commands/build.command.js +131 -10
- package/dist/cli/commands/build.command.js.map +1 -0
- package/dist/cli/commands/diagnostics.command.d.ts +16 -0
- package/dist/cli/commands/diagnostics.command.d.ts.map +1 -0
- package/dist/cli/commands/diagnostics.command.js +419 -0
- package/dist/cli/commands/diagnostics.command.js.map +1 -0
- package/dist/cli/commands/generate.command.d.ts +13 -6
- package/dist/cli/commands/generate.command.d.ts.map +1 -0
- package/dist/cli/commands/generate.command.js +201 -128
- package/dist/cli/commands/generate.command.js.map +1 -0
- package/dist/cli/commands/init.command.d.ts +11 -5
- package/dist/cli/commands/init.command.d.ts.map +1 -0
- package/dist/cli/commands/init.command.js +268 -305
- package/dist/cli/commands/init.command.js.map +1 -0
- package/dist/cli/commands/migrate.command.d.ts +12 -5
- package/dist/cli/commands/migrate.command.d.ts.map +1 -0
- package/dist/cli/commands/migrate.command.js +212 -83
- package/dist/cli/commands/migrate.command.js.map +1 -0
- package/dist/cli/commands/serve.command.d.ts +5 -4
- package/dist/cli/commands/serve.command.d.ts.map +1 -0
- package/dist/cli/commands/serve.command.js +179 -21
- package/dist/cli/commands/serve.command.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +22 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/container/di-container.d.ts +13 -7
- package/dist/core/container/di-container.d.ts.map +1 -0
- package/dist/core/container/di-container.js +76 -25
- package/dist/core/container/di-container.js.map +1 -0
- package/dist/core/decorators/application.decorator.d.ts +8 -0
- package/dist/core/decorators/application.decorator.d.ts.map +1 -0
- package/dist/core/decorators/application.decorator.js +16 -0
- package/dist/core/decorators/application.decorator.js.map +1 -0
- package/dist/core/decorators/auto-configuration.decorator.d.ts +2 -0
- package/dist/core/decorators/auto-configuration.decorator.d.ts.map +1 -0
- package/dist/core/decorators/auto-configuration.decorator.js +19 -0
- package/dist/core/decorators/auto-configuration.decorator.js.map +1 -0
- package/dist/core/decorators/conditional.decorators.d.ts +4 -0
- package/dist/core/decorators/conditional.decorators.d.ts.map +1 -0
- package/dist/core/decorators/conditional.decorators.js +22 -0
- package/dist/core/decorators/conditional.decorators.js.map +1 -0
- package/dist/core/decorators/controller.decorator.d.ts +1 -3
- package/dist/core/decorators/controller.decorator.d.ts.map +1 -0
- package/dist/core/decorators/controller.decorator.js +13 -9
- package/dist/core/decorators/controller.decorator.js.map +1 -0
- package/dist/core/decorators/http.decorators.d.ts +12 -0
- package/dist/core/decorators/http.decorators.d.ts.map +1 -0
- package/dist/core/decorators/http.decorators.js +52 -0
- package/dist/core/decorators/http.decorators.js.map +1 -0
- package/dist/core/decorators/injectable.decorator.d.ts +3 -3
- package/dist/core/decorators/injectable.decorator.d.ts.map +1 -0
- package/dist/core/decorators/injectable.decorator.js +12 -8
- package/dist/core/decorators/injectable.decorator.js.map +1 -0
- package/dist/core/decorators/injection.decorators.d.ts +5 -0
- package/dist/core/decorators/injection.decorators.d.ts.map +1 -0
- package/dist/core/decorators/injection.decorators.js +29 -0
- package/dist/core/decorators/injection.decorators.js.map +1 -0
- package/dist/core/decorators/repository.decorator.d.ts +1 -0
- package/dist/core/decorators/repository.decorator.d.ts.map +1 -0
- package/dist/core/decorators/repository.decorator.js +13 -1
- package/dist/core/decorators/repository.decorator.js.map +1 -0
- package/dist/core/decorators/service.decorator.d.ts +1 -0
- package/dist/core/decorators/service.decorator.d.ts.map +1 -0
- package/dist/core/decorators/service.decorator.js +13 -1
- package/dist/core/decorators/service.decorator.js.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +29 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/loader/file-loader.d.ts +5 -0
- package/dist/core/loader/file-loader.d.ts.map +1 -0
- package/dist/core/loader/file-loader.js +85 -0
- package/dist/core/loader/file-loader.js.map +1 -0
- package/dist/core/metadata/metadata-keys.d.ts +20 -0
- package/dist/core/metadata/metadata-keys.d.ts.map +1 -0
- package/dist/core/metadata/metadata-keys.js +23 -0
- package/dist/core/metadata/metadata-keys.js.map +1 -0
- package/dist/core/metadata/metadata-storage.d.ts +36 -0
- package/dist/core/metadata/metadata-storage.d.ts.map +1 -0
- package/dist/core/metadata/metadata-storage.js +53 -0
- package/dist/core/metadata/metadata-storage.js.map +1 -0
- package/dist/core/scanner/component-scanner.d.ts +16 -0
- package/dist/core/scanner/component-scanner.d.ts.map +1 -0
- package/dist/core/scanner/component-scanner.js +147 -0
- package/dist/core/scanner/component-scanner.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/plugin-manager.d.ts +14 -0
- package/dist/plugins/plugin-manager.d.ts.map +1 -0
- package/dist/{cli/utils/file-generator.js ā plugins/plugin-manager.js} +32 -23
- package/dist/plugins/plugin-manager.js.map +1 -0
- package/dist/shared/errors.d.ts +18 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/errors.js +41 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/testing/runner.d.ts +26 -0
- package/dist/testing/runner.d.ts.map +1 -0
- package/dist/testing/runner.js +143 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/typeorm/typeorm-module.d.ts +36 -0
- package/dist/typeorm/typeorm-module.d.ts.map +1 -0
- package/dist/typeorm/typeorm-module.js +150 -0
- package/dist/typeorm/typeorm-module.js.map +1 -0
- package/dist/web/application.d.ts +29 -0
- package/dist/web/application.d.ts.map +1 -0
- package/dist/web/application.js +301 -0
- package/dist/web/application.js.map +1 -0
- package/dist/web/interfaces.d.ts +14 -0
- package/dist/web/interfaces.d.ts.map +1 -0
- package/dist/{auth/dto/login.dto.js ā web/interfaces.js} +1 -0
- package/dist/web/interfaces.js.map +1 -0
- package/examples/ai-assistant/fragment.json +18 -0
- package/examples/ai-assistant/package-lock.json +2921 -0
- package/examples/ai-assistant/package.json +20 -0
- package/examples/ai-assistant/src/controllers/app.controller.ts +9 -0
- package/examples/ai-assistant/src/controllers/chat.controller.ts +69 -0
- package/examples/ai-assistant/src/controllers/conversation.controller.ts +29 -0
- package/examples/ai-assistant/src/controllers/message.controller.ts +29 -0
- package/examples/ai-assistant/src/controllers/search.controller.ts +16 -0
- package/examples/ai-assistant/src/dto/create-conversation.dto.ts +6 -0
- package/examples/ai-assistant/src/dto/create-message.dto.ts +6 -0
- package/examples/ai-assistant/src/entities/conversation.entity.ts +23 -0
- package/examples/ai-assistant/src/entities/message.entity.ts +27 -0
- package/examples/ai-assistant/src/entities/user.entity.ts +16 -0
- package/examples/ai-assistant/src/main.ts +15 -0
- package/examples/ai-assistant/src/migrations/1767738396740-CreateConversationTables.ts +37 -0
- package/examples/ai-assistant/src/repositories/conversation.repository.ts +32 -0
- package/examples/ai-assistant/src/repositories/message.repository.ts +30 -0
- package/examples/ai-assistant/src/services/ai.service.ts +41 -0
- package/examples/ai-assistant/src/services/app.service.ts +8 -0
- package/examples/ai-assistant/src/services/conversation.service.ts +75 -0
- package/examples/ai-assistant/src/services/message.service.ts +27 -0
- package/examples/ai-assistant/tsconfig.json +23 -0
- package/examples/blog-api/fragment.json +18 -0
- package/examples/blog-api/package.json +19 -0
- package/examples/blog-api/src/controllers/app.controller.ts +9 -0
- package/examples/blog-api/src/controllers/auth.controller.ts +17 -0
- package/examples/blog-api/src/controllers/category.controller.ts +29 -0
- package/examples/blog-api/src/controllers/comment.controller.ts +27 -0
- package/examples/blog-api/src/controllers/post.controller.ts +46 -0
- package/examples/blog-api/src/dto/create-category.dto.ts +6 -0
- package/examples/blog-api/src/dto/create-comment.dto.ts +6 -0
- package/examples/blog-api/src/dto/create-post.dto.ts +6 -0
- package/examples/blog-api/src/entities/category.entity.ts +16 -0
- package/examples/blog-api/src/entities/comment.entity.ts +29 -0
- package/examples/blog-api/src/entities/post.entity.ts +42 -0
- package/examples/blog-api/src/entities/user.entity.ts +25 -0
- package/examples/blog-api/src/main.ts +16 -0
- package/examples/blog-api/src/migrations/1767737463842-InitialSchema.ts +60 -0
- package/examples/blog-api/src/repositories/category.repository.ts +25 -0
- package/examples/blog-api/src/repositories/comment.repository.ts +25 -0
- package/examples/blog-api/src/repositories/post.repository.ts +29 -0
- package/examples/blog-api/src/seeds/SampleData.seed.ts +41 -0
- package/examples/blog-api/src/services/app.service.ts +8 -0
- package/examples/blog-api/src/services/auth.service.ts +15 -0
- package/examples/blog-api/src/services/category.service.ts +27 -0
- package/examples/blog-api/src/services/comment.service.ts +31 -0
- package/examples/blog-api/src/services/post.service.ts +35 -0
- package/examples/blog-api/tsconfig.json +23 -0
- package/package.json +56 -33
- package/src/ai/ai.module.ts +110 -0
- package/src/auth/auth.module.ts +77 -0
- package/src/cli/commands/build.command.ts +123 -13
- package/src/cli/commands/diagnostics.command.ts +438 -0
- package/src/cli/commands/generate.command.ts +206 -137
- package/src/cli/commands/init.command.ts +337 -349
- package/src/cli/commands/migrate.command.ts +203 -88
- package/src/cli/commands/serve.command.ts +176 -24
- package/src/cli/index.ts +23 -0
- package/src/core/container/di-container.ts +83 -26
- package/src/core/decorators/application.decorator.ts +26 -0
- package/src/core/decorators/auto-configuration.decorator.ts +17 -0
- package/src/core/decorators/conditional.decorators.ts +19 -0
- package/src/core/decorators/controller.decorator.ts +14 -11
- package/src/core/decorators/http.decorators.ts +71 -0
- package/src/core/decorators/injectable.decorator.ts +14 -9
- package/src/core/decorators/injection.decorators.ts +26 -0
- package/src/core/decorators/repository.decorator.ts +13 -2
- package/src/core/decorators/service.decorator.ts +13 -2
- package/src/core/index.ts +13 -0
- package/src/core/loader/file-loader.ts +55 -0
- package/src/core/metadata/metadata-keys.ts +19 -0
- package/src/core/metadata/metadata-storage.ts +91 -0
- package/src/core/scanner/component-scanner.ts +129 -0
- package/src/index.ts +45 -0
- package/src/plugins/plugin-manager.ts +52 -0
- package/src/shared/errors.ts +34 -0
- package/src/testing/runner.ts +143 -0
- package/src/typeorm/typeorm-module.ts +216 -0
- package/src/web/application.ts +348 -0
- package/src/web/interfaces.ts +17 -0
- package/tsconfig.json +8 -5
- package/.env.example +0 -0
- package/base.ts +0 -1810
- package/base2.ts +0 -968
- package/bin/frg.ts +0 -5
- package/config/fragment.lock.yaml +0 -0
- package/config/fragment.yaml +0 -0
- package/dist/app.d.ts +0 -15
- package/dist/app.js +0 -90
- package/dist/auth/auth.controller.d.ts +0 -10
- package/dist/auth/auth.controller.js +0 -87
- package/dist/auth/auth.middleware.d.ts +0 -2
- package/dist/auth/auth.middleware.js +0 -24
- package/dist/auth/auth.service.d.ts +0 -20
- package/dist/auth/auth.service.js +0 -143
- package/dist/auth/dto/login.dto.d.ts +0 -9
- package/dist/cli/cli.d.ts +0 -12
- package/dist/cli/cli.js +0 -186
- package/dist/cli/commands/config.command.d.ts +0 -6
- package/dist/cli/commands/config.command.js +0 -284
- package/dist/cli/templates/controller.template.d.ts +0 -1
- package/dist/cli/templates/controller.template.js +0 -52
- package/dist/cli/templates/entity.template.d.ts +0 -1
- package/dist/cli/templates/entity.template.js +0 -23
- package/dist/cli/templates/repository.template.d.ts +0 -1
- package/dist/cli/templates/repository.template.js +0 -43
- package/dist/cli/templates/service.template.d.ts +0 -1
- package/dist/cli/templates/service.template.js +0 -43
- package/dist/cli/utils/file-generator.d.ts +0 -9
- package/dist/cli/utils/logger.d.ts +0 -14
- package/dist/cli/utils/logger.js +0 -49
- package/dist/controllers/health.controller.d.ts +0 -13
- package/dist/controllers/health.controller.js +0 -50
- package/dist/core/config/config-loader.d.ts +0 -31
- package/dist/core/config/config-loader.js +0 -98
- package/dist/core/decorators/auth-guard.decorator.d.ts +0 -3
- package/dist/core/decorators/auth-guard.decorator.js +0 -18
- package/dist/core/decorators/autowire.decorator.d.ts +0 -3
- package/dist/core/decorators/autowire.decorator.js +0 -17
- package/dist/core/decorators/middleware.decorator.d.ts +0 -3
- package/dist/core/decorators/middleware.decorator.js +0 -20
- package/dist/core/decorators/route.decorator.d.ts +0 -14
- package/dist/core/decorators/route.decorator.js +0 -32
- package/dist/core/openai/openai-client.d.ts +0 -12
- package/dist/core/openai/openai-client.js +0 -93
- package/dist/database/data-source.d.ts +0 -4
- package/dist/database/data-source.js +0 -26
- package/dist/entities/session.entity.d.ts +0 -9
- package/dist/entities/session.entity.js +0 -45
- package/dist/entities/user.entity.d.ts +0 -10
- package/dist/entities/user.entity.js +0 -48
- package/dist/middlewares/logging.middleware.d.ts +0 -2
- package/dist/middlewares/logging.middleware.js +0 -28
- package/dist/repositories/session.repository.d.ts +0 -9
- package/dist/repositories/session.repository.js +0 -50
- package/dist/repositories/user.repository.d.ts +0 -10
- package/dist/repositories/user.repository.js +0 -43
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -30
- package/dist/services/health.service.d.ts +0 -13
- package/dist/services/health.service.js +0 -44
- package/readme.md +0 -120
- package/src/app.ts +0 -121
- package/src/auth/auth.controller.ts +0 -52
- package/src/auth/auth.middleware.ts +0 -27
- package/src/auth/auth.service.ts +0 -110
- package/src/auth/dto/login.dto.ts +0 -11
- package/src/cli/cli.ts +0 -212
- package/src/cli/commands/config.command.ts +0 -280
- package/src/cli/templates/controller.template.ts +0 -51
- package/src/cli/templates/entity.template.ts +0 -22
- package/src/cli/templates/repository.template.ts +0 -42
- package/src/cli/templates/service.template.ts +0 -42
- package/src/cli/utils/file-generator.ts +0 -37
- package/src/cli/utils/logger.ts +0 -52
- package/src/controllers/health.controller.ts +0 -24
- package/src/core/config/config-loader.ts +0 -98
- package/src/core/decorators/auth-guard.decorator.ts +0 -15
- package/src/core/decorators/autowire.decorator.ts +0 -18
- package/src/core/decorators/middleware.decorator.ts +0 -18
- package/src/core/decorators/route.decorator.ts +0 -33
- package/src/core/openai/openai-client.ts +0 -99
- package/src/database/data-source.ts +0 -29
- package/src/entities/session.entity.ts +0 -25
- package/src/entities/user.entity.ts +0 -27
- package/src/middlewares/logging.middleware.ts +0 -28
- package/src/repositories/session.repository.ts +0 -42
- package/src/repositories/user.repository.ts +0 -37
- package/src/server.ts +0 -32
- package/src/services/health.service.ts +0 -29
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import { spawn } from "child_process";
|
|
6
|
+
|
|
7
|
+
export class DiagnosticsCommand {
|
|
8
|
+
static register(program: Command): void {
|
|
9
|
+
program
|
|
10
|
+
.command("routes")
|
|
11
|
+
.description("List all registered routes")
|
|
12
|
+
.option(
|
|
13
|
+
"--env <environment>",
|
|
14
|
+
"Environment mode: dev (use src/) or prod (use dist/)",
|
|
15
|
+
"auto",
|
|
16
|
+
)
|
|
17
|
+
.action(async (options) => {
|
|
18
|
+
await this.showRoutes(options.env);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
program
|
|
22
|
+
.command("beans")
|
|
23
|
+
.description("List all registered beans")
|
|
24
|
+
.option("--tree", "Show as tree")
|
|
25
|
+
.option(
|
|
26
|
+
"--env <environment>",
|
|
27
|
+
"Environment mode: dev (use src/) or prod (use dist/)",
|
|
28
|
+
"auto",
|
|
29
|
+
)
|
|
30
|
+
.action(async (options) => {
|
|
31
|
+
await this.showBeans(options.tree, options.env);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
program
|
|
35
|
+
.command("info")
|
|
36
|
+
.description("Show application info")
|
|
37
|
+
.action(() => {
|
|
38
|
+
this.showInfo();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
program
|
|
42
|
+
.command("config")
|
|
43
|
+
.description("Show current configuration")
|
|
44
|
+
.action(() => {
|
|
45
|
+
this.showConfig();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
program
|
|
49
|
+
.command("version")
|
|
50
|
+
.description("Show Fragment version")
|
|
51
|
+
.action(() => {
|
|
52
|
+
this.showVersion();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private static async showRoutes(env: string = "auto"): Promise<void> {
|
|
57
|
+
console.log(chalk.blue("\nš Scanning for routes...\n"));
|
|
58
|
+
|
|
59
|
+
const result = await this.runDiagnosticScript("routes", env);
|
|
60
|
+
|
|
61
|
+
if (!result.success) {
|
|
62
|
+
console.log(chalk.yellow(" Unable to load routes."));
|
|
63
|
+
if (result.error) {
|
|
64
|
+
console.log(chalk.red(` Error: ${result.error}`));
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!result.data || result.data.length === 0) {
|
|
70
|
+
console.log(chalk.yellow(" No routes registered"));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
result.data.forEach((controller: any) => {
|
|
75
|
+
if (controller.methods.length > 0) {
|
|
76
|
+
console.log(chalk.green(` ${controller.name}:`));
|
|
77
|
+
|
|
78
|
+
controller.methods.forEach((method: any) => {
|
|
79
|
+
const methodColor = this.getMethodColor(method.method);
|
|
80
|
+
const methodIcon = this.getMethodIcon(method.method);
|
|
81
|
+
console.log(
|
|
82
|
+
` ${methodIcon} ${methodColor}${method.method.toUpperCase().padEnd(7)}\x1b[0m ${method.path}`,
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
console.log("");
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private static async showBeans(
|
|
91
|
+
tree: boolean,
|
|
92
|
+
env: string = "auto",
|
|
93
|
+
): Promise<void> {
|
|
94
|
+
console.log(chalk.blue("\nš« Scanning for beans...\n"));
|
|
95
|
+
|
|
96
|
+
const result = await this.runDiagnosticScript("beans", env);
|
|
97
|
+
|
|
98
|
+
if (!result.success) {
|
|
99
|
+
console.log(chalk.yellow(" Unable to load beans."));
|
|
100
|
+
if (result.error) {
|
|
101
|
+
console.log(chalk.red(` Error: ${result.error}`));
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!result.data || Object.keys(result.data).length === 0) {
|
|
107
|
+
console.log(chalk.yellow(" No beans registered"));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
Object.entries(result.data).forEach(([type, beans]: [string, any]) => {
|
|
112
|
+
const icon = this.getTypeIcon(type);
|
|
113
|
+
console.log(chalk.green(` ${icon} ${type.toUpperCase()}:`));
|
|
114
|
+
|
|
115
|
+
beans.forEach((bean: any) => {
|
|
116
|
+
const scope = bean.scope || "singleton";
|
|
117
|
+
console.log(
|
|
118
|
+
` ${tree ? "āā" : "ā¢"} ${bean.name} ${chalk.gray(`(${scope})`)}`,
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
console.log("");
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private static async runDiagnosticScript(
|
|
126
|
+
type: "routes" | "beans",
|
|
127
|
+
env: string = "auto",
|
|
128
|
+
): Promise<any> {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
const cwd = process.cwd();
|
|
131
|
+
|
|
132
|
+
// Detect available directories
|
|
133
|
+
const hasSource = fs.existsSync(path.join(cwd, "src"));
|
|
134
|
+
const hasDist = fs.existsSync(path.join(cwd, "dist"));
|
|
135
|
+
|
|
136
|
+
// Determine which mode to use based on --env flag
|
|
137
|
+
let useTypeScript: boolean;
|
|
138
|
+
let mode: string;
|
|
139
|
+
|
|
140
|
+
if (env === "dev") {
|
|
141
|
+
// Force development mode (TypeScript source)
|
|
142
|
+
if (!hasSource) {
|
|
143
|
+
resolve({
|
|
144
|
+
success: false,
|
|
145
|
+
error: "Development mode requested but src/ directory not found",
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
useTypeScript = true;
|
|
150
|
+
mode = "development (src/)";
|
|
151
|
+
} else if (env === "prod") {
|
|
152
|
+
// Force production mode (compiled JavaScript)
|
|
153
|
+
if (!hasDist) {
|
|
154
|
+
resolve({
|
|
155
|
+
success: false,
|
|
156
|
+
error:
|
|
157
|
+
"Production mode requested but dist/ directory not found. Run: fragment build",
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
useTypeScript = false;
|
|
162
|
+
mode = "production (dist/)";
|
|
163
|
+
} else {
|
|
164
|
+
// Auto-detect - DEFAULT TO SOURCE
|
|
165
|
+
if (hasSource) {
|
|
166
|
+
// Prefer source (development)
|
|
167
|
+
useTypeScript = true;
|
|
168
|
+
mode = "auto-detected development (src/)";
|
|
169
|
+
} else if (hasDist) {
|
|
170
|
+
// Fall back to compiled
|
|
171
|
+
useTypeScript = false;
|
|
172
|
+
mode = "auto-detected production (dist/)";
|
|
173
|
+
} else {
|
|
174
|
+
resolve({
|
|
175
|
+
success: false,
|
|
176
|
+
error: "No src/ or dist/ directory found. Run: fragment init",
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const userBasePath = useTypeScript ? "src" : "dist";
|
|
183
|
+
console.log(chalk.gray(` Mode: ${mode}\n`));
|
|
184
|
+
|
|
185
|
+
// Create diagnostic script
|
|
186
|
+
const scriptContent = `
|
|
187
|
+
${useTypeScript ? "require('ts-node/register/transpile-only');" : ""}
|
|
188
|
+
require('reflect-metadata');
|
|
189
|
+
|
|
190
|
+
async function diagnose() {
|
|
191
|
+
try {
|
|
192
|
+
// Load Fragment framework from node_modules
|
|
193
|
+
const { MetadataStorage } = require('fragment');
|
|
194
|
+
const { ComponentScanner } = require('fragment');
|
|
195
|
+
|
|
196
|
+
// Scan user's components
|
|
197
|
+
const patterns = [
|
|
198
|
+
'${userBasePath}/**/*.controller.${useTypeScript ? "ts" : "js"}',
|
|
199
|
+
'${userBasePath}/**/*.service.${useTypeScript ? "ts" : "js"}',
|
|
200
|
+
'${userBasePath}/**/*.repository.${useTypeScript ? "ts" : "js"}',
|
|
201
|
+
'${userBasePath}/**/*.entity.${useTypeScript ? "ts" : "js"}'
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
${
|
|
205
|
+
useTypeScript
|
|
206
|
+
? "await ComponentScanner.scanSource(patterns);"
|
|
207
|
+
: "await ComponentScanner.scan(patterns);"
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const storage = MetadataStorage.getInstance();
|
|
211
|
+
|
|
212
|
+
if ('${type}' === 'routes') {
|
|
213
|
+
const controllers = storage.getAllClasses().filter(c => c.type === 'controller');
|
|
214
|
+
const result = controllers.map(ctrl => {
|
|
215
|
+
const methods = storage.getAllMethods()
|
|
216
|
+
.filter(m => m.target === ctrl.target)
|
|
217
|
+
.map(m => ({
|
|
218
|
+
method: m.method,
|
|
219
|
+
path: (ctrl.path || '') + m.path || '/'
|
|
220
|
+
}));
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
name: ctrl.target.name,
|
|
224
|
+
methods
|
|
225
|
+
};
|
|
226
|
+
}).filter(c => c.methods.length > 0);
|
|
227
|
+
|
|
228
|
+
console.log(JSON.stringify({ success: true, data: result }));
|
|
229
|
+
} else if ('${type}' === 'beans') {
|
|
230
|
+
const classes = storage.getAllClasses();
|
|
231
|
+
const grouped = classes.reduce((acc, cls) => {
|
|
232
|
+
if (!acc[cls.type]) acc[cls.type] = [];
|
|
233
|
+
acc[cls.type].push({
|
|
234
|
+
name: cls.target.name,
|
|
235
|
+
scope: cls.scope || 'singleton'
|
|
236
|
+
});
|
|
237
|
+
return acc;
|
|
238
|
+
}, {});
|
|
239
|
+
|
|
240
|
+
console.log(JSON.stringify({ success: true, data: grouped }));
|
|
241
|
+
}
|
|
242
|
+
} catch (error) {
|
|
243
|
+
console.log(JSON.stringify({
|
|
244
|
+
success: false,
|
|
245
|
+
error: error.message,
|
|
246
|
+
stack: error.stack
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
process.exit(0);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
diagnose();
|
|
253
|
+
`;
|
|
254
|
+
|
|
255
|
+
const scriptPath = path.join(cwd, ".fragment-diagnostic-temp.js");
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
fs.writeFileSync(scriptPath, scriptContent);
|
|
259
|
+
|
|
260
|
+
const proc = spawn("node", [scriptPath], {
|
|
261
|
+
cwd,
|
|
262
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
263
|
+
env: { ...process.env, TS_NODE_TRANSPILE_ONLY: "true" },
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
let output = "";
|
|
267
|
+
let errorOutput = "";
|
|
268
|
+
|
|
269
|
+
proc.stdout?.on("data", (data) => {
|
|
270
|
+
output += data.toString();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
proc.stderr?.on("data", (data) => {
|
|
274
|
+
errorOutput += data.toString();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
proc.on("close", (code) => {
|
|
278
|
+
// Clean up temp file
|
|
279
|
+
try {
|
|
280
|
+
fs.unlinkSync(scriptPath);
|
|
281
|
+
} catch {}
|
|
282
|
+
|
|
283
|
+
if (output) {
|
|
284
|
+
try {
|
|
285
|
+
// Find the JSON output (last line that's valid JSON)
|
|
286
|
+
const lines = output.trim().split("\n");
|
|
287
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
288
|
+
try {
|
|
289
|
+
const result = JSON.parse(lines[i]);
|
|
290
|
+
if (result.success !== undefined) {
|
|
291
|
+
resolve(result);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
} catch {}
|
|
295
|
+
}
|
|
296
|
+
} catch {}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
resolve({
|
|
300
|
+
success: false,
|
|
301
|
+
error: errorOutput || "Failed to parse diagnostic output",
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
proc.on("error", (error) => {
|
|
306
|
+
try {
|
|
307
|
+
fs.unlinkSync(scriptPath);
|
|
308
|
+
} catch {}
|
|
309
|
+
resolve({ success: false, error: error.message });
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// Timeout after 15 seconds
|
|
313
|
+
setTimeout(() => {
|
|
314
|
+
proc.kill();
|
|
315
|
+
try {
|
|
316
|
+
fs.unlinkSync(scriptPath);
|
|
317
|
+
} catch {}
|
|
318
|
+
resolve({ success: false, error: "Diagnostic scan timed out" });
|
|
319
|
+
}, 15000);
|
|
320
|
+
} catch (error: any) {
|
|
321
|
+
resolve({ success: false, error: error.message });
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private static getMethodColor(method: string): string {
|
|
327
|
+
const colors: Record<string, string> = {
|
|
328
|
+
GET: "\x1b[32m", // Green
|
|
329
|
+
POST: "\x1b[33m", // Yellow
|
|
330
|
+
PUT: "\x1b[34m", // Blue
|
|
331
|
+
DELETE: "\x1b[31m", // Red
|
|
332
|
+
PATCH: "\x1b[35m", // Magenta
|
|
333
|
+
};
|
|
334
|
+
return colors[method.toUpperCase()] || "\x1b[37m";
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private static getMethodIcon(method: string): string {
|
|
338
|
+
const icons: Record<string, string> = {
|
|
339
|
+
GET: "š",
|
|
340
|
+
POST: "ā",
|
|
341
|
+
PUT: "āļø",
|
|
342
|
+
DELETE: "šļø",
|
|
343
|
+
PATCH: "š§",
|
|
344
|
+
};
|
|
345
|
+
return icons[method.toUpperCase()] || "ā¢";
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
private static getTypeIcon(type: string): string {
|
|
349
|
+
const icons: Record<string, string> = {
|
|
350
|
+
controller: "š®",
|
|
351
|
+
service: "āļø",
|
|
352
|
+
repository: "š¾",
|
|
353
|
+
injectable: "š",
|
|
354
|
+
"auto-configuration": "š§",
|
|
355
|
+
};
|
|
356
|
+
return icons[type] || "š";
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
private static showInfo(): void {
|
|
360
|
+
console.log(chalk.blue("\nš Application Information:\n"));
|
|
361
|
+
|
|
362
|
+
const packageJson = this.loadPackageJson();
|
|
363
|
+
const cwd = process.cwd();
|
|
364
|
+
const hasSource = fs.existsSync(path.join(cwd, "src"));
|
|
365
|
+
const hasDist = fs.existsSync(path.join(cwd, "dist"));
|
|
366
|
+
|
|
367
|
+
console.log(` Name: ${packageJson.name || "N/A"}`);
|
|
368
|
+
console.log(` Version: ${packageJson.version || "N/A"}`);
|
|
369
|
+
console.log(` Node: ${process.version}`);
|
|
370
|
+
console.log(` Platform: ${process.platform}`);
|
|
371
|
+
console.log(` Architecture: ${process.arch}`);
|
|
372
|
+
console.log(` Environment: ${process.env.NODE_ENV || "development"}`);
|
|
373
|
+
console.log(` Source: ${hasSource ? "ā src/" : "ā src/"}`);
|
|
374
|
+
console.log(` Built: ${hasDist ? "ā dist/" : "ā dist/"}`);
|
|
375
|
+
console.log("");
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private static showConfig(): void {
|
|
379
|
+
console.log(chalk.blue("\nāļø Configuration:\n"));
|
|
380
|
+
|
|
381
|
+
const configPath = path.join(process.cwd(), "fragment.json");
|
|
382
|
+
|
|
383
|
+
if (fs.existsSync(configPath)) {
|
|
384
|
+
try {
|
|
385
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
386
|
+
console.log(
|
|
387
|
+
" " + JSON.stringify(config, null, 2).replace(/\n/g, "\n "),
|
|
388
|
+
);
|
|
389
|
+
} catch (error) {
|
|
390
|
+
console.log(chalk.red(" Error reading fragment.json"));
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
console.log(chalk.yellow(" No fragment.json found"));
|
|
394
|
+
console.log(chalk.gray("\n Create one with:"));
|
|
395
|
+
console.log(chalk.cyan(" fragment init"));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
console.log("");
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private static showVersion(): void {
|
|
402
|
+
const packageJson = this.loadFragmentPackageJson();
|
|
403
|
+
const version = packageJson.version || "1.0.0";
|
|
404
|
+
|
|
405
|
+
console.log(chalk.bold(`\n⨠Fragment Framework v${version}\n`));
|
|
406
|
+
console.log(` Node: ${process.version}`);
|
|
407
|
+
console.log(` Platform: ${process.platform}-${process.arch}\n`);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
private static loadPackageJson(): any {
|
|
411
|
+
try {
|
|
412
|
+
const packagePath = path.join(process.cwd(), "package.json");
|
|
413
|
+
return JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
|
414
|
+
} catch {
|
|
415
|
+
return {};
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private static loadFragmentPackageJson(): any {
|
|
420
|
+
try {
|
|
421
|
+
const possiblePaths = [
|
|
422
|
+
path.join(__dirname, "..", "..", "..", "package.json"),
|
|
423
|
+
path.join(__dirname, "..", "..", "package.json"),
|
|
424
|
+
path.join(process.cwd(), "node_modules", "fragment", "package.json"),
|
|
425
|
+
];
|
|
426
|
+
|
|
427
|
+
for (const packagePath of possiblePaths) {
|
|
428
|
+
if (fs.existsSync(packagePath)) {
|
|
429
|
+
return JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return { version: "1.0.0" };
|
|
434
|
+
} catch {
|
|
435
|
+
return { version: "1.0.0" };
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|