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,41 +38,40 @@ 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)) {
// 删除旧链接 try {
if (fs.existsSync(linkPath)) { const stat = fs.lstatSync(linkPath);
try { if (stat.isSymbolicLink() || stat.isDirectory()) {
const stat = fs.lstatSync(linkPath); fs.rmSync(linkPath, { recursive: true, force: true });
if (stat.isSymbolicLink() || stat.isDirectory()) { } else {
fs.rmSync(linkPath, { recursive: true, force: true }); fs.unlinkSync(linkPath);
} else { }
fs.unlinkSync(linkPath); } catch (e) {
// 忽略删除失败,继续创建
} }
} catch (e) {
// 忽略删除失败,继续创建
} }
}
// 创建 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) { console.warn(` [警告] junction 失败,将复制替代链接`);
// junction 失败则用目录拷贝替代 run(`xcopy /E /I /Y "${linkTarget}" "${linkPath}"`);
console.warn(` [警告] junction 失败,将复制替代链接`); }
run(`xcopy /E /I /Y "${linkTarget}" "${linkPath}"`); } else {
fs.symlinkSync(linkTarget, linkPath);
} }
} else { console.log(` 链接 @${scope}/${pkgName} -> ${localPkg}`);
fs.symlinkSync(linkTarget, linkPath);
} }
console.log(` 链接 @cssyq/ggzc-web -> ${LOCAL_PKG}`);
// 安装依赖 // 安装依赖
console.log(' 安装依赖...'); console.log(' 安装依赖...');