@longzai-intelligence-paper-report/config 0.0.0-stage → 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/.turbo/turbo-build.log +15 -0
- package/.turbo/turbo-test.log +24 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +18 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +2 -0
- package/lzi-builder.config.ts +9 -0
- package/lzi-dev-tools.config.ts +7 -0
- package/oxlint.config.ts +3 -0
- package/package.json +34 -4
- package/src/__tests__/domain-config.schema.test.ts +35 -0
- package/src/__tests__/loader.utils.test.ts +155 -0
- package/src/domain-config.schema.ts +58 -0
- package/src/index.ts +8 -0
- package/src/loader.utils.ts +75 -0
- package/src/scaffold.utils.ts +63 -0
- package/tsconfig/.cache/build.tsbuildinfo +1 -0
- package/tsconfig/.cache/node.tsbuildinfo +1 -0
- package/tsconfig/.cache/test.tsbuildinfo +1 -0
- package/tsconfig/app.json +13 -0
- package/tsconfig/build.json +15 -0
- package/tsconfig/node.json +12 -0
- package/tsconfig/test.json +15 -0
- package/tsconfig.json +22 -0
- package/README.md +0 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
$ lzi-builder
|
|
2
|
+
ℹ lzi-builder v0.2.22 powered by rolldown v1.2.15
|
|
3
|
+
ℹ @longzai-intelligence-paper-report/config tsconfig: tsconfig/build.json
|
|
4
|
+
ℹ Cleaning 2 files
|
|
5
|
+
TypeScript 7.0 尚未提供稳定的 API,仍处于实验阶段。部分选项将不可用。
|
|
6
|
+
src/loader.utils.ts (15:24) [33m[UNRESOLVED_IMPORT] [0mCould not resolve 'node:path' in src/loader.utils.ts
|
|
7
|
+
[38;5;246m╭[0m[38;5;246m─[0m[38;5;246m[[0m src/loader.utils.ts:15:25 [38;5;246m][0m
|
|
8
|
+
[38;5;246m│[0m
|
|
9
|
+
[38;5;246m15 │[0m [38;5;249mi[0m[38;5;249mm[0m[38;5;249mp[0m[38;5;249mo[0m[38;5;249mr[0m[38;5;249mt[0m[38;5;249m [0m[38;5;249m{[0m[38;5;249m [0m[38;5;249mr[0m[38;5;249me[0m[38;5;249ms[0m[38;5;249mo[0m[38;5;249ml[0m[38;5;249mv[0m[38;5;249me[0m[38;5;249m [0m[38;5;249m}[0m[38;5;249m [0m[38;5;249mf[0m[38;5;249mr[0m[38;5;249mo[0m[38;5;249mm[0m[38;5;249m [0m'node:path'[38;5;249m;[0m
|
|
10
|
+
[38;5;240m │[0m ─────┬─────
|
|
11
|
+
[38;5;240m │[0m ╰─────── Module not found, treating it as an external dependency
|
|
12
|
+
[38;5;240m │[0m
|
|
13
|
+
[38;5;240m │[0m [38;5;115mHelp[0m: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
|
|
14
|
+
[38;5;246m────╯[0m
|
|
15
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
$ lzi-bun-cli test
|
|
2
|
+
警告: @longzai-intelligence-paper-report/config 本包的目录分层是 package,声明的预设却是 root。固定分层预设必须与目录分层一致,custom 与 type-only 不受目录分层约束。请改用 @longzai-intelligence-bun/presets/package 子路径的 defineConfig 声明配置
|
|
3
|
+
bun test v1.4.0 (34cbb9a40)
|
|
4
|
+
|
|
5
|
+
src/__tests__/domain-config.schema.test.ts:
|
|
6
|
+
(pass) PaperReportConfigSchema > 新式编号合法且 dataRoot 缺省为点号 [1.61ms]
|
|
7
|
+
(pass) PaperReportConfigSchema > 带版本后缀的编号合法 [0.02ms]
|
|
8
|
+
(pass) PaperReportConfigSchema > 旧式斜杠编号拒绝 [0.13ms]
|
|
9
|
+
(pass) PaperReportConfigSchema > 空编号拒绝 [0.03ms]
|
|
10
|
+
|
|
11
|
+
src/__tests__/loader.utils.test.ts:
|
|
12
|
+
(pass) discoverConfigPath > 显式路径存在则直接采用 [0.35ms]
|
|
13
|
+
(pass) discoverConfigPath > 显式路径不存在返回 undefined [0.02ms]
|
|
14
|
+
(pass) discoverConfigPath > 自子目录向上发现 [0.34ms]
|
|
15
|
+
(pass) loadPaperReportConfig > 加载并绝对化 dataRoot [16.61ms]
|
|
16
|
+
(pass) loadPaperReportConfig > 缺失配置文件报未找到 [1.01ms]
|
|
17
|
+
(pass) loadPaperReportConfig > 非法导出报结构错误 [0.56ms]
|
|
18
|
+
(pass) scaffoldConfigText > 缺省形态生成零参工厂调用 [0.04ms]
|
|
19
|
+
(pass) scaffoldConfigText > 带编号形态生成对应字段 [0.07ms]
|
|
20
|
+
|
|
21
|
+
12 pass
|
|
22
|
+
0 fail
|
|
23
|
+
22 expect() calls
|
|
24
|
+
Ran 12 tests across 2 files. [62.00ms]
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
本项目的所有重要更改都将记录在此文件中。
|
|
4
|
+
|
|
5
|
+
格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
|
|
6
|
+
本项目遵循 [语义化版本](https://semver.org/lang-zh-CN/)。
|
|
7
|
+
|
|
8
|
+
## [0.0.2] - 2026-11-11
|
|
9
|
+
|
|
10
|
+
### 变更
|
|
11
|
+
|
|
12
|
+
- build:prod 统一为 bun 转发标准形态
|
|
13
|
+
|
|
14
|
+
## [0.0.1] - 2026-10-23
|
|
15
|
+
|
|
16
|
+
### 变更
|
|
17
|
+
|
|
18
|
+
- 升级 @longzai-intelligence-paper-report/config 至 0.0.1
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { ConfigLoadErr, ConfigLoadError, ConfigLoadOk, ConfigLoadResult, ConfigLoadResult as ConfigLoadResult$1 } from "@longzai-intelligence-shared-config/core";
|
|
3
|
+
/**
|
|
4
|
+
* 配置结构
|
|
5
|
+
*/
|
|
6
|
+
declare const PaperReportConfigSchema: z.ZodObject<{
|
|
7
|
+
dataRoot: z.ZodDefault<z.ZodString>;
|
|
8
|
+
paperId: z.ZodString;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
/**
|
|
11
|
+
* 配置类型
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* schema 推断形态,`paperId` 未带版本后缀时以最新版为准
|
|
15
|
+
*/
|
|
16
|
+
type PaperReportConfig = z.infer<typeof PaperReportConfigSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* 配置工厂
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* 类型收口用 identity 语义,运行时校验由加载方执行,导出名统一为
|
|
22
|
+
* `defineConfig`,全局 ADR 0097 决策 2,禁域前缀工厂名
|
|
23
|
+
* @param config - 就地配置取值
|
|
24
|
+
* @returns 原样返回的配置对象
|
|
25
|
+
*/
|
|
26
|
+
declare function defineConfig(config: PaperReportConfig): PaperReportConfig;
|
|
27
|
+
/**
|
|
28
|
+
* 配置文件约定名
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* 以工具命名,全局 ADR 0090,与 bin 名及 env 前缀三同源
|
|
32
|
+
*/
|
|
33
|
+
declare const CONFIG_FILENAME = "lzi-paper-report.config.ts";
|
|
34
|
+
/**
|
|
35
|
+
* 自 cwd 向上查找配置文件
|
|
36
|
+
*
|
|
37
|
+
* @param explicitPath - 显式指定的配置文件路径,可空
|
|
38
|
+
* @returns 命中的绝对路径,未命中为 undefined
|
|
39
|
+
*/
|
|
40
|
+
declare function discoverConfigPath(explicitPath?: string): string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* 加载并校验配置
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* 相对路径以配置文件所在目录为基准绝对化
|
|
46
|
+
* @param explicitPath - 显式指定的配置文件路径,可空,缺省走向上发现
|
|
47
|
+
* @returns 成功为绝对路径形态配置与文件路径,失败为可读错误
|
|
48
|
+
*/
|
|
49
|
+
declare function loadPaperReportConfig(explicitPath?: string): Promise<ConfigLoadResult$1<PaperReportConfig>>;
|
|
50
|
+
/**
|
|
51
|
+
* 配置骨架生成
|
|
52
|
+
*
|
|
53
|
+
* `config init` 用,`defineConfig` 工厂导出形态,全局 ADR 0097 决策 2,裸对象过渡
|
|
54
|
+
* 形态废止,禁 `version` 字段,代际由包 npm 版本承载,骨架依赖目标目录已安装
|
|
55
|
+
* config 包,依赖就绪门沿 ADR 0100 先例,本模块自持文本生成,域形态不走引擎
|
|
56
|
+
* `ScaffoldTemplate`,非引擎能力分叉
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* 骨架入参
|
|
60
|
+
*/
|
|
61
|
+
type ScaffoldParams = {
|
|
62
|
+
/**
|
|
63
|
+
* 数据根
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* 缺省 `.` 即就地自指
|
|
67
|
+
*/
|
|
68
|
+
readonly dataRoot?: string;
|
|
69
|
+
/**
|
|
70
|
+
* arXiv 论文编号
|
|
71
|
+
*/
|
|
72
|
+
readonly paperId?: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 生成配置骨架文本
|
|
76
|
+
*
|
|
77
|
+
* @param params - 骨架入参
|
|
78
|
+
* @returns 就地配置全文
|
|
79
|
+
*/
|
|
80
|
+
declare function scaffoldConfigText(params?: ScaffoldParams): string;
|
|
81
|
+
export { CONFIG_FILENAME, type ConfigLoadErr, type ConfigLoadError, type ConfigLoadOk, type ConfigLoadResult, PaperReportConfig, PaperReportConfigSchema, ScaffoldParams, defineConfig, discoverConfigPath, loadPaperReportConfig, scaffoldConfigText };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import*as e from"zod";import{createDomainConfigLoader as t}from"@longzai-intelligence-shared-config/core";import{resolve as n}from"node:path";const r=e.object({dataRoot:e.string().min(1).default(`.`),paperId:e.string().regex(/^\d{4}\.\d{4,5}(v\d+)?$/,{message:`论文编号须为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀`})});function i(e){return e}const a=`lzi-paper-report.config.ts`,o=()=>t({configFilename:a,schema:r,shapeHint:`defineConfig 收口的 dataRoot 加 paperId,禁 version 字段,代际由包 npm 版本承载`,absolutize:(e,t)=>({...e,dataRoot:n(t,e.dataRoot)})});function s(e){return o().discoverConfigPath(e)}async function c(e){return o().loadConfig(e)}function l(e={}){let t=[];return e.dataRoot!==void 0&&e.dataRoot!==`.`&&t.push(`dataRoot: '${e.dataRoot}'`),e.paperId!==void 0&&t.push(`paperId: '${e.paperId}'`),[`// lzi-paper-report 就地配置,以工具命名,全局 ADR 0090,defineConfig 工厂收口,全局 ADR 0097 决策 2`,`// 相对路径以本文件所在目录为基准,放在数据根时工厂默认 dataRoot 为点号,零参调用即可`,`// 论文编号为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀`,`import { defineConfig } from '@longzai-intelligence-paper-report/config';`,``,t.length===0?`export default defineConfig();`:`export default defineConfig({ ${t.join(`, `)} });`,``].join(`
|
|
2
|
+
`)}export{a as CONFIG_FILENAME,r as PaperReportConfigSchema,i as defineConfig,s as discoverConfigPath,c as loadPaperReportConfig,l as scaffoldConfigText};
|
package/oxlint.config.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-paper-report/config",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Longzai Intelligence 配置包",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"config",
|
|
7
|
+
"longzai-intelligence"
|
|
8
|
+
],
|
|
9
|
+
"license": "UNLICENSED",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "lzi-builder",
|
|
21
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
22
|
+
"prepublishOnly": "bun run build:prod",
|
|
23
|
+
"typecheck": "lzi-typecheck",
|
|
24
|
+
"lint": "lzi-lint lint",
|
|
25
|
+
"lint:fix": "lzi-lint fix",
|
|
26
|
+
"test": "lzi-bun-cli test",
|
|
27
|
+
"test:watch": "lzi-bun-cli test --watch",
|
|
28
|
+
"test:coverage": "lzi-bun-cli test --coverage",
|
|
29
|
+
"clean": "lzi-dev-cli clean"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@longzai-intelligence-markdown/data-engine": "^0.0.5",
|
|
33
|
+
"@longzai-intelligence-shared-config/core": "^0.0.9",
|
|
34
|
+
"zod": "^4.6.5"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置 Schema 单测:合法编号、版本后缀、旧式拒绝、dataRoot 缺省
|
|
3
|
+
*/
|
|
4
|
+
import { describe, expect, it } from 'bun:test';
|
|
5
|
+
|
|
6
|
+
import { PaperReportConfigSchema } from '@/domain-config.schema';
|
|
7
|
+
|
|
8
|
+
describe('PaperReportConfigSchema', () => {
|
|
9
|
+
it('新式编号合法且 dataRoot 缺省为点号', () => {
|
|
10
|
+
const parsed = PaperReportConfigSchema.safeParse({ paperId: '2609.22068' });
|
|
11
|
+
|
|
12
|
+
expect(parsed.success).toBe(true);
|
|
13
|
+
if (parsed.success) {
|
|
14
|
+
expect(parsed.data.dataRoot).toBe('.');
|
|
15
|
+
expect(parsed.data.paperId).toBe('2609.22068');
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('带版本后缀的编号合法', () => {
|
|
20
|
+
const parsed = PaperReportConfigSchema.safeParse({ paperId: '2609.22068v1' });
|
|
21
|
+
|
|
22
|
+
expect(parsed.success).toBe(true);
|
|
23
|
+
if (parsed.success) {
|
|
24
|
+
expect(parsed.data.paperId).toBe('2609.22068v1');
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('旧式斜杠编号拒绝', () => {
|
|
29
|
+
expect(PaperReportConfigSchema.safeParse({ paperId: 'cs/0301012' }).success).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('空编号拒绝', () => {
|
|
33
|
+
expect(PaperReportConfigSchema.safeParse({ paperId: '' }).success).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置加载器与骨架单测:显式路径、向上发现、相对路径绝对化、非法导出、骨架形态
|
|
3
|
+
*/
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
|
|
5
|
+
import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
import { CONFIG_FILENAME, discoverConfigPath, loadPaperReportConfig } from '@/loader.utils';
|
|
10
|
+
import { scaffoldConfigText } from '@/scaffold.utils';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 临时工作区
|
|
14
|
+
*/
|
|
15
|
+
let workspace: string;
|
|
16
|
+
|
|
17
|
+
beforeAll(() => {
|
|
18
|
+
workspace = mkdtempSync(join(tmpdir(), 'lzi-paper-report-config-'));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(() => {
|
|
22
|
+
rmSync(workspace, { recursive: true, force: true });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 在临时工作区写一份合法配置文件
|
|
27
|
+
*
|
|
28
|
+
* @returns 配置文件绝对路径
|
|
29
|
+
*/
|
|
30
|
+
function writeValidConfig(): string {
|
|
31
|
+
/**
|
|
32
|
+
* 配置文件绝对路径
|
|
33
|
+
*/
|
|
34
|
+
const configPath = join(workspace, CONFIG_FILENAME);
|
|
35
|
+
|
|
36
|
+
writeFileSync(configPath, "export default { dataRoot: '.', paperId: '2609.22068' };", 'utf8');
|
|
37
|
+
|
|
38
|
+
return configPath;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('discoverConfigPath', () => {
|
|
42
|
+
it('显式路径存在则直接采用', () => {
|
|
43
|
+
const configPath = writeValidConfig();
|
|
44
|
+
|
|
45
|
+
expect(discoverConfigPath(configPath)).toBe(configPath);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('显式路径不存在返回 undefined', () => {
|
|
49
|
+
expect(discoverConfigPath(join(workspace, 'missing.config.ts'))).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('自子目录向上发现', () => {
|
|
53
|
+
/**
|
|
54
|
+
* 配置文件路径
|
|
55
|
+
*/
|
|
56
|
+
const configPath = writeValidConfig();
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 子目录路径
|
|
60
|
+
*/
|
|
61
|
+
const subDir = join(workspace, 'sources', '2609.22068');
|
|
62
|
+
mkdirSync(subDir, { recursive: true });
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 原工作目录
|
|
66
|
+
*/
|
|
67
|
+
const originalCwd = process.cwd();
|
|
68
|
+
process.chdir(subDir);
|
|
69
|
+
try {
|
|
70
|
+
/**
|
|
71
|
+
* 实符号路径,chdir 后 cwd 已解析符号链接,期望值同基比较
|
|
72
|
+
*/
|
|
73
|
+
const resolvedPath = realpathSync(configPath);
|
|
74
|
+
|
|
75
|
+
expect(discoverConfigPath()).toBe(resolvedPath);
|
|
76
|
+
} finally {
|
|
77
|
+
process.chdir(originalCwd);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('loadPaperReportConfig', () => {
|
|
83
|
+
it('加载并绝对化 dataRoot', async () => {
|
|
84
|
+
/**
|
|
85
|
+
* 配置文件路径
|
|
86
|
+
*/
|
|
87
|
+
const configPath = writeValidConfig();
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 加载结果
|
|
91
|
+
*/
|
|
92
|
+
const loaded = await loadPaperReportConfig(configPath);
|
|
93
|
+
|
|
94
|
+
expect(loaded.ok).toBe(true);
|
|
95
|
+
if (loaded.ok) {
|
|
96
|
+
expect(loaded.config.dataRoot).toBe(workspace);
|
|
97
|
+
expect(loaded.config.paperId).toBe('2609.22068');
|
|
98
|
+
expect(loaded.path).toBe(configPath);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('缺失配置文件报未找到', async () => {
|
|
103
|
+
/**
|
|
104
|
+
* 空临时目录
|
|
105
|
+
*/
|
|
106
|
+
const emptyDir = mkdtempSync(join(tmpdir(), 'lzi-paper-report-empty-'));
|
|
107
|
+
try {
|
|
108
|
+
const loaded = await loadPaperReportConfig(join(emptyDir, CONFIG_FILENAME));
|
|
109
|
+
|
|
110
|
+
expect(loaded.ok).toBe(false);
|
|
111
|
+
if (!loaded.ok) {
|
|
112
|
+
expect(loaded.error.code).toBe('CONFIG_NOT_FOUND');
|
|
113
|
+
}
|
|
114
|
+
} finally {
|
|
115
|
+
rmSync(emptyDir, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('非法导出报结构错误', async () => {
|
|
120
|
+
/**
|
|
121
|
+
* 非法配置文件路径
|
|
122
|
+
*/
|
|
123
|
+
const badPath = join(workspace, 'bad.config.ts');
|
|
124
|
+
writeFileSync(badPath, 'export default 42;', 'utf8');
|
|
125
|
+
|
|
126
|
+
const loaded = await loadPaperReportConfig(badPath);
|
|
127
|
+
|
|
128
|
+
expect(loaded.ok).toBe(false);
|
|
129
|
+
if (!loaded.ok) {
|
|
130
|
+
expect(loaded.error.code).toBe('CONFIG_INVALID');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('scaffoldConfigText', () => {
|
|
136
|
+
it('缺省形态生成零参工厂调用', () => {
|
|
137
|
+
/**
|
|
138
|
+
* 骨架文本
|
|
139
|
+
*/
|
|
140
|
+
const text = scaffoldConfigText();
|
|
141
|
+
|
|
142
|
+
expect(text).toContain('export default defineConfig();');
|
|
143
|
+
expect(text).toContain('@longzai-intelligence-paper-report/config');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('带编号形态生成对应字段', () => {
|
|
147
|
+
/**
|
|
148
|
+
* 骨架文本
|
|
149
|
+
*/
|
|
150
|
+
const text = scaffoldConfigText({ paperId: '2609.22068' });
|
|
151
|
+
|
|
152
|
+
expect(text).toContain("paperId: '2609.22068'");
|
|
153
|
+
expect(text).not.toContain("dataRoot: '");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置 Schema
|
|
3
|
+
*
|
|
4
|
+
* `lzi-paper-report.config.ts` 结构真源,就地配置置于数据仓根,领域形态为单篇论文
|
|
5
|
+
* 报告仓,配置承载 `dataRoot` 与 `paperId` 双字段,论文编号仅收 arXiv 新式形态即
|
|
6
|
+
* `YYMM.NNNNN` 可带 `v` 版本后缀,旧式斜杠形态不收,理由见本仓 ADR 0002
|
|
7
|
+
*/
|
|
8
|
+
import * as z from 'zod';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* arXiv 新式论文编号模式,形如 `2609.22068` 或 `2609.22068v1`
|
|
12
|
+
*/
|
|
13
|
+
const PAPER_ID_PATTERN = /^\d{4}\.\d{4,5}(v\d+)?$/;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 配置结构
|
|
17
|
+
*/
|
|
18
|
+
export const PaperReportConfigSchema = z.object({
|
|
19
|
+
/**
|
|
20
|
+
* 数据根
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* 相对路径以配置文件所在目录为基准,就地配置可用 `.`
|
|
24
|
+
* @default
|
|
25
|
+
*/
|
|
26
|
+
dataRoot: z.string().min(1).default('.'),
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* arXiv 论文编号
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* 新式形态 `YYMM.NNNNN` 可带 `v` 版本后缀,旧式斜杠形态不收
|
|
33
|
+
*/
|
|
34
|
+
paperId: z.string().regex(PAPER_ID_PATTERN, {
|
|
35
|
+
message: '论文编号须为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀',
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 配置类型
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* schema 推断形态,`paperId` 未带版本后缀时以最新版为准
|
|
44
|
+
*/
|
|
45
|
+
export type PaperReportConfig = z.infer<typeof PaperReportConfigSchema>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 配置工厂
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* 类型收口用 identity 语义,运行时校验由加载方执行,导出名统一为
|
|
52
|
+
* `defineConfig`,全局 ADR 0097 决策 2,禁域前缀工厂名
|
|
53
|
+
* @param config - 就地配置取值
|
|
54
|
+
* @returns 原样返回的配置对象
|
|
55
|
+
*/
|
|
56
|
+
export function defineConfig(config: PaperReportConfig): PaperReportConfig {
|
|
57
|
+
return config;
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ConfigLoadResult,
|
|
3
|
+
createDomainConfigLoader,
|
|
4
|
+
} from '@longzai-intelligence-shared-config/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 配置文件加载器
|
|
8
|
+
*
|
|
9
|
+
* 经 shared-config 的 `createDomainConfigLoader` 声明式装配,全局 ADR 0118:查找、
|
|
10
|
+
* 导入、zod 校验、显式路径、绝对化与错误码统一由共享设施承载,域只声明文件名、
|
|
11
|
+
* schema、结构提示与绝对化语义,配置文件必备,执行全局 ADR 0097 决策 9:未找到
|
|
12
|
+
* 即错误,env 不作整体替代,本工具的 env 通道仅承载 LLM 凭据,见 core 包
|
|
13
|
+
* `env/env.schema`
|
|
14
|
+
*/
|
|
15
|
+
import { resolve } from 'node:path';
|
|
16
|
+
|
|
17
|
+
import { type PaperReportConfig, PaperReportConfigSchema } from './domain-config.schema';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 配置文件约定名
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* 以工具命名,全局 ADR 0090,与 bin 名及 env 前缀三同源
|
|
24
|
+
*/
|
|
25
|
+
export const CONFIG_FILENAME = 'lzi-paper-report.config.ts';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 惰性构造域配置加载器
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* 引擎的向上发现以构造期 cwd 为基,故按调用时点惰性构造,保证自调用方当前
|
|
32
|
+
* 目录向上查找,文件名、schema、结构提示、绝对化四参数装配
|
|
33
|
+
* @returns 域配置加载器实例
|
|
34
|
+
*/
|
|
35
|
+
const buildLoader = () =>
|
|
36
|
+
createDomainConfigLoader<PaperReportConfig>({
|
|
37
|
+
configFilename: CONFIG_FILENAME,
|
|
38
|
+
schema: PaperReportConfigSchema,
|
|
39
|
+
shapeHint: 'defineConfig 收口的 dataRoot 加 paperId,禁 version 字段,代际由包 npm 版本承载',
|
|
40
|
+
absolutize: (config, configDir) => ({
|
|
41
|
+
...config,
|
|
42
|
+
dataRoot: resolve(configDir, config.dataRoot),
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 自 cwd 向上查找配置文件
|
|
48
|
+
*
|
|
49
|
+
* @param explicitPath - 显式指定的配置文件路径,可空
|
|
50
|
+
* @returns 命中的绝对路径,未命中为 undefined
|
|
51
|
+
*/
|
|
52
|
+
export function discoverConfigPath(explicitPath?: string): string | undefined {
|
|
53
|
+
return buildLoader().discoverConfigPath(explicitPath);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 加载并校验配置
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* 相对路径以配置文件所在目录为基准绝对化
|
|
61
|
+
* @param explicitPath - 显式指定的配置文件路径,可空,缺省走向上发现
|
|
62
|
+
* @returns 成功为绝对路径形态配置与文件路径,失败为可读错误
|
|
63
|
+
*/
|
|
64
|
+
export async function loadPaperReportConfig(
|
|
65
|
+
explicitPath?: string,
|
|
66
|
+
): Promise<ConfigLoadResult<PaperReportConfig>> {
|
|
67
|
+
return buildLoader().loadConfig(explicitPath);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type {
|
|
71
|
+
ConfigLoadError,
|
|
72
|
+
ConfigLoadErr,
|
|
73
|
+
ConfigLoadOk,
|
|
74
|
+
ConfigLoadResult,
|
|
75
|
+
} from '@longzai-intelligence-shared-config/core';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置骨架生成
|
|
3
|
+
*
|
|
4
|
+
* `config init` 用,`defineConfig` 工厂导出形态,全局 ADR 0097 决策 2,裸对象过渡
|
|
5
|
+
* 形态废止,禁 `version` 字段,代际由包 npm 版本承载,骨架依赖目标目录已安装
|
|
6
|
+
* config 包,依赖就绪门沿 ADR 0100 先例,本模块自持文本生成,域形态不走引擎
|
|
7
|
+
* `ScaffoldTemplate`,非引擎能力分叉
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 骨架入参
|
|
12
|
+
*/
|
|
13
|
+
export type ScaffoldParams = {
|
|
14
|
+
/**
|
|
15
|
+
* 数据根
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* 缺省 `.` 即就地自指
|
|
19
|
+
*/
|
|
20
|
+
readonly dataRoot?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* arXiv 论文编号
|
|
24
|
+
*/
|
|
25
|
+
readonly paperId?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 生成配置骨架文本
|
|
30
|
+
*
|
|
31
|
+
* @param params - 骨架入参
|
|
32
|
+
* @returns 就地配置全文
|
|
33
|
+
*/
|
|
34
|
+
export function scaffoldConfigText(params: ScaffoldParams = {}): string {
|
|
35
|
+
/**
|
|
36
|
+
* 工厂入参字段序列
|
|
37
|
+
*/
|
|
38
|
+
const fields: string[] = [];
|
|
39
|
+
if (params.dataRoot !== undefined && params.dataRoot !== '.') {
|
|
40
|
+
fields.push(`dataRoot: '${params.dataRoot}'`);
|
|
41
|
+
}
|
|
42
|
+
if (params.paperId !== undefined) {
|
|
43
|
+
fields.push(`paperId: '${params.paperId}'`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 工厂调用行
|
|
48
|
+
*/
|
|
49
|
+
const configCall =
|
|
50
|
+
fields.length === 0
|
|
51
|
+
? 'export default defineConfig();'
|
|
52
|
+
: `export default defineConfig({ ${fields.join(', ')} });`;
|
|
53
|
+
|
|
54
|
+
return [
|
|
55
|
+
'// lzi-paper-report 就地配置,以工具命名,全局 ADR 0090,defineConfig 工厂收口,全局 ADR 0097 决策 2',
|
|
56
|
+
'// 相对路径以本文件所在目录为基准,放在数据根时工厂默认 dataRoot 为点号,零参调用即可',
|
|
57
|
+
'// 论文编号为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀',
|
|
58
|
+
"import { defineConfig } from '@longzai-intelligence-paper-report/config';",
|
|
59
|
+
'',
|
|
60
|
+
configCall,
|
|
61
|
+
'',
|
|
62
|
+
].join('\n');
|
|
63
|
+
}
|