bitrise-api-cli 0.0.8 → 0.0.9-beta2

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.
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  app,
4
4
  buildContext
5
- } from "./chunk-WFYIERBR.js";
5
+ } from "./chunk-YAG6H26E.js";
6
6
  import "./chunk-CF25N4TY.js";
7
7
 
8
8
  // src/cli/bin/bash-complete.ts
@@ -5,7 +5,7 @@ import {
5
5
  // src/cli/commands/download/command.ts
6
6
  import { buildCommand } from "@stricli/core";
7
7
  var downloadCommand = buildCommand({
8
- loader: async () => import("./impl-PVD6QYYZ.js"),
8
+ loader: async () => import("./impl-WOGNQXCX.js"),
9
9
  parameters: {
10
10
  flags: {
11
11
  artifact: {
@@ -42,7 +42,7 @@ var downloadCommand = buildCommand({
42
42
  },
43
43
  install: {
44
44
  kind: "boolean",
45
- brief: "Install the downloaded artifact [android only]",
45
+ brief: "Install the downloaded apk/aab artifact [android only]",
46
46
  default: false
47
47
  }
48
48
  },
@@ -65,7 +65,7 @@ import { buildApplication, buildRouteMap } from "@stricli/core";
65
65
 
66
66
  // package.json
67
67
  var name = "bitrise-api-cli";
68
- var version = "0.0.8";
68
+ var version = "0.0.9-beta2";
69
69
  var description = "bitrise api CLI wrapper";
70
70
 
71
71
  // src/cli/app.ts
@@ -85,15 +85,9 @@ var app = buildApplication(root, {
85
85
  });
86
86
 
87
87
  // src/cli/context.ts
88
- import fs from "node:fs";
89
- import os from "node:os";
90
- import path from "node:path";
91
88
  function buildContext(process2) {
92
89
  return {
93
- process: process2,
94
- os,
95
- fs,
96
- path
90
+ process: process2
97
91
  };
98
92
  }
99
93
 
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  app,
4
4
  buildContext
5
- } from "./chunk-WFYIERBR.js";
5
+ } from "./chunk-YAG6H26E.js";
6
6
  import "./chunk-CF25N4TY.js";
7
7
 
8
8
  // src/cli/bin/cli.ts
@@ -56,6 +56,69 @@ var installApk = async (apkPath) => {
56
56
  throw new Error("unknown Error");
57
57
  }
58
58
  };
59
+ var installSplitApk = async (apkFolder) => {
60
+ const startTime = Date.now();
61
+ try {
62
+ const { stdout, stderr, code } = await exec(adbPath, ["install-multiple", "-r", "-d", `${apkFolder}/*`], {
63
+ shell: true
64
+ });
65
+ if (code !== 0) throw new Error(`Failed to install split apk error code: ${code}`);
66
+ return { duration: Date.now() - startTime };
67
+ } catch (e) {
68
+ if (e instanceof Error && "stderr" in e) throw new Error(`${e.stderr}`);
69
+ throw new Error("unknown Error");
70
+ }
71
+ };
72
+
73
+ // src/device/install/convertAabToApk.ts
74
+ import fs2 from "node:fs/promises";
75
+ import path2 from "node:path";
76
+
77
+ // src/helper/tempDir.ts
78
+ import fs from "node:fs/promises";
79
+ import { tmpdir } from "node:os";
80
+ import path from "node:path";
81
+ var createTempDir = async (prefix) => {
82
+ const tmpDir = path.join(tmpdir(), `${prefix}-${Date.now()}`);
83
+ await fs.mkdir(tmpDir, { recursive: true });
84
+ return tmpDir;
85
+ };
86
+
87
+ // src/device/install/convertAabToApk.ts
88
+ import { exec as exec2 } from "teen_process";
89
+ var convertAabToApk = async (aabPath, flags) => {
90
+ const startTime = Date.now();
91
+ try {
92
+ const tempDir = await createTempDir("bitrise-api-cli");
93
+ const fileName = path2.basename(aabPath, ".aab");
94
+ const outPath = path2.join(tempDir, `${fileName}.apks`);
95
+ const zipPath = path2.join(tempDir, `${fileName}.zip`);
96
+ if (flags.debug)
97
+ console.log(
98
+ "run command:",
99
+ "bundletool",
100
+ ["build-apks", "--connected-device", `--bundle=${fileName}.aab`, `--output=${outPath}`].join(" ")
101
+ );
102
+ const { code } = await exec2("bundletool", [
103
+ "build-apks",
104
+ "--connected-device",
105
+ `--bundle=${fileName}.aab`,
106
+ `--output=${outPath}`
107
+ ]);
108
+ if (flags.debug) console.log("run command:", "bundletool:", code);
109
+ if (code !== 0) throw new Error(`Failed to convert aab to apk: ${code}`);
110
+ if (flags.debug) console.log(`pre rename: ${JSON.stringify({ outPath, zipPath })}`);
111
+ await fs2.rename(outPath, zipPath);
112
+ if (flags.debug) console.log("post command:");
113
+ const { code: code2 } = await exec2("unzip", ["-o", zipPath, "-d", tempDir]);
114
+ if (flags.debug) console.log(`post unzip: ${JSON.stringify({ zipPath, tempDir })}`);
115
+ if (code2 !== 0) throw new Error(`Failed to unzip ${code2}`);
116
+ return { apkFolder: path2.join(tempDir, "./splits"), duration: Date.now() - startTime };
117
+ } catch (e) {
118
+ if (e instanceof Error && "stderr" in e) throw new Error(`${e.stderr}`);
119
+ throw new Error("unknown Error");
120
+ }
121
+ };
59
122
 
60
123
  // src/helper/formatTime.ts
61
124
  var formatTime = (timeMs) => {
@@ -63,10 +126,20 @@ var formatTime = (timeMs) => {
63
126
  return `${(timeMs / 1e3).toFixed(1)}s`;
64
127
  };
65
128
 
129
+ // src/helper/typeHelper.ts
130
+ var isFetchError = (e) => {
131
+ if (typeof e !== "object" || !e) return false;
132
+ return "response" in e && typeof e.response === "object" && !!e.response && "status" in e.response && "statusText" in e.response;
133
+ };
134
+
66
135
  // src/helper/oraHelper.ts
67
136
  var getOraTexts = (label) => ({
68
137
  text: label,
69
- failText: (error) => `${label} failed with error: ${error.message}`,
138
+ failText: (error) => {
139
+ if (isFetchError(error))
140
+ return `${label} failed with HTTP Error ${error.response.status} ${error.response.statusText}`;
141
+ return `${label} failed with error: ${error.message}`;
142
+ },
70
143
  successText: (data) => {
71
144
  if (data && typeof data === "object" && "duration" in data && typeof data.duration === "number") {
72
145
  return `${label} [took ${formatTime(data.duration)}]`;
@@ -78,9 +151,13 @@ var getOraTexts = (label) => ({
78
151
  // src/device/install/run.ts
79
152
  import { oraPromise } from "ora";
80
153
  var installApp = async ({ file, flags }) => {
81
- if (flags.artifact === "android-apk") {
82
- if (!file.endsWith(".apk")) return console.log("Artifact is not an APK file");
154
+ if (flags.artifact === "android-apk" && file.endsWith(".aab")) {
155
+ const { apkFolder } = await oraPromise(convertAabToApk(file, flags), getOraTexts("Convert AAB to Split APK"));
156
+ await oraPromise(installSplitApk(apkFolder), getOraTexts("installing Split APK"));
157
+ } else if (flags.artifact === "android-apk" && file.endsWith(".apk")) {
83
158
  await oraPromise(installApk(file), getOraTexts("installing APK"));
159
+ } else if (flags.artifact === "android-apk") {
160
+ throw Error("Artifact is not an APK or AAB file");
84
161
  } else {
85
162
  return console.log("Installing on iOS is not supported yet");
86
163
  }
@@ -761,6 +838,7 @@ function V0BuildTriggerParamsBuildParamsToJSONTyped(value, ignoreDiscriminator =
761
838
  "environments": value["environments"] == null ? void 0 : value["environments"].map(V0BuildParamsEnvironmentToJSON),
762
839
  "head_repository_url": value["headRepositoryUrl"],
763
840
  "pipeline_id": value["pipelineId"],
841
+ "priority": value["priority"],
764
842
  "pull_request_author": value["pullRequestAuthor"],
765
843
  "pull_request_head_branch": value["pullRequestHeadBranch"],
766
844
  "pull_request_id": value["pullRequestId"],
@@ -1075,6 +1153,12 @@ var BuildsApi = class extends BaseAPI {
1075
1153
  'Required parameter "before" was null or undefined when calling archivedBuildsList().'
1076
1154
  );
1077
1155
  }
1156
+ if (requestParameters["limit"] == null) {
1157
+ throw new RequiredError(
1158
+ "limit",
1159
+ 'Required parameter "limit" was null or undefined when calling archivedBuildsList().'
1160
+ );
1161
+ }
1078
1162
  const queryParameters = {};
1079
1163
  if (requestParameters["after"] != null) {
1080
1164
  queryParameters["after"] = requestParameters["after"];
@@ -1082,6 +1166,9 @@ var BuildsApi = class extends BaseAPI {
1082
1166
  if (requestParameters["before"] != null) {
1083
1167
  queryParameters["before"] = requestParameters["before"];
1084
1168
  }
1169
+ if (requestParameters["limit"] != null) {
1170
+ queryParameters["limit"] = requestParameters["limit"];
1171
+ }
1085
1172
  const headerParameters = {};
1086
1173
  if (this.configuration && this.configuration.apiKey) {
1087
1174
  headerParameters["Bitrise-Addon-Auth-Token"] = await this.configuration.apiKey("Bitrise-Addon-Auth-Token");
@@ -1576,9 +1663,10 @@ var downloadLatestArtifacts = async (options) => {
1576
1663
  fetchArtifact({ artifactSlug: artifactMetadata.slug, buildSlug: latestBuild.slug }),
1577
1664
  getOraTexts("fetching artifact metadata")
1578
1665
  );
1666
+ const fileType = artifact.title?.split(".").pop() ?? "unknown";
1579
1667
  const { file } = await oraPromise2(downloadFile(artifact.expiringDownloadUrl, artifactMetadata.title), {
1580
- ...getOraTexts("downloading apk file"),
1581
- text: `downloading apk file [${formatBytes(artifact.fileSizeBytes ?? 0)}]`
1668
+ ...getOraTexts(`downloading ${fileType} file`),
1669
+ text: `downloading ${fileType} file [${formatBytes(artifact.fileSizeBytes ?? 0)}]`
1582
1670
  });
1583
1671
  return file;
1584
1672
  };
@@ -1588,8 +1676,7 @@ async function impl_default(flags) {
1588
1676
  if (!setupEnv(flags)) return process.exit(1);
1589
1677
  const file = await downloadLatestArtifacts(flags);
1590
1678
  if (flags.install) {
1591
- await installApp({ file, flags }).catch(() => {
1592
- });
1679
+ await installApp({ file, flags });
1593
1680
  }
1594
1681
  }
1595
1682
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitrise-api-cli",
3
- "version": "0.0.8",
3
+ "version": "0.0.9-beta2",
4
4
  "description": "bitrise api CLI wrapper",
5
5
  "module": "index",
6
6
  "type": "module",
@@ -23,17 +23,16 @@
23
23
  "prepublishOnly": "bun i && bun run lint:CI && tsc && bun run build"
24
24
  },
25
25
  "dependencies": {
26
- "@stricli/auto-complete": "1.1.1",
27
26
  "@stricli/core": "1.1.1",
28
27
  "ora": "8.2.0",
29
- "teen_process": "2.2.3"
28
+ "teen_process": "2.3.1"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@biomejs/biome": "1.9.4",
33
- "@openapitools/openapi-generator-cli": "2.16.3",
32
+ "@openapitools/openapi-generator-cli": "2.18.4",
34
33
  "@types/bun": "latest",
35
34
  "@types/teen_process": "^2.0.4",
36
35
  "tsup": "8.4.0",
37
- "typescript": "5.7.3"
36
+ "typescript": "5.8.2"
38
37
  }
39
38
  }