Skip to content

Commit 6e6896d

Browse files
authored
feat(aigc-site): support changelog (#4230)
1 parent dacf608 commit 6e6896d

9 files changed

Lines changed: 532 additions & 462 deletions

File tree

packages/tdesign-react-aigc/CHANGELOG.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ spline: explain
1818
- **ChatMarkdown**: The issue of increased packaging size caused by dependency on CherryMarkdown has been significantly resolved. Highlighting for code blocks is no longer built-in; businesses need to introduce this functionality manually via configuration @LzhengH @carolin913 ([#4119](https://github.com/Tencent/tdesign-react/pull/4119)).
1919
- **ChatSender**: The `readyToSend` property now allows for pre-sending validation to be handled @LzhengH ([#4119](https://github.com/Tencent/tdesign-react/pull/4119).
2020

21-
## 🌈 1.0.0 `2026-11-20`
21+
## 🌈 1.0.0 `2025-11-20`
2222

2323
- Release 1st version

packages/tdesign-react-aigc/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ spline: explain
1818
- `ChatMarkdown`: 大幅优化依赖CherryMarkdown造成的打包体积膨胀问题,**不再内置highlight代码块样式高亮**,需要业务自行引入配置 @LzhengH @carolin913 ([#4119](https://github.com/Tencent/tdesign-react/pull/4119))
1919
- `ChatSender`: 支持readyToSend可以接管发送前校验 @LzhengH ([#4119](https://github.com/Tencent/tdesign-react/pull/4119))
2020

21-
## 🌈 1.0.0 `2026-11-20`
21+
## 🌈 1.0.0 `2025-11-20`
2222

2323
- Release 1st version

packages/tdesign-react-aigc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"zod": "^3.24.2"
6363
},
6464
"devDependencies": {
65+
"@tdesign/common-docs": "workspace:^",
6566
"cors": "^2.8.5",
6667
"express": "^4.17.3",
6768
"tdesign-icons-react": "0.6.4",

packages/tdesign-react-aigc/site/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "@tdesign/react-aigc-site",
33
"private": true,
4+
"type": "module",
45
"scripts": {
56
"start": "pnpm run dev",
6-
"dev": "vite",
7-
"build": "vite build",
8-
"intranet": "vite build --mode intranet",
9-
"preview": "vite build --mode preview && cp dist/index.html dist/404.html"
7+
"dev": "vite --configLoader runner",
8+
"build": "vite build --configLoader runner",
9+
"intranet": "vite build --mode intranet --configLoader runner",
10+
"preview": "vite build --mode preview --configLoader runner && cp dist/index.html dist/404.html"
1011
},
1112
"author": "tdesign",
1213
"license": "MIT",
@@ -27,13 +28,13 @@
2728
"@types/react": "^18.2.0",
2829
"@types/react-dom": "^18.2.0",
2930
"@types/rimraf": "^4.0.5",
30-
"@vitejs/plugin-react": "^4.3.1",
31+
"@vitejs/plugin-react": "^5.1.1",
3132
"camelcase": "^6.2.1",
3233
"gray-matter": "^4.0.3",
3334
"markdown-it-fence": "^0.1.3",
3435
"semver": "^7.6.3",
3536
"typescript": "5.6.2",
36-
"vite": "^5.4.7",
37+
"vite": "^6.2.0",
3738
"vite-plugin-istanbul": "^6.0.2",
3839
"vite-plugin-tdoc": "^2.0.4",
3940
"vitest": "^2.1.1",

packages/tdesign-react-aigc/site/plugin-tdoc/md-to-react.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
/* eslint-disable */
2+
import camelCase from 'camelcase';
23
import fs from 'fs';
3-
import path from 'path';
44
import matter from 'gray-matter';
5-
import camelCase from 'camelcase';
5+
import path, { dirname } from 'path';
6+
import { fileURLToPath } from 'url';
7+
import pluginTransformTypescript from '@babel/plugin-transform-typescript';
8+
import presetReact from '@babel/preset-react';
69

710
import { compileUsage, getGitTimestamp } from '../../../../packages/common/docs/compile';
811

912
import testCoverage from '../test-coverage';
1013

1114
import { transformSync } from '@babel/core';
1215

16+
// eslint-disable-next-line no-underscore-dangle
17+
const __dirname = dirname(fileURLToPath(import.meta.url));
18+
1319
export default async function mdToReact(options) {
1420
const mdSegment = await customRender(options);
1521
const { demoDefsStr, demoCodesDefsStr } = options;
@@ -95,7 +101,6 @@ export default async function mdToReact(options) {
95101
ref={tdDocHeader}
96102
spline="${mdSegment.spline}"
97103
platform="web"
98-
changelog="false"
99104
>
100105
</td-doc-header>`
101106
: ''
@@ -137,8 +142,8 @@ export default async function mdToReact(options) {
137142
generatorOpts: {
138143
decoratorsBeforeExport: true,
139144
},
140-
presets: [require('@babel/preset-react')],
141-
plugins: [[require('@babel/plugin-transform-typescript'), { isTSX: true }]],
145+
presets: [presetReact],
146+
plugins: [[pluginTransformTypescript, { isTSX: true }]],
142147
});
143148

144149
return { code: result.code, map: result.map };

packages/tdesign-react-aigc/site/plugin-tdoc/transforms.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
/* eslint-disable indent */
22
/* eslint-disable no-param-reassign */
3-
import path from 'path';
43
import fs from 'fs';
4+
import path, { dirname } from 'path';
5+
import { fileURLToPath } from 'url';
56

67
import mdToReact from './md-to-react';
78

9+
// eslint-disable-next-line no-underscore-dangle
10+
const __dirname = dirname(fileURLToPath(import.meta.url));
11+
812
let demoImports = {};
913
let demoCodesImports = {};
1014

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { promises as fs } from 'fs';
2+
import path, { dirname } from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
import generateChangelogJson from '@tdesign/common-docs/plugins/changelog-to-json';
6+
7+
// eslint-disable-next-line no-underscore-dangle
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
const distDir = path.resolve(__dirname, '../../dist');
10+
const rootDir = path.resolve(__dirname, '../../../');
11+
12+
const changelogConfigs = [
13+
{
14+
input: 'CHANGELOG.md',
15+
output: 'changelog.json',
16+
},
17+
{
18+
input: 'CHANGELOG.en-US.md',
19+
output: 'changelog.en-US.json',
20+
},
21+
];
22+
23+
async function generate(input) {
24+
return generateChangelogJson(path.resolve(rootDir, input), 'chat');
25+
}
26+
27+
export default function changelog2Json() {
28+
return {
29+
name: 'changelog-to-json',
30+
configureServer(server) {
31+
// 开发模式时拦截请求
32+
changelogConfigs.forEach(({ input, output }) => {
33+
server.middlewares.use(`/${output}`, async (_, res) => {
34+
const json = await generate(input);
35+
res.setHeader('Content-Type', 'application/json');
36+
res.end(JSON.stringify(json));
37+
});
38+
});
39+
},
40+
41+
async closeBundle(error) {
42+
// 构建失败时跳过
43+
if (error) return;
44+
// 生产构建时写入物理文件
45+
if (process.env.NODE_ENV !== 'production') return;
46+
await Promise.all(
47+
changelogConfigs.map(async ({ input, output }) => {
48+
const json = await generate(input);
49+
await fs.writeFile(path.resolve(distDir, output), JSON.stringify(json));
50+
}),
51+
);
52+
},
53+
};
54+
}

0 commit comments

Comments
 (0)