@catladder/cli 3.37.0 → 3.39.0

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/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "3.37.0",
56
+ "version": "3.39.0",
57
57
  "scripts": {
58
58
  "lint": "eslint \"src/**/*.ts\"",
59
59
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -1,14 +1,27 @@
1
1
  import type Vorpal from "vorpal";
2
2
  import {
3
+ getAllPipelineContexts,
3
4
  getEnvVarsResolved,
4
5
  getPipelineContextByChoice,
5
6
  } from "../../../../../config/getProjectConfig";
6
7
  import type { CloudSqlBackgroundProxy } from "../../../../../gcloud/cloudSql/startProxy";
7
8
  import { startCloudSqlProxyInBackground } from "../../../../../gcloud/cloudSql/startProxy";
8
- import { envAndComponents } from "../utils/autocompletions";
9
9
 
10
10
  import { parseConnectionString } from "../../../../../gcloud/cloudSql/parseConnectionString";
11
11
  import { spawnCopyDb } from "../../../../../gcloud/cloudSql/copyDb";
12
+ import type { ComponentContext } from "@catladder/pipeline";
13
+ import { isOfDeployType } from "@catladder/pipeline";
14
+
15
+ const hasCloudSql = (context: ComponentContext) => {
16
+ const deployConfig = context.deploy?.config;
17
+ if (isOfDeployType(deployConfig, "google-cloudrun")) {
18
+ return !!deployConfig.cloudSql;
19
+ }
20
+ if (isOfDeployType(deployConfig, "kubernetes")) {
21
+ return !!deployConfig.values?.cloudsql?.enabled;
22
+ }
23
+ return false;
24
+ };
12
25
 
13
26
  export default async (vorpal: Vorpal) =>
14
27
  vorpal
@@ -17,7 +30,29 @@ export default async (vorpal: Vorpal) =>
17
30
  "restores a project db from one source to another target",
18
31
  )
19
32
  .action(async function restoreDb() {
20
- const envs = await envAndComponents();
33
+ const allContexts = await getAllPipelineContexts(undefined, {
34
+ includeLocal: true,
35
+ });
36
+ const filteredContexts = allContexts.filter(hasCloudSql);
37
+ const sortByEnv = (a: string, b: string) => {
38
+ const aLocal = a.startsWith("local:");
39
+ const bLocal = b.startsWith("local:");
40
+ if (aLocal !== bLocal) return aLocal ? 1 : -1;
41
+ return a.localeCompare(b);
42
+ };
43
+ const envs = filteredContexts
44
+ .map((c) => `${c.env}:${c.name}`)
45
+ .sort(sortByEnv);
46
+ const targetEnvChoices = filteredContexts
47
+ .map((c) => {
48
+ const value = `${c.env}:${c.name}`;
49
+ const isProd = c.environment.envType === "prod";
50
+ return {
51
+ name: isProd ? `⚠️ ${value}` : value,
52
+ value,
53
+ };
54
+ })
55
+ .sort((a, b) => sortByEnv(a.value, b.value));
21
56
 
22
57
  const { sourceEnvAndComponent } = await this.prompt({
23
58
  type: "list",
@@ -83,7 +118,7 @@ export default async (vorpal: Vorpal) =>
83
118
  const { targetEnvAndComponent } = await this.prompt({
84
119
  type: "list",
85
120
  name: "targetEnvAndComponent",
86
- choices: envs,
121
+ choices: targetEnvChoices,
87
122
 
88
123
  message: "target env? 🤔 ",
89
124
  });
@@ -94,6 +94,7 @@ export const getAllComponentsWithAllEnvsHierarchical = async (): Promise<{
94
94
 
95
95
  export const getAllPipelineContexts = async (
96
96
  onlyComponent?: string | string[],
97
+ { includeLocal = false }: { includeLocal?: boolean } = {},
97
98
  ) => {
98
99
  const onlyComponentsArray = onlyComponent
99
100
  ? Array.isArray(onlyComponent)
@@ -102,7 +103,7 @@ export const getAllPipelineContexts = async (
102
103
  : null;
103
104
  return Promise.all(
104
105
  (await getAllComponentsWithAllEnvsFlat())
105
- .filter((c) => c.env !== "local")
106
+ .filter((c) => includeLocal || c.env !== "local")
106
107
  .filter(
107
108
  (c) =>
108
109
  !onlyComponentsArray || onlyComponentsArray.includes(c.componentName),