Commit a31cebdb by 张立顺

chore: 补充二手车分包 npm 初始化脚本与文档

Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 867c1236
# 项目名 精品升级小程序 小程序搜索精品升级 # 项目名 精品升级小程序 小程序搜索精品升级
# 环境初始化(SAAS+V5.8.3 等含二手车分包的分支)
克隆或切换分支并 `git pull` 后:
```bash
npm run verify:npm-config # 检查 project.config 引用的 package.json 是否存在
npm run setup # 安装主包 + packageUsedCar 依赖
```
微信开发者工具:**工具 → 构建 npm**(主包与 `packageUsedCar` 分包均需构建)。
若报错 `packageUsedCar/package.json not found`:
```bash
git checkout HEAD -- project.config.json packageUsedCar/package.json packageUsedCar/package-lock.json
npm run setup
```
然后在开发者工具中重新「构建 npm」;仍异常可 **清缓存 → 全部清除** 后重开项目。
# 账号登录可以使用以下(验证码 开发和测试环境任意输入即可): # 账号登录可以使用以下(验证码 开发和测试环境任意输入即可):
超级管理员:13022223223(测试环境) 13476670746(开发环境) 超级管理员:13022223223(测试环境) 13476670746(开发环境)
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
"prettier-plugin-mp": "^2.5.0" "prettier-plugin-mp": "^2.5.0"
}, },
"scripts": { "scripts": {
"setup": "npm install && node scripts/setup-package-used-car.mjs",
"verify:npm-config": "node scripts/verify-npm-config.mjs",
"test": "node --test packageDynamicForm/tests/**/*.test.mjs tabIndex/tests/**/*.test.mjs packageEquity/tests/**/*.test.mjs tabWorkOrder/pages/createOrder/tests/**/*.test.mjs tests/**/*.test.mjs", "test": "node --test packageDynamicForm/tests/**/*.test.mjs tabIndex/tests/**/*.test.mjs packageEquity/tests/**/*.test.mjs tabWorkOrder/pages/createOrder/tests/**/*.test.mjs tests/**/*.test.mjs",
"test:tabIndex": "node --test tabIndex/tests/**/*.test.mjs", "test:tabIndex": "node --test tabIndex/tests/**/*.test.mjs",
"test:equity": "node --test packageEquity/tests/**/*.test.mjs", "test:equity": "node --test packageEquity/tests/**/*.test.mjs",
......
/**
* @file 在 packageUsedCar 目录安装 npm 依赖。
* 避免 Windows 下 `npm install --prefix packageUsedCar` 与 lockfile 兼容问题。
*/
import { execSync } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
const packageUsedCarDir = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'..',
'packageUsedCar'
)
execSync('npm install', { cwd: packageUsedCarDir, stdio: 'inherit' })
/**
* @file 校验 project.config.json 中 packNpmRelationList 引用的 package.json 均存在。
* 用于排查「packageUsedCar/package.json not found」等微信开发者工具构建 npm 报错。
*/
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const projectConfigPath = path.join(root, 'project.config.json')
/**
* @param {string} relativePath project.config 中的 packageJsonPath
* @returns {string} 绝对路径
*/
function resolvePackageJsonPath(relativePath) {
const normalized = relativePath.replace(/^\.\//, '')
return path.join(root, normalized)
}
function main() {
if (!fs.existsSync(projectConfigPath)) {
console.error('[verify:npm-config] 缺少 project.config.json')
console.error('请执行: git checkout HEAD -- project.config.json')
process.exit(1)
}
let config
try {
config = JSON.parse(fs.readFileSync(projectConfigPath, 'utf8'))
} catch (err) {
console.error('[verify:npm-config] project.config.json 解析失败:', err.message)
process.exit(1)
}
const relationList = config?.setting?.packNpmRelationList
if (!Array.isArray(relationList) || relationList.length === 0) {
console.log('[verify:npm-config] 未配置 packNpmRelationList,跳过检查')
process.exit(0)
}
const missing = []
const restorePaths = []
for (const item of relationList) {
const packageJsonPath = item?.packageJsonPath
if (!packageJsonPath) continue
const absolutePath = resolvePackageJsonPath(packageJsonPath)
const relativeFromRoot = path.relative(root, absolutePath).replace(/\\/g, '/')
if (!fs.existsSync(absolutePath)) {
missing.push(relativeFromRoot)
restorePaths.push(relativeFromRoot)
}
}
if (missing.length > 0) {
console.error('[verify:npm-config] 以下 package.json 不存在:')
missing.forEach(p => console.error(` - ${p}`))
console.error('')
console.error('常见原因: 未 git pull 最新代码,或本地旧 project.config 未更新。')
console.error('恢复命令:')
console.error(
` git checkout HEAD -- project.config.json ${restorePaths.join(' ')}`
)
console.error('')
console.error('然后执行: npm run setup')
console.error('并在微信开发者工具中: 工具 → 构建 npm')
process.exit(1)
}
console.log('[verify:npm-config] 通过,共检查', relationList.length, '项 npm 配置')
process.exit(0)
}
main()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!