@lark-apaas/fullstack-cli 1.1.0 → 1.1.1-alpha.0
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/commands/gen-db-schema.js +14 -15
- package/package.json +2 -2
|
@@ -23,6 +23,7 @@ const require = createRequire(import.meta.url);
|
|
|
23
23
|
*/
|
|
24
24
|
export async function run(options = {}) {
|
|
25
25
|
// 加载用户项目的 .env 文件
|
|
26
|
+
let exitCode = 0;
|
|
26
27
|
const envPath = path.resolve(process.cwd(), '.env');
|
|
27
28
|
if (fs.existsSync(envPath)) {
|
|
28
29
|
loadEnv({ path: envPath });
|
|
@@ -31,7 +32,6 @@ export async function run(options = {}) {
|
|
|
31
32
|
const databaseUrl = process.env.SUDA_DATABASE_URL;
|
|
32
33
|
if (!databaseUrl) {
|
|
33
34
|
console.error('[gen-db-schema] Error: SUDA_DATABASE_URL environment variable is required');
|
|
34
|
-
console.error('[gen-db-schema] Please set it in .env file or pass it as environment variable');
|
|
35
35
|
process.exit(1);
|
|
36
36
|
}
|
|
37
37
|
// 命令行选项优先于环境变量
|
|
@@ -39,7 +39,6 @@ export async function run(options = {}) {
|
|
|
39
39
|
const OUT_DIR = path.resolve(process.cwd(), 'server/database/.introspect');
|
|
40
40
|
const SCHEMA_FILE = path.resolve(process.cwd(), outputPath);
|
|
41
41
|
console.log('[gen-db-schema] Starting...');
|
|
42
|
-
console.log(`[gen-db-schema] Output: ${outputPath}`);
|
|
43
42
|
// 获取当前文件所在目录(ESM 方式)
|
|
44
43
|
const __filename = fileURLToPath(import.meta.url);
|
|
45
44
|
const __dirname = path.dirname(__filename);
|
|
@@ -63,32 +62,27 @@ export async function run(options = {}) {
|
|
|
63
62
|
const result = spawnSync('npx', spawnArgs, { stdio: 'inherit', env });
|
|
64
63
|
if (result.error) {
|
|
65
64
|
console.error('[gen-db-schema] Execution failed:', result.error);
|
|
66
|
-
|
|
65
|
+
throw result.error;
|
|
67
66
|
}
|
|
68
67
|
if ((result.status ?? 0) !== 0) {
|
|
69
|
-
|
|
68
|
+
throw new Error(`drizzle-kit introspect failed with status ${result.status}`);
|
|
70
69
|
}
|
|
71
70
|
// 复制生成的 schema
|
|
72
71
|
const generatedSchema = path.join(OUT_DIR, 'schema.ts');
|
|
73
72
|
if (!fs.existsSync(generatedSchema)) {
|
|
74
73
|
console.error('[gen-db-schema] schema.ts not generated');
|
|
75
|
-
|
|
74
|
+
throw new Error('drizzle-kit introspect failed to generate schema.ts');
|
|
76
75
|
}
|
|
77
76
|
fs.mkdirSync(path.dirname(SCHEMA_FILE), { recursive: true });
|
|
78
77
|
fs.copyFileSync(generatedSchema, SCHEMA_FILE);
|
|
79
78
|
console.log(`[gen-db-schema] ✓ Copied to ${outputPath}`);
|
|
80
79
|
// 后处理 schema(使用 CommonJS require 方式加载)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
console.warn('[gen-db-schema] Unmatched custom types detected:', stats.unmatchedUnknown);
|
|
86
|
-
}
|
|
87
|
-
console.log('[gen-db-schema] ✓ Postprocessed schema');
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
console.warn('[gen-db-schema] Postprocess failed:', error instanceof Error ? error.message : String(error));
|
|
80
|
+
const { postprocessDrizzleSchema } = require('@lark-apaas/devtool-kits');
|
|
81
|
+
const stats = postprocessDrizzleSchema(SCHEMA_FILE);
|
|
82
|
+
if (stats?.unmatchedUnknown?.length) {
|
|
83
|
+
console.warn('[gen-db-schema] Unmatched custom types detected:', stats.unmatchedUnknown);
|
|
91
84
|
}
|
|
85
|
+
console.log('[gen-db-schema] ✓ Postprocessed schema');
|
|
92
86
|
try {
|
|
93
87
|
if (options.enableNestModuleGenerate) {
|
|
94
88
|
const { parseAndGenerateNestResourceTemplate } = require('@lark-apaas/devtool-kits');
|
|
@@ -107,10 +101,15 @@ export async function run(options = {}) {
|
|
|
107
101
|
}
|
|
108
102
|
console.log('[gen-db-schema] ✓ Complete');
|
|
109
103
|
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
console.error('[gen-db-schema] Failed:', err instanceof Error ? err.message : String(err));
|
|
106
|
+
exitCode = 1;
|
|
107
|
+
}
|
|
110
108
|
finally {
|
|
111
109
|
// 清理临时文件
|
|
112
110
|
if (fs.existsSync(OUT_DIR)) {
|
|
113
111
|
fs.rmSync(OUT_DIR, { recursive: true, force: true });
|
|
114
112
|
}
|
|
113
|
+
process.exit(exitCode);
|
|
115
114
|
}
|
|
116
115
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-cli",
|
|
3
|
-
"version": "1.1.0",
|
|
3
|
+
"version": "1.1.1-alpha.0",
|
|
4
4
|
"description": "CLI tool for fullstack template management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@lark-apaas/devtool-kits": "^1.2.
|
|
32
|
+
"@lark-apaas/devtool-kits": "^1.2.2",
|
|
33
33
|
"@vercel/nft": "^0.30.3",
|
|
34
34
|
"cac": "^6.7.14",
|
|
35
35
|
"dotenv": "^16.0.0",
|