@pitcher/cli-scripts 2.0.0 → 2.0.2

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/README.md CHANGED
@@ -44,4 +44,4 @@ p publish-app --increment-version --install-to-env-name "Production"
44
44
  - `--dry-run`: Perform a dry run without publishing
45
45
  - `--publish-url <url>`: Explicit publish URL
46
46
  - `--install-to <instanceIds>`: Comma-separated list of instance IDs to install the app to after publishing
47
- - `--install-to-env-name <envName>`: Environment name to filter instances and install the app to after publishing
47
+ - `--install-to-env-name <envName>`: Environment name to filter instances and install the app to after publishing (case-insensitive)
@@ -6,16 +6,53 @@ import path from "path";
6
6
  import FormData from "form-data";
7
7
  import { fileURLToPath } from "url";
8
8
  async function fetchAllInstances(baseUrl, apiKey) {
9
+ const pageSize = 100;
10
+ const maxPages = 1000;
9
11
  try {
10
- const response = await axios.get(`${baseUrl}/api/v1/instances`, {
12
+ console.log("Fetching instances page 1 to determine total count...");
13
+ const firstResponse = await axios.get(`${baseUrl}/api/v1/instances`, {
11
14
  headers: {
12
15
  accept: "application/json",
13
16
  "x-api-key": apiKey,
14
17
  },
18
+ params: {
19
+ page_size: pageSize,
20
+ page: 1,
21
+ },
15
22
  });
16
- const instances = response.data.results || response.data;
17
- console.log(`Fetched ${instances.length} total instance(s) from API`);
18
- return instances;
23
+ const firstData = firstResponse.data;
24
+ const firstInstances = firstData.results || [];
25
+ if (firstInstances.length === 0) {
26
+ console.log("No instances found");
27
+ return [];
28
+ }
29
+ const totalCount = firstData.count || firstInstances.length;
30
+ const totalPages = Math.min(Math.ceil(totalCount / pageSize), maxPages);
31
+ console.log(`Found ${totalCount} instance(s) across ${totalPages} page(s)`);
32
+ if (totalPages === 1) {
33
+ console.log(`✓ Fetched ${firstInstances.length} total instance(s) from API`);
34
+ return firstInstances;
35
+ }
36
+ const remainingPageNumbers = Array.from({ length: totalPages - 1 }, (_, i) => i + 2);
37
+ console.log(`Fetching remaining ${totalPages - 1} pages in parallel...`);
38
+ const remainingPagePromises = remainingPageNumbers.map((page) => axios.get(`${baseUrl}/api/v1/instances`, {
39
+ headers: {
40
+ accept: "application/json",
41
+ "x-api-key": apiKey,
42
+ },
43
+ params: {
44
+ page_size: pageSize,
45
+ page: page,
46
+ },
47
+ }));
48
+ const remainingResponses = await Promise.all(remainingPagePromises);
49
+ const remainingInstances = remainingResponses.flatMap((response) => response.data.results || []);
50
+ const allInstances = [...firstInstances, ...remainingInstances];
51
+ if (totalPages >= maxPages) {
52
+ console.warn(`⚠ Warning: Reached maximum page limit (${maxPages}). There may be more instances.`);
53
+ }
54
+ console.log(`✓ Fetched ${allInstances.length} total instance(s) from API`);
55
+ return allInstances;
19
56
  }
20
57
  catch (error) {
21
58
  const axiosError = error;
@@ -24,7 +61,9 @@ async function fetchAllInstances(baseUrl, apiKey) {
24
61
  }
25
62
  }
26
63
  function filterInstancesByEnvName(instances, envName) {
27
- const filtered = instances.filter((instance) => instance.env_name === envName);
64
+ const normalizedEnvName = envName.toLowerCase();
65
+ const filtered = instances.filter((instance) => instance.env_name &&
66
+ instance.env_name.toLowerCase() === normalizedEnvName);
28
67
  if (filtered.length === 0) {
29
68
  console.warn(`No instances found with environment name "${envName}"`);
30
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitcher/cli-scripts",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "The Pitcher CLI for various tasks in its ecosystem.",
5
5
  "author": "Pitcher AG",
6
6
  "license": "MIT",