bitrise-api-cli 0.0.3 → 0.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.
Files changed (3) hide show
  1. package/README.md +9 -8
  2. package/dist/bin.js +36 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -23,7 +23,7 @@ npx bitrise-api-cli@latest download --token <BITRISE_TOKEN> --workflow <WORKFLOW
23
23
  npx bitrise-api-cli@latest download \
24
24
  --token <BITRISE_TOKEN> \
25
25
  --workflow <WORKFLOW_NAME> \
26
- --app-slug <APP_SLUG>
26
+ --slug <APP_SLUG>
27
27
  ```
28
28
 
29
29
  ## 🔐 Configuration
@@ -40,11 +40,12 @@ npx bitrise-api-cli@latest download \
40
40
 
41
41
  ```bash
42
42
  Options:
43
- -t, --token <TOKEN> Bitrise API token
44
- -w, --workflow <NAME> Workflow name
45
- -s, --app-slug <SLUG> Bitrise app slug
46
- -d, --debug Enable debug logging
47
- -h, --help Display help information
43
+ -t, --token <TOKEN> bitrise api token (or $BITRISE_API_CLI_TOKEN)
44
+ -w, --workflow <WORKFLOW_NAME> workflow to get apk from (or $BITRISE_API_CLI_WORKFLOW)
45
+ -s, --slug <APP_SLUG> bitrise app slug (or $BITRISE_APP_SLUG) see bitrise project url to get slug
46
+ -a, --artifact <ARTIFACT_TYPE> bitrise artifact type "ios-ipa" or "android-apk"
47
+ -d, --debug output extra debugging (default: false)
48
+ -h, --help display help for command
48
49
  ```
49
50
 
50
51
  ## 💡 Examples
@@ -56,7 +57,7 @@ Options:
56
57
  npx bitrise-api-cli@latest download \
57
58
  --token abc123 \
58
59
  --workflow android-release \
59
- --app-slug a1b2c3d4e5f6
60
+ --slug a1b2c3d4e5f6
60
61
 
61
62
  # Enable debug logging
62
63
  npx bitrise-api-cli@latest download --debug \
@@ -100,7 +101,7 @@ Download the latest artifacts to test without building:
100
101
  npx bitrise-api-cli@latest download \
101
102
  --token $BITRISE_API_TOKEN \
102
103
  --workflow android-release \
103
- --app-slug $BITRISE_APP_SLUG
104
+ --slug $BITRISE_APP_SLUG
104
105
  ```
105
106
 
106
107
  ## 📝 License
package/dist/bin.js CHANGED
@@ -3,16 +3,21 @@
3
3
  // src/bin.ts
4
4
  import { Command } from "commander";
5
5
 
6
+ // src/cliOptions.types.ts
7
+ var validArtifactTypes = ["android-apk", "ios-ipa"];
8
+
6
9
  // src/bitrise/env.ts
7
10
  var ENV = {
8
11
  appSlug: "",
9
12
  token: "",
10
- workflow: ""
13
+ workflow: "",
14
+ artifactType: "android-apk"
11
15
  };
12
16
  var saveOptions = (options) => {
13
- ENV.appSlug = options?.app ?? process.env.BITRISE_APP_SLUG ?? "";
14
- ENV.token = options?.token ?? process.env.BITRISE_API_CLI_TOKEN ?? "";
15
- ENV.workflow = options?.workflow ?? process.env.BITRISE_API_CLI_WORKFLOW ?? "";
17
+ ENV.appSlug = options.slug;
18
+ ENV.token = options.token;
19
+ ENV.workflow = options.workflow;
20
+ ENV.artifactType = options.artifact;
16
21
  };
