fragment-ts 1.0.44 → 1.0.46
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 +96 -91
- package/dist/cli/commands/build.command.d.ts.map +1 -1
- package/dist/cli/commands/build.command.js +12 -19
- package/dist/cli/commands/build.command.js.map +1 -1
- package/dist/cli/commands/diagnostics.command.d.ts.map +1 -1
- package/dist/cli/commands/diagnostics.command.js +68 -14
- package/dist/cli/commands/diagnostics.command.js.map +1 -1
- package/dist/cli/commands/env.config.d.ts +10 -0
- package/dist/cli/commands/env.config.d.ts.map +1 -0
- package/dist/cli/commands/env.config.js +202 -0
- package/dist/cli/commands/env.config.js.map +1 -0
- package/dist/cli/commands/generate.command.js +9 -9
- package/dist/cli/commands/init.command.d.ts.map +1 -1
- package/dist/cli/commands/init.command.js +16 -59
- package/dist/cli/commands/init.command.js.map +1 -1
- package/dist/cli/commands/migrate.command.d.ts +5 -4
- package/dist/cli/commands/migrate.command.d.ts.map +1 -1
- package/dist/cli/commands/migrate.command.js +34 -9
- package/dist/cli/commands/migrate.command.js.map +1 -1
- package/dist/cli/commands/serve.command.d.ts.map +1 -1
- package/dist/cli/commands/serve.command.js +74 -38
- package/dist/cli/commands/serve.command.js.map +1 -1
- package/dist/cli/commands/test.command.d.ts.map +1 -1
- package/dist/cli/commands/test.command.js +21 -9
- package/dist/cli/commands/test.command.js.map +1 -1
- package/dist/cli/index.js +3 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/core/scanner/component-scanner.d.ts +4 -0
- package/dist/core/scanner/component-scanner.d.ts.map +1 -1
- package/dist/core/scanner/component-scanner.js +15 -0
- package/dist/core/scanner/component-scanner.js.map +1 -1
- package/dist/shared/config.utils.d.ts +27 -0
- package/dist/shared/config.utils.d.ts.map +1 -1
- package/dist/shared/config.utils.js +38 -7
- package/dist/shared/config.utils.js.map +1 -1
- package/dist/shared/env.utils.d.ts +6 -6
- package/dist/shared/env.utils.d.ts.map +1 -1
- package/dist/shared/env.utils.js +25 -84
- package/dist/shared/env.utils.js.map +1 -1
- package/dist/testing/runner.d.ts.map +1 -1
- package/dist/testing/runner.js +12 -2
- package/dist/testing/runner.js.map +1 -1
- package/dist/typeorm/typeorm-module.d.ts.map +1 -1
- package/dist/typeorm/typeorm-module.js +16 -4
- package/dist/typeorm/typeorm-module.js.map +1 -1
- package/dist/web/application.d.ts.map +1 -1
- package/dist/web/application.js +20 -1
- package/dist/web/application.js.map +1 -1
- package/examples/blog-api/package-lock.json +0 -38
- package/package.json +3 -3
- package/src/cli/commands/build.command.ts +13 -29
- package/src/cli/commands/diagnostics.command.ts +74 -13
- package/src/cli/commands/{env.command.ts → env.config.ts} +9 -32
- package/src/cli/commands/generate.command.ts +9 -9
- package/src/cli/commands/init.command.ts +17 -63
- package/src/cli/commands/migrate.command.ts +37 -9
- package/src/cli/commands/serve.command.ts +205 -170
- package/src/cli/commands/test.command.ts +30 -8
- package/src/cli/index.ts +3 -10
- package/src/core/scanner/component-scanner.ts +15 -0
- package/src/shared/config.utils.ts +54 -10
- package/src/shared/env.utils.ts +27 -55
- package/src/testing/runner.ts +11 -2
- package/src/typeorm/typeorm-module.ts +14 -5
- package/src/web/application.ts +21 -1
package/src/shared/env.utils.ts
CHANGED
|
@@ -1,78 +1,50 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
|
|
4
1
|
export class EnvUtils {
|
|
5
2
|
static getString(key: string, defaultValue?: string): string {
|
|
6
|
-
|
|
3
|
+
const value = process.env[key];
|
|
4
|
+
return value !== undefined ? value : (defaultValue ?? "");
|
|
7
5
|
}
|
|
8
6
|
|
|
9
|
-
static getBoolean(key: string, defaultValue = false): boolean {
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
return ["true", "1", "yes", "on"].includes(
|
|
7
|
+
static getBoolean(key: string, defaultValue: boolean = false): boolean {
|
|
8
|
+
const value = process.env[key];
|
|
9
|
+
if (value === undefined) return defaultValue;
|
|
10
|
+
return ["true", "1", "yes", "on"].includes(value.toLowerCase());
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
static getNumber(key: string, defaultValue = 0): number {
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
const num = Number(
|
|
13
|
+
static getNumber(key: string, defaultValue: number = 0): number {
|
|
14
|
+
const value = process.env[key];
|
|
15
|
+
if (value === undefined) return defaultValue;
|
|
16
|
+
const num = Number(value);
|
|
19
17
|
return isNaN(num) ? defaultValue : num;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
static getJson<T>(key: string, defaultValue: T): T {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
21
|
+
const value = process.env[key];
|
|
22
|
+
if (value === undefined) return defaultValue;
|
|
25
23
|
try {
|
|
26
|
-
return JSON.parse(
|
|
24
|
+
return JSON.parse(value) as T;
|
|
27
25
|
} catch {
|
|
28
|
-
console.warn(`⚠️ Invalid JSON in env var ${key}`);
|
|
26
|
+
console.warn(`⚠️ Invalid JSON in env var ${key}, using default`);
|
|
29
27
|
return defaultValue;
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
/**
|
|
34
|
-
*
|
|
35
|
-
* - If .env matches .env.prod → returns "prod"
|
|
36
|
-
* - If .env matches .env.staging → returns "staging"
|
|
37
|
-
* - If .env is custom or unmatched → returns "local"
|
|
38
|
-
* - If no .env exists → returns "default"
|
|
32
|
+
* Check if running in development mode
|
|
39
33
|
*/
|
|
40
|
-
static
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Fast path: check for .env.mode (written by `fragment env:use`)
|
|
45
|
-
const modePath = path.join(cwd, ".env.mode");
|
|
46
|
-
if (fs.existsSync(modePath)) {
|
|
47
|
-
try {
|
|
48
|
-
const mode = fs.readFileSync(modePath, "utf8").trim();
|
|
49
|
-
if (mode) return mode;
|
|
50
|
-
} catch {
|
|
51
|
-
// Ignore read errors
|
|
52
|
-
}
|
|
34
|
+
static isDevelopmentMode(): boolean {
|
|
35
|
+
if (process.env.FRAGMENT_DEV_MODE !== undefined) {
|
|
36
|
+
return process.env.FRAGMENT_DEV_MODE === "true";
|
|
53
37
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!fs.existsSync(envPath)) {
|
|
57
|
-
return "default";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const envContent = fs.readFileSync(envPath, "utf8");
|
|
61
|
-
const files = fs.readdirSync(cwd).filter((f) => /^\.env\..+$/.test(f));
|
|
62
|
-
|
|
63
|
-
for (const file of files) {
|
|
64
|
-
const name = file.replace(/\.env\./, "");
|
|
65
|
-
const fullPath = path.join(cwd, file);
|
|
66
|
-
try {
|
|
67
|
-
const content = fs.readFileSync(fullPath, "utf8");
|
|
68
|
-
if (content === envContent) {
|
|
69
|
-
return name;
|
|
70
|
-
}
|
|
71
|
-
} catch {
|
|
72
|
-
// Skip unreadable files
|
|
73
|
-
}
|
|
38
|
+
if (process.env.NODE_ENV) {
|
|
39
|
+
return process.env.NODE_ENV === "development";
|
|
74
40
|
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
75
43
|
|
|
76
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Get current environment mode ('development' or 'production')
|
|
46
|
+
*/
|
|
47
|
+
static getEnvironmentMode(): "development" | "production" {
|
|
48
|
+
return this.isDevelopmentMode() ? "development" : "production";
|
|
77
49
|
}
|
|
78
50
|
}
|
package/src/testing/runner.ts
CHANGED
|
@@ -191,8 +191,17 @@ export class TestRunner {
|
|
|
191
191
|
* Auto-detect test patterns based on environment and configuration
|
|
192
192
|
*/
|
|
193
193
|
getAutoTestPattern(): string {
|
|
194
|
-
const
|
|
195
|
-
|
|
194
|
+
const isDevMode = EnvUtils.isDevelopmentMode();
|
|
195
|
+
|
|
196
|
+
if (isDevMode) {
|
|
197
|
+
// Development mode - use TypeScript
|
|
198
|
+
const srcDir = TsConfigUtils.getRootDir();
|
|
199
|
+
return `${path.relative(process.cwd(), srcDir)}/**/*.spec.ts`;
|
|
200
|
+
} else {
|
|
201
|
+
// Production mode - use JavaScript
|
|
202
|
+
const outDir = TsConfigUtils.getOutDir();
|
|
203
|
+
return `${path.relative(process.cwd(), outDir)}/**/*.spec.js`;
|
|
204
|
+
}
|
|
196
205
|
}
|
|
197
206
|
}
|
|
198
207
|
|
|
@@ -749,12 +749,21 @@ export class TypeORMModule {
|
|
|
749
749
|
fs.readFileSync(configPath, "utf-8"),
|
|
750
750
|
) as FragmentConfig;
|
|
751
751
|
|
|
752
|
-
|
|
753
|
-
|
|
752
|
+
// Determine environment mode
|
|
753
|
+
const isDevMode = EnvUtils.isDevelopmentMode();
|
|
754
|
+
console.log(`Detected ${isDevMode ? "development" : "production"} mode`);
|
|
755
|
+
|
|
756
|
+
// Get the appropriate config section
|
|
757
|
+
let dbConfig = {};
|
|
758
|
+
if (isDevMode && raw.development?.database) {
|
|
759
|
+
dbConfig = raw.development.database;
|
|
760
|
+
} else if (!isDevMode && raw.production?.database) {
|
|
761
|
+
dbConfig = raw.production.database;
|
|
762
|
+
} else if (raw.development?.database) {
|
|
763
|
+
// Fallback to development if production not found
|
|
764
|
+
dbConfig = raw.development.database;
|
|
765
|
+
console.warn("Production config not found, using development config");
|
|
754
766
|
}
|
|
755
|
-
var dbConfig;
|
|
756
|
-
|
|
757
|
-
dbConfig = raw.development.database;
|
|
758
767
|
|
|
759
768
|
// Interpolate environment variables
|
|
760
769
|
return this.interpolateEnvVars(dbConfig);
|
package/src/web/application.ts
CHANGED
|
@@ -90,7 +90,27 @@ export class FragmentWebApplication {
|
|
|
90
90
|
const distExists = fs.existsSync(path.join(cwd, "dist"));
|
|
91
91
|
const srcExists = fs.existsSync(path.join(cwd, "src"));
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
console.log(`📁 Current working directory: ${cwd}`);
|
|
94
|
+
console.log(`📁 dist/ exists: ${distExists}`);
|
|
95
|
+
console.log(`📁 src/ exists: ${srcExists}`);
|
|
96
|
+
|
|
97
|
+
// Use EnvUtils for consistent environment detection
|
|
98
|
+
const isDevMode = EnvUtils.isDevelopmentMode();
|
|
99
|
+
console.log(
|
|
100
|
+
`💻 Running in ${isDevMode ? "development" : "production"} mode`,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (isDevMode && srcExists) {
|
|
104
|
+
// Development mode: scan TypeScript source files
|
|
105
|
+
console.log(" 📝 Development mode: scanning TypeScript files");
|
|
106
|
+
await ComponentScanner.scanSource();
|
|
107
|
+
} else if (distExists) {
|
|
108
|
+
// Production mode: scan compiled JavaScript files
|
|
109
|
+
console.log(" 📦 Production mode: scanning compiled files");
|
|
110
|
+
await ComponentScanner.scan();
|
|
111
|
+
} else {
|
|
112
|
+
console.warn(" ⚠️ Warning: No src/ or dist/ directory found");
|
|
113
|
+
}
|
|
94
114
|
}
|
|
95
115
|
|
|
96
116
|
// Remove the old isRunningTypeScript method since we're using EnvUtils
|