@catladder/cli 0.0.0-refactor-cli-add-improved-git-utilities-fba867df → 0.0.0-refactor-remove-rails-hosts-afe04cf0

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 (119) hide show
  1. package/dist/bundles/catci/index.js +43322 -44345
  2. package/dist/bundles/catenv/index.js +27561 -43984
  3. package/dist/bundles/cli/index.js +81346 -97135
  4. package/dist/cli/src/apps/catenv/catenv.js +1 -1
  5. package/dist/cli/src/apps/catenv/catenv.js.map +1 -1
  6. package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.d.ts +1 -2
  7. package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js +1 -3
  8. package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -1
  9. package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js +2 -4
  10. package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -1
  11. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.d.ts +1 -2
  12. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js +9 -23
  13. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -1
  14. package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js +4 -6
  15. package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js.map +1 -1
  16. package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -1
  17. package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js +4 -3
  18. package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -1
  19. package/dist/cli/src/packageInfos.js +0 -1
  20. package/dist/cli/src/packageInfos.js.map +1 -1
  21. package/dist/cli/src/utils/gitlab.d.ts +7 -10
  22. package/dist/cli/src/utils/gitlab.js +45 -67
  23. package/dist/cli/src/utils/gitlab.js.map +1 -1
  24. package/dist/cli/src/utils/preferences/index.d.ts +3 -0
  25. package/dist/cli/src/utils/preferences/index.js +35 -0
  26. package/dist/cli/src/utils/preferences/index.js.map +1 -0
  27. package/dist/pipeline/src/build/cache/createJobCache.js +2 -2
  28. package/dist/pipeline/src/build/cache/createJobCache.js.map +1 -1
  29. package/dist/pipeline/src/build/sbom.js +2 -2
  30. package/dist/pipeline/src/build/sbom.js.map +1 -1
  31. package/dist/pipeline/src/build/types.d.ts +3 -3
  32. package/dist/pipeline/src/config/readConfig.js +0 -1
  33. package/dist/pipeline/src/config/readConfig.js.map +1 -1
  34. package/dist/pipeline/src/context/createComponentContext.js +1 -1
  35. package/dist/pipeline/src/context/createComponentContext.js.map +1 -1
  36. package/dist/pipeline/src/context/getEnvironmentVariables.d.ts +1 -1
  37. package/dist/pipeline/src/context/getEnvironmentVariables.js +1 -5
  38. package/dist/pipeline/src/context/getEnvironmentVariables.js.map +1 -1
  39. package/dist/pipeline/src/deploy/base/deploy.js +3 -3
  40. package/dist/pipeline/src/deploy/base/deploy.js.map +1 -1
  41. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js +1 -1
  42. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js.map +1 -1
  43. package/dist/pipeline/src/deploy/types/index.d.ts +3 -3
  44. package/dist/pipeline/src/pipeline/createMainPipeline.js +13 -7
  45. package/dist/pipeline/src/pipeline/createMainPipeline.js.map +1 -1
  46. package/dist/pipeline/src/pipeline/generatePipelineFiles.d.ts +7 -40
  47. package/dist/pipeline/src/pipeline/generatePipelineFiles.js +69 -42
  48. package/dist/pipeline/src/pipeline/generatePipelineFiles.js.map +1 -1
  49. package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.d.ts +6 -4
  50. package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.d.ts +0 -2
  51. package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js +2 -4
  52. package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js.map +1 -1
  53. package/dist/pipeline/src/pipeline/index.d.ts +0 -1
  54. package/dist/pipeline/src/pipeline/index.js +0 -1
  55. package/dist/pipeline/src/pipeline/index.js.map +1 -1
  56. package/dist/pipeline/src/types/config.d.ts +3 -3
  57. package/dist/pipeline/src/types/gitlab-types.d.ts +2 -1
  58. package/dist/pipeline/src/types/pipeline.d.ts +0 -1
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +14 -13
  61. package/src/apps/catenv/catenv.ts +1 -1
  62. package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +1 -11
  63. package/src/apps/cli/commands/project/setup/setupCloudRun.ts +2 -4
  64. package/src/apps/cli/commands/project/setup/setupKubernetes.ts +27 -30
  65. package/src/apps/cli/commands/project/setup/setupTopic.ts +11 -6
  66. package/src/apps/cli/utils/getGoogleAuthUserNumber.ts +4 -6
  67. package/src/packageInfos.ts +0 -1
  68. package/src/utils/gitlab.ts +101 -99
  69. package/src/utils/preferences/index.ts +36 -0
  70. package/dist/cli/src/git/getGitConfigVars.d.ts +0 -4
  71. package/dist/cli/src/git/getGitConfigVars.js +0 -14
  72. package/dist/cli/src/git/getGitConfigVars.js.map +0 -1
  73. package/dist/cli/src/git/getGitRemoteHostAndPath.d.ts +0 -9
  74. package/dist/cli/src/git/getGitRemoteHostAndPath.js +0 -23
  75. package/dist/cli/src/git/getGitRemoteHostAndPath.js.map +0 -1
  76. package/dist/cli/src/git/getProjectRootPath.d.ts +0 -1
  77. package/dist/cli/src/git/getProjectRootPath.js +0 -10
  78. package/dist/cli/src/git/getProjectRootPath.js.map +0 -1
  79. package/dist/cli/src/git/gitConfig.d.ts +0 -23
  80. package/dist/cli/src/git/gitConfig.js +0 -60
  81. package/dist/cli/src/git/gitConfig.js.map +0 -1
  82. package/dist/cli/src/git/index.d.ts +0 -4
  83. package/dist/cli/src/git/index.js +0 -21
  84. package/dist/cli/src/git/index.js.map +0 -1
  85. package/dist/cli/src/gitlab/apiClient.d.ts +0 -5
  86. package/dist/cli/src/gitlab/apiClient.js +0 -21
  87. package/dist/cli/src/gitlab/apiClient.js.map +0 -1
  88. package/dist/cli/src/gitlab/getGitlabProjectId.d.ts +0 -4
  89. package/dist/cli/src/gitlab/getGitlabProjectId.js +0 -29
  90. package/dist/cli/src/gitlab/getGitlabProjectId.js.map +0 -1
  91. package/dist/cli/src/gitlab/gitlabToken.d.ts +0 -10
  92. package/dist/cli/src/gitlab/gitlabToken.js +0 -42
  93. package/dist/cli/src/gitlab/gitlabToken.js.map +0 -1
  94. package/dist/cli/src/gitlab/index.d.ts +0 -3
  95. package/dist/cli/src/gitlab/index.js +0 -20
  96. package/dist/cli/src/gitlab/index.js.map +0 -1
  97. package/dist/cli/src/utils/preferences.d.ts +0 -15
  98. package/dist/cli/src/utils/preferences.js +0 -61
  99. package/dist/cli/src/utils/preferences.js.map +0 -1
  100. package/dist/cli/src/utils/projectPreferences.d.ts +0 -5
  101. package/dist/cli/src/utils/projectPreferences.js +0 -54
  102. package/dist/cli/src/utils/projectPreferences.js.map +0 -1
  103. package/dist/pipeline/src/pipeline/createChildPipeline.d.ts +0 -3
  104. package/dist/pipeline/src/pipeline/createChildPipeline.js +0 -30
  105. package/dist/pipeline/src/pipeline/createChildPipeline.js.map +0 -1
  106. package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +0 -1
  107. package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +0 -32
  108. package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js.map +0 -1
  109. package/src/git/getGitConfigVars.ts +0 -11
  110. package/src/git/getGitRemoteHostAndPath.ts +0 -28
  111. package/src/git/getProjectRootPath.ts +0 -6
  112. package/src/git/gitConfig.ts +0 -86
  113. package/src/git/index.ts +0 -4
  114. package/src/gitlab/apiClient.ts +0 -23
  115. package/src/gitlab/getGitlabProjectId.ts +0 -32
  116. package/src/gitlab/gitlabToken.ts +0 -52
  117. package/src/gitlab/index.ts +0 -3
  118. package/src/utils/preferences.ts +0 -85
  119. package/src/utils/projectPreferences.ts +0 -78
