@catladder/cli 0.0.1-bla → 1.0.3

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 (288) hide show
  1. package/.nvmrc +1 -1
  2. package/bin/catenv +3 -0
  3. package/bin/catladder +1 -1
  4. package/dist/apps/catenv/catenv.d.ts +2 -0
  5. package/dist/apps/catenv/catenv.js +135 -0
  6. package/dist/apps/catenv/catenv.js.map +1 -0
  7. package/dist/apps/cli/cli.d.ts +2 -0
  8. package/dist/apps/cli/cli.js +81 -0
  9. package/dist/apps/cli/cli.js.map +1 -0
  10. package/dist/apps/cli/commands/general/index.d.ts +4 -0
  11. package/dist/apps/cli/commands/general/index.js +274 -0
  12. package/dist/apps/cli/commands/general/index.js.map +1 -0
  13. package/dist/apps/cli/commands/general/namespaceAutoCompletion.d.ts +3 -0
  14. package/dist/apps/cli/commands/general/namespaceAutoCompletion.js +56 -0
  15. package/dist/apps/cli/commands/general/namespaceAutoCompletion.js.map +1 -0
  16. package/dist/apps/cli/commands/general/portForward.d.ts +3 -0
  17. package/dist/apps/cli/commands/general/portForward.js +98 -0
  18. package/dist/apps/cli/commands/general/portForward.js.map +1 -0
  19. package/dist/apps/cli/commands/mongodb/index.d.ts +3 -0
  20. package/dist/apps/cli/commands/mongodb/index.js +53 -0
  21. package/dist/apps/cli/commands/mongodb/index.js.map +1 -0
  22. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.d.ts +3 -0
  23. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js +190 -0
  24. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js.map +1 -0
  25. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.d.ts +3 -0
  26. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js +96 -0
  27. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js.map +1 -0
  28. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.d.ts +3 -0
  29. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js +105 -0
  30. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -0
  31. package/dist/apps/cli/commands/mongodb/utils/index.d.ts +13 -0
  32. package/dist/apps/cli/commands/mongodb/utils/index.js +167 -0
  33. package/dist/apps/cli/commands/mongodb/utils/index.js.map +1 -0
  34. package/dist/apps/cli/commands/project/commandCloudSqlProxy.d.ts +3 -0
  35. package/dist/apps/cli/commands/project/commandCloudSqlProxy.js +128 -0
  36. package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -0
  37. package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +3 -0
  38. package/dist/apps/cli/commands/project/commandConfigSecrets.js +254 -0
  39. package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -0
  40. package/dist/apps/cli/commands/project/commandCopyDB.d.ts +3 -0
  41. package/dist/apps/cli/commands/project/commandCopyDB.js +102 -0
  42. package/dist/apps/cli/commands/project/commandCopyDB.js.map +1 -0
  43. package/dist/apps/cli/commands/project/commandDeletePods.d.ts +3 -0
  44. package/dist/apps/cli/commands/project/commandDeletePods.js +119 -0
  45. package/dist/apps/cli/commands/project/commandDeletePods.js.map +1 -0
  46. package/dist/apps/cli/commands/project/commandDeleteProject.d.ts +3 -0
  47. package/dist/apps/cli/commands/project/commandDeleteProject.js +97 -0
  48. package/dist/apps/cli/commands/project/commandDeleteProject.js.map +1 -0
  49. package/dist/apps/cli/commands/project/commandEnvVars.d.ts +3 -0
  50. package/dist/apps/cli/commands/project/commandEnvVars.js +74 -0
  51. package/dist/apps/cli/commands/project/commandEnvVars.js.map +1 -0
  52. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.d.ts +3 -0
  53. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js +58 -0
  54. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js.map +1 -0
  55. package/dist/apps/cli/commands/project/commandGetShell.d.ts +3 -0
  56. package/dist/apps/cli/commands/project/commandGetShell.js +92 -0
  57. package/dist/apps/cli/commands/project/commandGetShell.js.map +1 -0
  58. package/dist/apps/cli/commands/project/commandGitlabCi.d.ts +3 -0
  59. package/dist/apps/cli/commands/project/commandGitlabCi.js +185 -0
  60. package/dist/apps/cli/commands/project/commandGitlabCi.js.map +1 -0
  61. package/dist/apps/cli/commands/project/commandInitGitlab.d.ts +3 -0
  62. package/dist/apps/cli/commands/project/commandInitGitlab.js +245 -0
  63. package/dist/apps/cli/commands/project/commandInitGitlab.js.map +1 -0
  64. package/dist/apps/cli/commands/project/commandInitProject.d.ts +3 -0
  65. package/dist/apps/cli/commands/project/commandInitProject.js +345 -0
  66. package/dist/apps/cli/commands/project/commandInitProject.js.map +1 -0
  67. package/dist/apps/cli/commands/project/commandListPods.d.ts +3 -0
  68. package/dist/apps/cli/commands/project/commandListPods.js +78 -0
  69. package/dist/apps/cli/commands/project/commandListPods.js.map +1 -0
  70. package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +7 -0
  71. package/dist/apps/cli/commands/project/commandMigrateHelm3.js +113 -0
  72. package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -0
  73. package/dist/apps/cli/commands/project/commandNamespace.d.ts +3 -0
  74. package/dist/apps/cli/commands/project/commandNamespace.js +70 -0
  75. package/dist/apps/cli/commands/project/commandNamespace.js.map +1 -0
  76. package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +3 -0
  77. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js +83 -0
  78. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js.map +1 -0
  79. package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +3 -0
  80. package/dist/apps/cli/commands/project/commandOpenDashboard.js +92 -0
  81. package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -0
  82. package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +3 -0
  83. package/dist/apps/cli/commands/project/commandOpenEnv.js +80 -0
  84. package/dist/apps/cli/commands/project/commandOpenEnv.js.map +1 -0
  85. package/dist/apps/cli/commands/project/commandOpenGit.d.ts +3 -0
  86. package/dist/apps/cli/commands/project/commandOpenGit.js +56 -0
  87. package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -0
  88. package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +3 -0
  89. package/dist/apps/cli/commands/project/commandOpenGrafana.js +83 -0
  90. package/dist/apps/cli/commands/project/commandOpenGrafana.js.map +1 -0
  91. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +3 -0
  92. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +99 -0
  93. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -0
  94. package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +3 -0
  95. package/dist/apps/cli/commands/project/commandOpenLogs.js +87 -0
  96. package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -0
  97. package/dist/apps/cli/commands/project/commandPauseProject.d.ts +3 -0
  98. package/dist/apps/cli/commands/project/commandPauseProject.js +97 -0
  99. package/dist/apps/cli/commands/project/commandPauseProject.js.map +1 -0
  100. package/dist/apps/cli/commands/project/commandPortForward.d.ts +3 -0
  101. package/dist/apps/cli/commands/project/commandPortForward.js +106 -0
  102. package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -0
  103. package/dist/apps/cli/commands/project/commandReloadConfig.d.ts +3 -0
  104. package/dist/apps/cli/commands/project/commandReloadConfig.js +62 -0
  105. package/dist/apps/cli/commands/project/commandReloadConfig.js.map +1 -0
  106. package/dist/apps/cli/commands/project/commandTriggerCronjob.d.ts +3 -0
  107. package/dist/apps/cli/commands/project/commandTriggerCronjob.js +144 -0
  108. package/dist/apps/cli/commands/project/commandTriggerCronjob.js.map +1 -0
  109. package/dist/apps/cli/commands/project/index.d.ts +3 -0
  110. package/dist/apps/cli/commands/project/index.js +97 -0
  111. package/dist/apps/cli/commands/project/index.js.map +1 -0
  112. package/dist/apps/cli/commands/project/utils/autocompletions.d.ts +3 -0
  113. package/dist/apps/cli/commands/project/utils/autocompletions.js +96 -0
  114. package/dist/apps/cli/commands/project/utils/autocompletions.js.map +1 -0
  115. package/dist/apps/cli/commands/project/utils/ensureCluster.d.ts +1 -0
  116. package/dist/apps/cli/commands/project/utils/ensureCluster.js +84 -0
  117. package/dist/apps/cli/commands/project/utils/ensureCluster.js.map +1 -0
  118. package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +1 -0
  119. package/dist/apps/cli/commands/project/utils/ensureNamespace.js +92 -0
  120. package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -0
  121. package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +2 -0
  122. package/dist/apps/cli/commands/project/utils/showProjectBanner.js +58 -0
  123. package/dist/apps/cli/commands/project/utils/showProjectBanner.js.map +1 -0
  124. package/dist/apps/cli/commands/shared/index.d.ts +2 -0
  125. package/dist/apps/cli/commands/shared/index.js +72 -0
  126. package/dist/apps/cli/commands/shared/index.js.map +1 -0
  127. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +3 -0
  128. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js +131 -0
  129. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js.map +1 -0
  130. package/dist/apps/cli/config/writeConfig.d.ts +5 -0
  131. package/dist/apps/cli/config/writeConfig.js +104 -0
  132. package/dist/apps/cli/config/writeConfig.js.map +1 -0
  133. package/dist/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -0
  134. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js +69 -0
  135. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -0
  136. package/dist/apps/cli/verify/index.d.ts +2 -0
  137. package/dist/apps/cli/verify/index.js +90 -0
  138. package/dist/apps/cli/verify/index.js.map +1 -0
  139. package/dist/apps/cli/verify/migration/fromv2.d.ts +3 -0
  140. package/dist/apps/cli/verify/migration/fromv2.js +322 -0
  141. package/dist/apps/cli/verify/migration/fromv2.js.map +1 -0
  142. package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +4 -0
  143. package/dist/apps/cli/verify/migration/migrateSecrets.js +88 -0
  144. package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -0
  145. package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +17 -0
  146. package/dist/apps/cli/verify/migration/oldGitlabCi.js +26 -0
  147. package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -0
  148. package/dist/catenv.d.ts +1 -0
  149. package/dist/catenv.js +8 -0
  150. package/dist/catenv.js.map +1 -0
  151. package/dist/cli.d.ts +1 -0
  152. package/dist/cli.js +13 -0
  153. package/dist/cli.js.map +1 -0
  154. package/dist/config/clusters.d.ts +14 -0
  155. package/dist/config/clusters.js +72 -0
  156. package/dist/config/clusters.js.map +1 -0
  157. package/dist/config/constants.d.ts +4 -0
  158. package/dist/config/constants.js +8 -0
  159. package/dist/config/constants.js.map +1 -0
  160. package/dist/config/getProjectConfig.d.ts +21 -0
  161. package/dist/config/getProjectConfig.js +212 -0
  162. package/dist/config/getProjectConfig.js.map +1 -0
  163. package/dist/k8sApi/index.d.ts +5 -0
  164. package/dist/k8sApi/index.js +11 -0
  165. package/dist/k8sApi/index.js.map +1 -0
  166. package/dist/packageInfos.d.ts +2 -0
  167. package/dist/packageInfos.js +6 -0
  168. package/dist/packageInfos.js.map +1 -0
  169. package/dist/tsconfig.tsbuildinfo +1 -0
  170. package/dist/types/types.d.ts +18 -0
  171. package/dist/types/types.js +3 -0
  172. package/dist/types/types.js.map +1 -0
  173. package/dist/utils/cluster.d.ts +12 -0
  174. package/dist/utils/cluster.js +100 -0
  175. package/dist/utils/cluster.js.map +1 -0
  176. package/dist/utils/editAsFile.d.ts +1 -0
  177. package/dist/utils/editAsFile.js +85 -0
  178. package/dist/utils/editAsFile.js.map +1 -0
  179. package/dist/utils/files.d.ts +2 -0
  180. package/dist/utils/files.js +83 -0
  181. package/dist/utils/files.js.map +1 -0
  182. package/dist/utils/formatEnvVars.d.ts +2 -0
  183. package/dist/utils/formatEnvVars.js +10 -0
  184. package/dist/utils/formatEnvVars.js.map +1 -0
  185. package/dist/utils/getEditor.d.ts +4 -0
  186. package/dist/utils/getEditor.js +70 -0
  187. package/dist/utils/getEditor.js.map +1 -0
  188. package/dist/utils/gitlab.d.ts +21 -0
  189. package/dist/utils/gitlab.js +258 -0
  190. package/dist/utils/gitlab.js.map +1 -0
  191. package/dist/utils/log.d.ts +1 -0
  192. package/dist/utils/log.js +14 -0
  193. package/dist/utils/log.js.map +1 -0
  194. package/dist/utils/passwordstore/index.d.ts +8 -0
  195. package/dist/utils/passwordstore/index.js +378 -0
  196. package/dist/utils/passwordstore/index.js.map +1 -0
  197. package/dist/utils/portForward.d.ts +4 -0
  198. package/dist/utils/portForward.js +116 -0
  199. package/dist/utils/portForward.js.map +1 -0
  200. package/dist/utils/preferences/index.d.ts +3 -0
  201. package/dist/utils/preferences/index.js +119 -0
  202. package/dist/utils/preferences/index.js.map +1 -0
  203. package/dist/utils/projects/index.d.ts +8 -0
  204. package/dist/utils/projects/index.js +150 -0
  205. package/dist/utils/projects/index.js.map +1 -0
  206. package/dist/utils/promise.d.ts +2 -0
  207. package/dist/utils/promise.js +62 -0
  208. package/dist/utils/promise.js.map +1 -0
  209. package/dist/utils/shell.d.ts +1 -0
  210. package/dist/utils/shell.js +81 -0
  211. package/dist/utils/shell.js.map +1 -0
  212. package/package.json +12 -20
  213. package/src/apps/catenv/catenv.ts +48 -27
  214. package/src/apps/{shell/shell.ts → cli/cli.ts} +10 -2
  215. package/src/apps/{shell → cli}/commands/general/index.ts +1 -1
  216. package/src/apps/{shell → cli}/commands/general/namespaceAutoCompletion.ts +0 -0
  217. package/src/apps/{shell → cli}/commands/general/portForward.ts +1 -1
  218. package/src/apps/{shell → cli}/commands/mongodb/index.ts +1 -1
  219. package/src/apps/{shell → cli}/commands/mongodb/projectMongoDestroyMember.ts +18 -18
  220. package/src/apps/{shell → cli}/commands/mongodb/projectMongoGetShell.ts +12 -10
  221. package/src/apps/{shell → cli}/commands/mongodb/projectMongoPortForward.ts +13 -8
  222. package/src/apps/{shell → cli}/commands/mongodb/utils/index.ts +9 -8
  223. package/src/apps/{shell → cli}/commands/project/commandCloudSqlProxy.ts +23 -17
  224. package/src/apps/cli/commands/project/commandConfigSecrets.ts +208 -0
  225. package/src/apps/{shell → cli}/commands/project/commandCopyDB.ts +22 -23
  226. package/src/apps/{shell → cli}/commands/project/commandDeletePods.ts +8 -9
  227. package/src/apps/{shell → cli}/commands/project/commandDeleteProject.ts +7 -8
  228. package/src/apps/cli/commands/project/commandEnvVars.ts +15 -0
  229. package/src/apps/{shell → cli}/commands/project/commandGetMyTotalWorktime.ts +2 -2
  230. package/src/apps/{shell → cli}/commands/project/commandGetShell.ts +10 -10
  231. package/src/apps/{shell → cli}/commands/project/commandGitlabCi.ts +1 -1
  232. package/src/apps/cli/commands/project/commandInitGitlab.ts +203 -0
  233. package/src/apps/{shell → cli}/commands/project/commandInitProject.ts +14 -6
  234. package/src/apps/cli/commands/project/commandListPods.ts +18 -0
  235. package/src/apps/{shell → cli}/commands/project/commandMigrateHelm3.ts +16 -7
  236. package/src/apps/cli/commands/project/commandNamespace.ts +14 -0
  237. package/src/apps/{shell → cli}/commands/project/commandOpenCostDashboard.ts +10 -7
  238. package/src/apps/cli/commands/project/commandOpenDashboard.ts +45 -0
  239. package/src/apps/cli/commands/project/commandOpenEnv.ts +22 -0
  240. package/src/apps/{shell → cli}/commands/project/commandOpenGit.ts +1 -1
  241. package/src/apps/{shell → cli}/commands/project/commandOpenGrafana.ts +7 -7
  242. package/src/apps/{shell → cli}/commands/project/commandOpenGrafanaPod.ts +9 -10
  243. package/src/apps/{shell → cli}/commands/project/commandOpenLogs.ts +7 -7
  244. package/src/apps/{shell → cli}/commands/project/commandPauseProject.ts +9 -7
  245. package/src/apps/{shell → cli}/commands/project/commandPortForward.ts +8 -8
  246. package/src/apps/cli/commands/project/commandReloadConfig.ts +12 -0
  247. package/src/apps/{shell → cli}/commands/project/commandTriggerCronjob.ts +7 -7
  248. package/src/apps/{shell → cli}/commands/project/index.ts +4 -3
  249. package/src/apps/cli/commands/project/utils/autocompletions.ts +26 -0
  250. package/src/apps/cli/commands/project/utils/ensureCluster.ts +37 -0
  251. package/src/apps/{shell → cli}/commands/project/utils/ensureNamespace.ts +2 -3
  252. package/src/apps/cli/commands/project/utils/showProjectBanner.ts +11 -0
  253. package/src/apps/{shell → cli}/commands/shared/index.ts +0 -0
  254. package/src/apps/{shell → cli}/commands/theStuffThatReallyMatters/index.ts +11 -11
  255. package/src/apps/cli/config/writeConfig.ts +69 -0
  256. package/src/apps/{shell → cli}/utils/getGoogleAuthUserNumber.ts +0 -0
  257. package/src/apps/cli/verify/index.ts +34 -0
  258. package/src/apps/cli/verify/migration/fromv2.ts +241 -0
  259. package/src/apps/cli/verify/migration/migrateSecrets.ts +37 -0
  260. package/src/apps/cli/verify/migration/oldGitlabCi.ts +43 -0
  261. package/src/catenv.ts +3 -0
  262. package/src/cli.ts +8 -0
  263. package/src/config/getProjectConfig.ts +118 -0
  264. package/src/types/types.ts +0 -2
  265. package/src/utils/cluster.ts +15 -2
  266. package/src/utils/editAsFile.ts +31 -0
  267. package/src/utils/files.ts +6 -2
  268. package/src/utils/gitlab.ts +126 -32
  269. package/src/utils/passwordstore/index.ts +19 -21
  270. package/src/utils/preferences/index.ts +6 -3
  271. package/src/utils/projects/index.ts +14 -134
  272. package/tsconfig.json +3 -7
  273. package/bin/catenv.sh +0 -1
  274. package/src/apps/shell/commands/project/commandConfigSecrets.ts +0 -245
  275. package/src/apps/shell/commands/project/commandEnvVars.ts +0 -17
  276. package/src/apps/shell/commands/project/commandInitGitlab.ts +0 -157
  277. package/src/apps/shell/commands/project/commandListPods.ts +0 -21
  278. package/src/apps/shell/commands/project/commandNamespace.ts +0 -12
  279. package/src/apps/shell/commands/project/commandOpenDashboard.ts +0 -27
  280. package/src/apps/shell/commands/project/commandOpenEnv.ts +0 -18
  281. package/src/apps/shell/commands/project/commandVariables.ts +0 -13
  282. package/src/apps/shell/commands/project/utils/autocompletions.ts +0 -7
  283. package/src/apps/shell/commands/project/utils/ensureCluster.ts +0 -31
  284. package/src/apps/shell/commands/project/utils/monorepo.ts +0 -45
  285. package/src/index.ts +0 -17
  286. package/src/types/git-repo-name.d.ts +0 -1
  287. package/src/types/yawn-yaml.d.ts +0 -1
  288. package/src/utils/dashboardToken.ts +0 -20
