chore: 安装依赖的脚本

This commit is contained in:
liulujian 2026-04-29 20:45:36 +08:00
parent e091c2539f
commit cfeb920294

View File

@ -11,7 +11,11 @@ const fs = require('fs');
const ROOT = __dirname; const ROOT = __dirname;
const WEBS = ['txw-gxzx-web', 'txw-kxtfwzx-web', 'txw-mhzc-web', 'txw-tzzx-web', 'txw-ytzx-web', 'txw-yygl-web']; const WEBS = ['txw-gxzx-web', 'txw-kxtfwzx-web', 'txw-mhzc-web', 'txw-tzzx-web', 'txw-ytzx-web', 'txw-yygl-web'];
const LOCAL_PKG = 'local-nodemodules/@cssyq/ggzc-web'; const LOCAL_PKGS = [
'local-nodemodules/@cssyq/ggzc-web',
'local-nodemodules/@gt4/common-front',
'local-nodemodules/@gtff/tdesign-gt-vue',
];
function run(cmd, opts = {}) { function run(cmd, opts = {}) {
console.log(` > ${cmd}`); console.log(` > ${cmd}`);
@ -34,14 +38,14 @@ for (const web of WEBS) {
console.log(`\n[${web}]`); console.log(`\n[${web}]`);
// 创建 symlink for (const localPkg of LOCAL_PKGS) {
const cssyqDir = path.join(webPath, 'node_modules/@cssyq'); const pkgName = localPkg.split('/').pop();
const linkTarget = path.join(ROOT, LOCAL_PKG); const scope = localPkg.split('/')[1].slice(1); // remove '@'
const linkPath = path.join(cssyqDir, 'ggzc-web'); const scopeDir = path.join(webPath, 'node_modules', `@${scope}`);
const linkTarget = path.join(ROOT, localPkg);
const linkPath = path.join(scopeDir, pkgName);
fs.mkdirSync(cssyqDir, { recursive: true }); fs.mkdirSync(scopeDir, { recursive: true });
// 删除旧链接(可能已存在)
// 删除旧链接
if (fs.existsSync(linkPath)) { if (fs.existsSync(linkPath)) {
try { try {
const stat = fs.lstatSync(linkPath); const stat = fs.lstatSync(linkPath);
@ -55,20 +59,19 @@ for (const web of WEBS) {
} }
} }
// 创建 symlink
const isWin = process.platform === 'win32'; const isWin = process.platform === 'win32';
if (isWin) { if (isWin) {
try { try {
fs.symlinkSync(linkTarget, linkPath, 'junction'); fs.symlinkSync(linkTarget, linkPath, 'junction');
} catch (e) { } catch (e) {
// junction 失败则用目录拷贝替代
console.warn(` [警告] junction 失败,将复制替代链接`); console.warn(` [警告] junction 失败,将复制替代链接`);
run(`xcopy /E /I /Y "${linkTarget}" "${linkPath}"`); run(`xcopy /E /I /Y "${linkTarget}" "${linkPath}"`);
} }
} else { } else {
fs.symlinkSync(linkTarget, linkPath); fs.symlinkSync(linkTarget, linkPath);
} }
console.log(` 链接 @cssyq/ggzc-web -> ${LOCAL_PKG}`); console.log(` 链接 @${scope}/${pkgName} -> ${localPkg}`);
}
// 安装依赖 // 安装依赖
console.log(' 安装依赖...'); console.log(' 安装依赖...');