chore(docs): 版本同步文档脚本

This commit is contained in:
wangxuefeng
2025-03-24 16:08:17 +08:00
parent cc7c632af6
commit c92b045c8a
7 changed files with 98 additions and 4 deletions

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// 获取当前脚本的目录
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 需要处理的应用列表
const appsToProcess = ['renderer', 'designer', 'platform'];
// 复制CHANGELOG.md文件
function copyChangelogFile(appName) {
const changelogSrcPath = path.resolve(
process.cwd(),
`../${appName}/CHANGELOG.md`,
);
const changelogDestDir = path.resolve(__dirname, `../src/${appName}`);
const changelogDestPath = path.resolve(changelogDestDir, 'CHANGELOG.md');
console.log(`正在复制${appName}的CHANGELOG.md文件...`);
// 检查源文件是否存在
if (!fs.existsSync(changelogSrcPath)) {
console.warn(
`⚠️ 警告:${appName}的CHANGELOG文件 "${changelogSrcPath}" 不存在!`,
);
return;
}
// 确保目标目录存在
if (!fs.existsSync(changelogDestDir)) {
console.log(`创建目标目录 "${changelogDestDir}"...`);
fs.mkdirSync(changelogDestDir, { recursive: true });
}
// 复制文件
try {
fs.copyFileSync(changelogSrcPath, changelogDestPath);
console.log(
`✅ 成功将${appName}的CHANGELOG.md复制到 "${changelogDestPath}"`,
);
} catch (error) {
console.error(
`❌ 复制${appName}的CHANGELOG.md时发生错误${error.message}`,
);
}
}
try {
// 复制各个应用的CHANGELOG.md文件
for (const app of appsToProcess) {
copyChangelogFile(app);
}
console.log(`✅ 所有CHANGELOG.md文件复制完成`);
} catch (error) {
console.error(`❌ 复制过程中发生错误:${error.message}`);
process.exit(1);
}