58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
// 根据不同场景生成不同配置文件
|
|
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
function copyIt(from, to) {
|
|
fs.writeFileSync(to, fs.readFileSync(from));
|
|
}
|
|
|
|
|
|
function copyDir(from, to) {
|
|
fs.readdir(from, (err, files) => {
|
|
if (err) {
|
|
return;
|
|
}
|
|
if (!fs.existsSync(to)) {
|
|
fs.mkdirSync(to);
|
|
} else {
|
|
files.forEach((item, index) => {
|
|
let itemPath = path.join(from, item);
|
|
let tempFile = fs.statSync(itemPath);
|
|
if (tempFile.isFile()) {
|
|
copyIt(itemPath, path.join(to, item))
|
|
} else {
|
|
copyDir(itemPath, path.join(to, item));
|
|
}
|
|
});
|
|
}
|
|
})
|
|
}
|
|
|
|
let argv = process.argv[2] || "vast-box";
|
|
console.log('process.argv', argv);
|
|
|
|
// env配置文件
|
|
let fromEnvPath = path.join(__dirname, 'build_config', argv, '.env');
|
|
let toEnvPath = path.join(__dirname, '.env');
|
|
// assets目录
|
|
let fromConstantPath = path.join(__dirname, 'build_config', argv, 'assets');
|
|
let toConstantPath = path.join(__dirname, 'src', 'assets');
|
|
// 小程序可配置参数文件
|
|
let fromConfigPath = path.join(__dirname, 'build_config', argv, 'config.js');
|
|
let toConfigPath = path.join(__dirname, 'src', 'config', 'config.js');
|
|
// 小程序工程配置
|
|
let fromProjectPath = path.join(__dirname, 'build_config', argv, 'project.config.json');
|
|
let toProjectPath = path.join(__dirname, 'project.config.json');
|
|
|
|
let copyArr = [[fromEnvPath, toEnvPath], [fromConstantPath, toConstantPath], [fromConfigPath, toConfigPath], [fromProjectPath, toProjectPath]];
|
|
|
|
//拷贝文件到对应目录下
|
|
copyArr.map((item, idx) => {
|
|
if (idx == 1) {
|
|
copyDir(item[0], item[1])
|
|
} else {
|
|
copyIt(item[0], item[1])
|
|
}
|
|
});
|