Files
lilishop-ui/seller/scripts/copy-manager-migrations.js
lifenlong 832fda813b 升级Vue3,iView替换ElementPlus
- 删除babel配置、更新依赖与入口初始化
- 全量替换UI组件、样式适配,新增迁移文档与标签/过滤器自动化替换脚本
2026-06-05 17:49:43 +08:00

133 lines
6.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Copy migrated manager Vue files to seller, preserving seller API imports where they differ.
*/
const fs = require("fs");
const path = require("path");
const SELLER = path.join(__dirname, "..");
const MANAGER = path.join(__dirname, "../../manager");
const FILE_MAP = [
["src/views/distribution/distributionOrder.vue", "src/views/distribution/distributionOrder.vue"],
["src/views/distribution/distributionGoods.vue", "src/views/distribution/distributionGoods.vue"],
["src/views/statistics/order.vue", "src/views/statistics/order.vue"],
["src/views/statistics/goods.vue", "src/views/statistics/goods.vue"],
["src/views/statistics/traffic.vue", "src/views/statistics/traffic.vue"],
["src/views/statistics/order/orderDetail.vue", "src/views/statistics/order/orderDetail.vue"],
["src/views/statistics/order/refundOrder.vue", "src/views/statistics/order/refundOrder.vue"],
["src/views/promotion/coupon/coupon.vue", "src/views/promotions/coupon/coupon.vue"],
["src/views/promotion/coupon/coupon-publish.vue", "src/views/promotions/coupon/coupon-publish.vue"],
["src/views/promotion/coupon/coupon-receive.vue", "src/views/promotions/coupon/coupon-receive.vue"],
["src/views/promotion/full-discount/full-discount.vue", "src/views/promotions/full-discount/full-discount.vue"],
["src/views/promotion/full-discount/full-discount-add.vue", "src/views/promotions/full-discount/full-discount-detail.vue"],
["src/views/promotion/pintuan/pintuan.vue", "src/views/promotions/pintuan/pintuan.vue"],
["src/views/promotion/pintuan/pintuan-goods.vue", "src/views/promotions/pintuan/pintuan-goods.vue"],
["src/views/promotion/pintuan/pintuan-edit.vue", "src/views/promotions/pintuan/pintuan-goods.vue"],
["src/views/promotion/seckill/seckill.vue", "src/views/promotions/seckill/seckill.vue"],
["src/views/promotion/seckill/seckill-goods.vue", "src/views/promotions/seckill/seckill-goods.vue"],
["src/views/promotion/live/live.vue", "src/views/promotions/live/live.vue"],
["src/views/promotion/live/liveGoods.vue", "src/views/promotions/live/live-detail.vue"],
["src/views/goods/goods-seller/goods.vue", "src/views/goods/goods-info/goods.vue"],
["src/views/goods/goods-manage/category.vue", "src/views/goods/goods-manage/category.vue"],
["src/views/sys/oss-manage/ossManage.vue", "src/views/sys/oss-manage/ossManage.vue"],
["src/views/order/order/orderList.vue", "src/views/order/order/orderList.vue"],
["src/views/order/order/orderDetail.vue", "src/views/order/order/orderDetail.vue"],
["src/views/order/order/virtualOrderList.vue", "src/views/order/order/fictitiousOrderList.vue"],
["src/views/order/after-order/orderComplaint.vue", "src/views/order/after-order/orderComplaint.vue"],
["src/views/order/after-order/orderComplaintDetail.vue", "src/views/order/after-order/orderComplaintDetail.vue"],
["src/views/order/after-order/returnGoodsOrder.vue", "src/views/order/after-order/afterSaleOrder.vue"],
["src/views/order/after-order/returnMoneyOrder.vue", "src/views/order/after-order/afterSale.vue"],
["src/views/order/after-order/reurnGoodsOrderDetail.vue", "src/views/order/after-order/afterSaleOrderDetail.vue"],
["src/views/shop/ossManage.vue", "src/views/sys/oss-manage/ossManage.vue"],
];
function extractImports(content) {
const imports = [];
const re = /^import\s+.+from\s+["']@\/api\/[^"']+["'];?\s*$/gm;
let m;
while ((m = re.exec(content)) !== null) imports.push(m[0]);
return imports;
}
function adaptForSeller(content, sellerRel, sellerOriginal) {
let c = content;
// Restore seller API imports from original file
if (sellerOriginal) {
const sellerImports = extractImports(sellerOriginal);
const managerImports = extractImports(content);
for (const mi of managerImports) {
const apiPath = mi.match(/from\s+["'](@\/api\/[^"']+)["']/);
if (!apiPath) continue;
const sellerMatch = sellerImports.find((si) => si.includes(apiPath[1]) || si.includes(path.basename(apiPath[1])));
if (sellerMatch && sellerMatch !== mi) {
c = c.replace(mi, sellerMatch);
}
}
// Also restore seller-specific import paths that differ
sellerImports.forEach((si) => {
const from = si.match(/from\s+["']([^"']+)["']/);
if (from && from[1].includes("@/api/")) {
const apiName = from[1].split("/").pop();
const managerImport = managerImports.find((mi) => mi.includes(apiName));
if (!managerImport) {
// seller-only import - append if missing
if (!c.includes(si)) {
const scriptIdx = c.indexOf("<script>");
if (scriptIdx >= 0) {
const insertAt = c.indexOf("\n", scriptIdx) + 1;
c = c.slice(0, insertAt) + si + "\n" + c.slice(insertAt);
}
}
}
}
});
}
// Seller path adjustments
c = c.replace(/@\/views\/page-decoration\//g, "@/views/shop/");
c = c.replace(/@\/components\/affix-time/g, "@/views/lili-components/affix-time");
c = c.replace(/admin-setting/g, "seller-setting");
c = c.replace(/adminPCPageCache/g, "sellerPCPageCache");
c = c.replace(/userInfoManager/g, "userInfoSeller");
c = c.replace(/JSON\.parse\(Cookies\.get\("userInfoManager"\)\)/g, 'JSON.parse(Cookies.get("userInfoSeller"))');
// ossManage seller variant - hide role tabs, use STORE only
if (sellerRel.includes("shop/ossManage.vue")) {
c = c.replace(/<el-tab-pane label="管理员" name="MANAGER" \/>[\s\S]*?<el-tab-pane label="客服" name="CUSTOMER" \/>/,
'<el-tab-pane label="商家" name="STORE" />');
c = c.replace(/activeRoleTab: "MANAGER"/, 'activeRoleTab: "STORE"');
}
return c;
}
const copied = [];
const missing = [];
const skipped = [];
for (const [sellerRel, managerRel] of FILE_MAP) {
const managerPath = path.join(MANAGER, managerRel);
const sellerPath = path.join(SELLER, sellerRel);
if (!fs.existsSync(managerPath)) {
missing.push({ seller: sellerRel, manager: managerRel });
continue;
}
const sellerOriginal = fs.existsSync(sellerPath) ? fs.readFileSync(sellerPath, "utf8") : null;
let content = fs.readFileSync(managerPath, "utf8");
content = adaptForSeller(content, sellerRel, sellerOriginal);
fs.mkdirSync(path.dirname(sellerPath), { recursive: true });
fs.writeFileSync(sellerPath, content);
copied.push(sellerRel);
}
console.log(`Copied ${copied.length} files from manager`);
if (missing.length) {
console.log("Missing manager files:");
missing.forEach((m) => console.log(` ${m.seller} <- ${m.manager}`));
}