@catladder/cli 0.0.0-main-8e49a2ce → 0.0.0-main-0d4bc87f

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
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@bitwarden/cli": "^1.8.0",
20
- "@catladder/pipeline": "0.0.0-main-8e49a2ce",
20
+ "@catladder/pipeline": "0.0.0-main-0d4bc87f",
21
21
  "@kubernetes/client-node": "^0.16.1",
22
22
  "child-process-promise": "^2.2.1",
23
23
  "clipboardy": "^2.2.0",
@@ -60,6 +60,6 @@
60
60
  "eslint": "^8.7.0",
61
61
  "typescript": "^4.5.4"
62
62
  },
63
- "version": "0.0.0-main-8e49a2ce",
63
+ "version": "0.0.0-main-0d4bc87f",
64
64
  "stableVersion": "0.0.0-test7"
65
65
  }
@@ -1,5 +1,5 @@
1
1
  import { Config } from "@catladder/pipeline";
2
- import { spawn } from "child-process-promise";
2
+ import { spawn, exec } from "child-process-promise";
3
3
  import { writeFile } from "fs-extra";
4
4
  import { safeDump } from "js-yaml";
5
5
  import { format } from "prettier";
@@ -44,9 +44,10 @@ export const writeConfig = async (
44
44
  encoding: "utf-8",
45
45
  });
46
46
  vorpal.log("adding type @catladder/pipeline....");
47
- await spawn("yarn add @catladder/pipeline -D", {
47
+ await spawn("yarn add @catladder/pipeline -DW", {
48
48
  shell: true,
49
49
  });
50
+ await exec("git add " + gitRoot + "/catladder.ts");
50
51
  } else {
51
52
  const content = safeDump(config);
52
53
 
@@ -61,6 +62,7 @@ export const writeConfig = async (
61
62
  encoding: "utf-8",
62
63
  }
63
64
  );
65
+ await exec("git add " + gitRoot + "/catladder.ts");
64
66
  }
65
67
  vorpal.log("done!");
66
68
  vorpal.log("");
@@ -1,11 +1,19 @@
1
1
  import {
2
2
  BuildConfig,
3
+ ComponentConfig,
3
4
  Config,
4
5
  DeployConfigKubernetes,
5
6
  Env,
6
7
  } from "@catladder/pipeline";
7
- import { readFile, writeFile } from "fs-extra";
8
+ import {
9
+ existsSync,
10
+ lstatSync,
11
+ readdirSync,
12
+ readFile,
13
+ writeFile,
14
+ } from "fs-extra";
8
15
  import { isEmpty } from "lodash";
16
+ import { join } from "path";
9
17
  import Vorpal from "vorpal";
