sync-shared.js脚本优化,现在先清空后拷贝。
This commit is contained in:
@@ -35,6 +35,10 @@ async function syncShared() {
|
||||
// 确保目标目录存在
|
||||
await fs.ensureDir(CLIENT_SHARED_PATH);
|
||||
|
||||
// 清空目标目录(删除旧文件)
|
||||
console.log('🗑️ 正在清空目标目录...');
|
||||
await fs.emptyDir(CLIENT_SHARED_PATH);
|
||||
|
||||
// 复制目录
|
||||
console.log('📦 正在复制文件...');
|
||||
await fs.copy(SERVER_SHARED_PATH, CLIENT_SHARED_PATH, {
|
||||
@@ -52,7 +56,7 @@ async function syncShared() {
|
||||
|
||||
console.log('✅ 同步完成!');
|
||||
console.log('');
|
||||
|
||||
|
||||
// 列出同步的文件
|
||||
const files = await getFileList(CLIENT_SHARED_PATH);
|
||||
console.log(`共同步 ${files.length} 个文件:`);
|
||||
@@ -60,10 +64,10 @@ async function syncShared() {
|
||||
const relativePath = path.relative(CLIENT_SHARED_PATH, file);
|
||||
console.log(' -', relativePath);
|
||||
});
|
||||
|
||||
|
||||
console.log('');
|
||||
console.log('==========================================');
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 同步失败:', error.message);
|
||||
process.exit(1);
|
||||
@@ -75,14 +79,14 @@ async function syncShared() {
|
||||
*/
|
||||
async function getFileList(dir) {
|
||||
const files = [];
|
||||
|
||||
|
||||
async function walk(currentPath) {
|
||||
const items = await fs.readdir(currentPath);
|
||||
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = path.join(currentPath, item);
|
||||
const stat = await fs.stat(itemPath);
|
||||
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
await walk(itemPath);
|
||||
} else {
|
||||
@@ -90,7 +94,7 @@ async function getFileList(dir) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await walk(dir);
|
||||
return files;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user