@cfp-studio/analyzer-api 0.1.11 → 0.1.13
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/README.md +55 -0
- package/dist/analyzer.d.mts +39 -0
- package/dist/analyzer.mjs +1 -0
- package/dist/api-3X9rm2RT.d.mts +140 -0
- package/dist/factory.d.mts +4 -8
- package/dist/factory.mjs +1 -1
- package/dist/index.d.mts +36 -12
- package/dist/index.mjs +1 -1
- package/package.json +26 -16
- package/dist/factory.d.ts +0 -15
- package/dist/index.d.ts +0 -33
- package/dist/shared/analyzer-api.40adf6f7.d.mts +0 -141
- package/dist/shared/analyzer-api.40adf6f7.d.ts +0 -141
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @cfp-studio/analyzer-api
|
|
2
|
+
|
|
3
|
+
核心分析 API,用于组件/Story/TS 类型的静态分析、可预览 ID 生成与解析、分析器工厂等。为 CFP Studio 设计器和相关工具提供统一的类型分析与组件元数据抽象。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 提供统一的 `Analyzer` 接口,支持 TS 组件/Story 批量分析、属性/类型收集、资源释放
|
|
8
|
+
- 支持可预览 ID 的生成与解析,便于组件/Story 的唯一定位
|
|
9
|
+
- 支持分析器工厂模式,可自定义 reader/logger
|
|
10
|
+
- 类型定义清晰,便于二次开发和类型推断
|
|
11
|
+
- 内置 Vitest 测试用例
|
|
12
|
+
|
|
13
|
+
## 主要 API/模块
|
|
14
|
+
|
|
15
|
+
- `Analyzer`/`AnalyzerFactory`:分析器主接口与工厂
|
|
16
|
+
- `Component`/`Story`/`BasePreviewable`:可预览对象抽象
|
|
17
|
+
- `generatePreviewableId`/`decodePreviewableId`:可预览 ID 生成与解析
|
|
18
|
+
- `factoryWithDefaultOptions`:分析器工厂默认参数包装
|
|
19
|
+
|
|
20
|
+
## 用法示例
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { AnalyzerFactory } from '@cfp-studio/analyzer-api';
|
|
24
|
+
|
|
25
|
+
const factory: AnalyzerFactory = ...;
|
|
26
|
+
const analyzer = factory({ rootDir: '/project/root' });
|
|
27
|
+
const { components, stories } = await analyzer.crawlFiles(['src/App.tsx']);
|
|
28
|
+
await components[0].analyze();
|
|
29
|
+
analyzer.dispose();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
可预览 ID:
|
|
33
|
+
```ts
|
|
34
|
+
import { generatePreviewableId, decodePreviewableId } from '@cfp-studio/analyzer-api';
|
|
35
|
+
const id = generatePreviewableId({ filePath: '/src/App.tsx', name: 'App' });
|
|
36
|
+
const { filePath, name } = decodePreviewableId(id);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 依赖
|
|
40
|
+
- `@cfp-studio/serializable-values`:可序列化值类型
|
|
41
|
+
- `@cfp-studio/type-analyzer`:TS 类型分析
|
|
42
|
+
- `@cfp-studio/vfs`:虚拟文件系统
|
|
43
|
+
- `pino`:日志
|
|
44
|
+
- `tsdown`:打包
|
|
45
|
+
- `vitest`:测试
|
|
46
|
+
|
|
47
|
+
## 构建
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
pnpm build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 许可证
|
|
54
|
+
|
|
55
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { l as Story, n as AnalyzerFactory, o as Component } from "./api-3X9rm2RT.mjs";
|
|
2
|
+
import { Reader } from "@cfp-studio/vfs";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
import { TypeResolver, createTypeAnalyzer } from "@cfp-studio/type-analyzer";
|
|
5
|
+
|
|
6
|
+
//#region src/analyzer.d.ts
|
|
7
|
+
type CreateTypeAnalyzerOptions = Parameters<typeof createTypeAnalyzer>[0];
|
|
8
|
+
interface AnalyzerAdapterContext {
|
|
9
|
+
rootDir: string;
|
|
10
|
+
/** 已含骨架默认值的 reader(文件系统 reader)。需要额外映射时在其上堆叠。 */
|
|
11
|
+
reader: Reader;
|
|
12
|
+
logger: Logger;
|
|
13
|
+
}
|
|
14
|
+
interface CrawlFileContext extends AnalyzerAdapterContext {
|
|
15
|
+
resolver: TypeResolver;
|
|
16
|
+
absoluteFilePath: string;
|
|
17
|
+
}
|
|
18
|
+
interface AnalyzerAdapter {
|
|
19
|
+
/**
|
|
20
|
+
* `createTypeAnalyzer` 的选项。
|
|
21
|
+
*
|
|
22
|
+
* 骨架会补 `rootDir` / `warn`;这里只需要返回 `reader`(通常是 `context.reader` 或在其上
|
|
23
|
+
* 堆叠映射)、`specialTypes`、`tsCompilerOptions` 等框架相关部分。
|
|
24
|
+
*/
|
|
25
|
+
typeAnalyzerOptions(context: AnalyzerAdapterContext): Omit<CreateTypeAnalyzerOptions, "rootDir" | "warn">;
|
|
26
|
+
/** 真实文件 → 虚拟 TypeScript 路径(如 `App.vue` → `App.vue.ts`)。默认恒等。 */
|
|
27
|
+
toTypeScriptPath?(absoluteFilePath: string): string;
|
|
28
|
+
/** 爬取单个文件里的可预览对象。 */
|
|
29
|
+
crawlFile(context: CrawlFileContext): Promise<Array<Component | Story>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 用 adapter 构造 `AnalyzerFactory`。
|
|
33
|
+
*
|
|
34
|
+
* 返回的 Analyzer 具备:`typeAnalyzer`、`crawlFiles`(含虚拟路径映射与 components/stories
|
|
35
|
+
* 分类)、`dispose`(透传到 typeAnalyzer)。
|
|
36
|
+
*/
|
|
37
|
+
declare function createAnalyzer(adapter: AnalyzerAdapter): AnalyzerFactory;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { AnalyzerAdapter, AnalyzerAdapterContext, CrawlFileContext, createAnalyzer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{factoryWithDefaultOptions as e}from"./factory.mjs";import{createTypeAnalyzer as t}from"@cfp-studio/type-analyzer";import n from"node:path";function r(r){return e(({rootDir:e,reader:i,logger:a})=>{let o={rootDir:e,reader:i,logger:a},s=t({rootDir:e,warn:a.warn.bind(a),...r.typeAnalyzerOptions(o)}),c=r.toTypeScriptPath??(e=>e);return{typeAnalyzer:s,crawlFiles:async t=>{let i=t.map(t=>n.isAbsolute(t)?t:n.join(e,t)),a=s.analyze(i.map(c)),l=[],u=[];for(let e of i)for(let t of await r.crawlFile({...o,resolver:a,absoluteFilePath:e}))`exported`in t?l.push(t):u.push(t);return{components:l,stories:u}},dispose:()=>{s.dispose()}}})}export{r as createAnalyzer};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Reader } from "@cfp-studio/vfs";
|
|
2
|
+
import { Logger } from "pino";
|
|
3
|
+
import { CollectedTypes, TypeAnalyzer, ValueType } from "@cfp-studio/type-analyzer";
|
|
4
|
+
import { SerializableValue } from "@cfp-studio/serializable-values";
|
|
5
|
+
|
|
6
|
+
//#region src/api.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* 定义 FileSourcePosition 类型,包含文件路径和位置信息
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 定义 Analyzer 类型,包含类型分析器、文件爬取方法和资源释放方法
|
|
12
|
+
*/
|
|
13
|
+
type Analyzer = {
|
|
14
|
+
/**
|
|
15
|
+
* 类型分析器,去除了 dispose 方法
|
|
16
|
+
*/
|
|
17
|
+
typeAnalyzer: Omit<TypeAnalyzer, "dispose">;
|
|
18
|
+
/**
|
|
19
|
+
* 爬取指定文件路径的文件,返回组件和故事的集合
|
|
20
|
+
* @param filePaths - 要爬取的文件路径数组
|
|
21
|
+
* @returns 包含组件和故事数组的 Promise
|
|
22
|
+
*/
|
|
23
|
+
crawlFiles: (filePaths: string[]) => Promise<{
|
|
24
|
+
components: Component[];
|
|
25
|
+
stories: Story[];
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* 释放 Analyzer 占用的资源
|
|
29
|
+
*/
|
|
30
|
+
dispose: () => void;
|
|
31
|
+
};
|
|
32
|
+
type AnalyzerOptions = {
|
|
33
|
+
rootDir: string;
|
|
34
|
+
reader?: Reader;
|
|
35
|
+
logger?: Logger;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* 定义 AnalyzerFactory 类型,是一个函数,用于创建 Analyzer 实例
|
|
39
|
+
* @param options - 创建 Analyzer 所需的选项
|
|
40
|
+
* @param options.rootDir - 根目录路径
|
|
41
|
+
* @param options.reader - 可选的读取器
|
|
42
|
+
* @param options.logger - 可选的日志记录器
|
|
43
|
+
* @returns 新创建的 Analyzer 实例
|
|
44
|
+
*/
|
|
45
|
+
type AnalyzerFactory = (options: AnalyzerOptions) => Analyzer;
|
|
46
|
+
/**
|
|
47
|
+
* 定义 BasePreviewable 接口,作为可预览对象的基础接口
|
|
48
|
+
*/
|
|
49
|
+
interface BasePreviewable {
|
|
50
|
+
/**
|
|
51
|
+
* 可预览对象的唯一标识符
|
|
52
|
+
*/
|
|
53
|
+
id: string;
|
|
54
|
+
/**
|
|
55
|
+
* 可预览对象在文件中的源位置
|
|
56
|
+
*/
|
|
57
|
+
sourcePosition: FileSourcePosition;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 定义 Component 接口,继承自 BasePreviewable 接口,代表一个组件
|
|
61
|
+
*/
|
|
62
|
+
interface Component extends BasePreviewable {
|
|
63
|
+
/**
|
|
64
|
+
* 指示组件是否被导出
|
|
65
|
+
*/
|
|
66
|
+
exported: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 分析组件,返回组件分析结果的 Promise
|
|
69
|
+
* @returns 包含组件属性和类型信息的 ComponentAnalysis 对象的 Promise
|
|
70
|
+
*/
|
|
71
|
+
analyze: () => Promise<ComponentAnalysis>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 定义 ComponentAnalysis 接口,包含组件分析的结果
|
|
75
|
+
*/
|
|
76
|
+
interface ComponentAnalysis {
|
|
77
|
+
/**
|
|
78
|
+
* 组件的属性类型
|
|
79
|
+
*/
|
|
80
|
+
props: ValueType;
|
|
81
|
+
/**
|
|
82
|
+
* 收集到的组件类型信息
|
|
83
|
+
*/
|
|
84
|
+
types: CollectedTypes;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 定义 Story 接口,继承自 BasePreviewable 接口,代表一个故事
|
|
88
|
+
*/
|
|
89
|
+
interface Story extends BasePreviewable {
|
|
90
|
+
/**
|
|
91
|
+
* 分析故事,返回故事分析结果的 Promise
|
|
92
|
+
* @returns 包含故事参数信息的 StoryAnalysis 对象的 Promise
|
|
93
|
+
*/
|
|
94
|
+
analyze: () => Promise<StoryAnalysis>;
|
|
95
|
+
/**
|
|
96
|
+
* 与故事关联的基本组件,可能为 null
|
|
97
|
+
*/
|
|
98
|
+
associatedComponent: BasicComponent | null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 定义 StoryAnalysis 接口,包含故事分析的结果
|
|
102
|
+
*/
|
|
103
|
+
interface StoryAnalysis {
|
|
104
|
+
/**
|
|
105
|
+
* 故事的参数,可能为 null
|
|
106
|
+
*/
|
|
107
|
+
args: StoryArgs | null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 定义 StoryArgs 类型,包含故事参数的源位置和值
|
|
111
|
+
*/
|
|
112
|
+
type StoryArgs = {
|
|
113
|
+
/**
|
|
114
|
+
* 故事参数在文件中的源位置
|
|
115
|
+
*/
|
|
116
|
+
sourcePosition: FileSourcePosition;
|
|
117
|
+
/**
|
|
118
|
+
* 故事参数的值
|
|
119
|
+
*/
|
|
120
|
+
value: SerializableValue;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* 定义 FileSourcePosition 类型,包含文件中某个位置的起始和结束索引
|
|
124
|
+
*/
|
|
125
|
+
type FileSourcePosition = {
|
|
126
|
+
/**
|
|
127
|
+
* 起始索引
|
|
128
|
+
*/
|
|
129
|
+
start: number;
|
|
130
|
+
/**
|
|
131
|
+
* 结束索引
|
|
132
|
+
*/
|
|
133
|
+
end: number;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* 定义 BasicComponent 类型,是 Component 类型的部分属性集合
|
|
137
|
+
*/
|
|
138
|
+
type BasicComponent = Pick<Component, "id" | "analyze">;
|
|
139
|
+
//#endregion
|
|
140
|
+
export { BasicComponent as a, FileSourcePosition as c, StoryArgs as d, BasePreviewable as i, Story as l, AnalyzerFactory as n, Component as o, AnalyzerOptions as r, ComponentAnalysis as s, Analyzer as t, StoryAnalysis as u };
|
package/dist/factory.d.mts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '@cfp-studio/serializable-values';
|
|
3
|
-
import '@cfp-studio/type-analyzer';
|
|
4
|
-
import '@cfp-studio/vfs';
|
|
5
|
-
import 'pino';
|
|
6
|
-
import '@cfp-studio/jsx-processor';
|
|
1
|
+
import { n as AnalyzerFactory, r as AnalyzerOptions, t as Analyzer } from "./api-3X9rm2RT.mjs";
|
|
7
2
|
|
|
3
|
+
//#region src/factory.d.ts
|
|
8
4
|
/**
|
|
9
5
|
* 给 AnalyzerFactory 工厂函数进行默认选项填充
|
|
10
6
|
* @param factory - 工厂函数名,接受包含默认选项的 AnalyzerFactoryOptions 并返回一个 Analyzer 实例
|
|
11
7
|
* @returns 一个新的 AnalyzerFactory 函数,该函数会在调用时填充默认选项
|
|
12
8
|
*/
|
|
13
9
|
declare function factoryWithDefaultOptions(factory: (options: Required<AnalyzerOptions>) => Analyzer): AnalyzerFactory;
|
|
14
|
-
|
|
15
|
-
export { factoryWithDefaultOptions };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { factoryWithDefaultOptions };
|
package/dist/factory.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createFileSystemReader as
|
|
1
|
+
import{createFileSystemReader as e}from"@cfp-studio/vfs";import t from"pino";import n from"pino-pretty";const{pino:r}=t,i=n;function a(t){return n=>t({...n,reader:n.reader||e(),logger:n.logger||r({level:`debug`},i({colorize:!0}))})}export{a as factoryWithDefaultOptions};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import '@cfp-studio/type-analyzer';
|
|
4
|
-
import '@cfp-studio/vfs';
|
|
5
|
-
import 'pino';
|
|
6
|
-
import '@cfp-studio/jsx-processor';
|
|
1
|
+
import { a as BasicComponent, c as FileSourcePosition, d as StoryArgs, i as BasePreviewable, l as Story, n as AnalyzerFactory, o as Component, r as AnalyzerOptions, s as ComponentAnalysis, t as Analyzer, u as StoryAnalysis } from "./api-3X9rm2RT.mjs";
|
|
2
|
+
import { ValueType } from "@cfp-studio/type-analyzer";
|
|
7
3
|
|
|
4
|
+
//#region src/previewable-id.d.ts
|
|
8
5
|
type PreviewableId = {
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
filePath: string;
|
|
7
|
+
name: string;
|
|
11
8
|
};
|
|
12
9
|
/**
|
|
13
10
|
* 生成可预览 ID。
|
|
@@ -18,8 +15,8 @@ type PreviewableId = {
|
|
|
18
15
|
* @returns 生成的可预览 ID,格式为 "文件路径:名称"。
|
|
19
16
|
*/
|
|
20
17
|
declare function generatePreviewableId(options: {
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
filePath: string;
|
|
19
|
+
name: string;
|
|
23
20
|
}): string;
|
|
24
21
|
/**
|
|
25
22
|
* 解码可预览 ID。
|
|
@@ -29,5 +26,32 @@ declare function generatePreviewableId(options: {
|
|
|
29
26
|
* @throws 如果 ID 格式无效(不包含冒号),则抛出错误。
|
|
30
27
|
*/
|
|
31
28
|
declare function decodePreviewableId(id: string): PreviewableId;
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/special-types.d.ts
|
|
31
|
+
type SpecialTypes = Record<string, ValueType>;
|
|
32
|
+
/**
|
|
33
|
+
* 声明一组框架专属类型映射。
|
|
34
|
+
*
|
|
35
|
+
* 只是带类型的恒等函数:用于让各插件的 `special-types.ts` 形状一致,
|
|
36
|
+
* 并在合并处拿到 `SpecialTypes` 的类型约束。
|
|
37
|
+
*/
|
|
38
|
+
declare function defineSpecialTypes(types: SpecialTypes): SpecialTypes;
|
|
39
|
+
/**
|
|
40
|
+
* 合并多组类型映射(后者覆盖前者)。
|
|
41
|
+
*
|
|
42
|
+
* 用途:默认映射(如 `Component → NODE_TYPE`)+ 框架专属映射。
|
|
43
|
+
*/
|
|
44
|
+
declare function mergeSpecialTypes(...sets: Array<SpecialTypes | undefined>): SpecialTypes;
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/wrapper.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* 默认 wrapper 的路径约定。
|
|
49
|
+
*
|
|
50
|
+
* 5 个插件此前各自硬编码 `__previewjs__/Wrapper.<ext>`,差异只有扩展名。
|
|
51
|
+
* 收敛成一处后,新增框架只需给出语言扩展名。
|
|
52
|
+
*/
|
|
53
|
+
type WrapperLanguage = "tsx" | "jsx" | "vue" | "svelte" | "ts" | "js";
|
|
54
|
+
/** 默认 wrapper 路径:`__previewjs__/Wrapper.<language>`。 */
|
|
55
|
+
declare function wrapperPathFor(language: WrapperLanguage): string;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Analyzer, AnalyzerFactory, AnalyzerOptions, BasePreviewable, BasicComponent, Component, ComponentAnalysis, FileSourcePosition, PreviewableId, SpecialTypes, Story, StoryAnalysis, StoryArgs, WrapperLanguage, decodePreviewableId, defineSpecialTypes, generatePreviewableId, mergeSpecialTypes, wrapperPathFor };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function e(e){return`${e.filePath.replace(/\\/g,`/`)}:${e.name}`}function t(e){if(e.lastIndexOf(`:`)===-1)throw Error(`无效的 ID: "${e}"`);let[t,n]=e.split(`:`);return{filePath:t,name:n}}function n(e){return e}function r(...e){let t={};for(let n of e)n&&Object.assign(t,n);return t}function i(e){return`__previewjs__/Wrapper.${e}`}export{t as decodePreviewableId,n as defineSpecialTypes,e as generatePreviewableId,r as mergeSpecialTypes,i as wrapperPathFor};
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfp-studio/analyzer-api",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
5
8
|
"type": "module",
|
|
6
9
|
"main": "./dist/index.mjs",
|
|
7
10
|
"exports": {
|
|
@@ -12,28 +15,35 @@
|
|
|
12
15
|
"./factory": {
|
|
13
16
|
"import": "./dist/factory.mjs",
|
|
14
17
|
"types": "./dist/factory.d.mts"
|
|
18
|
+
},
|
|
19
|
+
"./analyzer": {
|
|
20
|
+
"import": "./dist/analyzer.mjs",
|
|
21
|
+
"types": "./dist/analyzer.d.mts"
|
|
15
22
|
}
|
|
16
23
|
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
24
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"@cfp-studio/type-analyzer": "
|
|
24
|
-
"@cfp-studio/vfs": "
|
|
25
|
-
"
|
|
26
|
-
"pino-pretty": "^13.1.1"
|
|
25
|
+
"pino": "9.11.0",
|
|
26
|
+
"pino-pretty": "13.1.1",
|
|
27
|
+
"@cfp-studio/type-analyzer": "10.1.8",
|
|
28
|
+
"@cfp-studio/vfs": "2.1.6",
|
|
29
|
+
"@cfp-studio/serializable-values": "9.0.8"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"typescript": "5.
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
+
"typescript": "5.9.3",
|
|
33
|
+
"vitest": "5.0.5"
|
|
34
|
+
},
|
|
35
|
+
"cfp": {
|
|
36
|
+
"domain": "web-preview",
|
|
37
|
+
"layer": "analysis"
|
|
32
38
|
},
|
|
33
39
|
"scripts": {
|
|
34
40
|
"prepublish": "pnpm release",
|
|
35
|
-
"build": "
|
|
36
|
-
"
|
|
37
|
-
"
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"release": "tsdown --minify",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest watch",
|
|
46
|
+
"lint": "oxlint",
|
|
47
|
+
"format": "oxfmt --write ."
|
|
38
48
|
}
|
|
39
49
|
}
|
package/dist/factory.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { a as AnalyzerOptions, A as Analyzer, b as AnalyzerFactory } from './shared/analyzer-api.40adf6f7.js';
|
|
2
|
-
import '@cfp-studio/serializable-values';
|
|
3
|
-
import '@cfp-studio/type-analyzer';
|
|
4
|
-
import '@cfp-studio/vfs';
|
|
5
|
-
import 'pino';
|
|
6
|
-
import '@cfp-studio/jsx-processor';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 给 AnalyzerFactory 工厂函数进行默认选项填充
|
|
10
|
-
* @param factory - 工厂函数名,接受包含默认选项的 AnalyzerFactoryOptions 并返回一个 Analyzer 实例
|
|
11
|
-
* @returns 一个新的 AnalyzerFactory 函数,该函数会在调用时填充默认选项
|
|
12
|
-
*/
|
|
13
|
-
declare function factoryWithDefaultOptions(factory: (options: Required<AnalyzerOptions>) => Analyzer): AnalyzerFactory;
|
|
14
|
-
|
|
15
|
-
export { factoryWithDefaultOptions };
|
package/dist/index.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export { A as Analyzer, b as AnalyzerFactory, a as AnalyzerOptions, B as BasePreviewable, f as BasicComponent, C as Component, c as ComponentAnalysis, F as FileSourcePosition, S as Story, d as StoryAnalysis, e as StoryArgs } from './shared/analyzer-api.40adf6f7.js';
|
|
2
|
-
import '@cfp-studio/serializable-values';
|
|
3
|
-
import '@cfp-studio/type-analyzer';
|
|
4
|
-
import '@cfp-studio/vfs';
|
|
5
|
-
import 'pino';
|
|
6
|
-
import '@cfp-studio/jsx-processor';
|
|
7
|
-
|
|
8
|
-
type PreviewableId = {
|
|
9
|
-
filePath: string;
|
|
10
|
-
name: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* 生成可预览 ID。
|
|
14
|
-
*
|
|
15
|
-
* @param options - 包含文件路径和名称的选项对象。
|
|
16
|
-
* @param options.filePath - 文件的路径。
|
|
17
|
-
* @param options.name - 与文件相关的名称。
|
|
18
|
-
* @returns 生成的可预览 ID,格式为 "文件路径:名称"。
|
|
19
|
-
*/
|
|
20
|
-
declare function generatePreviewableId(options: {
|
|
21
|
-
filePath: string;
|
|
22
|
-
name: string;
|
|
23
|
-
}): string;
|
|
24
|
-
/**
|
|
25
|
-
* 解码可预览 ID。
|
|
26
|
-
*
|
|
27
|
-
* @param id - 要解码的可预览 ID。
|
|
28
|
-
* @returns 包含文件路径和名称的对象。
|
|
29
|
-
* @throws 如果 ID 格式无效(不包含冒号),则抛出错误。
|
|
30
|
-
*/
|
|
31
|
-
declare function decodePreviewableId(id: string): PreviewableId;
|
|
32
|
-
|
|
33
|
-
export { type PreviewableId, decodePreviewableId, generatePreviewableId };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { SerializableValue } from '@cfp-studio/serializable-values';
|
|
2
|
-
import { TypeAnalyzer, ValueType, CollectedTypes } from '@cfp-studio/type-analyzer';
|
|
3
|
-
import { Reader } from '@cfp-studio/vfs';
|
|
4
|
-
import { Logger } from 'pino';
|
|
5
|
-
import { JSXNode } from '@cfp-studio/jsx-processor';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 定义 FileSourcePosition 类型,包含文件路径和位置信息
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* 定义 Analyzer 类型,包含类型分析器、文件爬取方法和资源释放方法
|
|
12
|
-
*/
|
|
13
|
-
type Analyzer = {
|
|
14
|
-
/**
|
|
15
|
-
* 类型分析器,去除了 dispose 方法
|
|
16
|
-
*/
|
|
17
|
-
typeAnalyzer: Omit<TypeAnalyzer, "dispose">;
|
|
18
|
-
/**
|
|
19
|
-
* 爬取指定文件路径的文件,返回组件和故事的集合
|
|
20
|
-
* @param filePaths - 要爬取的文件路径数组
|
|
21
|
-
* @returns 包含组件和故事数组的 Promise
|
|
22
|
-
*/
|
|
23
|
-
crawlFiles: (filePaths: string[]) => Promise<{
|
|
24
|
-
components: Component[];
|
|
25
|
-
stories: Story[];
|
|
26
|
-
}>;
|
|
27
|
-
/**
|
|
28
|
-
* 释放 Analyzer 占用的资源
|
|
29
|
-
*/
|
|
30
|
-
dispose: () => void;
|
|
31
|
-
};
|
|
32
|
-
type AnalyzerOptions = {
|
|
33
|
-
rootDir: string;
|
|
34
|
-
reader?: Reader;
|
|
35
|
-
logger?: Logger;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* 定义 AnalyzerFactory 类型,是一个函数,用于创建 Analyzer 实例
|
|
39
|
-
* @param options - 创建 Analyzer 所需的选项
|
|
40
|
-
* @param options.rootDir - 根目录路径
|
|
41
|
-
* @param options.reader - 可选的读取器
|
|
42
|
-
* @param options.logger - 可选的日志记录器
|
|
43
|
-
* @returns 新创建的 Analyzer 实例
|
|
44
|
-
*/
|
|
45
|
-
type AnalyzerFactory = (options: AnalyzerOptions) => Analyzer;
|
|
46
|
-
/**
|
|
47
|
-
* 定义 BasePreviewable 接口,作为可预览对象的基础接口
|
|
48
|
-
*/
|
|
49
|
-
interface BasePreviewable {
|
|
50
|
-
/**
|
|
51
|
-
* 可预览对象的唯一标识符
|
|
52
|
-
*/
|
|
53
|
-
id: string;
|
|
54
|
-
/**
|
|
55
|
-
* 可预览对象在文件中的源位置
|
|
56
|
-
*/
|
|
57
|
-
sourcePosition: FileSourcePosition;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 定义 Component 接口,继承自 BasePreviewable 接口,代表一个组件
|
|
61
|
-
*/
|
|
62
|
-
interface Component extends BasePreviewable {
|
|
63
|
-
/**
|
|
64
|
-
* 指示组件是否被导出
|
|
65
|
-
*/
|
|
66
|
-
exported: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* 分析组件,返回组件分析结果的 Promise
|
|
69
|
-
* @returns 包含组件属性和类型信息的 ComponentAnalysis 对象的 Promise
|
|
70
|
-
*/
|
|
71
|
-
analyze: (withTreeData?: boolean) => Promise<ComponentAnalysis>;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 定义 ComponentAnalysis 接口,包含组件分析的结果
|
|
75
|
-
*/
|
|
76
|
-
interface ComponentAnalysis {
|
|
77
|
-
/**
|
|
78
|
-
* 组件的属性类型
|
|
79
|
-
*/
|
|
80
|
-
props: ValueType;
|
|
81
|
-
/**
|
|
82
|
-
* 收集到的组件类型信息
|
|
83
|
-
*/
|
|
84
|
-
types: CollectedTypes;
|
|
85
|
-
jsxTree?: JSXNode;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 定义 Story 接口,继承自 BasePreviewable 接口,代表一个故事
|
|
89
|
-
*/
|
|
90
|
-
interface Story extends BasePreviewable {
|
|
91
|
-
/**
|
|
92
|
-
* 分析故事,返回故事分析结果的 Promise
|
|
93
|
-
* @returns 包含故事参数信息的 StoryAnalysis 对象的 Promise
|
|
94
|
-
*/
|
|
95
|
-
analyze: () => Promise<StoryAnalysis>;
|
|
96
|
-
/**
|
|
97
|
-
* 与故事关联的基本组件,可能为 null
|
|
98
|
-
*/
|
|
99
|
-
associatedComponent: BasicComponent | null;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 定义 StoryAnalysis 接口,包含故事分析的结果
|
|
103
|
-
*/
|
|
104
|
-
interface StoryAnalysis {
|
|
105
|
-
/**
|
|
106
|
-
* 故事的参数,可能为 null
|
|
107
|
-
*/
|
|
108
|
-
args: StoryArgs | null;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* 定义 StoryArgs 类型,包含故事参数的源位置和值
|
|
112
|
-
*/
|
|
113
|
-
type StoryArgs = {
|
|
114
|
-
/**
|
|
115
|
-
* 故事参数在文件中的源位置
|
|
116
|
-
*/
|
|
117
|
-
sourcePosition: FileSourcePosition;
|
|
118
|
-
/**
|
|
119
|
-
* 故事参数的值
|
|
120
|
-
*/
|
|
121
|
-
value: SerializableValue;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* 定义 FileSourcePosition 类型,包含文件中某个位置的起始和结束索引
|
|
125
|
-
*/
|
|
126
|
-
type FileSourcePosition = {
|
|
127
|
-
/**
|
|
128
|
-
* 起始索引
|
|
129
|
-
*/
|
|
130
|
-
start: number;
|
|
131
|
-
/**
|
|
132
|
-
* 结束索引
|
|
133
|
-
*/
|
|
134
|
-
end: number;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* 定义 BasicComponent 类型,是 Component 类型的部分属性集合
|
|
138
|
-
*/
|
|
139
|
-
type BasicComponent = Pick<Component, "id" | "analyze">;
|
|
140
|
-
|
|
141
|
-
export type { Analyzer as A, BasePreviewable as B, Component as C, FileSourcePosition as F, Story as S, AnalyzerOptions as a, AnalyzerFactory as b, ComponentAnalysis as c, StoryAnalysis as d, StoryArgs as e, BasicComponent as f };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { SerializableValue } from '@cfp-studio/serializable-values';
|
|
2
|
-
import { TypeAnalyzer, ValueType, CollectedTypes } from '@cfp-studio/type-analyzer';
|
|
3
|
-
import { Reader } from '@cfp-studio/vfs';
|
|
4
|
-
import { Logger } from 'pino';
|
|
5
|
-
import { JSXNode } from '@cfp-studio/jsx-processor';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 定义 FileSourcePosition 类型,包含文件路径和位置信息
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* 定义 Analyzer 类型,包含类型分析器、文件爬取方法和资源释放方法
|
|
12
|
-
*/
|
|
13
|
-
type Analyzer = {
|
|
14
|
-
/**
|
|
15
|
-
* 类型分析器,去除了 dispose 方法
|
|
16
|
-
*/
|
|
17
|
-
typeAnalyzer: Omit<TypeAnalyzer, "dispose">;
|
|
18
|
-
/**
|
|
19
|
-
* 爬取指定文件路径的文件,返回组件和故事的集合
|
|
20
|
-
* @param filePaths - 要爬取的文件路径数组
|
|
21
|
-
* @returns 包含组件和故事数组的 Promise
|
|
22
|
-
*/
|
|
23
|
-
crawlFiles: (filePaths: string[]) => Promise<{
|
|
24
|
-
components: Component[];
|
|
25
|
-
stories: Story[];
|
|
26
|
-
}>;
|
|
27
|
-
/**
|
|
28
|
-
* 释放 Analyzer 占用的资源
|
|
29
|
-
*/
|
|
30
|
-
dispose: () => void;
|
|
31
|
-
};
|
|
32
|
-
type AnalyzerOptions = {
|
|
33
|
-
rootDir: string;
|
|
34
|
-
reader?: Reader;
|
|
35
|
-
logger?: Logger;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* 定义 AnalyzerFactory 类型,是一个函数,用于创建 Analyzer 实例
|
|
39
|
-
* @param options - 创建 Analyzer 所需的选项
|
|
40
|
-
* @param options.rootDir - 根目录路径
|
|
41
|
-
* @param options.reader - 可选的读取器
|
|
42
|
-
* @param options.logger - 可选的日志记录器
|
|
43
|
-
* @returns 新创建的 Analyzer 实例
|
|
44
|
-
*/
|
|
45
|
-
type AnalyzerFactory = (options: AnalyzerOptions) => Analyzer;
|
|
46
|
-
/**
|
|
47
|
-
* 定义 BasePreviewable 接口,作为可预览对象的基础接口
|
|
48
|
-
*/
|
|
49
|
-
interface BasePreviewable {
|
|
50
|
-
/**
|
|
51
|
-
* 可预览对象的唯一标识符
|
|
52
|
-
*/
|
|
53
|
-
id: string;
|
|
54
|
-
/**
|
|
55
|
-
* 可预览对象在文件中的源位置
|
|
56
|
-
*/
|
|
57
|
-
sourcePosition: FileSourcePosition;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 定义 Component 接口,继承自 BasePreviewable 接口,代表一个组件
|
|
61
|
-
*/
|
|
62
|
-
interface Component extends BasePreviewable {
|
|
63
|
-
/**
|
|
64
|
-
* 指示组件是否被导出
|
|
65
|
-
*/
|
|
66
|
-
exported: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* 分析组件,返回组件分析结果的 Promise
|
|
69
|
-
* @returns 包含组件属性和类型信息的 ComponentAnalysis 对象的 Promise
|
|
70
|
-
*/
|
|
71
|
-
analyze: (withTreeData?: boolean) => Promise<ComponentAnalysis>;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 定义 ComponentAnalysis 接口,包含组件分析的结果
|
|
75
|
-
*/
|
|
76
|
-
interface ComponentAnalysis {
|
|
77
|
-
/**
|
|
78
|
-
* 组件的属性类型
|
|
79
|
-
*/
|
|
80
|
-
props: ValueType;
|
|
81
|
-
/**
|
|
82
|
-
* 收集到的组件类型信息
|
|
83
|
-
*/
|
|
84
|
-
types: CollectedTypes;
|
|
85
|
-
jsxTree?: JSXNode;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 定义 Story 接口,继承自 BasePreviewable 接口,代表一个故事
|
|
89
|
-
*/
|
|
90
|
-
interface Story extends BasePreviewable {
|
|
91
|
-
/**
|
|
92
|
-
* 分析故事,返回故事分析结果的 Promise
|
|
93
|
-
* @returns 包含故事参数信息的 StoryAnalysis 对象的 Promise
|
|
94
|
-
*/
|
|
95
|
-
analyze: () => Promise<StoryAnalysis>;
|
|
96
|
-
/**
|
|
97
|
-
* 与故事关联的基本组件,可能为 null
|
|
98
|
-
*/
|
|
99
|
-
associatedComponent: BasicComponent | null;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 定义 StoryAnalysis 接口,包含故事分析的结果
|
|
103
|
-
*/
|
|
104
|
-
interface StoryAnalysis {
|
|
105
|
-
/**
|
|
106
|
-
* 故事的参数,可能为 null
|
|
107
|
-
*/
|
|
108
|
-
args: StoryArgs | null;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* 定义 StoryArgs 类型,包含故事参数的源位置和值
|
|
112
|
-
*/
|
|
113
|
-
type StoryArgs = {
|
|
114
|
-
/**
|
|
115
|
-
* 故事参数在文件中的源位置
|
|
116
|
-
*/
|
|
117
|
-
sourcePosition: FileSourcePosition;
|
|
118
|
-
/**
|
|
119
|
-
* 故事参数的值
|
|
120
|
-
*/
|
|
121
|
-
value: SerializableValue;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* 定义 FileSourcePosition 类型,包含文件中某个位置的起始和结束索引
|
|
125
|
-
*/
|
|
126
|
-
type FileSourcePosition = {
|
|
127
|
-
/**
|
|
128
|
-
* 起始索引
|
|
129
|
-
*/
|
|
130
|
-
start: number;
|
|
131
|
-
/**
|
|
132
|
-
* 结束索引
|
|
133
|
-
*/
|
|
134
|
-
end: number;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* 定义 BasicComponent 类型,是 Component 类型的部分属性集合
|
|
138
|
-
*/
|
|
139
|
-
type BasicComponent = Pick<Component, "id" | "analyze">;
|
|
140
|
-
|
|
141
|
-
export type { Analyzer as A, BasePreviewable as B, Component as C, FileSourcePosition as F, Story as S, AnalyzerOptions as a, AnalyzerFactory as b, ComponentAnalysis as c, StoryAnalysis as d, StoryArgs as e, BasicComponent as f };
|