diff --git a/package.json b/package.json index dfb4ef1..7dbf187 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,10 @@ "README.md" ], "scripts": { + "dev": "vite build --watch", "build": "vite build", + "link:consumers": "node scripts/link-consumers.mjs", + "unlink:consumers": "node scripts/link-consumers.mjs --unlink", "prepublishOnly": "pnpm build" }, "publishConfig": { diff --git a/scripts/link-consumers.mjs b/scripts/link-consumers.mjs new file mode 100644 index 0000000..d71e5ab --- /dev/null +++ b/scripts/link-consumers.mjs @@ -0,0 +1,69 @@ +import { lstatSync, mkdirSync, realpathSync, rmSync, symlinkSync, unlinkSync } from 'node:fs' +import path from 'node:path' +import { spawnSync } from 'node:child_process' +import { fileURLToPath } from 'node:url' + +const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') +const consumers = [ + path.resolve(packageRoot, '../cmvr-iot-ui'), + path.resolve(packageRoot, '../cmvr-iot-aima'), + path.resolve(packageRoot, '../changan-inspection') +] +const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm' +const pnpmCommand = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm' +const shouldUnlink = process.argv.includes('--unlink') + +function run(command, args, cwd) { + const executable = process.platform === 'win32' ? process.env.ComSpec : command + const commandArgs = process.platform === 'win32' + ? ['/d', '/s', '/c', [command, ...args].join(' ')] + : args + const env = { ...process.env } + delete env.npm_config_verify_deps_before_run + + const result = spawnSync(executable, commandArgs, { + cwd, + stdio: 'inherit', + env + }) + if (result.error) throw result.error + if (result.status !== 0) process.exit(result.status ?? 1) +} + +function removePackageLink(linkedPackage) { + try { + const stats = lstatSync(linkedPackage) + if (stats.isSymbolicLink()) unlinkSync(linkedPackage) + else rmSync(linkedPackage, { recursive: true, force: true }) + } catch (error) { + if (error.code !== 'ENOENT') throw error + } +} + +if (shouldUnlink) { + for (const consumer of consumers) { + const linkedPackage = path.join(consumer, 'node_modules/@cmvr/iot-common') + removePackageLink(linkedPackage) + run(pnpmCommand, ['install', '--offline', '--frozen-lockfile'], consumer) + console.log(`[restored] ${path.basename(consumer)} -> published dependency`) + } + process.exit(0) +} + +const linkOptions = [ + '--ignore-scripts', + '--package-lock=false', + '--audit=false', + '--fund=false', + '--legacy-peer-deps' +] + +run(npmCommand, ['link', ...linkOptions], packageRoot) + +for (const consumer of consumers) { + const linkedPackage = path.join(consumer, 'node_modules/@cmvr/iot-common') + removePackageLink(linkedPackage) + mkdirSync(path.dirname(linkedPackage), { recursive: true }) + symlinkSync(packageRoot, linkedPackage, process.platform === 'win32' ? 'junction' : 'dir') + console.log(`[linked] ${path.basename(consumer)} -> ${realpathSync(linkedPackage)}`) +} diff --git a/src/utils/jsencrypt.js b/src/utils/jsencrypt.js index 78d9523..91eeff6 100644 --- a/src/utils/jsencrypt.js +++ b/src/utils/jsencrypt.js @@ -1,4 +1,4 @@ -import JSEncrypt from 'jsencrypt/bin/jsencrypt.min' +import JSEncrypt from 'jsencrypt' // 密钥对生成 http://web.chacuo.net/netrsakeypair diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 6528964..671b039 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -3,7 +3,7 @@
- + @@ -457,3 +457,90 @@ onMounted(() => { }) }) + +