@@ -22,15 +22,16 @@ import commandPauseProject from "./commandPauseProject";
22
22
  import commandOpenGrafana from "./commandOpenGrafana";
23
23
  import commandPortForward from "./commandPortForward";
24
24
  import commandTriggerCronjob from "./commandTriggerCronjob";
25
- import commandVariables from "./commandVariables";
25
+
26
26
  import commandOpenGrafanaPod from "./commandOpenGrafanaPod";
27
+ import commandReloadConfig from "./commandReloadConfig";
27
28
 
28
- export default (vorpal: Vorpal) => {
29
+ export default async (vorpal: Vorpal) => {
30
+ commandReloadConfig(vorpal);
29
31
  commandInitProject(vorpal);
30
32
  commandInitGitlab(vorpal);
31
33
  commandEnvVars(vorpal);
32
34
 
33
- commandVariables(vorpal);
34
35
  commandNamespace(vorpal);
35
36
  commandListPods(vorpal);
36
37
  commandPauseProject(vorpal);
@@ -0,0 +1,26 @@
1
+ import { getAllEnvs, getAllEnvsInAllComponents } from "@catladder/pipeline";
2
+ import {
3
+ getAllComponentsWithAllEnvs,
4
+ getProjectConfig,
5
+ } from "../../../../../config/getProjectConfig";
6
+
7
+ export const allEnvs = async () => {
8
+ const config = await getProjectConfig();
9
+ if (!config) {
10
+ return [];
11
+ }
12
+ return getAllEnvsInAllComponents(config);
13
+ };
14
+
15
+ export const envAndComponents = async () => {
16
+ const allEnvAndcomponents = await getAllComponentsWithAllEnvs();
17
+
18
+ return allEnvAndcomponents.reduce<string[]>(
19
+ (acc, { env, componentName }) => [...acc, env + ":" + componentName],
20
+ []
21
+ );
22
+ };
23
+
24
+ export const allEnvsAndAllComponents = async () => {
25
+ return [...(await allEnvs()), ...(await envAndComponents())];
26
+ };
@@ -0,0 +1,37 @@
1
+ import { isOfDeployType } from "@catladder/pipeline";
2
+ import {
3
+ getPipelineContextByChoice,
4
+ parseChoice,
5
+ } from "../../../../../config/getProjectConfig";
6
+ import {
7
+ connectToCluster,
8
+ getCurrentConnectedClusterName,
9
+ } from "../../../../../utils/cluster";
10
+ export default async function (envComponent: string) {
11
+ const { env, componentName } = parseChoice(envComponent);
12
+ const context = await getPipelineContextByChoice(env, componentName);
13
+ if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
14
+ throw new Error("can't ensure cluster for non-kubernetes deployments");
15
+ }
16
+ const cluster = context.componentConfig.deploy.cluster || "production";
17
+ const connectedClusterName = await getCurrentConnectedClusterName();
18
+
19
+ if (cluster !== connectedClusterName) {
20
+ this.log(
21
+ `you are currently connected to cluster '${connectedClusterName}'`
22
+ );
23
+ this.log(`but the project requires cluster '${cluster}'`);
24
+ const { shouldContinue } = await this.prompt({
25
+ type: "confirm",
26
+ name: "shouldContinue",
27
+ default: true,
28
+ message: `Do you want to connect to '${cluster}'?`,
29
+ });
30
+ if (!shouldContinue) {
31
+ this.log("abort");
32
+ } else {
33
+ await connectToCluster(cluster);
34
+ this.log(`connected to cluster '${cluster}'`);
35
+ }
36
+ }
37
+ }
@@ -1,10 +1,9 @@
1
1
  import { V1Namespace, V1ObjectMeta } from "@kubernetes/client-node";
2
2
  import k8sApi from "../../../../../k8sApi";
3
- import { Env } from "../../../../../types/types";
4
3
  import { getProjectNamespace } from "../../../../../utils/projects/index";
5
4
 
6
- export default async function (env: Env) {
7
- const namespace = await getProjectNamespace(env);
5
+ export default async function (envComponent: string) {
6
+ const namespace = await getProjectNamespace(envComponent);
8
7
  try {
9
8
  await k8sApi.readNamespace(namespace);
10
9
  } catch (e) {
@@ -0,0 +1,11 @@
1
+ import Vorpal from "vorpal";
2
+ import { getProjectConfig } from "../../../../../config/getProjectConfig";
3
+
4
+ export const showProjectBanner = async (vorpal: Vorpal) => {
5
+ const projectConfig = await getProjectConfig();
6
+ if (projectConfig) {
7
+ vorpal.log("project: " + projectConfig.appName);
8
+ vorpal.log("customer: " + projectConfig.customerName);
9
+ vorpal.log("");
10
+ }
11
+ };
File without changes
@@ -2,31 +2,31 @@ import { spawn } from "child-process-promise";
2
2
  import fetch from "node-fetch";
3
3
  import Vorpal from "vorpal";
4
4
 
5
- export default (vorpal: Vorpal) => {
6
- vorpal.command("dadjoke", "something for jonas.").action(async function() {
5
+ export default async (vorpal: Vorpal) => {
6
+ vorpal.command("dadjoke", "something for jonas.").action(async function () {
7
7
  const result = await fetch("https://icanhazdadjoke.com/", {
8
8
  headers: {
9
- Accept: "text/plain"
10
- }
9
+ Accept: "text/plain",
10
+ },
11
11
  });
12
12
  const text = await result.text();
13
13
  this.log("");
14
14
  this.log(text);
15
15
  this.log("");
16
16
  });
17
- vorpal.command("pantobot", "the allknowing oracle").action(async function() {
17
+ vorpal.command("pantobot", "the allknowing oracle").action(async function () {
18
18
  const { message } = await this.prompt({
19
19
  type: "string",
20
20
  name: "message",
21
21
 
22
- message: "Your question, unworthy?: "
22
+ message: "Your question, unworthy?: ",
23
23
  });
24
24
  const result = await fetch(
25
25
  `https://paas.panter.cloud/api/pantobot/${message}`,
26
26
  {
27
27
  headers: {
28
- Accept: "text/plain"
29
- }
28
+ Accept: "text/plain",
29
+ },
30
30
  }
31
31
  );
32
32
  const text = await result.text();
@@ -37,15 +37,15 @@ export default (vorpal: Vorpal) => {
37
37
  let starwarsPromise: any;
38
38
  vorpal
39
39
  .command("starwars", "Long time ago... in a galaxy far far away...")
40
- .action(async function() {
40
+ .action(async function () {
41
41
  starwarsPromise = spawn("telnet", ["towel.blinkenlights.nl"], {
42
- stdio: ["pipe", "inherit", "pipe"]
42
+ stdio: ["pipe", "inherit", "pipe"],
43
43
  });
44
44
  await starwarsPromise;
45
45
  })
46
46
  // we need to close it properly, because telnet towel.blinkenlights.nl has no way to cancel and stop itself
47
47
  // this is also why we need to only inherit the stdout and not the stdin
48
- .cancel(async function() {
48
+ .cancel(async function () {
49
49
  starwarsPromise.childProcess.kill();
50
50
  });
51
51
  };
@@ -0,0 +1,69 @@
1
+ import { Config } from "@catladder/pipeline";
2
+ import { spawn, exec } from "child-process-promise";
3
+ import { writeFile } from "fs-extra";
4
+ import { dump } from "js-yaml";
5
+ import { format } from "prettier";
6
+ import { CommandInstance } from "vorpal";
7
+ import { getGitRoot } from "../../../utils/projects";
8
+
9
+ export const writeConfig = async (
10
+ vorpal: CommandInstance,
11
+ config: Config,
12
+ options?: {
13
+ endComment?: string;
14
+ }
15
+ ) => {
16
+ const gitRoot = await getGitRoot();
17
+ const TS = "typescript (recommended)";
18
+ const { configType } = await vorpal.prompt({
19
+ type: "list",
20
+ name: "configType",
21
+ choices: [TS, "yaml"],
22
+ message: "In which format do you want the config? 🤔",
23
+ });
24
+ vorpal.log("");
25
+ if (configType === TS) {
26
+ const content = format(
27
+ `
28
+ import type { Config } from "@catladder/pipeline";
29
+
30
+ const config: Config = ${JSON.stringify(config)};
31
+
32
+ export default config;
33
+
34
+
35
+ ${options?.endComment ? `/*${options.endComment}*/` : ""}
36
+
37
+ `,
38
+ {
39
+ parser: "babel",
40
+ }
41
+ );
42
+
43
+ await writeFile(gitRoot + "/catladder.ts", content, {
44
+ encoding: "utf-8",
45
+ });
46
+ vorpal.log("adding type @catladder/pipeline....");
47
+ await spawn("yarn add @catladder/pipeline -DW", {
48
+ shell: true,
49
+ });
50
+ await exec("git add " + gitRoot + "/catladder.ts");
51
+ } else {
52
+ const content = dump(config);
53
+
54
+ await writeFile(
55
+ gitRoot + "/catladder.yml",
56
+ content +
57
+ "\n\n" +
58
+ (options.endComment
59
+ ? "# " + options.endComment.split("\n").join("\n# ")
60
+ : ""),
61
+ {
62
+ encoding: "utf-8",
63
+ }
64
+ );
65
+ await exec("git add " + gitRoot + "/catladder.ts");
66
+ }
67
+ vorpal.log("done!");
68
+ vorpal.log("");
69
+ };
@@ -0,0 +1,34 @@
1
+ import Vorpal from "vorpal";
2
+ import {
3
+ getGitlabCi,
4
+ getProjectConfig,
5
+ } from "../../../config/getProjectConfig";
6
+ import { hasGitlabToken, setupGitlabToken } from "../../../utils/gitlab";
7
+ import { migrateV2 } from "./migration/fromv2";
8
+
9
+ export const verify = async (vorpal: Vorpal) => {
10
+ // check if has all settings
11
+
12
+ if (!(await hasGitlabToken())) {
13
+ vorpal.command("setup-gitlab-token").action(async function () {
14
+ await setupGitlabToken(this);
15
+ });
16
+ vorpal.exec("setup-gitlab-token");
17
+ }
18
+
19
+ const projectConfig = await getProjectConfig();
20
+ try {
21
+ const gitlabCi = getGitlabCi();
22
+
23
+ if (!gitlabCi) {
24
+ vorpal.log("not initialized");
25
+ }
26
+
27
+ if (!projectConfig) {
28
+ vorpal.log("no project config, needs migration");
29
+ await migrateV2(vorpal);
30
+ }
31
+ } catch (e) {
32
+ // no gitroot, ignore
33
+ }
34
+ };
@@ -0,0 +1,241 @@
1
+ import {
2
+ BuildConfig,
3
+ ComponentConfig,
4
+ Config,
5
+ DeployConfigKubernetes,
6
+ Env,
7
+ } from "@catladder/pipeline";
8
+ import {
9
+ existsSync,
10
+ lstatSync,
11
+ readdirSync,
12
+ readFile,
13
+ writeFile,
14
+ } from "fs-extra";
15
+ import { isEmpty } from "lodash";
16
+ import { join } from "path";
17
+ import Vorpal from "vorpal";
18
+ import {
19
+ getGitlabCi,
20
+ getGitlabCiFilePath,
21
+ } from "../../../../config/getProjectConfig";
22
+ import { readYaml } from "../../../../utils/files";
23
+ import { syncBitwarden } from "../../../../utils/passwordstore";
24
+ import { getGitRoot } from "../../../../utils/projects";
25
+ import { writeConfig } from "../../config/writeConfig";
26
+ import { migrateSecrets } from "./migrateSecrets";
27
+ import { detectBuildConfig, OldGitlabCiFile } from "./oldGitlabCi";
28
+ export const LEGACY_ENVS = [
29
+ "dev-local",
30
+ "dev",
31
+ "review",
32
+ "stage",
33
+ "prod",
34
+ ] as const;
35
+
36
+ const arrayToRecord = (arr: { name: string }[]): Record<string, any> => {
37
+ if (!arr) return undefined;
38
+ return Object.fromEntries(arr.map(({ name, ...rest }) => [name, rest]));
39
+ };
40
+
41
+ const transformVars = (rawVars: {
42
+ public: Record<string, any>;
43
+ secret: Record<string, any>;
44
+ fromCommponents: any;
45
+ }) => {
46
+ if (rawVars.fromCommponents) {
47
+ console.warn("cant transform legacy fromCommponents");
48
+ }
49
+
50
+ return {
51
+ public: rawVars.public,
52
+ secret: rawVars.secret ? Object.keys(rawVars.secret) : undefined,
53
+ };
54
+ };
55
+
56
+ const getLegacyMonorepoSubCiFiles = (dir: string) => {
57
+ return readdirSync(dir)
58
+ .filter((file) => lstatSync(file).isDirectory())
59
+ .map((dir) => ({
60
+ dir,
61
+ ci: join(dir, ".gitlab-ci.yml"),
62
+ }))
63
+ .filter(({ ci }) => existsSync(ci));
64
+ };
65
+
66
+ const transformValues = (
67
+ valuesIn: Record<string, any>
68
+ ): DeployConfigKubernetes["values"] => {
69
+ if (isEmpty(valuesIn)) {
70
+ return undefined;
71
+ }
72
+ delete valuesIn?.application?.hostname;
73
+ delete valuesIn?.application?.command;
74
+
75
+ return {
76
+ ...valuesIn,
77
+ jobs: arrayToRecord(valuesIn?.jobs),
78
+ cronjobs: arrayToRecord(valuesIn?.cronjobs),
79
+ };
80
+ };
81
+ export const migrateV2 = async (vorpal: Vorpal) => {
82
+ const gitlabCi = await getGitlabCi<OldGitlabCiFile>();
83
+ const gitRoot = await getGitRoot();
84
+
85
+ const {
86
+ CUSTOMER_NAME,
87
+ APP_NAME,
88
+ COMPONENT_NAME,
89
+ APP_DIR = ".",
90
+ CLUSTER_NAME,
91
+ STAGING_ENABLED,
92
+ } = gitlabCi.variables;
93
+
94
+ vorpal
95
+ .command("migrate")
96
+
97
+ .action(async function () {
98
+ this.log("");
99
+ this.log("⚠️ this project uses legacy catladder (v2)");
100
+ this.log("");
101
+ this.log(
102
+ "😼 I can migrate the project for you. This contains the following steps:"
103
+ );
104
+ this.log("");
105
+ this.log(
106
+ " - migrate the config from values-*.yml to catladder config file"
107
+ );
108
+ this.log(
109
+ " - migrate the secrets from bitwarden to gitlab (this will trash the entries in bitwarden)"
110
+ );
111
+ this.log("");
112
+ this.log(
113
+ "☝ make sure that you checked in your current state in case something goes wrong."
114
+ );
115
+ this.log(
116
+ "☝ secrets in bitwarden are deleted, but can be restored within 30 days."
117
+ );
118
+ this.log("");
119
+ const { shouldContinue } = await this.prompt({
120
+ default: true,
121
+ message: "Migrate project now? 🤔",
122
+ name: "shouldContinue",
123
+ type: "confirm",
124
+ });
125
+ vorpal.log("");
126
+ vorpal.log("");
127
+ vorpal.log("💪😼 ok, let's go...");
128
+ vorpal.log("");
129
+ vorpal.log("");
130
+
131
+ if (shouldContinue) {
132
+ const createComponent = async (
133
+ dir: string,
134
+ ciFile: OldGitlabCiFile
135
+ ): Promise<ComponentConfig> => {
136
+ const { env, ...baseValues } =
137
+ (await readYaml(dir + "/values.yml")) ?? {};
138
+
139
+ const startCommand = baseValues?.application?.command?.join(" ");
140
+ return {
141
+ vars: env ? transformVars(env) : undefined,
142
+ dir: dir,
143
+ build: {
144
+ type: detectBuildConfig(ciFile),
145
+ startCommand: startCommand,
146
+ } as BuildConfig,
147
+ deploy: {
148
+ type: "kubernetes",
149
+ values: transformValues(baseValues),
150
+ cluster: CLUSTER_NAME,
151
+ },
152
+ env: await LEGACY_ENVS.reduce<Promise<Env>>(
153
+ async (acc, envName) => {
154
+ if (envName === "stage" && !STAGING_ENABLED) {
155
+ return {
156
+ ...(await acc),
157
+ [envName]: false,
158
+ };
159
+ }
160
+ const newEnvName = envName === "dev-local" ? "local" : envName;
161
+
162
+ const envValues =
163
+ (await readYaml(dir + `/values-${envName}.yml`)) ?? {};
164
+ const { env, ...rest } = envValues;
165
+ const hostname = rest?.application?.hostname;
166
+ const values = transformValues(rest);
167
+ return {
168
+ ...(await acc),
169
+ [newEnvName]: {
170
+ hostname: hostname,
171
+ vars: env ? transformVars(env) : undefined,
172
+ deploy: values
173
+ ? {
174
+ values: values,
175
+ }
176
+ : undefined,
177
+ },
178
+ };
179
+ },
180
+ Promise.resolve({})
181
+ ),
182
+ };
183
+ };
184
+ let components: Record<string, ComponentConfig>;
185
+ if (detectBuildConfig(gitlabCi) === "monorepo") {
186
+ components = await getLegacyMonorepoSubCiFiles(gitRoot).reduce<
187
+ Promise<Record<string, ComponentConfig>>
188
+ >(async (acc, el) => {
189
+ return {
190
+ ...(await acc),
191
+ [el.dir]: await createComponent(el.dir, await readYaml(el.ci)),
192
+ };
193
+ }, Promise.resolve({}));
194
+ } else {
195
+ components = {
196
+ [COMPONENT_NAME]: await createComponent(APP_DIR, gitlabCi),
197
+ };
198
+ }
199
+ // we only have one component
200
+ const config: Config = {
201
+ customerName: CUSTOMER_NAME,
202
+ appName: APP_NAME,
203
+ components,
204
+ };
205
+
206
+ const comment =
207
+ "Old migrated config:\n\n" +
208
+ (await readFile(await getGitlabCiFilePath(), {
209
+ encoding: "utf-8",
210
+ }));
211
+
212
+ this.log("-------------------");
213
+ this.log("migrate config");
214
+ await writeConfig(this, config, {
215
+ endComment: comment,
216
+ });
217
+ this.log("write gitlab-ci.yml");
218
+ await writeFile(
219
+ await getGitlabCiFilePath(),
220
+ "include: https://git.panter.ch/api/v4/projects/catladder%2Fcatladder/packages/generic/ci-includes/main/gitlab-ci.yml",
221
+ { encoding: "utf-8" }
222
+ );
223
+
224
+ this.log("-------------------");
225
+ this.log("migrate secrets");
226
+ await syncBitwarden();
227
+ for (const env of LEGACY_ENVS) {
228
+ if (env === "stage" && !STAGING_ENABLED) return;
229
+ await migrateSecrets(this, config, env);
230
+ }
231
+
232
+ this.log("-------------------");
233
+
234
+ this.log("done!");
235
+
236
+ this.log("-------------------");
237
+ }
238
+ });
239
+
240
+ vorpal.exec("migrate");
241
+ };
@@ -0,0 +1,37 @@
1
+ import { Config, getEnvironment } from "@catladder/pipeline";
2
+ import { load } from "js-yaml";
3
+ import { pick } from "lodash";
4
+ import { CommandInstance } from "vorpal";
5
+ import { upsertAllVariables } from "../../../../utils/gitlab";
6
+ import { readPass, trashItem } from "../../../../utils/passwordstore";
7
+ import { LEGACY_ENVS } from "./fromv2";
8
+
9
+ const getPassPath = (newConfig: Config, env: string) => {
10
+ return `${newConfig.customerName}/${newConfig.appName}/${env}/secrets.yml`;
11
+ };
12
+
13
+ export const migrateSecrets = async (
14
+ vorpal: CommandInstance,
15
+ newConfig: Config,
16
+ oldEnv: typeof LEGACY_ENVS[number]
17
+ ) => {
18
+ const newEnv = oldEnv === "dev-local" ? "local" : oldEnv;
19
+ const path = getPassPath(newConfig, oldEnv);
20
+ try {
21
+ const yamlstring = await readPass(path);
22
+ const secrets = load(yamlstring);
23
+
24
+ Object.keys(newConfig.components).forEach(async (componentName) => {
25
+ const environment = getEnvironment(newConfig, componentName, newEnv);
26
+ await upsertAllVariables(
27
+ vorpal,
28
+ pick(secrets, environment.secretEnvVarKeys),
29
+ newEnv,
30
+ componentName
31
+ );
32
+ });
33
+ await trashItem(path);
34
+ } catch (e) {
35
+ console.warn(`could not migrate secrets for env '${oldEnv}': ${e}`);
36
+ }
37
+ };
@@ -0,0 +1,43 @@
1
+ import { BuildConfig } from "@catladder/pipeline";
2
+
3
+ export type OldGitlabCiFile = {
4
+ variables: {
5
+ CUSTOMER_NAME: string;
6
+ APP_NAME: string;
7
+ COMPONENT_NAME?: string;
8
+ APP_DIR?: string;
9
+ CLUSTER_NAME?: string;
10
+ STAGING_ENABLED?: string;
11
+ };
12
+ include: {
13
+ project: string;
14
+ ref: string;
15
+ file: string;
16
+ }[];
17
+ };
18
+
19
+ export const detectBuildConfig = (
20
+ gitlabCi: OldGitlabCiFile
21
+ ): BuildConfig["type"] | "monorepo" => {
22
+ const firstInclude = gitlabCi.include[0];
23
+ if (!firstInclude || gitlabCi.include[0]?.project !== "catladder/gitlab-ci") {
24
+ throw new Error("unsupported gitlab-ci file");
25
+ }
26
+
27
+ if (firstInclude.file === "monorepo.yml") return "monorepo";
28
+
29
+ if (firstInclude.file === "node-kubernetes.yml") {
30
+ return "node";
31
+ }
32
+
33
+ if (firstInclude.file === "static-js-kubernetes.yml") {
34
+ return "node-static";
35
+ }
36
+ if (firstInclude.file === "meteor-kubernetes.yml") {
37
+ return "meteor";
38
+ }
39
+
40
+ if (firstInclude.file === "rails-kubernetes.yml") {
41
+ throw new Error("rails is not yet implemented");
42
+ }
43
+ };
package/src/catenv.ts ADDED
@@ -0,0 +1,3 @@
1
+ import catenv from "./apps/catenv/catenv";
2
+
3
+ catenv();
package/src/cli.ts ADDED
@@ -0,0 +1,8 @@
1
+ import updateNotifier from "update-notifier";
2
+ import cli from "./apps/cli/cli";
3
+ import packageInfos from "./packageInfos";
4
+
5
+ updateNotifier({
6
+ pkg: packageInfos,
7
+ }).notify();
8
+ cli();