refactor: 统一 npm scripts 命名并新增一键打包命令
- 按前缀归类: dev:*(h5/adb/electron)、build:*(h5/app/exe/apk)、android:*(prepare/pack) - 改名: dev:h5:electron→dev:h5、debug:electron→dev:electron、build:h5:electron→build:h5、build:app-plus→build:app - 新增快捷入口: dev→dev:h5、build→build:h5、build:apk(编译+打包+发布一键) - build:apk 不重复调 prepare.cjs(pack.ps1 内部已注入) - 同步更新所有内部引用(dev-electron/build-exe/dev-adb/pack.ps1 提示)与文档
This commit is contained in:
parent
f393523bf0
commit
3a99587cc5
@ -6,7 +6,7 @@
|
||||
|
||||
1. 自动列出所有 ADB 设备(多台时交互选择,单台自动选中)
|
||||
2. 进程常驻,监听 `src/` 与原生工程源码(`simpleDemo/src/main/java`、`AndroidManifest.xml`)
|
||||
3. 保存文件后自动:`build:app-plus` → 离线打包(gradle 增量) → `adb install -r` → 启动应用(约 20 秒/轮)
|
||||
3. 保存文件后自动:`build:app` → 离线打包(gradle 增量) → `adb install -r` → 启动应用(约 20 秒/轮)
|
||||
4. **真机 console 实时打印到终端**(含视图层 renderjs)
|
||||
|
||||
可选参数:
|
||||
|
||||
@ -47,7 +47,7 @@ android-offline/
|
||||
|
||||
## 3. 离线打包流程(命令打包,无需 Android Studio)
|
||||
|
||||
1. 生成 App 资源:`npm run build:app-plus`(或 HBuilderX「发行 → 原生App-本地打包」,产物路径写到 `pack-config.json` 的 `wwwSource`)
|
||||
1. 生成 App 资源:`npm run build:app`(或 HBuilderX「发行 → 原生App-本地打包」,产物路径写到 `pack-config.json` 的 `wwwSource`)
|
||||
2. 一条命令注入配置并打包 APK:
|
||||
```
|
||||
npm run android:pack
|
||||
|
||||
@ -82,7 +82,7 @@ const candidates = [
|
||||
const wwwSource = candidates.find((dir) => fs.existsSync(dir))
|
||||
if (!wwwSource) {
|
||||
failed = true
|
||||
console.error('[prepare][错误] 未找到 App 资源,请先执行 npm run build:app-plus(或 HBuilderX 生成本地打包资源)')
|
||||
console.error('[prepare][错误] 未找到 App 资源,请先执行 npm run build:app(或 HBuilderX 生成本地打包资源)')
|
||||
} else {
|
||||
fs.rmSync(wwwTarget, { recursive: true, force: true })
|
||||
fs.cpSync(wwwSource, wwwTarget, { recursive: true })
|
||||
|
||||
@ -42,4 +42,4 @@
|
||||
2. `cp config/deploy.example.json config/deploy.json` 并填写(仅发布 APK 时需要)
|
||||
3. `cp .env.example .env.local` 并填写接口地址
|
||||
3. `npm install`
|
||||
4. 打包:`npm run build:exe`(Windows,发布到 worker_station_windows)、`npm run android:pack`(Android,发布到 worker_station)
|
||||
4. 打包:`npm run build:apk`(Android 一键打包+发布,或拆分为 `npm run build:app` + `npm run android:pack`)、`npm run build:exe`(Windows,发布到 worker_station_windows)
|
||||
|
||||
17
package.json
17
package.json
@ -5,15 +5,18 @@
|
||||
"author": "tianbao",
|
||||
"main": "electron/main.js",
|
||||
"scripts": {
|
||||
"dev:h5:electron": "uni --mode electron",
|
||||
"debug:electron": "node scripts/dev-electron.js",
|
||||
"start:electron": "electron electron/main.js",
|
||||
"build:h5:electron": "uni build --mode electron",
|
||||
"build:app-plus": "uni build -p app",
|
||||
"dev": "npm run dev:h5",
|
||||
"dev:h5": "uni --mode electron",
|
||||
"dev:adb": "node scripts/dev-adb.cjs",
|
||||
"dev:electron": "node scripts/dev-electron.js",
|
||||
"build": "npm run build:h5",
|
||||
"build:h5": "uni build --mode electron",
|
||||
"build:app": "uni build -p app",
|
||||
"build:exe": "node scripts/build-exe.cjs",
|
||||
"build:apk": "npm run build:app && npm run android:pack",
|
||||
"android:prepare": "node android-offline/prepare.cjs",
|
||||
"android:pack": "powershell -NoProfile -ExecutionPolicy Bypass -File android-offline/pack.ps1",
|
||||
"dev:adb": "node scripts/dev-adb.cjs",
|
||||
"build:exe": "node scripts/build-exe.cjs"
|
||||
"start:electron": "electron electron/main.js"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
|
||||
@ -27,7 +27,7 @@ function run(cmd, args) {
|
||||
}
|
||||
|
||||
console.log('[1/2] 编译前端资源 -> dist/build/h5')
|
||||
run(npmCmd, ['run', 'build:h5:electron'])
|
||||
run(npmCmd, ['run', 'build:h5'])
|
||||
|
||||
console.log('\n[2/2] electron-builder 打包 exe -> release/windows/')
|
||||
run(npxCmd, ['electron-builder', '--config', 'electron-builder.config.cjs'])
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* ADB 真机调试(类热更新):
|
||||
* 1. 列出所有已连接设备,可选择目标设备(多台时交互选择,单台自动选中)
|
||||
* 2. 进程常驻,监听源码变更
|
||||
* 3. 变更后自动:build:app-plus → 离线打包(gradle 增量) → adb install -r → 启动应用
|
||||
* 3. 变更后自动:build:app → 离线打包(gradle 增量) → adb install -r → 启动应用
|
||||
*
|
||||
* 用法:
|
||||
* npm run dev:adb # 自动选唯一设备
|
||||
@ -209,8 +209,8 @@ async function buildAndInstall(serial, trigger) {
|
||||
const t0 = Date.now()
|
||||
log(`开始构建(触发: ${trigger})`)
|
||||
// 1. uni-app 编译 App 资源
|
||||
if (!run('npm', ['run', 'build:app-plus'])) {
|
||||
log('✗ build:app-plus 失败,跳过安装')
|
||||
if (!run('npm', ['run', 'build:app'])) {
|
||||
log('✗ build:app 失败,跳过安装')
|
||||
return false
|
||||
}
|
||||
// 2. 离线打包(prepare + gradle 增量 + 复制 APK),跳过发布上传
|
||||
|
||||
@ -36,7 +36,7 @@ const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'
|
||||
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx'
|
||||
const useShell = process.platform === 'win32'
|
||||
|
||||
const devProcess = spawn(npmCmd, ['run', 'dev:h5:electron', '--', '--port', rendererPort, '--strictPort'], {
|
||||
const devProcess = spawn(npmCmd, ['run', 'dev:h5', '--', '--port', rendererPort, '--strictPort'], {
|
||||
stdio: 'inherit',
|
||||
shell: useShell,
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user