bitrise-api-cli 0.0.7 → 0.0.8
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/dist/bash-complete.js
CHANGED
|
@@ -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-
|
|
8
|
+
loader: async () => import("./impl-PVD6QYYZ.js"),
|
|
9
9
|
parameters: {
|
|
10
10
|
flags: {
|
|
11
11
|
artifact: {
|
|
@@ -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.
|
|
68
|
+
var version = "0.0.8";
|
|
69
69
|
var description = "bitrise api CLI wrapper";
|
|
70
70
|
|
|
71
71
|
// src/cli/app.ts
|
package/dist/cli.js
CHANGED
|
@@ -2,31 +2,6 @@ import {
|
|
|
2
2
|
validArtifactTypes
|
|
3
3
|
} from "./chunk-CF25N4TY.js";
|
|
4
4
|
|
|
5
|
-
// src/device/install/android.ts
|
|
6
|
-
import { exec } from "teen_process";
|
|
7
|
-
var adbPath = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
|
8
|
-
var installApk = async (apkPath) => {
|
|
9
|
-
const { stdout, stderr, code } = await exec(adbPath, ["install", "-r", "-d", apkPath]);
|
|
10
|
-
if (code !== 0) {
|
|
11
|
-
console.log(stderr);
|
|
12
|
-
throw new Error(`Failed to install apk: ${stderr}`);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/device/install/run.ts
|
|
17
|
-
import { oraPromise } from "ora";
|
|
18
|
-
var installApp = async ({ file, flags }) => {
|
|
19
|
-
if (flags.artifact === "android-apk") {
|
|
20
|
-
if (!file.endsWith(".apk")) return console.log("Artifact is not an APK file");
|
|
21
|
-
await oraPromise(installApk(file), {
|
|
22
|
-
text: "installing APK",
|
|
23
|
-
failText: (error) => `installing APK failed with error: ${error}`
|
|
24
|
-
});
|
|
25
|
-
} else {
|
|
26
|
-
return console.log("Installing on iOS is not supported yet");
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
5
|
// src/bitrise/env.ts
|
|
31
6
|
var ENV = {
|
|
32
7
|
debug: false,
|
|
@@ -61,6 +36,55 @@ var isEnvValid = () => {
|
|
|
61
36
|
}
|
|
62
37
|
return true;
|
|
63
38
|
};
|
|
39
|
+
var setupEnv = (flags) => {
|
|
40
|
+
if (flags.debug) console.log(JSON.stringify(flags, null, 2));
|
|
41
|
+
saveOptions(flags);
|
|
42
|
+
return isEnvValid();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/device/install/android.ts
|
|
46
|
+
import { exec } from "teen_process";
|
|
47
|
+
var adbPath = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
|
48
|
+
var installApk = async (apkPath) => {
|
|
49
|
+
const startTime = Date.now();
|
|
50
|
+
try {
|
|
51
|
+
const { stdout, stderr, code } = await exec(adbPath, ["install", "-r", "-d", apkPath]);
|
|
52
|
+
if (code !== 0) throw new Error(`Failed to install apk error code: ${code}`);
|
|
53
|
+
return { duration: Date.now() - startTime };
|
|
54
|
+
} catch (e) {
|
|
55
|
+
if (e instanceof Error && "stderr" in e) throw new Error(`${e.stderr}`);
|
|
56
|
+
throw new Error("unknown Error");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/helper/formatTime.ts
|
|
61
|
+
var formatTime = (timeMs) => {
|
|
62
|
+
if (timeMs < 1e3) return `${timeMs}ms`;
|
|
63
|
+
return `${(timeMs / 1e3).toFixed(1)}s`;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/helper/oraHelper.ts
|
|
67
|
+
var getOraTexts = (label) => ({
|
|
68
|
+
text: label,
|
|
69
|
+
failText: (error) => `${label} failed with error: ${error.message}`,
|
|
70
|
+
successText: (data) => {
|
|
71
|
+
if (data && typeof data === "object" && "duration" in data && typeof data.duration === "number") {
|
|
72
|
+
return `${label} [took ${formatTime(data.duration)}]`;
|
|
73
|
+
}
|
|
74
|
+
return label;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// src/device/install/run.ts
|
|
79
|
+
import { oraPromise } from "ora";
|
|
80
|
+
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");
|
|
83
|
+
await oraPromise(installApk(file), getOraTexts("installing APK"));
|
|
84
|
+
} else {
|
|
85
|
+
return console.log("Installing on iOS is not supported yet");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
64
88
|
|
|
65
89
|
// src/generated_api/runtime.ts
|
|
66
90
|
var BASE_PATH = "https://api.bitrise.io/v0.1".replace(/\/+$/, "");
|
|
@@ -1461,12 +1485,20 @@ var api = {
|
|
|
1461
1485
|
// src/helper/debugLog.ts
|
|
1462
1486
|
var debugLog = (label, data) => console.log(`${label}: ${JSON.stringify(data, void 0, 2)}`);
|
|
1463
1487
|
|
|
1488
|
+
// src/helper/ensureMandatoryFields.ts
|
|
1489
|
+
var ensureMandatoryFields = (input, mandatory) => {
|
|
1490
|
+
for (const field of mandatory) {
|
|
1491
|
+
if (!input[field]) throw new Error(`Missing mandatory field: ${String(field)}`);
|
|
1492
|
+
}
|
|
1493
|
+
return input;
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1464
1496
|
// src/bitrise/fetchArtifact.ts
|
|
1465
1497
|
var fetchArtifact = async ({ artifactSlug, buildSlug }) => {
|
|
1466
1498
|
const { data } = await api.buildArtifact().artifactShow({ appSlug: ENV.appSlug, artifactSlug, buildSlug });
|
|
1467
1499
|
if (!data) throw new Error("buildArtifact().artifactShow returned no data");
|
|
1468
1500
|
if (ENV.debug) debugLog("artifact", data);
|
|
1469
|
-
return data;
|
|
1501
|
+
return ensureMandatoryFields(data, ["expiringDownloadUrl"]);
|
|
1470
1502
|
};
|
|
1471
1503
|
|
|
1472
1504
|
// src/bitrise/fetchArtifactList.ts
|
|
@@ -1478,10 +1510,9 @@ var fetchArtifactList = async (buildSlug) => {
|
|
|
1478
1510
|
var fetchArtifactByType = async (buildSlug) => {
|
|
1479
1511
|
const artifactInfo = await fetchArtifactList(buildSlug);
|
|
1480
1512
|
const artifactMetadata = artifactInfo.find((artifact) => artifact.artifactType === ENV.artifactType);
|
|
1481
|
-
if (!artifactMetadata || !artifactMetadata.slug)
|
|
1482
|
-
throw new Error(`Found no ${ENV.artifactType} in build Slug: ${buildSlug}`);
|
|
1483
1513
|
if (ENV.debug) debugLog("artifactMetadata", artifactMetadata);
|
|
1484
|
-
|
|
1514
|
+
if (!artifactMetadata) throw new Error(`Found no ${ENV.artifactType} in build Slug: ${buildSlug}`);
|
|
1515
|
+
return ensureMandatoryFields(artifactMetadata, ["slug", "title"]);
|
|
1485
1516
|
};
|
|
1486
1517
|
|
|
1487
1518
|
// src/bitrise/fetchBuilds.ts
|
|
@@ -1495,7 +1526,7 @@ var getLatestBuild = async () => {
|
|
|
1495
1526
|
const latestBuild = builds.find((build) => build.triggeredWorkflow === ENV.workflow);
|
|
1496
1527
|
if (!latestBuild) throw `Found no build with the workflow: "${ENV.workflow}"`;
|
|
1497
1528
|
if (ENV.debug) debugLog("latestBuild", latestBuild);
|
|
1498
|
-
return latestBuild;
|
|
1529
|
+
return ensureMandatoryFields(latestBuild, ["slug"]);
|
|
1499
1530
|
};
|
|
1500
1531
|
|
|
1501
1532
|
// src/helper/formatBytes.ts
|
|
@@ -1518,11 +1549,6 @@ import { createWriteStream } from "node:fs";
|
|
|
1518
1549
|
import { get } from "node:https";
|
|
1519
1550
|
import { pipeline } from "node:stream/promises";
|
|
1520
1551
|
import { URL } from "node:url";
|
|
1521
|
-
|
|
1522
|
-
// src/helper/formatTime.ts
|
|
1523
|
-
var formatTime = (timeMs) => `${(timeMs / 1e3).toFixed(1)}s`;
|
|
1524
|
-
|
|
1525
|
-
// src/helper/downloadFile.ts
|
|
1526
1552
|
var downloadFile = async (fileUrl, outputLocationPath) => {
|
|
1527
1553
|
const startTime = Date.now();
|
|
1528
1554
|
const url = new URL(fileUrl);
|
|
@@ -1536,42 +1562,34 @@ var downloadFile = async (fileUrl, outputLocationPath) => {
|
|
|
1536
1562
|
}).on("error", reject);
|
|
1537
1563
|
});
|
|
1538
1564
|
await pipeline(response, createWriteStream(outputLocationPath));
|
|
1539
|
-
return { file: outputLocationPath, duration:
|
|
1565
|
+
return { file: outputLocationPath, duration: Date.now() - startTime };
|
|
1540
1566
|
};
|
|
1541
1567
|
|
|
1542
1568
|
// src/downloadLatestArtifacts.ts
|
|
1543
1569
|
var downloadLatestArtifacts = async (options) => {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
});
|
|
1550
|
-
if (!latestBuild.slug) throw Error("Latest build contained no Slug");
|
|
1551
|
-
const artifactMetadata = await oraPromise2(fetchArtifactByType(latestBuild.slug), {
|
|
1552
|
-
text: "fetching artifact list",
|
|
1553
|
-
failText: (error) => `fetching artifact list failed with error: ${error}`
|
|
1554
|
-
});
|
|
1555
|
-
if (!artifactMetadata.slug || !artifactMetadata.title) throw Error("Artifact was Invalid");
|
|
1570
|
+
const latestBuild = await oraPromise2(getLatestBuild(), getOraTexts("fetching latest build"));
|
|
1571
|
+
const artifactMetadata = await oraPromise2(
|
|
1572
|
+
fetchArtifactByType(latestBuild.slug),
|
|
1573
|
+
getOraTexts("fetching artifact list")
|
|
1574
|
+
);
|
|
1556
1575
|
const artifact = await oraPromise2(
|
|
1557
1576
|
fetchArtifact({ artifactSlug: artifactMetadata.slug, buildSlug: latestBuild.slug }),
|
|
1558
|
-
|
|
1577
|
+
getOraTexts("fetching artifact metadata")
|
|
1559
1578
|
);
|
|
1560
|
-
if (!artifact.expiringDownloadUrl) throw Error("Artifact is missing expiringDownloadUrl");
|
|
1561
|
-
const fileSize = formatBytes(artifact.fileSizeBytes ?? 0);
|
|
1562
1579
|
const { file } = await oraPromise2(downloadFile(artifact.expiringDownloadUrl, artifactMetadata.title), {
|
|
1563
|
-
|
|
1564
|
-
|
|
1580
|
+
...getOraTexts("downloading apk file"),
|
|
1581
|
+
text: `downloading apk file [${formatBytes(artifact.fileSizeBytes ?? 0)}]`
|
|
1565
1582
|
});
|
|
1566
1583
|
return file;
|
|
1567
1584
|
};
|
|
1568
1585
|
|
|
1569
1586
|
// src/cli/commands/download/impl.ts
|
|
1570
1587
|
async function impl_default(flags) {
|
|
1571
|
-
if (flags
|
|
1588
|
+
if (!setupEnv(flags)) return process.exit(1);
|
|
1572
1589
|
const file = await downloadLatestArtifacts(flags);
|
|
1573
1590
|
if (flags.install) {
|
|
1574
|
-
await installApp({ file, flags })
|
|
1591
|
+
await installApp({ file, flags }).catch(() => {
|
|
1592
|
+
});
|
|
1575
1593
|
}
|
|
1576
1594
|
}
|
|
1577
1595
|
export {
|