17
22
  var isEnvValid = () => {
18
23
  if (ENV.appSlug.length < 1) {
@@ -27,6 +32,10 @@ var isEnvValid = () => {
27
32
  console.log("No workflow provided! (see --help for more information)");
28
33
  return false;
29
34
  }
35
+ if (!validArtifactTypes.includes(ENV.artifactType)) {
36
+ console.log(`Invalid artifact type "${ENV.artifactType}"! (see --help for more information)`);
37
+ return false;
38
+ }
30
39
  return true;
31
40
  };
32
41
 
@@ -1454,13 +1463,20 @@ var fetchArtifactList = async (buildSlug) => {
1454
1463
  if (!data) throw new Error("buildArtifact().artifactList returned no data");
1455
1464
  return data;
1456
1465
  };
1466
+ var fetchArtifactByType = async (buildSlug) => {
1467
+ const artifactInfo = await fetchArtifactList(buildSlug);
1468
+ const artifactMetadata = artifactInfo.find((artifact) => artifact.artifactType === ENV.artifactType);
1469
+ if (!artifactMetadata || !artifactMetadata.slug)
1470
+ throw new Error(`Found no ${ENV.artifactType} in build Slug: ${buildSlug}`);
1471
+ return artifactMetadata;
1472
+ };
1457
1473
 
1458
1474
  // src/helper/debugLog.ts
1459
1475
  var debugLog = (label, data) => console.log(`${label}: ${JSON.stringify(data, void 0, 2)}`);
1460
1476
 
1461
1477
  // src/bitrise/fetchBuilds.ts
1462
1478
  var getAllBuilds = async () => {
1463
- const { data } = await api.builds().buildList({ appSlug: ENV.appSlug });
1479
+ const { data } = await api.builds().buildList({ appSlug: ENV.appSlug, status: 1 });
1464
1480
  if (!data) throw Error("no build data");
1465
1481
  return data;
1466
1482
  };
@@ -1492,7 +1508,6 @@ var downloadFile = async (fileUrl, outputLocationPath) => {
1492
1508
  };
1493
1509
 
1494
1510
  // src/downloadLatestArtifacts.ts
1495
- var targetArtifactType = "android-apk";
1496
1511
  var downloadLatestArtifacts = async (options) => {
1497
1512
  saveOptions(options);
1498
1513
  if (!isEnvValid()) return process.exit(1);
@@ -1504,11 +1519,12 @@ var downloadLatestArtifacts = async (options) => {
1504
1519
  console.log("Latest build contained no Slug");
1505
1520
  return process.exit(1);
1506
1521
  }
1507
- const artifactInfo = await oraPromise(fetchArtifactList(latestBuild.slug), { text: "fetching artifact list" });
1508
- const artifactMetadata = artifactInfo.find((artifact2) => artifact2.artifactType === targetArtifactType);
1509
- if (!artifactMetadata || !artifactMetadata.slug)
1510
- throw new Error(`Found no apk in build #${latestBuild.buildNumber}`);
1522
+ const artifactMetadata = await oraPromise(fetchArtifactByType(latestBuild.slug), {
1523
+ text: "fetching artifact list",
1524
+ failText: (error) => `fetching artifact list failed with error: ${error}`
1525
+ });
1511
1526
  if (options.debug) debugLog("artifactMetadata", artifactMetadata);
1527
+ if (!artifactMetadata || !artifactMetadata.slug) return process.exit(1);
1512
1528
  const artifact = await oraPromise(
1513
1529
  fetchArtifact({
1514
1530
  artifactSlug: artifactMetadata.slug,
@@ -1529,6 +1545,14 @@ var downloadLatestArtifacts = async (options) => {
1529
1545
 
1530
1546
  // src/bin.ts
1531
1547
  var program = new Command();
1532
- program.version("0.0.3");
1533
- program.command("download").option("-t, --token <TOKEN>", "bitrise api token (or $BITRISE_API_CLI_TOKEN)").option("-w, --workflow <WORKFLOW_NAME>", "workflow to get apk from (or $BITRISE_API_CLI_WORKFLOW)").option("-a, --app <APP_SLUG>", "bitrise app slug (or $BITRISE_APP_SLUG) see bitrise project url to get slug").option("-d, --debug", "output extra debugging", false).description("Download bitrise artifacts").action((options) => downloadLatestArtifacts(options).catch(() => process.exit(1)));
1548
+ program.version("0.0.4");
1549
+ program.command("download").option("-t, --token <TOKEN>", "bitrise api token (or $BITRISE_API_CLI_TOKEN)", process.env.BITRISE_API_CLI_TOKEN).option(
1550
+ "-w, --workflow <WORKFLOW_NAME>",
1551
+ "workflow to get apk from (or $BITRISE_API_CLI_WORKFLOW)",
1552
+ process.env.BITRISE_API_CLI_WORKFLOW
1553
+ ).option(
1554
+ "-s, --slug <APP_SLUG>",
1555
+ "bitrise app slug (or $BITRISE_APP_SLUG) see bitrise project url to get slug",
1556
+ process.env.BITRISE_APP_SLUG
1557
+ ).option("-a, --artifact <ARTIFACT_TYPE>", 'bitrise artifact type "ios-ipa" or "android-apk"', "android-apk").option("-d, --debug", "output extra debugging", false).description("Download bitrise artifacts").action((options) => downloadLatestArtifacts(options).catch(() => process.exit(1)));
1534
1558
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitrise-api-cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "bitrise api CLI wrapper",
5
5
  "module": "index",
6
6
  "type": "module",