gf-packages-cli 1.0.3 → 1.0.5
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 +2 -1
- package/src/exportPackage.js +18 -10
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gf-packages-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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",
|
package/src/exportPackage.js
CHANGED
|
@@ -5,7 +5,7 @@ const { execSync, spawn } = require('child_process');
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const os = require('os');
|
|
8
|
-
const
|
|
8
|
+
const archiver = require('archiver');
|
|
9
9
|
const { getDeviceList, selectDevice, runAdbSync } = require('../lib/tools/adb.js');
|
|
10
10
|
const { getThirdPartyPackages, selectPackages } = require('../lib/common/appCommon.js');
|
|
11
11
|
const REMOTE_APK_SUFFIX = '.apk';
|
|
@@ -88,14 +88,22 @@ async function pullApk(deviceId, remotePath, localSavePath, onProgress) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
function buildApks(tmpDir, targetApksPath) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
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 resolve(false);
|
|
96
|
+
|
|
97
|
+
const output = fs.createWriteStream(targetApksPath);
|
|
98
|
+
const archive = new archiver.ZipArchive();
|
|
99
|
+
|
|
100
|
+
output.on('close', () => resolve(true));
|
|
101
|
+
archive.on('error', reject);
|
|
102
|
+
|
|
103
|
+
archive.pipe(output);
|
|
104
|
+
apkFiles.forEach(file => archive.file(file, { name: path.basename(file) }));
|
|
105
|
+
archive.finalize();
|
|
106
|
+
});
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
// ===================== 单个包导出 =====================
|
|
@@ -139,7 +147,7 @@ async function exportSinglePackage(deviceId, pkg, tmpBase, outputRoot) {
|
|
|
139
147
|
|
|
140
148
|
const apksFileName = `${pkg}_${version}.apks`;
|
|
141
149
|
const targetApksPath = path.join(outputRoot, apksFileName);
|
|
142
|
-
const buildSuccess = buildApks(tmpDir, targetApksPath);
|
|
150
|
+
const buildSuccess = await buildApks(tmpDir, targetApksPath);
|
|
143
151
|
|
|
144
152
|
if (buildSuccess) {
|
|
145
153
|
console.log(chalk.green(`✅ 导出完成: ${apksFileName}`));
|