chore: 安装依赖的脚本
This commit is contained in:
parent
e091c2539f
commit
cfeb920294
@ -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,14 +38,14 @@ 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 });
|
||||
// 删除旧链接(可能已存在)
|
||||
// 删除旧链接
|
||||
fs.mkdirSync(scopeDir, { recursive: true });
|
||||
if (fs.existsSync(linkPath)) {
|
||||
try {
|
||||
const stat = fs.lstatSync(linkPath);
|
||||
@ -55,20 +59,19 @@ for (const web of WEBS) {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 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}"`);
|
||||
}
|
||||
} else {
|
||||
fs.symlinkSync(linkTarget, linkPath);
|
||||
}
|
||||
console.log(` 链接 @cssyq/ggzc-web -> ${LOCAL_PKG}`);
|
||||
console.log(` 链接 @${scope}/${pkgName} -> ${localPkg}`);
|
||||
}
|
||||
|
||||
// 安装依赖
|
||||
console.log(' 安装依赖...');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user