tangweijie 5099f2e87e Initial commit: Vue3 + TypeScript 前端项目
- Vue 3 + TypeScript + Element Plus 前端界面
- Pinia 状态管理
- Vue Router 4 路由管理
- Axios HTTP 客户端
- MSW (Mock Service Worker) 开发环境模拟
- 账户管理界面 (列表、详情、三科目余额展示)
- 交易管理界面 (列表、详情)
- 对账管理界面 (三账校验)
- 完善的 API 客户端封装
- Docker 容器化配置
- Nginx 配置用于生产环境
2026-01-05 17:57:11 +08:00

37 lines
1.0 KiB
JavaScript

import fs from 'node:fs'
import path from 'node:path'
import { execSync } from 'node:child_process'
// When executing the "postinstall" script, the "process.cwd" equals
// the package directory, not the parent project where the package is installed.
// NPM stores the parent project directory in the "INIT_CWD" env variable.
const parentPackageCwd = process.env.INIT_CWD
function postInstall() {
const packageJson = JSON.parse(
fs.readFileSync(path.resolve(parentPackageCwd, 'package.json'), 'utf8'),
)
if (!packageJson.msw || !packageJson.msw.workerDirectory) {
return
}
const cliExecutable = path.resolve(process.cwd(), 'cli/index.js')
try {
/**
* @note Call the "init" command directly. It will now copy the worker script
* to all saved paths in "msw.workerDirectory"
*/
execSync(`node ${cliExecutable} init`, {
cwd: parentPackageCwd,
})
} catch (error) {
console.error(
`[MSW] Failed to automatically update the worker script.\n\n${error}`,
)
}
}
postInstall()