-
Notifications
You must be signed in to change notification settings - Fork 478
/
Copy pathbuildApiDoc.mjs
241 lines (223 loc) · 8.59 KB
/
buildApiDoc.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import fs from "fs";
import path from "path";
import { rimrafSync } from "rimraf";
import { Application, OptionDefaults } from "typedoc";
const outDir = path.join(".", "docs");
const ourTags = ["@en", "@zh", "@perfTag", "@performanceTool"];
const currentVersion = "3.2.4";
const configVersions = [
"3.2.4",
"3.3.0-beta.2",
"3.1.6",
"3.0.11",
];
const packageJson = {
"versions": {
[currentVersion]: {
"entryPoints": [path.join(".", "src", "layaAir")],
"tsconfig": path.join(".", "src", "layaAir", "tsconfig.json"),
"out": path.join(".", "docs", currentVersion)
}
}
};
async function main() {
rimrafSync(outDir);
// 直接使用导入的 Application
const app = await Application.bootstrapWithPlugins({
excludeInternal: true,
excludePrivate: true,
excludeProtected: true,
hideGenerator: true,
// theme: "default",
darkHighlightTheme: "dark-plus",
exclude: [
"**/node_modules/**",
"**/*.d.ts",
"**/ILaya.ts",
"**/ILaya3D.ts",
"**/AniLibPack.ts",
"**/AnimationContent.ts",
"**/AnimationNodeContent.ts",
"**/AnimationParser01.ts",
"**/AnimationParser02.ts",
"**/AnimationState.ts",
"**/Bone.ts",
"**/DeformAniData.ts",
"**/DeformSlotData.ts",
"**/DeformSlotDisplayData.ts",
"**/DrawOrderData.ts",
"**/IkConstraint.ts",
"**/IkConstraintData.ts",
"**/PathConstraint.ts",
"**/PathConstraintData.ts",
"**/SkinData.ts",
"**/TfConstraint.ts",
"**/TfConstraintData.ts",
"**/UVTools.ts",
"**/ModuleDef.ts",
"**/TempletLoader.ts",
"**/AnimationClipParser03.ts",
"**/AnimationClipParser04.ts",
"**/VolumetricGIManager.ts",
"**/LightQueue.ts",
"**/LightSprite.ts",
"**/ExtendTerrainMaterial.ts",
"**/PixelLineVertex.ts",
"**/BatchMark.ts",
"**/DrawMeshCMD.ts",
"**/MaterialInstanceProperty.ts",
"**/SetGlobalShaderDataCMD.ts",
"**/SetRenderTargetCMD.ts",
"**/SkinRenderElement.ts",
"**/SubMeshRenderElement.ts",
"**/Input3D.ts",
"**/Scene3DShaderDeclaration.ts",
"**/InstanceBatchManager.ts",
"**/FrustumCulling.ts",
"**/MeshInstanceGeometry.ts",
"**/Cluster.ts",
"**/SubMeshInstanceBatch.ts",
"**/AnimationClipLoader.ts",
"**/AvatarMaskLoader.ts",
"**/CubemapLoader.ts",
"**/LoadModelV04.ts",
"**/LoadModelV05.ts",
"**/MeshReader.ts",
"**/Texture2DArrayLoader.ts",
"**/Texture3DLoader.ts",
"**/IBoundsCell.ts",
"**/VertexPositionTexture0.ts",
"**/ModuleDef.ts",
"**/StaticMeshBatchManager.ts",
"**/StaticBatchMeshRenderElement.ts",
"**/Constraint3D_deprecated.ts",
"**/RaycastVehicle_deprecated.ts",
"**/RaycastWheel_deprecated.ts",
"**/HeightfieldTerrainShape_deprecated.ts",
"**/StaticPlaneColliderShape_deprecated.ts",
"**/LensFlareSettingsLoader.ts",
"**/TextureGenerator.ts",
"**/PBRDefaultDFG.ts",
"**/ShaderInit3D.ts",
"**/ShadowCasterPass.ts",
"**/WebXRCamera.ts",
"**/CacheStyle.ts",
"**/GraphicsBounds.ts",
"**/glTFExtension.ts",
"**/KHR_*.ts",
"**/glTFInterface.ts",
"**/CommandEncoder.ts",
"**/glTFShader.ts",
"**/glTFResource.ts",
"**/laya/legacy/*.ts",
"**/AnimationClip2DLoader.ts",
"**/AnimationController2DLoader.ts",
"**/AtlasLoader.ts",
"**/BitmapFontLoader.ts",
"**/GLSLLoader.ts",
"**/ShaderLoader.ts",
"**/TextResourceLoader.ts",
"**/TTFFontLoader.ts",
"**/MathUtil.ts",
"**/WebAudioLoader.ts",
"**/BaseData.ts",
"**/NavAgentLinkAnim.ts",
"**/TitleConfig.ts",
"**/AtlasInfoManager.ts",
"**/ShapeUtils.ts",
"**/ShuriKenParticle3DShaderDeclaration.ts",
"**/ShurikenParticleData.ts",
"**/VertexShuriKenParticle.ts",
"**/VertexShurikenParticleBillboard.ts",
"**/VertexShurikenParticleMesh.ts",
"**/ColliderStructInfo.ts",
"**/JointDefStructInfo.ts",
"**/RigidBody2DInfo.ts",
"**/CollisionTool.ts",
"**/pxPrismaticJoint.ts",
"**/GLESInternalTex.ts",
"**/GLESShaderInstance.ts",
"**/NativeTransform3D.ts",
"**/WebGLInternalTex.ts",
"**/GLSLCodeGenerator.ts",
"**/RenderStateCommand.ts",
"**/RenderStateContext.ts",
"**/Context.ts",
"**/LayaGLQuickRunner.ts",
"**/RenderSprite.ts",
"**/SpriteCache.ts",
"**/SpineTempletLoader.ts",
"**/VertexTrail.ts",
"**/ColorUtils.ts",
"**/IClone.ts",
"**/WordText.ts",
"**/TextRender.ts",
],
entryPointStrategy: "Expand",
blockTags: [...OptionDefaults.blockTags, ...ourTags], // 加入自定义标签
entryPoints: [path.join(".", "src", "layaAir")], // 入口文件或目录
tsconfig: path.join(".", "src", "layaAir", "tsconfig.json"),
plugin: ["@shipgirl/typedoc-plugin-versions"],
lang: "zh", // 设置中文
favicon: "./favicon.ico",
readme: "./README.zh-CN.md",
name: "LayaAir3引擎API"
});
// **解析 package.json 里的 typedocVersions**
const versions = packageJson?.versions || {};
if (!versions[currentVersion]) {
console.error(`❌ 版本 ${currentVersion} 未在 package.json 配置`);
return;
}
// **自动获取 entryPoints 和 tsconfig**
app.options.setValue("entryPoints", versions[currentVersion].entryPoints);
app.options.setValue("tsconfig", versions[currentVersion].tsconfig);
// **转换项目**
const project = await app.convert();
if (!project) {
console.error(`❌ 生成 ${currentVersion} 失败`);
return;
}
// **自动获取 `out` 目录**
const docDir = versions[currentVersion].out || path.join(".", "docs", currentVersion);
await app.generateDocs(project, docDir);
console.log(`✅ 版本 ${currentVersion} 文档已生成: ${docDir}`);
//
let sourceFile = path.join(outDir, "dev", "assets", "versionsMenu.js");
try {
fs.copyFileSync(sourceFile, path.join(docDir, "assets", "versionsMenu.js"));
console.log("✅ 拷贝versionMenu.js成功");
} catch (error) {
console.error(`❌ 拷贝versionMenu.js失败: ${error.message}`);
}
// configVersions
try {
// 读取 version.js 文件内容(同步)
const data = await fs.promises.readFile(path.join(outDir, "versions.js"), 'utf8');
// 正则表达式匹配 DOC_VERSIONS 数组
const regex = /export const DOC_VERSIONS = \[([^\]]*)\];/;
// 替换 DOC_VERSIONS 数组内容
const newVersions = JSON.stringify(configVersions, null, 2); // 格式化为漂亮的 JSON 字符串
const updatedData = data.replace(regex, `export const DOC_VERSIONS = ${newVersions};`);
// 写回修改后的内容到文件(同步)
await fs.promises.writeFile(path.join(outDir, "versions.js"), updatedData, 'utf8');
console.log('✅ 版本更新成功');
} catch (err) {
console.error('❌ 文件操作失败:', err);
}
//
try {
// 读取 HTML 文件内容
const data = await fs.promises.readFile(path.join(outDir, "index.html"), 'utf8');
// 正则表达式匹配 <meta http-equiv="refresh"> 标签中的 url= 部分
const regex = /<meta http-equiv="refresh" content="[^"]*url=([^"]*)[^"]*"/;
// 替换 url 的值
const updatedData = data.replace(regex, `<meta http-equiv="refresh" content="0; url=${configVersions[0]}"/>`);
// 写回修改后的 HTML 文件
await fs.promises.writeFile(path.join(outDir, "index.html"), updatedData, 'utf8');
console.log('✅ HTML 文件更新成功');
} catch (err) {
console.error('❌ 文件操作失败:', err);
}
}
main();