gf-packages-cli 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "gf-packages-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "bin": {
5
5
  "gf-packages-cli": "./bin/cli.js"
6
6
  },
7
7
  "dependencies": {
8
8
  "adbkit-apkreader": "^3.2.0",
9
9
  "adm-zip": "^0.5.18",
10
+ "archiver": "^8.0.0",
10
11
  "chalk": "^5.6.2",
11
12
  "commander": "^15.0.0",
12
13
  "ejs": "^6.0.1",
@@ -6,6 +6,7 @@ const fs = require('fs');
6
6
  const path = require('path');
7
7
  const os = require('os');
8
8
  const AdmZip = require('adm-zip');
9
+ const archiver = require('archiver');
9
10
  const { getDeviceList, selectDevice, runAdbSync } = require('../lib/tools/adb.js');
10
11
  const { getThirdPartyPackages, selectPackages } = require('../lib/common/appCommon.js');
11
12
  const REMOTE_APK_SUFFIX = '.apk';
@@ -88,14 +89,22 @@ async function pullApk(deviceId, remotePath, localSavePath, onProgress) {
88
89
  }
89
90
 
90
91
  function buildApks(tmpDir, targetApksPath) {
91
- const zip = new AdmZip();
92
- const apkFiles = fs.readdirSync(tmpDir)
93
- .filter(f => f.endsWith(REMOTE_APK_SUFFIX))
94
- .map(f => path.join(tmpDir, f));
95
- if (apkFiles.length === 0) return false;
96
- apkFiles.forEach(file => zip.addLocalFile(file));
97
- zip.writeZip(targetApksPath);
98
- return true;
92
+ return new Promise((resolve, reject) => {
93
+ const apkFiles = fs.readdirSync(tmpDir)
94
+ .filter(f => f.endsWith(REMOTE_APK_SUFFIX))
95
+ .map(f => path.join(tmpDir, f));
96
+ if (apkFiles.length === 0) return resolve(false);
97
+
98
+ const output = fs.createWriteStream(targetApksPath);
99
+ const archive = archiver('zip', { zlib: { level: 0 } });
100
+
101
+ output.on('close', () => resolve(true));
102
+ archive.on('error', reject);
103
+
104
+ archive.pipe(output);
105
+ apkFiles.forEach(file => archive.file(file, { name: path.basename(file) }));
106
+ archive.finalize();
107
+ });
99
108
  }
100
109
 
101
110
  // ===================== 单个包导出 =====================
@@ -139,7 +148,7 @@ async function exportSinglePackage(deviceId, pkg, tmpBase, outputRoot) {
139
148
 
140
149
  const apksFileName = `${pkg}_${version}.apks`;
141
150
  const targetApksPath = path.join(outputRoot, apksFileName);
142
- const buildSuccess = buildApks(tmpDir, targetApksPath);
151
+ const buildSuccess = await buildApks(tmpDir, targetApksPath);
143
152
 
144
153
  if (buildSuccess) {
145
154
  console.log(chalk.green(`✅ 导出完成: ${apksFileName}`));