|
1 | | -import { getAllPackages, post, uploadFile, doDelete } from './api'; |
2 | | -import { question, saveToLocal } from './utils'; |
3 | | - |
4 | | -import { getPlatform, getSelectedApp } from './app'; |
| 1 | +import os from 'os'; |
| 2 | +import path from 'path'; |
| 3 | +import fs from 'fs-extra'; |
5 | 4 | import Table from 'tty-table'; |
| 5 | +import { doDelete, getAllPackages, post, uploadFile } from './api'; |
| 6 | +import { getPlatform, getSelectedApp } from './app'; |
6 | 7 | import type { Platform } from './types'; |
7 | | -import { getAabInfo, getApkInfo, getAppInfo, getIpaInfo } from './utils'; |
| 8 | +import { |
| 9 | + getAabInfo, |
| 10 | + getApkInfo, |
| 11 | + getAppInfo, |
| 12 | + getIpaInfo, |
| 13 | + question, |
| 14 | + saveToLocal, |
| 15 | +} from './utils'; |
| 16 | +import { AabParser } from './utils/app-info-parser/aab'; |
8 | 17 | import { depVersions } from './utils/dep-versions'; |
9 | 18 | import { getCommitInfo } from './utils/git'; |
10 | | -import { AabParser } from './utils/app-info-parser/aab'; |
11 | 19 | import { t } from './utils/i18n'; |
12 | | -import path from 'path'; |
13 | 20 |
|
14 | 21 | export async function listPackage(appId: string) { |
15 | 22 | const allPkgs = (await getAllPackages(appId)) || []; |
@@ -144,6 +151,48 @@ export const packageCommands = { |
144 | 151 | saveToLocal(fn, `${appId}/package/${id}.apk`); |
145 | 152 | console.log(t('apkUploadSuccess', { id, version: versionName, buildTime })); |
146 | 153 | }, |
| 154 | + uploadAab: async ({ |
| 155 | + args, |
| 156 | + options, |
| 157 | + }: { |
| 158 | + args: string[]; |
| 159 | + options: Record<string, any>; |
| 160 | + }) => { |
| 161 | + const source = args[0]; |
| 162 | + if (!source || !source.endsWith('.aab')) { |
| 163 | + throw new Error(t('usageUploadAab')); |
| 164 | + } |
| 165 | + |
| 166 | + const output = path.join( |
| 167 | + os.tmpdir(), |
| 168 | + `${path.basename(source, path.extname(source))}-${Date.now()}.apk`, |
| 169 | + ); |
| 170 | + |
| 171 | + const includeAllSplits = |
| 172 | + options.includeAllSplits === true || options.includeAllSplits === 'true'; |
| 173 | + const splits = options.splits |
| 174 | + ? String(options.splits) |
| 175 | + .split(',') |
| 176 | + .map((item) => item.trim()) |
| 177 | + .filter(Boolean) |
| 178 | + : null; |
| 179 | + |
| 180 | + const parser = new AabParser(source); |
| 181 | + try { |
| 182 | + await parser.extractApk(output, { |
| 183 | + includeAllSplits, |
| 184 | + splits, |
| 185 | + }); |
| 186 | + await packageCommands.uploadApk({ |
| 187 | + args: [output], |
| 188 | + options, |
| 189 | + }); |
| 190 | + } finally { |
| 191 | + if (await fs.pathExists(output)) { |
| 192 | + await fs.remove(output); |
| 193 | + } |
| 194 | + } |
| 195 | + }, |
147 | 196 | uploadApp: async ({ |
148 | 197 | args, |
149 | 198 | options, |
|
0 commit comments