56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
|
const fs = require("fs");
|
||
|
const path = require("path");
|
||
|
|
||
|
const config = [
|
||
|
{
|
||
|
name: "app1",
|
||
|
title: "建安施工管理平台",
|
||
|
dirPath: "app1",
|
||
|
},
|
||
|
{
|
||
|
name: "app2",
|
||
|
title: "数字项管+",
|
||
|
dirPath: "app2",
|
||
|
},
|
||
|
];
|
||
|
|
||
|
config.forEach((item) => {
|
||
|
// 在 dist 目录下创建 app 目录
|
||
|
const appDirPath = path.join(__dirname, "dist", item.dirPath);
|
||
|
fs.mkdir(appDirPath, { recursive: true }, (err) => {
|
||
|
if (err) {
|
||
|
console.error("创建目录时出错:", err);
|
||
|
return;
|
||
|
}
|
||
|
console.log("目录创建成功或已存在");
|
||
|
});
|
||
|
const xdAppPath = path.join(__dirname, "dist", "xd");
|
||
|
// 源文件路径
|
||
|
const sourceFilePath = path.join(xdAppPath, "index.html");
|
||
|
// 目标文件路径
|
||
|
const targetFilePath = path.join(appDirPath, "index.html");
|
||
|
|
||
|
// 读取源文件内容
|
||
|
fs.readFile(sourceFilePath, "utf8", (err, data) => {
|
||
|
if (err) {
|
||
|
console.error("读取文件时出错:", err);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// 替换文本
|
||
|
const newData = data
|
||
|
.replace(/数字建安施工/g, item.title)
|
||
|
.replaceAll(`src="./`, `src = "/xd/`)
|
||
|
.replaceAll(`href="./`, `href = "/xd/`);
|
||
|
|
||
|
// 将替换后的内容写入目标文件
|
||
|
fs.writeFile(targetFilePath, newData, "utf8", (err) => {
|
||
|
if (err) {
|
||
|
console.error("写入文件时出错:", err);
|
||
|
return;
|
||
|
}
|
||
|
console.log("文件复制并替换成功");
|
||
|
});
|
||
|
});
|
||
|
});
|