@catladder/pipeline 1.149.1 → 1.149.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.
- package/dist/build/base/createAppBuildJob.js +1 -2
- package/dist/build/base/writeDotEnv.d.ts +2 -1
- package/dist/build/base/writeDotEnv.js +7 -2
- package/dist/build/node/buildJob.js +4 -4
- package/dist/build/node/cache.js +5 -6
- package/dist/build/node/testJob.js +9 -9
- package/dist/build/node/yarn.js +3 -6
- package/dist/build/sbom.js +4 -4
- package/dist/bundles/catladder-gitlab/index.js +1 -1
- package/dist/constants.js +1 -1
- package/dist/context/createComponentContext.d.ts +15 -0
- package/dist/context/createComponentContext.js +194 -0
- package/dist/context/index.d.ts +2 -17
- package/dist/context/index.js +2 -186
- package/dist/pipeline/createJobsForComponent.d.ts +1 -1
- package/dist/pipeline/createJobsForComponent.js +2 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/context.d.ts +2 -2
- package/package.json +1 -1
- package/src/build/base/createAppBuildJob.ts +5 -2
- package/src/build/base/writeDotEnv.ts +6 -0
- package/src/build/node/buildJob.ts +2 -2
- package/src/build/node/cache.ts +3 -3
- package/src/build/node/testJob.ts +1 -1
- package/src/build/node/yarn.ts +3 -3
- package/src/build/sbom.ts +1 -1
- package/src/context/createComponentContext.ts +96 -0
- package/src/context/index.ts +1 -92
- package/src/pipeline/createJobsForComponent.ts +2 -12
- package/src/types/context.ts +2 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isFunction } from "lodash";
|
|
2
|
+
import { BUILD_TYPES } from "../build";
|
|
3
|
+
import type { BuildConfig, BuildConfigType } from "../build/types";
|
|
4
|
+
import { DEPLOY_TYPES } from "../deploy";
|
|
5
|
+
import type { DeployConfig, DeployConfigType } from "../deploy/types";
|
|
6
|
+
import type { PipelineType } from "../types";
|
|
7
|
+
import type { Config, PipelineTrigger } from "../types/config";
|
|
8
|
+
import type { ComponentContext } from "../types/context";
|
|
9
|
+
import type { PartialDeep } from "../types/utils";
|
|
10
|
+
import { mergeWithMergingArrays } from "../utils";
|
|
11
|
+
import { getEnvironment } from "./getEnvironment";
|
|
12
|
+
import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
13
|
+
import { getPackageManagerInfo } from "../pipeline/packageManager";
|
|
14
|
+
|
|
15
|
+
export type CreateComponentContextContext = {
|
|
16
|
+
config: Config;
|
|
17
|
+
componentName: string;
|
|
18
|
+
env: string;
|
|
19
|
+
pipelineType?: PipelineType;
|
|
20
|
+
trigger?: PipelineTrigger;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const createComponentContext = async (
|
|
24
|
+
ctx: CreateComponentContextContext,
|
|
25
|
+
): Promise<ComponentContext> => {
|
|
26
|
+
if (!/^[a-z0-9-]+$/.test(ctx.componentName)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"componentName may only contain lower case letters, numbers and -",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const packageManagerInfo = await getPackageManagerInfo(
|
|
33
|
+
ctx.config,
|
|
34
|
+
ctx.componentName,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const envContext = getEnvironmentContext(ctx);
|
|
38
|
+
|
|
39
|
+
const componentConfigWithoutDefaults = envContext.envConfigRaw;
|
|
40
|
+
const defaults: {
|
|
41
|
+
build: PartialDeep<BuildConfig>;
|
|
42
|
+
deploy: PartialDeep<DeployConfig>;
|
|
43
|
+
} = componentConfigWithoutDefaults.deploy
|
|
44
|
+
? {
|
|
45
|
+
build:
|
|
46
|
+
BUILD_TYPES[
|
|
47
|
+
componentConfigWithoutDefaults.build.type as BuildConfigType
|
|
48
|
+
].defaults(envContext),
|
|
49
|
+
deploy: DEPLOY_TYPES[
|
|
50
|
+
componentConfigWithoutDefaults.deploy.type as DeployConfigType
|
|
51
|
+
].defaults(envContext as any),
|
|
52
|
+
}
|
|
53
|
+
: {
|
|
54
|
+
build: {},
|
|
55
|
+
deploy: {},
|
|
56
|
+
};
|
|
57
|
+
const componentConfig = mergeWithMergingArrays(
|
|
58
|
+
defaults,
|
|
59
|
+
componentConfigWithoutDefaults,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const environment = await getEnvironment(ctx);
|
|
63
|
+
const { deploy, build, customJobs, dir } = componentConfig;
|
|
64
|
+
const context: Omit<ComponentContext, "customJobs"> = {
|
|
65
|
+
fullConfig: ctx.config,
|
|
66
|
+
componentConfig,
|
|
67
|
+
|
|
68
|
+
build: {
|
|
69
|
+
dir: dir,
|
|
70
|
+
packageManagerInfo: packageManagerInfo,
|
|
71
|
+
config: build,
|
|
72
|
+
},
|
|
73
|
+
deploy: deploy
|
|
74
|
+
? {
|
|
75
|
+
config: deploy,
|
|
76
|
+
}
|
|
77
|
+
: null,
|
|
78
|
+
componentName: ctx.componentName,
|
|
79
|
+
environment,
|
|
80
|
+
packageManagerInfo: packageManagerInfo,
|
|
81
|
+
pipelineType: ctx.pipelineType,
|
|
82
|
+
trigger: ctx.trigger,
|
|
83
|
+
};
|
|
84
|
+
const resolvedCustomJobs = isFunction(customJobs)
|
|
85
|
+
? customJobs(context)
|
|
86
|
+
: customJobs;
|
|
87
|
+
return {
|
|
88
|
+
...context,
|
|
89
|
+
customJobs: resolvedCustomJobs,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated use createComponentContext instead
|
|
95
|
+
*/
|
|
96
|
+
export const createContext = createComponentContext;
|
package/src/context/index.ts
CHANGED
|
@@ -1,94 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import { BUILD_TYPES } from "../build";
|
|
3
|
-
import type { BuildConfig, BuildConfigType } from "../build/types";
|
|
4
|
-
import { DEPLOY_TYPES } from "../deploy";
|
|
5
|
-
import type { DeployConfig, DeployConfigType } from "../deploy/types";
|
|
6
|
-
import type { PipelineType } from "../types";
|
|
7
|
-
import type { Config, PipelineTrigger } from "../types/config";
|
|
8
|
-
import type { ComponentContext, PackageManagerInfo } from "../types/context";
|
|
9
|
-
import type { PartialDeep } from "../types/utils";
|
|
10
|
-
import { mergeWithMergingArrays } from "../utils";
|
|
11
|
-
import { getEnvironment } from "./getEnvironment";
|
|
12
|
-
import { getEnvironmentContext } from "./getEnvironmentContext";
|
|
13
|
-
|
|
1
|
+
export * from "./createComponentContext";
|
|
14
2
|
export * from "./getEnvironment";
|
|
15
3
|
export * from "./getEnvironmentVariables";
|
|
16
|
-
|
|
17
|
-
export type CreateComponentContextContext = {
|
|
18
|
-
config: Config;
|
|
19
|
-
componentName: string;
|
|
20
|
-
env: string;
|
|
21
|
-
pipelineType?: PipelineType;
|
|
22
|
-
trigger?: PipelineTrigger;
|
|
23
|
-
packageManagerInfo?: PackageManagerInfo;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const createComponentContext = async (
|
|
27
|
-
ctx: CreateComponentContextContext,
|
|
28
|
-
): Promise<ComponentContext> => {
|
|
29
|
-
if (!/^[a-z0-9-]+$/.test(ctx.componentName)) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
"componentName may only contain lower case letters, numbers and -",
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const envContext = getEnvironmentContext(ctx);
|
|
36
|
-
|
|
37
|
-
const componentConfigWithoutDefaults = envContext.envConfigRaw;
|
|
38
|
-
const defaults: {
|
|
39
|
-
build: PartialDeep<BuildConfig>;
|
|
40
|
-
deploy: PartialDeep<DeployConfig>;
|
|
41
|
-
} = componentConfigWithoutDefaults.deploy
|
|
42
|
-
? {
|
|
43
|
-
build:
|
|
44
|
-
BUILD_TYPES[
|
|
45
|
-
componentConfigWithoutDefaults.build.type as BuildConfigType
|
|
46
|
-
].defaults(envContext),
|
|
47
|
-
deploy: DEPLOY_TYPES[
|
|
48
|
-
componentConfigWithoutDefaults.deploy.type as DeployConfigType
|
|
49
|
-
].defaults(envContext as any),
|
|
50
|
-
}
|
|
51
|
-
: {
|
|
52
|
-
build: {},
|
|
53
|
-
deploy: {},
|
|
54
|
-
};
|
|
55
|
-
const componentConfig = mergeWithMergingArrays(
|
|
56
|
-
defaults,
|
|
57
|
-
componentConfigWithoutDefaults,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const environment = await getEnvironment(ctx);
|
|
61
|
-
const { deploy, build, customJobs, dir } = componentConfig;
|
|
62
|
-
const context: Omit<ComponentContext, "customJobs"> = {
|
|
63
|
-
fullConfig: ctx.config,
|
|
64
|
-
componentConfig,
|
|
65
|
-
|
|
66
|
-
build: {
|
|
67
|
-
dir: dir,
|
|
68
|
-
packageManagerInfo: ctx.packageManagerInfo,
|
|
69
|
-
config: build,
|
|
70
|
-
},
|
|
71
|
-
deploy: deploy
|
|
72
|
-
? {
|
|
73
|
-
config: deploy,
|
|
74
|
-
}
|
|
75
|
-
: null,
|
|
76
|
-
componentName: ctx.componentName,
|
|
77
|
-
environment,
|
|
78
|
-
packageManagerInfo: ctx.packageManagerInfo,
|
|
79
|
-
pipelineType: ctx.pipelineType,
|
|
80
|
-
trigger: ctx.trigger,
|
|
81
|
-
};
|
|
82
|
-
const resolvedCustomJobs = isFunction(customJobs)
|
|
83
|
-
? customJobs(context)
|
|
84
|
-
: customJobs;
|
|
85
|
-
return {
|
|
86
|
-
...context,
|
|
87
|
-
customJobs: resolvedCustomJobs,
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @deprecated use createComponentContext instead
|
|
93
|
-
*/
|
|
94
|
-
export const createContext = createComponentContext;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isFunction } from "lodash";
|
|
2
1
|
import { BUILD_TYPES } from "../build";
|
|
3
2
|
import type { CreateComponentContextContext } from "../context";
|
|
4
3
|
import { createComponentContext } from "../context";
|
|
@@ -9,7 +8,6 @@ import type {
|
|
|
9
8
|
Context,
|
|
10
9
|
} from "../types/context";
|
|
11
10
|
import type { CatladderJob } from "../types/jobs";
|
|
12
|
-
import { getPackageManagerInfo } from "./packageManager";
|
|
13
11
|
|
|
14
12
|
const injectDefaultVarsInCustomJobs = (
|
|
15
13
|
context: ComponentContext,
|
|
@@ -40,16 +38,8 @@ const createRawJobs = (context: Context): CatladderJob[] => {
|
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
export const createJobsForComponent = async (
|
|
43
|
-
contextContext:
|
|
41
|
+
contextContext: CreateComponentContextContext,
|
|
44
42
|
): Promise<Array<CatladderJobWithContext>> => {
|
|
45
|
-
const
|
|
46
|
-
contextContext.config,
|
|
47
|
-
contextContext.componentName,
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const context = await createComponentContext({
|
|
51
|
-
...contextContext,
|
|
52
|
-
packageManagerInfo,
|
|
53
|
-
});
|
|
43
|
+
const context = await createComponentContext(contextContext);
|
|
54
44
|
return createRawJobs(context).map((job) => ({ ...job, context }));
|
|
55
45
|
};
|
package/src/types/context.ts
CHANGED
|
@@ -87,7 +87,7 @@ export type ContextBeforeConfig = {
|
|
|
87
87
|
|
|
88
88
|
export type BuildContext = {
|
|
89
89
|
dir: string;
|
|
90
|
-
packageManagerInfo
|
|
90
|
+
packageManagerInfo: PackageManagerInfo;
|
|
91
91
|
config: BuildConfig;
|
|
92
92
|
};
|
|
93
93
|
|
|
@@ -114,7 +114,7 @@ export type ComponentContext = {
|
|
|
114
114
|
/**
|
|
115
115
|
* @deprecated use buildContext.packageManagerInfo instead
|
|
116
116
|
*/
|
|
117
|
-
packageManagerInfo
|
|
117
|
+
packageManagerInfo: PackageManagerInfo;
|
|
118
118
|
|
|
119
119
|
customJobs?: CatladderJob[];
|
|
120
120
|
};
|