@lark-apaas/fullstack-cli 0.1.0-alpha.7 → 0.1.0-alpha.9
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/bin/{cli.js → cli.mjs}
RENAMED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
4
10
|
|
|
5
11
|
const command = process.argv[2];
|
|
6
12
|
const distPath = path.join(__dirname, '..', 'dist');
|
|
@@ -9,13 +15,14 @@ async function main() {
|
|
|
9
15
|
try {
|
|
10
16
|
switch (command) {
|
|
11
17
|
case 'gen-db-schema': {
|
|
12
|
-
const
|
|
18
|
+
const modulePath = path.join(distPath, 'commands', 'gen-db-schema.js');
|
|
19
|
+
const { run } = await import(modulePath);
|
|
13
20
|
await run();
|
|
14
21
|
break;
|
|
15
22
|
}
|
|
16
23
|
case 'sync':
|
|
17
24
|
case 'postinstall': {
|
|
18
|
-
// 调用原有的 sync-scripts.js
|
|
25
|
+
// 调用原有的 sync-scripts.js (CommonJS)
|
|
19
26
|
require('./sync-scripts.js');
|
|
20
27
|
break;
|
|
21
28
|
}
|
|
@@ -40,6 +47,7 @@ async function main() {
|
|
|
40
47
|
}
|
|
41
48
|
} catch (error) {
|
|
42
49
|
console.error(`Failed to execute command "${command}":`, error.message);
|
|
50
|
+
console.error(error.stack);
|
|
43
51
|
process.exit(1);
|
|
44
52
|
}
|
|
45
53
|
}
|
|
@@ -2,8 +2,11 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
5
6
|
// 加载 .env 配置
|
|
6
7
|
import { config as loadEnv } from 'dotenv';
|
|
8
|
+
// 创建 require 函数来加载 CommonJS 模块
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
7
10
|
/**
|
|
8
11
|
* 生成数据库 schema
|
|
9
12
|
*
|
|
@@ -67,9 +70,9 @@ export async function run() {
|
|
|
67
70
|
fs.mkdirSync(path.dirname(SCHEMA_FILE), { recursive: true });
|
|
68
71
|
fs.copyFileSync(generatedSchema, SCHEMA_FILE);
|
|
69
72
|
console.log(`[gen-db-schema] ✓ Copied to ${outputPath}`);
|
|
70
|
-
//
|
|
73
|
+
// 后处理 schema(使用 CommonJS require 方式加载)
|
|
71
74
|
try {
|
|
72
|
-
const { postprocessDrizzleSchema } =
|
|
75
|
+
const { postprocessDrizzleSchema } = require('@lark-apaas/devtool-kits');
|
|
73
76
|
const stats = postprocessDrizzleSchema(SCHEMA_FILE);
|
|
74
77
|
if (stats?.unmatchedUnknown?.length) {
|
|
75
78
|
console.warn('[gen-db-schema] Unmatched custom types detected:', stats.unmatchedUnknown);
|
|
@@ -77,7 +80,7 @@ export async function run() {
|
|
|
77
80
|
console.log('[gen-db-schema] ✓ Postprocessed schema');
|
|
78
81
|
}
|
|
79
82
|
catch (error) {
|
|
80
|
-
console.warn('[gen-db-schema] Postprocess
|
|
83
|
+
console.warn('[gen-db-schema] Postprocess failed:', error instanceof Error ? error.message : String(error));
|
|
81
84
|
}
|
|
82
85
|
// 清理临时文件
|
|
83
86
|
if (fs.existsSync(OUT_DIR)) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.9",
|
|
4
4
|
"description": "CLI tool for fullstack template management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"bin": "./bin/cli.
|
|
7
|
+
"bin": "./bin/cli.mjs",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"templates",
|
|
@@ -4,15 +4,14 @@ import { defineConfig } from 'drizzle-kit';
|
|
|
4
4
|
// 通过环境变量传递具体参数
|
|
5
5
|
const outputDir = process.env.__DRIZZLE_OUT_DIR__ || './server/database/.introspect';
|
|
6
6
|
const schemaPath = process.env.__DRIZZLE_SCHEMA_PATH__ || './server/database/schema.ts';
|
|
7
|
-
const schemaFilter = process.env.DRIZZLE_SCHEMA_FILTER?.split(',') || [];
|
|
8
|
-
const tablesFilter = process.env.DRIZZLE_TABLES_FILTER?.split(',') || ['*'];
|
|
9
7
|
|
|
10
8
|
const parsedUrl = new URL(process.env.SUDA_DATABASE_URL || '');
|
|
9
|
+
const schemaFilter = parsedUrl.searchParams.get('schema')?.split(',') ?? [];
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
const config = {
|
|
13
12
|
schema: schemaPath,
|
|
14
13
|
out: outputDir,
|
|
15
|
-
tablesFilter,
|
|
14
|
+
tablesFilter: ['*'],
|
|
16
15
|
schemaFilter,
|
|
17
16
|
dialect: 'postgresql',
|
|
18
17
|
dbCredentials: {
|
|
@@ -22,4 +21,5 @@ export default defineConfig({
|
|
|
22
21
|
password: decodeURIComponent(parsedUrl.password),
|
|
23
22
|
database: parsedUrl.pathname.split('/')[1],
|
|
24
23
|
},
|
|
25
|
-
}
|
|
24
|
+
}
|
|
25
|
+
export default defineConfig(config);
|