Skip to content

Commit

Permalink
ci: build 命令新增删除 dist 下所有 README.md
Browse files Browse the repository at this point in the history
build 命令新增删除 dist 下所有 README.md
  • Loading branch information
hewx815 committed Jul 2, 2023
1 parent ff829e7 commit 11c1669
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cli/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
copyPackages,
delDir,
checkoutDir,
// eslint-disable-next-line import/extensions
deleteReadmeFiles,
// eslint-disable-next-line import/extensions
} from './utils.js';

const startBuild = async () => {
Expand All @@ -24,6 +25,7 @@ const startBuild = async () => {
destDir: getPath('../../dist/for-vue3'),
};

// 把packages文件夹拷贝至 dist
checkoutDir(vue2Package.destDir);
checkoutDir(vue3Package.destDir);

Expand All @@ -33,12 +35,16 @@ const startBuild = async () => {
copyPackages(vue2Package.srcDir, vue2Package.destDir);
copyPackages(vue3Package.srcDir, vue3Package.destDir);

// 删除dist目录下所有的 README.md
deleteReadmeFiles(getPath('../../dist'));

// 解决 vitepress vue2包 冲突问题(vitepress新版本似乎已修复,保持运行无影响)
const vue2PackagePath = path.resolve(CurrentPath, '../../for-vue2/node_modules/vue');
const newVue2PackagePath = path.resolve(CurrentPath, '../../for-vue2/node_modules/vue_old');
if (fs.existsSync(vue2PackagePath)) {
fs.renameSync(vue2PackagePath, newVue2PackagePath);
}

// 执行vitepress打包
spawnSync('yarn vitepress build', { shell: true, stdio: 'inherit' });

if (fs.existsSync(newVue2PackagePath)) {
Expand Down
15 changes: 15 additions & 0 deletions cli/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,18 @@ export const checkoutDir = (filePath) => {
};
ensureDirectoryExistence(filePath);
};

/**
* 递归删除指定目录及其子目录下的所有 README.md 文件
* @param {String} dir - 目标目录的路径
*/
export const deleteReadmeFiles = (dir) => {
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
deleteReadmeFiles(filePath); // 递归处理子目录
} else if (file === 'README.md') {
fs.unlinkSync(filePath);
}
});
};

0 comments on commit 11c1669

Please sign in to comment.