@lark-apaas/fullstack-cli 1.0.5 → 1.1.0-alpha.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.
|
@@ -50,47 +50,67 @@ export async function run(options = {}) {
|
|
|
50
50
|
console.error('[gen-db-schema] Error: drizzle config not found in CLI package');
|
|
51
51
|
process.exit(1);
|
|
52
52
|
}
|
|
53
|
-
// 通过环境变量传递绝对路径给配置文件
|
|
54
|
-
const env = {
|
|
55
|
-
...process.env,
|
|
56
|
-
__DRIZZLE_OUT_DIR__: OUT_DIR,
|
|
57
|
-
__DRIZZLE_SCHEMA_PATH__: SCHEMA_FILE,
|
|
58
|
-
};
|
|
59
|
-
// 执行 drizzle-kit introspect
|
|
60
|
-
const args = process.argv.slice(3);
|
|
61
|
-
const spawnArgs = ['--yes', 'drizzle-kit', 'introspect', '--config', configPath, ...args];
|
|
62
|
-
const result = spawnSync('npx', spawnArgs, { stdio: 'inherit', env });
|
|
63
|
-
if (result.error) {
|
|
64
|
-
console.error('[gen-db-schema] Execution failed:', result.error);
|
|
65
|
-
process.exit(result.status ?? 1);
|
|
66
|
-
}
|
|
67
|
-
if ((result.status ?? 0) !== 0) {
|
|
68
|
-
process.exit(result.status ?? 1);
|
|
69
|
-
}
|
|
70
|
-
// 复制生成的 schema
|
|
71
|
-
const generatedSchema = path.join(OUT_DIR, 'schema.ts');
|
|
72
|
-
if (!fs.existsSync(generatedSchema)) {
|
|
73
|
-
console.error('[gen-db-schema] schema.ts not generated');
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
fs.mkdirSync(path.dirname(SCHEMA_FILE), { recursive: true });
|
|
77
|
-
fs.copyFileSync(generatedSchema, SCHEMA_FILE);
|
|
78
|
-
console.log(`[gen-db-schema] ✓ Copied to ${outputPath}`);
|
|
79
|
-
// 后处理 schema(使用 CommonJS require 方式加载)
|
|
80
53
|
try {
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
54
|
+
// 通过环境变量传递绝对路径给配置文件
|
|
55
|
+
const env = {
|
|
56
|
+
...process.env,
|
|
57
|
+
__DRIZZLE_OUT_DIR__: OUT_DIR,
|
|
58
|
+
__DRIZZLE_SCHEMA_PATH__: SCHEMA_FILE,
|
|
59
|
+
};
|
|
60
|
+
// 执行 drizzle-kit introspect
|
|
61
|
+
const args = process.argv.slice(3);
|
|
62
|
+
const spawnArgs = ['--yes', 'drizzle-kit', 'introspect', '--config', configPath, ...args];
|
|
63
|
+
const result = spawnSync('npx', spawnArgs, { stdio: 'inherit', env });
|
|
64
|
+
if (result.error) {
|
|
65
|
+
console.error('[gen-db-schema] Execution failed:', result.error);
|
|
66
|
+
process.exit(result.status ?? 1);
|
|
85
67
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
if ((result.status ?? 0) !== 0) {
|
|
69
|
+
process.exit(result.status ?? 1);
|
|
70
|
+
}
|
|
71
|
+
// 复制生成的 schema
|
|
72
|
+
const generatedSchema = path.join(OUT_DIR, 'schema.ts');
|
|
73
|
+
if (!fs.existsSync(generatedSchema)) {
|
|
74
|
+
console.error('[gen-db-schema] schema.ts not generated');
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
fs.mkdirSync(path.dirname(SCHEMA_FILE), { recursive: true });
|
|
78
|
+
fs.copyFileSync(generatedSchema, SCHEMA_FILE);
|
|
79
|
+
console.log(`[gen-db-schema] ✓ Copied to ${outputPath}`);
|
|
80
|
+
// 后处理 schema(使用 CommonJS require 方式加载)
|
|
81
|
+
try {
|
|
82
|
+
const { postprocessDrizzleSchema } = require('@lark-apaas/devtool-kits');
|
|
83
|
+
const stats = postprocessDrizzleSchema(SCHEMA_FILE);
|
|
84
|
+
if (stats?.unmatchedUnknown?.length) {
|
|
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));
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
if (options.enableNestModuleGenerate) {
|
|
94
|
+
const { parseAndGenerateNestResourceTemplate } = require('@lark-apaas/devtool-kits');
|
|
95
|
+
const tsConfigFilePath = path.resolve(process.cwd(), 'tsconfig.json');
|
|
96
|
+
const schemaFilePath = SCHEMA_FILE;
|
|
97
|
+
await parseAndGenerateNestResourceTemplate({
|
|
98
|
+
tsConfigFilePath,
|
|
99
|
+
schemaFilePath,
|
|
100
|
+
moduleOutputDir: path.resolve(process.cwd(), 'server/modules'),
|
|
101
|
+
});
|
|
102
|
+
console.log('[gen-db-schema] ✓ Generate NestJS Module Boilerplate Successfully');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.warn('[gen-db-schema] Generate NestJS Module Boilerplate failed:', error instanceof Error ? error.message : String(error));
|
|
107
|
+
}
|
|
108
|
+
console.log('[gen-db-schema] ✓ Complete');
|
|
90
109
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
fs.
|
|
110
|
+
finally {
|
|
111
|
+
// 清理临时文件
|
|
112
|
+
if (fs.existsSync(OUT_DIR)) {
|
|
113
|
+
fs.rmSync(OUT_DIR, { recursive: true, force: true });
|
|
114
|
+
}
|
|
94
115
|
}
|
|
95
|
-
console.log('[gen-db-schema] ✓ Complete');
|
|
96
116
|
}
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ cli
|
|
|
22
22
|
})
|
|
23
23
|
.option('--schema-filter <schemas>', 'Schema filter, comma-separated')
|
|
24
24
|
.option('--tables-filter <tables>', 'Tables filter, comma-separated')
|
|
25
|
+
.option('--enable-nest-module-generate', 'Enable generate NestJS module boilerplate')
|
|
25
26
|
.example('fullstack-cli gen-db-schema')
|
|
26
27
|
.example('fullstack-cli gen-db-schema --output custom/schema.ts')
|
|
27
28
|
.action(async (options) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.1",
|
|
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": "
|
|
32
|
+
"@lark-apaas/devtool-kits": "1.2.0-alpha.0",
|
|
33
33
|
"@vercel/nft": "^0.30.3",
|
|
34
34
|
"cac": "^6.7.14",
|
|
35
35
|
"dotenv": "^16.0.0",
|