@longzai-intelligence-builder/cli 0.0.1 → 0.0.2
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/config.d.ts +5 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +56 -12
- package/dist/config.js.map +1 -1
- package/package.json +2 -2
package/dist/config.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import type { BuilderConfig } from '@longzai-intelligence-builder/core';
|
|
|
2
2
|
/**
|
|
3
3
|
* 查找并加载 builder 配置文件
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* 按两种模式查找,优先级从高到低:
|
|
6
|
+
* 1. 单独配置:cwd 下的 lzi-builder.config.{ts,mts,js,mjs}
|
|
7
|
+
* 2. 统一配置:从 cwd 向上查找 lzi.config.ts,取其中的 builder 字段
|
|
8
|
+
*
|
|
9
|
+
* 使用 bun 原生 import 加载(bun 生态原生支持 .ts),无需 unrun。
|
|
8
10
|
*
|
|
9
11
|
* @param cwd - 当前工作目录
|
|
10
12
|
* @returns 解析后的构建配置,未找到配置文件时返回默认空配置
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AA2CxE;;;;;;;;;;;GAWG;AACH,iBAAe,UAAU,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,aAAa,CAAC,CA0B7E;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -2,31 +2,75 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
/**
|
|
5
|
-
* builder
|
|
5
|
+
* builder 单独配置文件可能的名字
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
8
|
-
'builder.config.ts',
|
|
9
|
-
'builder.config.mts',
|
|
10
|
-
'builder.config.js',
|
|
11
|
-
'builder.config.mjs',
|
|
7
|
+
const STANDALONE_CONFIG_FILES = [
|
|
8
|
+
'lzi-builder.config.ts',
|
|
9
|
+
'lzi-builder.config.mts',
|
|
10
|
+
'lzi-builder.config.js',
|
|
11
|
+
'lzi-builder.config.mjs',
|
|
12
12
|
];
|
|
13
|
+
/**
|
|
14
|
+
* 统一配置文件名
|
|
15
|
+
*/
|
|
16
|
+
const UNIFIED_CONFIG_FILE = 'lzi.config.ts';
|
|
17
|
+
/**
|
|
18
|
+
* 统一配置中 builder 字段名
|
|
19
|
+
*/
|
|
20
|
+
const BUILDER_CONFIG_KEY = 'builder';
|
|
21
|
+
/**
|
|
22
|
+
* 从指定目录开始向上查找统一配置文件 lzi.config.ts
|
|
23
|
+
*
|
|
24
|
+
* @param cwd - 查找起点目录
|
|
25
|
+
* @returns 配置文件绝对路径,未找到返回 null
|
|
26
|
+
*/
|
|
27
|
+
function resolveUnifiedConfigPath(cwd) {
|
|
28
|
+
let currentDir = resolve(cwd);
|
|
29
|
+
while (true) {
|
|
30
|
+
const candidate = resolve(currentDir, UNIFIED_CONFIG_FILE);
|
|
31
|
+
if (existsSync(candidate)) {
|
|
32
|
+
return candidate;
|
|
33
|
+
}
|
|
34
|
+
const parent = resolve(currentDir, '..');
|
|
35
|
+
if (parent === currentDir) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
currentDir = parent;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
13
41
|
/**
|
|
14
42
|
* 查找并加载 builder 配置文件
|
|
15
43
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
44
|
+
* 按两种模式查找,优先级从高到低:
|
|
45
|
+
* 1. 单独配置:cwd 下的 lzi-builder.config.{ts,mts,js,mjs}
|
|
46
|
+
* 2. 统一配置:从 cwd 向上查找 lzi.config.ts,取其中的 builder 字段
|
|
47
|
+
*
|
|
48
|
+
* 使用 bun 原生 import 加载(bun 生态原生支持 .ts),无需 unrun。
|
|
19
49
|
*
|
|
20
50
|
* @param cwd - 当前工作目录
|
|
21
51
|
* @returns 解析后的构建配置,未找到配置文件时返回默认空配置
|
|
22
52
|
*/
|
|
23
53
|
async function loadConfig(cwd = process.cwd()) {
|
|
24
|
-
|
|
54
|
+
/**
|
|
55
|
+
* 模式一:查找单独配置文件
|
|
56
|
+
*/
|
|
57
|
+
for (const file of STANDALONE_CONFIG_FILES) {
|
|
25
58
|
const filePath = resolve(cwd, file);
|
|
26
59
|
if (existsSync(filePath)) {
|
|
27
60
|
const module = await import(filePath);
|
|
28
|
-
|
|
29
|
-
|
|
61
|
+
return (module.default ?? module);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 模式二:查找统一配置 lzi.config.ts 的 builder 字段
|
|
66
|
+
*/
|
|
67
|
+
const unifiedPath = resolveUnifiedConfigPath(cwd);
|
|
68
|
+
if (unifiedPath) {
|
|
69
|
+
const module = await import(unifiedPath);
|
|
70
|
+
const unifiedConfig = module.default ?? module;
|
|
71
|
+
const builderConfig = unifiedConfig?.[BUILDER_CONFIG_KEY];
|
|
72
|
+
if (builderConfig) {
|
|
73
|
+
return builderConfig;
|
|
30
74
|
}
|
|
31
75
|
}
|
|
32
76
|
return {};
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,OAAO,MA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AAM,MAAM,CAAC,QAAQ,CAAC,CAAC;YACtC,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAkB,CAAC;QACrD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,WAAW,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;IAClD,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;QACzC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC;QAC/C,MAAM,aAAa,GAAG,aAAa,EAAE,CAAC,kBAAkB,CAAC,CAAC;QAC1D,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,aAA8B,CAAC;QACxC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport process from 'node:process';\n\nimport type { BuilderConfig } from '@longzai-intelligence-builder/core';\n\n/**\n * builder 单独配置文件可能的名字\n */\nconst STANDALONE_CONFIG_FILES = [\n 'lzi-builder.config.ts',\n 'lzi-builder.config.mts',\n 'lzi-builder.config.js',\n 'lzi-builder.config.mjs',\n] as const;\n\n/**\n * 统一配置文件名\n */\nconst UNIFIED_CONFIG_FILE = 'lzi.config.ts';\n\n/**\n * 统一配置中 builder 字段名\n */\nconst BUILDER_CONFIG_KEY = 'builder';\n\n/**\n * 从指定目录开始向上查找统一配置文件 lzi.config.ts\n *\n * @param cwd - 查找起点目录\n * @returns 配置文件绝对路径,未找到返回 null\n */\nfunction resolveUnifiedConfigPath(cwd: string): string | null {\n let currentDir = resolve(cwd);\n while (true) {\n const candidate = resolve(currentDir, UNIFIED_CONFIG_FILE);\n if (existsSync(candidate)) {\n return candidate;\n }\n const parent = resolve(currentDir, '..');\n if (parent === currentDir) {\n return null;\n }\n currentDir = parent;\n }\n}\n\n/**\n * 查找并加载 builder 配置文件\n *\n * 按两种模式查找,优先级从高到低:\n * 1. 单独配置:cwd 下的 lzi-builder.config.{ts,mts,js,mjs}\n * 2. 统一配置:从 cwd 向上查找 lzi.config.ts,取其中的 builder 字段\n *\n * 使用 bun 原生 import 加载(bun 生态原生支持 .ts),无需 unrun。\n *\n * @param cwd - 当前工作目录\n * @returns 解析后的构建配置,未找到配置文件时返回默认空配置\n */\nasync function loadConfig(cwd: string = process.cwd()): Promise<BuilderConfig> {\n /**\n * 模式一:查找单独配置文件\n */\n for (const file of STANDALONE_CONFIG_FILES) {\n const filePath = resolve(cwd, file);\n if (existsSync(filePath)) {\n const module = await import(filePath);\n return (module.default ?? module) as BuilderConfig;\n }\n }\n\n /**\n * 模式二:查找统一配置 lzi.config.ts 的 builder 字段\n */\n const unifiedPath = resolveUnifiedConfigPath(cwd);\n if (unifiedPath) {\n const module = await import(unifiedPath);\n const unifiedConfig = module.default ?? module;\n const builderConfig = unifiedConfig?.[BUILDER_CONFIG_KEY];\n if (builderConfig) {\n return builderConfig as BuilderConfig;\n }\n }\n\n return {};\n}\n\nexport { loadConfig };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-builder/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"clean": "rimraf dist out .cache"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@longzai-intelligence-builder/core": "0.0.
|
|
28
|
+
"@longzai-intelligence-builder/core": "0.0.2",
|
|
29
29
|
"@longzai-intelligence-tsdown/rolldown-plugin-dts": "^0.1.1",
|
|
30
30
|
"rolldown": "^1.1.5"
|
|
31
31
|
},
|