You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Global-sales/wai-server/copy-to-dist.js

48 lines
1.0 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const fs = require('fs-extra');
const path = require('path');
const copyItems = [
'api',
'config',
'core',
'helper',
'middleware',
'models',
'services',
'utils',
'index.js',
'server.js'
];
// 目标目录dist
const distPath = path.resolve(__dirname, 'dist');
async function copyFiles() {
try {
// 确保dist目录存在
await fs.ensureDir(distPath);
// 清空dist目录中的所有内容
await fs.emptyDir(distPath);
console.log('🧹 ', distPath);
// 遍历并复制每一项
for (const item of copyItems) {
const srcPath = path.resolve(__dirname, item);
const destPath = path.join(distPath, path.basename(item));
if (await fs.pathExists(srcPath)) {
await fs.copy(srcPath, destPath, { overwrite: true });
console.log(`${item}${destPath}`);
} else {
console.warn(`⚠️ ${srcPath}`);
}
}
console.log('🎉 Done');
} catch (err) {
console.error('❌ ', err);
process.exit(1);
}
}
copyFiles();