@@ -1,86 +0,0 @@
1
- import { exec } from "child-process-promise";
2
-
3
- const scopes = ["global", "local", "system", "worktree"] as const;
4
- type LocationScope = (typeof scopes)[number];
5
-
6
- type LocationOption = {
7
- location?: LocationScope;
8
- };
9
-
10
- export async function gitConfigGet(key: string, options: LocationOption = {}) {
11
- const optArgs = [options.location ? `--${options.location}` : undefined]
12
- .filter(Boolean)
13
- .join(" ");
14
- const execResult = await exec(`git config get ${optArgs} ${key}`);
15
- return execResult.stdout.trim();
16
- }
17
-
18
- type CommentOption = { comment?: string };
19
-
20
- export function gitConfigSet(
21
- key: string,
22
- value: string,
23
- options: LocationOption & CommentOption = {},
24
- ) {
25
- const optArgs = [
26
- options.location ? `--${options.location}` : undefined,
27
- options.comment ? `--comment=${options.comment}` : undefined,
28
- ]
29
- .filter(Boolean)
30
- .join(" ");
31
- return exec(`git config set ${optArgs} ${key} ${value}`);
32
- }
33
-
34
- const reduceScopelessConfigList = (configList: string[]) =>
35
- configList.reduce(
36
- (acc, line) => {
37
- const [key, value] = line.split("=");
38
- if (!key?.length) {
39
- return acc;
40
- }
41
- return { ...acc, [key]: value };
42
- },
43
- {} as Record<string, string>,
44
- );
45
-
46
- type ByScope = { [scope in LocationScope]?: Record<string, string> };
47
-
48
- const reduceScopedConfigList = (configList: string[]) =>
49
- configList.reduce((acc, line) => {
50
- const [scopeSplit, key_val] = line.split("\t");
51
- const scope = scopeSplit.trim() as LocationScope;
52
- if (!key_val?.length || !scope?.length) {
53
- return acc;
54
- }
55
- const [key, value] = key_val.split("=");
56
- if (!key?.length) {
57
- return acc;
58
- }
59
- acc[scope] = acc[scope] || {};
60
- acc[scope][key] = value;
61
- return acc;
62
- }, {} as ByScope);
63
-
64
- export async function gitConfigList({
65
- byScope = false,
66
- location,
67
- }: {
68
- /**
69
- * Returns the config values by location scope.
70
- * Only has an effect if the location is set.
71
- */
72
- byScope?: boolean;
73
- } & LocationOption = {}): Promise<Record<string, string> | ByScope> {
74
- const showScope = !location && byScope;
75
- const optArgs = [
76
- location ? `--${location}` : undefined,
77
- showScope ? "--show-scope" : undefined,
78
- ]
79
- .filter(Boolean)
80
- .join(" ");
81
- const configListOutput = await exec(`git config list ${optArgs}`);
82
- const configList = configListOutput.stdout.trim().split("\n");
83
- return showScope
84
- ? reduceScopedConfigList(configList)
85
- : reduceScopelessConfigList(configList);
86
- }
package/src/git/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from "./getGitConfigVars";
2
- export * from "./getGitRemoteHostAndPath";
3
- export * from "./getProjectRootPath";
4
- export * from "./gitConfig";
@@ -1,23 +0,0 @@
1
- import { Gitlab } from "@gitbeaker/rest";
2
- import { getGitlabToken } from "./gitlabToken";
3
-
4
- export type GitlabRestClient = InstanceType<typeof Gitlab<false>>;
5
-
6
- export const gitlabApiClient = async ({
7
- gitlabHost,
8
- }: {
9
- gitlabHost?: string;
10
- } = {}): Promise<GitlabRestClient> => {
11
- const { token, gitRemoteHost } = await getGitlabToken(gitlabHost);
12
- if (typeof token !== "string") {
13
- throw new Error("Gitlab personal access token is missing!");
14
- }
15
- if (!gitRemoteHost) {
16
- throw new Error("no gitlab host found");
17
- }
18
- return new Gitlab({
19
- token,
20
- host: `https://${gitRemoteHost}`,
21
- camelize: false,
22
- });
23
- };
@@ -1,32 +0,0 @@
1
- import type { ProjectSchema } from "@gitbeaker/rest";
2
- import { getGitRemoteHostAndPath } from "../git/getGitRemoteHostAndPath";
3
- import type { GitlabRestClient } from "./apiClient";
4
- import { gitlabApiClient } from "./apiClient";
5
- import {
6
- upsertProjectPerferences,
7
- getProjectPreferences,
8
- } from "../utils/projectPreferences";
9
-
10
- export const getGitlabProjectInfo = async (
11
- existingInstance?: GitlabRestClient,
12
- ): Promise<ProjectSchema> => {
13
- const api = existingInstance ?? (await gitlabApiClient());
14
- const { gitRemotePath } = await getGitRemoteHostAndPath();
15
- const projectInfo = await api.Projects.show(gitRemotePath, {
16
- statistics: false,
17
- withCustomAttributes: false,
18
- license: false,
19
- });
20
- // write unawaited intentionally
21
- upsertProjectPerferences({ gitlabProjectId: projectInfo.id });
22
- return projectInfo;
23
- };
24
-
25
- export const getGitlabProjectId = async (): Promise<number> => {
26
- const { gitlabProjectId } = await getProjectPreferences();
27
- if (gitlabProjectId) {
28
- return gitlabProjectId;
29
- }
30
- const projectInfo = await getGitlabProjectInfo();
31
- return projectInfo.id;
32
- };
@@ -1,52 +0,0 @@
1
- import { getGitRemoteHostAndPath } from "../git";
2
- import {
3
- getPreference,
4
- getPreferences,
5
- setPreference,
6
- } from "../utils/preferences";
7
-
8
- export async function getGitlabToken(hostname?: string) {
9
- const [{ gitRemoteHost }, preferences] = await Promise.all([
10
- hostname?.length
11
- ? Promise.resolve({ gitRemoteHost: hostname })
12
- : getGitRemoteHostAndPath(),
13
- getPreferences(),
14
- ]);
15
- const gitlabTokens = preferences.gitlabTokens ?? {};
16
- const currentPerferencesToken = gitlabTokens[gitRemoteHost];
17
- const token =
18
- currentPerferencesToken ??
19
- preferences["gitlab-personal-access-token"] ??
20
- process.env.GITLAB_TOKEN;
21
- if (
22
- (preferences["gitlab-personal-access-token"]?.length ||
23
- process.env.GITLAB_TOKEN?.length) &&
24
- !currentPerferencesToken?.length
25
- ) {
26
- await setGitlabToken(token, {
27
- hostname: gitRemoteHost,
28
- currentTokens: gitlabTokens,
29
- });
30
- }
31
- return { token, gitRemoteHost };
32
- }
33
-
34
- export async function setGitlabToken(
35
- token: string,
36
- {
37
- hostname,
38
- currentTokens,
39
- }: { hostname?: string; currentTokens?: { [host in string]?: string } } = {},
40
- ) {
41
- const [{ gitRemoteHost }, storedTokens] = await Promise.all([
42
- hostname?.length
43
- ? Promise.resolve({ gitRemoteHost: hostname })
44
- : getGitRemoteHostAndPath(),
45
- currentTokens
46
- ? Promise.resolve(currentTokens)
47
- : getPreference("gitlabTokens"),
48
- ]);
49
- const gitlabTokens = { ...(storedTokens ?? {}), [gitRemoteHost]: token };
50
- await setPreference("gitlabTokens", gitlabTokens);
51
- return gitlabTokens[gitRemoteHost];
52
- }
@@ -1,3 +0,0 @@
1
- export * from "./apiClient";
2
- export * from "./getGitlabProjectId";
3
- export * from "./gitlabToken";
@@ -1,85 +0,0 @@
1
- import { writeFile, readFile, mkdir } from "fs/promises";
2
- import { existsSync } from "fs";
3
- import { homedir } from "os";
4
- import { parse, stringify } from "yaml";
5
- import { join } from "path";
6
-
7
- const directory = join(homedir(), ".catladder");
8
- const file = join(directory, "preferences.yml");
9
-
10
- export type CatladderCliPreferences = {
11
- "gitlab-personal-access-token": string | null;
12
- googleAuthUserNumber: number | null;
13
- gitlabTokens: { [hostname in string]?: string };
14
- };
15
- type PreferenceKey = keyof CatladderCliPreferences;
16
- const perfKeys = [
17
- "gitlab-personal-access-token",
18
- "googleAuthUserNumber",
19
- "gitlabTokens",
20
- ] as const satisfies readonly PreferenceKey[];
21
-
22
- const fallbackValues = {
23
- "gitlab-personal-access-token": null,
24
- gitlabTokens: {},
25
- googleAuthUserNumber: null,
26
- } satisfies CatladderCliPreferences;
27
-
28
- const perferencesWithParsed = (
29
- parsed: Partial<CatladderCliPreferences>,
30
- ): CatladderCliPreferences =>
31
- perfKeys.reduce(
32
- (acc, key) =>
33
- Object.assign(acc, { [key]: parsed[key] ?? fallbackValues[key] }),
34
- {} as CatladderCliPreferences,
35
- );
36
-
37
- const encoding = "utf-8";
38
-
39
- const readPreferences = () => readFile(file, { encoding });
40
-
41
- const writePreferences = (preferences: CatladderCliPreferences) =>
42
- writeFile(file, stringify(preferences), { encoding, mode: 0o600 });
43
-
44
- const ensureDir = async () =>
45
- existsSync(directory)
46
- ? directory
47
- : mkdir(directory, { recursive: true, mode: 0o700 });
48
-
49
- const ensureFile = async () => {
50
- if (existsSync(file)) {
51
- return file;
52
- }
53
- await ensureDir();
54
- return writePreferences(perferencesWithParsed({}));
55
- };
56
-
57
- export const getPreferences = async (): Promise<CatladderCliPreferences> => {
58
- await ensureFile();
59
- const fileString = await readPreferences();
60
- const fileParsed = parse(fileString || "---\nnull") ?? {};
61
- return perferencesWithParsed(fileParsed);
62
- };
63
-
64
- export const hasPreference = async (key: PreferenceKey) => {
65
- const preferences = await getPreferences();
66
- return preferences[key] !== null && preferences[key] !== undefined;
67
- };
68
-
69
- export const getPreference = async <K extends PreferenceKey>(
70
- key: K,
71
- ): Promise<CatladderCliPreferences[K] | null> => {
72
- const preferences = await getPreferences();
73
- if (key in preferences) {
74
- return preferences[key] as CatladderCliPreferences[K];
75
- }
76
- return null;
77
- };
78
-
79
- export const setPreference = async (
80
- key: PreferenceKey,
81
- value: CatladderCliPreferences[typeof key],
82
- ) => {
83
- const preferences = await getPreferences();
84
- return writePreferences({ ...preferences, [key]: value });
85
- };
@@ -1,78 +0,0 @@
1
- import { writeFile, readFile, mkdir } from "fs/promises";
2
- import { existsSync } from "fs";
3
- import { join } from "path";
4
- import { getProjectRootPath } from "../git";
5
-
6
- const directory = ".catladder";
7
- const file = "preferences.json";
8
-
9
- export type CatladderCliProjectPreferences = {
10
- gitlabProjectId?: number | null;
11
- };
12
- type ProjectPreferenceKey = keyof CatladderCliProjectPreferences;
13
- const perfKeys = [
14
- "gitlabProjectId",
15
- ] as const satisfies readonly ProjectPreferenceKey[];
16
- const fallbackValues = {
17
- gitlabProjectId: null,
18
- } satisfies CatladderCliProjectPreferences;
19
-
20
- const perferencesWithParsed = (
21
- parsed: Partial<CatladderCliProjectPreferences>,
22
- ): CatladderCliProjectPreferences =>
23
- perfKeys.reduce(
24
- (acc, key) =>
25
- Object.assign(acc, { [key]: parsed[key] ?? fallbackValues[key] ?? null }),
26
- {} as CatladderCliProjectPreferences,
27
- );
28
-
29
- const encoding = "utf-8";
30
-
31
- const readPreferences = (filePath: string) => readFile(filePath, { encoding });
32
-
33
- const writePreferences = (
34
- filePath: string,
35
- preferences: CatladderCliProjectPreferences,
36
- ) =>
37
- writeFile(filePath, JSON.stringify(preferences, null, 2), {
38
- encoding,
39
- mode: 0o600,
40
- });
41
-
42
- const ensureDir = async (dirPath: string) =>
43
- existsSync(dirPath)
44
- ? dirPath
45
- : mkdir(dirPath, { recursive: true, mode: 0o700 });
46
-
47
- const ensureFile = async (givenFilePath?: string) => {
48
- if (givenFilePath?.length && existsSync(givenFilePath)) {
49
- return givenFilePath;
50
- }
51
- const rootPath = await getProjectRootPath();
52
- const dirPath = join(rootPath, directory);
53
- const filePath = join(dirPath, file);
54
- if (existsSync(filePath)) {
55
- return filePath;
56
- }
57
- await ensureDir(dirPath);
58
- await writePreferences(filePath, perferencesWithParsed({}));
59
- return filePath;
60
- };
61
-
62
- export const getProjectPreferences = async (
63
- givenFilePath?: string,
64
- ): Promise<CatladderCliProjectPreferences> => {
65
- const filePath = await ensureFile(givenFilePath);
66
- const fileString = await readPreferences(filePath);
67
- const fileParsed = JSON.parse(fileString || "null") ?? {};
68
- return perferencesWithParsed(fileParsed);
69
- };
70
-
71
- export const upsertProjectPerferences = async (
72
- newPerfs: Partial<CatladderCliProjectPreferences> = {},
73
- givenFilePath?: string,
74
- ) => {
75
- const filePath = await ensureFile(givenFilePath);
76
- const currentPerfs = await getProjectPreferences(filePath);
77
- return writePreferences(filePath, { ...currentPerfs, ...newPerfs });
78
- };