From cfeb920294277c1ba52d16d3650a757ea516926a Mon Sep 17 00:00:00 2001 From: liulujian Date: Wed, 29 Apr 2026 20:45:36 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=AE=89=E8=A3=85=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E7=9A=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/setup.js | 63 ++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/script/setup.js b/script/setup.js index 3c15e8b..281f11d 100644 --- a/script/setup.js +++ b/script/setup.js @@ -11,7 +11,11 @@ const fs = require('fs'); const ROOT = __dirname; 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 = {}) { console.log(` > ${cmd}`); @@ -34,41 +38,40 @@ for (const web of WEBS) { console.log(`\n[${web}]`); - // 创建 symlink - const cssyqDir = path.join(webPath, 'node_modules/@cssyq'); - const linkTarget = path.join(ROOT, LOCAL_PKG); - const linkPath = path.join(cssyqDir, 'ggzc-web'); + for (const localPkg of LOCAL_PKGS) { + const pkgName = localPkg.split('/').pop(); + const scope = localPkg.split('/')[1].slice(1); // remove '@' + 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 }); - // 删除旧链接(可能已存在) - // 删除旧链接 - if (fs.existsSync(linkPath)) { - try { - const stat = fs.lstatSync(linkPath); - if (stat.isSymbolicLink() || stat.isDirectory()) { - fs.rmSync(linkPath, { recursive: true, force: true }); - } else { - fs.unlinkSync(linkPath); + fs.mkdirSync(scopeDir, { recursive: true }); + if (fs.existsSync(linkPath)) { + try { + const stat = fs.lstatSync(linkPath); + if (stat.isSymbolicLink() || stat.isDirectory()) { + fs.rmSync(linkPath, { recursive: true, force: true }); + } else { + fs.unlinkSync(linkPath); + } + } catch (e) { + // 忽略删除失败,继续创建 } - } catch (e) { - // 忽略删除失败,继续创建 } - } - // 创建 symlink - const isWin = process.platform === 'win32'; - if (isWin) { - try { - fs.symlinkSync(linkTarget, linkPath, 'junction'); - } catch (e) { - // junction 失败则用目录拷贝替代 - console.warn(` [警告] junction 失败,将复制替代链接`); - run(`xcopy /E /I /Y "${linkTarget}" "${linkPath}"`); + const isWin = process.platform === 'win32'; + if (isWin) { + try { + fs.symlinkSync(linkTarget, linkPath, 'junction'); + } catch (e) { + console.warn(` [警告] junction 失败,将复制替代链接`); + run(`xcopy /E /I /Y "${linkTarget}" "${linkPath}"`); + } + } else { + fs.symlinkSync(linkTarget, linkPath); } - } else { - fs.symlinkSync(linkTarget, linkPath); + console.log(` 链接 @${scope}/${pkgName} -> ${localPkg}`); } - console.log(` 链接 @cssyq/ggzc-web -> ${LOCAL_PKG}`); // 安装依赖 console.log(' 安装依赖...');