@catladder/cli 3.37.0 → 3.38.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.38.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,18 @@ 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 envs = allContexts
37
+ .filter(hasCloudSql)
38
+ .map((c) => `${c.env}:${c.name}`)
39
+ .sort((a, b) => {
40
+ const aLocal = a.startsWith("local:");
41
+ const bLocal = b.startsWith("local:");
42
+ if (aLocal !== bLocal) return aLocal ? 1 : -1;
43
+ return a.localeCompare(b);
44
+ });
21
45
 
22
46
  const { sourceEnvAndComponent } = await this.prompt({
23
47
  type: "list",
@@ -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),