10
18
  import {
11
19
  getGitlabCi,
@@ -44,6 +52,16 @@ const transformVars = (rawVars: {
44
52
  };
45
53
  };
46
54
 
55
+ const getLegacyMonorepoSubCiFiles = (dir: string) => {
56
+ return readdirSync(dir)
57
+ .filter((file) => lstatSync(file).isDirectory())
58
+ .map((dir) => ({
59
+ dir,
60
+ ci: join(dir, ".gitlab-ci.yml"),
61
+ }))
62
+ .filter(({ ci }) => existsSync(ci));
63
+ };
64
+
47
65
  const transformValues = (
48
66
  valuesIn: Record<string, any>
49
67
  ): DeployConfigKubernetes["values"] => {
@@ -110,61 +128,78 @@ export const migrateV2 = async (vorpal: Vorpal) => {
110
128
  vorpal.log("");
111
129
 
112
130
  if (shouldContinue) {
113
- const { env, ...baseValues } =
114
- (await readYaml(gitRoot + "/values.yml")) ?? {};
115
-
116
- const startCommand = baseValues?.application?.command?.join(" ");
117
-
131
+ const createComponent = async (
132
+ dir: string,
133
+ ciFile: OldGitlabCiFile
134
+ ): Promise<ComponentConfig> => {
135
+ const { env, ...baseValues } =
136
+ (await readYaml(dir + "/values.yml")) ?? {};
137
+
138
+ const startCommand = baseValues?.application?.command?.join(" ");
139
+ return {
140
+ vars: env ? transformVars(env) : undefined,
141
+ dir: dir,
142
+ build: {
143
+ type: detectBuildConfig(ciFile),
144
+ startCommand: startCommand,
145
+ } as BuildConfig,
146
+ deploy: {
147
+ type: "kubernetes",
148
+ values: transformValues(baseValues),
149
+ cluster: CLUSTER_NAME,
150
+ },
151
+ env: await LEGACY_ENVS.reduce<Promise<Env>>(
152
+ async (acc, envName) => {
153
+ if (envName === "stage" && !STAGING_ENABLED) {
154
+ return {
155
+ ...(await acc),
156
+ [envName]: false,
157
+ };
158
+ }
159
+ const newEnvName = envName === "dev-local" ? "local" : envName;
160
+
161
+ const envValues =
162
+ (await readYaml(dir + `/values-${envName}.yml`)) ?? {};
163
+ const { env, ...rest } = envValues;
164
+ const hostname = rest?.application?.hostname;
165
+ const values = transformValues(rest);
166
+ return {
167
+ ...(await acc),
168
+ [newEnvName]: {
169
+ hostname: hostname,
170
+ vars: env ? transformVars(env) : undefined,
171
+ deploy: values
172
+ ? {
173
+ values: values,
174
+ }
175
+ : undefined,
176
+ },
177
+ };
178
+ },
179
+ Promise.resolve({})
180
+ ),
181
+ };
182
+ };
183
+ let components: Record<string, ComponentConfig>;
184
+ if (detectBuildConfig(gitlabCi) === "monorepo") {
185
+ components = await getLegacyMonorepoSubCiFiles(gitRoot).reduce<
186
+ Promise<Record<string, ComponentConfig>>
187
+ >(async (acc, el) => {
188
+ return {
189
+ ...(await acc),
190
+ [el.dir]: await createComponent(el.dir, await readYaml(el.ci)),
191
+ };
192
+ }, Promise.resolve({}));
193
+ } else {
194
+ components = {
195
+ [COMPONENT_NAME]: await createComponent(".", gitlabCi),
196
+ };
197
+ }
118
198
  // we only have one component
119
199
  const config: Config = {
120
200
  customerName: CUSTOMER_NAME,
121
201
  appName: APP_NAME,
122
- components: {
123
- [COMPONENT_NAME]: {
124
- vars: env ? transformVars(env) : undefined,
125
- dir: APP_DIR ?? ".",
126
- build: {
127
- type: detectBuildConfig(gitlabCi),
128
- startCommand: startCommand,
129
- } as BuildConfig,
130
- deploy: {
131
- type: "kubernetes",
132
- values: transformValues(baseValues),
133
- cluster: CLUSTER_NAME,
134
- },
135
- env: await LEGACY_ENVS.reduce<Promise<Env>>(
136
- async (acc, envName) => {
137
- if (envName === "stage" && !STAGING_ENABLED) {
138
- return {
139
- ...(await acc),
140
- [envName]: false,
141
- };
142
- }
143
- const newEnvName =
144
- envName === "dev-local" ? "local" : envName;
145
-
146
- const envValues =
147
- (await readYaml(gitRoot + `/values-${envName}.yml`)) ?? {};
148
- const { env, ...rest } = envValues;
149
- const hostname = rest?.application?.hostname;
150
- const values = transformValues(rest);
151
- return {
152
- ...(await acc),
153
- [newEnvName]: {
154
- hostname: hostname,
155
- vars: env ? transformVars(env) : undefined,
156
- deploy: values
157
- ? {
158
- values: values,
159
- }
160
- : undefined,
161
- },
162
- };
163
- },
164
- Promise.resolve({})
165
- ),
166
- },
167
- },
202
+ components,
168
203
  };
169
204
 
170
205
  const comment =
@@ -18,12 +18,14 @@ export type OldGitlabCiFile = {
18
18
 
19
19
  export const detectBuildConfig = (
20
20
  gitlabCi: OldGitlabCiFile
21
- ): BuildConfig["type"] => {
21
+ ): BuildConfig["type"] | "monorepo" => {
22
22
  const firstInclude = gitlabCi.include[0];
23
23
  if (!firstInclude || gitlabCi.include[0]?.project !== "catladder/gitlab-ci") {
24
24
  throw new Error("unsupported gitlab-ci file");
25
25
  }
26
26
 
27
+ if (firstInclude.file === "monorepo.yml") return "monorepo";
28
+
27
29
  if (firstInclude.file === "node-kubernetes.yml") {
28
30
  return "node";
29
31
  }