low-code/apps/docs/scripts/before-build.mjs
2025-03-24 16:08:17 +08:00

62 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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);
}