@catladder/pipeline 1.170.1 → 2.0.1
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/bash/BashExpression.d.ts +1 -6
- package/dist/bash/BashExpression.js +2 -15
- package/dist/bash/bashEscape.d.ts +34 -0
- package/dist/bash/bashEscape.js +114 -0
- package/dist/bash/bashYaml.js +25 -2
- package/dist/bash/getInjectVarsScript.js +4 -2
- package/dist/bash/index.d.ts +2 -0
- package/dist/bash/index.js +26 -0
- package/dist/build/base/createAppBuildJob.js +3 -3
- package/dist/build/base/writeDotEnv.js +6 -4
- package/dist/build/custom/testJob.js +12 -12
- package/dist/build/docker.d.ts +3 -3
- package/dist/build/node/buildJob.js +1 -1
- package/dist/build/node/cache.d.ts +2 -4
- package/dist/build/node/cache.js +3 -24
- package/dist/build/node/testJob.js +11 -11
- package/dist/build/rails/build.js +1 -1
- package/dist/build/rails/test.js +8 -8
- package/dist/build/types.d.ts +0 -10
- package/dist/constants.js +1 -1
- package/dist/context/createComponentContext.js +0 -1
- package/dist/context/getEnvConfig.js +2 -1
- package/dist/context/getEnvironment.js +1 -2
- package/dist/context/getEnvironmentVariables.d.ts +5 -6
- package/dist/context/getEnvironmentVariables.js +50 -38
- package/dist/deploy/base/deploy.js +3 -3
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +2 -2
- package/dist/deploy/cloudRun/index.js +2 -2
- package/dist/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +2 -2
- package/dist/deploy/kubernetes/cloudSql/index.js +3 -14
- package/dist/deploy/kubernetes/deployJob.js +1 -3
- package/dist/deploy/kubernetes/index.js +2 -2
- package/dist/deploy/kubernetes/kubeEnv.d.ts +3 -3
- package/dist/deploy/kubernetes/kubeValues.d.ts +3 -4
- package/dist/deploy/kubernetes/kubeValues.js +2 -3
- package/dist/deploy/types/base.d.ts +0 -6
- package/dist/deploy/types/kubernetes.d.ts +1 -34
- package/dist/globalScriptFunctions/index.d.ts +14 -0
- package/dist/globalScriptFunctions/index.js +37 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/pipeline/gitlab/createGitlabJobs.js +3 -5
- package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +1 -0
- package/dist/pipeline/gitlab/createGitlabPipeline.js +38 -2
- package/dist/pipeline/packageManager.js +1 -1
- package/dist/runner/index.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +6 -9
- package/dist/types/context.d.ts +2 -9
- package/dist/types/gitlab-types.d.ts +1 -0
- package/dist/types/jobs.d.ts +0 -8
- package/dist/utils/gitlab.js +4 -1
- package/dist/utils/writeFiles.js +1 -7
- package/dist/variables/VariableValue.d.ts +3 -0
- package/dist/variables/VariableValue.js +5 -0
- package/dist/variables/VariableValueContainingReferences.d.ts +24 -0
- package/dist/variables/VariableValueContainingReferences.js +97 -0
- package/dist/variables/__tests__/resolveAllReferences.test.js +219 -0
- package/dist/variables/__tests__/resolveAllReferencesOnce.test.d.ts +1 -0
- package/dist/variables/__tests__/resolveAllReferencesOnce.test.js +171 -0
- package/dist/variables/__tests__/resolveReferencesOnce.test.d.ts +1 -0
- package/dist/variables/__tests__/resolveReferencesOnce.test.js +202 -0
- package/dist/variables/__tests__/variableValue.test.d.ts +1 -0
- package/dist/variables/__tests__/variableValue.test.js +36 -0
- package/dist/variables/resolveAllReferences.d.ts +3 -0
- package/dist/{bash/replaceAsync.js → variables/resolveAllReferences.js} +60 -40
- package/dist/variables/resolveAllReferencesOnce.d.ts +5 -0
- package/dist/variables/resolveAllReferencesOnce.js +191 -0
- package/dist/variables/resolveReferencesOnce.d.ts +8 -0
- package/dist/variables/resolveReferencesOnce.js +22 -0
- package/examples/__snapshots__/cloud-run-http2.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-memory-limit.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +312 -222
- package/examples/__snapshots__/cloud-run-nextjs.test.ts.snap +1436 -0
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-no-service.test.ts.snap +316 -238
- package/examples/__snapshots__/cloud-run-non-public.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-post-stop-job.test.ts.snap +313 -238
- package/examples/__snapshots__/cloud-run-service-custom-vpc-connector.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-custom-vpc.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-gen2.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-increase-timout.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-service-with-volumes.test.ts.snap +316 -238
- package/examples/__snapshots__/cloud-run-storybook.test.ts.snap +294 -220
- package/examples/__snapshots__/cloud-run-with-ngnix.test.ts.snap +312 -238
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +652 -486
- package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +282 -288
- package/examples/__snapshots__/cloud-run-with-worker.test.ts.snap +312 -238
- package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +284 -194
- package/examples/__snapshots__/custom-build-job.test.ts.snap +278 -188
- package/examples/__snapshots__/custom-deploy.test.ts.snap +220 -154
- package/examples/__snapshots__/custom-envs.test.ts.snap +216 -126
- package/examples/__snapshots__/custom-sbom-java.test.ts.snap +278 -188
- package/examples/__snapshots__/git-submodule.test.ts.snap +312 -238
- package/examples/__snapshots__/kubernetes-application-customization.test.ts.snap +231 -253
- package/examples/__snapshots__/kubernetes-with-cloud-sql.test.ts.snap +240 -262
- package/examples/__snapshots__/kubernetes-with-jobs.test.ts.snap +504 -506
- package/examples/__snapshots__/kubernetes-with-mongodb.test.ts.snap +239 -261
- package/examples/__snapshots__/local-dot-env.test.ts.snap +236 -238
- package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +236 -242
- package/examples/__snapshots__/multiline-var.test.ts.snap +1355 -973
- package/examples/__snapshots__/native-app.test.ts.snap +438 -392
- package/examples/__snapshots__/node-build-with-custom-image.test.ts.snap +312 -238
- package/examples/__snapshots__/node-build-with-docker-additions.test.ts.snap +312 -238
- package/examples/__snapshots__/rails-k8s-with-worker-dockerfile.test.ts.snap +186 -188
- package/examples/__snapshots__/rails-k8s-with-worker.test.ts.snap +162 -164
- package/examples/__snapshots__/referencing-other-vars.test.ts.snap +971 -765
- package/examples/__snapshots__/wait-for-other-deploy.test.ts.snap +330 -228
- package/examples/__snapshots__/{workspace-api-www-custom-cache.test.ts.snap → workspace-api-www-turbo-cache.test.ts.snap} +457 -499
- package/examples/__snapshots__/workspace-api-www.test.ts.snap +452 -482
- package/examples/{workspace-api-www-custom-cache.test.ts → cloud-run-nextjs.test.ts} +2 -2
- package/examples/cloud-run-nextjs.ts +28 -0
- package/examples/cloud-run-with-sql.ts +0 -1
- package/examples/kubernetes-application-customization.ts +1 -0
- package/examples/kubernetes-with-cloud-sql.ts +1 -0
- package/examples/kubernetes-with-jobs.ts +1 -0
- package/examples/kubernetes-with-mongodb.ts +1 -0
- package/examples/meteor-kubernetes.ts +1 -1
- package/examples/native-app.ts +10 -7
- package/examples/rails-k8s-with-worker.ts +7 -1
- package/examples/{kubernetes-with-cloud-sql-legacy.test.ts → workspace-api-www-turbo-cache.test.ts} +2 -2
- package/examples/{workspace-api-www-custom-cache.ts → workspace-api-www-turbo-cache.ts} +4 -3
- package/examples/workspace-api-www.ts +3 -2
- package/package.json +2 -6
- package/scripts/generate-examples-test.ts +0 -7
- package/src/bash/BashExpression.ts +0 -13
- package/src/bash/bashEscape.ts +158 -0
- package/src/bash/bashYaml.ts +36 -2
- package/src/bash/getInjectVarsScript.ts +11 -2
- package/src/bash/index.ts +2 -0
- package/src/build/base/createAppBuildJob.ts +0 -1
- package/src/build/base/writeDotEnv.ts +6 -6
- package/src/build/custom/testJob.ts +0 -1
- package/src/build/node/buildJob.ts +2 -2
- package/src/build/node/cache.ts +0 -29
- package/src/build/node/testJob.ts +0 -1
- package/src/build/rails/build.ts +0 -1
- package/src/build/rails/test.ts +0 -1
- package/src/build/types.ts +0 -13
- package/src/context/createComponentContext.ts +0 -1
- package/src/context/getEnvConfig.ts +2 -2
- package/src/context/getEnvironment.ts +1 -1
- package/src/context/getEnvironmentContext.ts +1 -1
- package/src/context/getEnvironmentVariables.ts +44 -51
- package/src/deploy/base/deploy.ts +1 -1
- package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +4 -12
- package/src/deploy/cloudRun/index.ts +2 -2
- package/src/deploy/kubernetes/cloudSql/index.ts +3 -16
- package/src/deploy/kubernetes/deployJob.ts +0 -2
- package/src/deploy/kubernetes/index.ts +2 -2
- package/src/deploy/kubernetes/kubeEnv.ts +3 -3
- package/src/deploy/kubernetes/kubeValues.ts +5 -8
- package/src/deploy/types/base.ts +0 -6
- package/src/deploy/types/kubernetes.ts +1 -36
- package/src/globalScriptFunctions/index.ts +30 -0
- package/src/index.ts +2 -0
- package/src/pipeline/gitlab/createGitlabJobs.ts +1 -4
- package/src/pipeline/gitlab/createGitlabPipeline.ts +8 -1
- package/src/pipeline/packageManager.ts +7 -5
- package/src/runner/index.ts +0 -1
- package/src/types/config.ts +6 -9
- package/src/types/context.ts +3 -9
- package/src/types/gitlab-types.ts +1 -0
- package/src/types/jobs.ts +0 -8
- package/src/utils/gitlab.ts +19 -2
- package/src/utils/writeFiles.ts +1 -2
- package/src/variables/VariableValue.ts +6 -0
- package/src/variables/VariableValueContainingReferences.ts +89 -0
- package/src/variables/__tests__/resolveAllReferences.test.ts +110 -0
- package/src/variables/__tests__/resolveAllReferencesOnce.test.ts +64 -0
- package/src/variables/__tests__/resolveReferencesOnce.test.ts +117 -0
- package/src/variables/__tests__/variableValue.test.ts +73 -0
- package/src/variables/resolveAllReferences.ts +46 -0
- package/src/variables/resolveAllReferencesOnce.ts +44 -0
- package/src/variables/resolveReferencesOnce.ts +29 -0
- package/bin/catladder-gitlab-dev.js +0 -3
- package/bin/catladder-gitlab.js +0 -3
- package/dist/bash/replaceAsync.d.ts +0 -2
- package/dist/bundles/catladder-gitlab/index.js +0 -15
- package/dist/context/__tests__/resolveReferences.test.js +0 -368
- package/dist/context/resolveReferences.d.ts +0 -6
- package/dist/context/resolveReferences.js +0 -286
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +0 -85
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +0 -33
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.test.ts.snap +0 -1795
- package/examples/kubernetes-with-cloud-sql-legacy.ts +0 -35
- package/scripts/bundle +0 -2
- package/src/bash/replaceAsync.ts +0 -49
- package/src/context/__tests__/resolveReferences.test.ts +0 -148
- package/src/context/resolveReferences.ts +0 -93
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +0 -35
- /package/dist/{context/__tests__/resolveReferences.test.d.ts → variables/__tests__/resolveAllReferences.test.d.ts} +0 -0
package/dist/types/context.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import type { StringOrBashExpression } from "../bash/BashExpression";
|
|
|
2
2
|
import type { BuildConfigFromWorkspace, BuildConfigStandalone, WorkspaceBuildConfig } from "../build";
|
|
3
3
|
import type { PredefinedVariables, SecretEnvVar } from "../context";
|
|
4
4
|
import type { DeployConfig } from "../deploy";
|
|
5
|
+
import type { VariableValue } from "../variables/VariableValue";
|
|
5
6
|
import type { ComponentConfig, Config, EnvType, PipelineTrigger } from "./config";
|
|
6
7
|
import type { BaseStage, CatladderJob } from "./jobs";
|
|
7
8
|
import type { PipelineType } from "./pipeline";
|
|
8
|
-
export type UnspecifiedEnvVars = Record<string,
|
|
9
|
+
export type UnspecifiedEnvVars = Record<string, VariableValue | undefined | null>;
|
|
9
10
|
export type EnvironmentEnvVars<V extends UnspecifiedEnvVars = UnspecifiedEnvVars> = {
|
|
10
11
|
envVars: V & UnspecifiedEnvVars;
|
|
11
12
|
secretEnvVarKeys: SecretEnvVar[];
|
|
@@ -28,10 +29,6 @@ export type Environment = {
|
|
|
28
29
|
* the full name of the app. We use this as RELEASE_NAME in kubernetes and the service name in google cloud run
|
|
29
30
|
*/
|
|
30
31
|
fullName: StringOrBashExpression;
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated this is the same as context.env, use that instead
|
|
33
|
-
*/
|
|
34
|
-
shortName: string;
|
|
35
32
|
/**
|
|
36
33
|
* the environment slug without component name.
|
|
37
34
|
*/
|
|
@@ -120,10 +117,6 @@ export type ComponentContext<BC extends BuildContextComponent = BuildContextComp
|
|
|
120
117
|
* the name of the component
|
|
121
118
|
*/
|
|
122
119
|
name: string;
|
|
123
|
-
/**
|
|
124
|
-
* @deprecated use name instead
|
|
125
|
-
*/
|
|
126
|
-
componentName: string;
|
|
127
120
|
/**
|
|
128
121
|
* the merged component config.
|
|
129
122
|
*
|
package/dist/types/jobs.d.ts
CHANGED
|
@@ -52,14 +52,6 @@ export type CatladderJob<S = BaseStage> = {
|
|
|
52
52
|
*
|
|
53
53
|
*/
|
|
54
54
|
needs?: Array<CatladderJobNeed>;
|
|
55
|
-
/**
|
|
56
|
-
* @deprecated set `componentName` to `needs` if you want to wait for a job from another component
|
|
57
|
-
*/
|
|
58
|
-
needsOtherComponent?: Array<{
|
|
59
|
-
componentName: string;
|
|
60
|
-
job: string;
|
|
61
|
-
artifacts: boolean;
|
|
62
|
-
}>;
|
|
63
55
|
/**
|
|
64
56
|
* cache config, we use here the same shape as gitlab itself
|
|
65
57
|
*/
|
package/dist/utils/gitlab.js
CHANGED
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
35
35
|
value: true
|
|
36
36
|
});
|
|
37
37
|
exports.collapseableSection = exports.repeatOnFailure = exports.sanitizeForBashVariable = exports.allowFailureInScripts = void 0;
|
|
38
|
+
var globalScriptFunctions_1 = require("../globalScriptFunctions");
|
|
38
39
|
var allowFailureInScripts = function (script) {
|
|
39
40
|
return __spreadArray(__spreadArray(["set +e"], __read(script), false), ["set -e" // reenable
|
|
40
41
|
], false);
|
|
@@ -48,9 +49,11 @@ var repeatOnFailure = function (command, options) {
|
|
|
48
49
|
return "\n until ".concat(command, "\n do\n echo \"Trying again.\"\n sleep ").concat(options.pauseInSeconds, "\n done\n ");
|
|
49
50
|
};
|
|
50
51
|
exports.repeatOnFailure = repeatOnFailure;
|
|
52
|
+
var start = (0, globalScriptFunctions_1.registerGlobalScriptFunction)("collapseable_section_start", "local section_title=\"${1}\"\n local section_description=\"${2:-$section_title}\"\n echo -e \"section_start:`date +%s`:${section_title}[collapsed=true]\\r\\e[0K${section_description}\"\n");
|
|
53
|
+
var end = (0, globalScriptFunctions_1.registerGlobalScriptFunction)("collapseable_section_end", "local section_title=\"${1}\"\n echo -e \"section_end:`date +%s`:${section_title}\\r\\e[0K\"\n");
|
|
51
54
|
var collapseableSection = function (name, header) {
|
|
52
55
|
return function (commands) {
|
|
53
|
-
return __spreadArray(__spreadArray(["
|
|
56
|
+
return __spreadArray(__spreadArray([start.invoke("\"".concat(name, "\""), "\"".concat(header, "\""))], __read(commands), false), [end.invoke("\"".concat(name, "\""))], false);
|
|
54
57
|
};
|
|
55
58
|
};
|
|
56
59
|
exports.collapseableSection = collapseableSection;
|
package/dist/utils/writeFiles.js
CHANGED
|
@@ -115,20 +115,14 @@ var __generator = this && this.__generator || function (thisArg, body) {
|
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
-
var __importDefault = this && this.__importDefault || function (mod) {
|
|
119
|
-
return mod && mod.__esModule ? mod : {
|
|
120
|
-
"default": mod
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
118
|
Object.defineProperty(exports, "__esModule", {
|
|
124
119
|
value: true
|
|
125
120
|
});
|
|
126
121
|
exports.writeYamlfile = exports.yamlStringifyOptions = exports.writeGeneratedFile = exports.getAutoGeneratedHeader = void 0;
|
|
127
122
|
var promises_1 = require("fs/promises");
|
|
128
123
|
var yaml_1 = require("yaml");
|
|
129
|
-
var packageInfos_1 = __importDefault(require("../packageInfos"));
|
|
130
124
|
var getAutoGeneratedHeader = function (commentChar) {
|
|
131
|
-
return ["-------------------------------------------------", "\uD83D\uDC31 \uD83D\uDD28 This file is generated by catladder
|
|
125
|
+
return ["-------------------------------------------------", "\uD83D\uDC31 \uD83D\uDD28 This file is generated by catladder", "\uD83D\uDEA8 Do not edit this file manually \uD83D\uDEA8", "-------------------------------------------------"].map(function (line) {
|
|
132
126
|
return "".concat(commentChar, " ").concat(line);
|
|
133
127
|
}).join("\n").concat("\n");
|
|
134
128
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BashExpression } from "../bash/BashExpression";
|
|
2
|
+
import type { EscapeOptions } from "../bash/bashEscape";
|
|
3
|
+
export declare class UnresolvableReference {
|
|
4
|
+
reference: VariableReference;
|
|
5
|
+
constructor(reference: VariableReference);
|
|
6
|
+
toString(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare class VariableReference {
|
|
9
|
+
componentName: string;
|
|
10
|
+
variableName: string;
|
|
11
|
+
constructor(componentName: string, variableName: string);
|
|
12
|
+
toString(): string;
|
|
13
|
+
}
|
|
14
|
+
type VariableValuePart = string | BashExpression | VariableReference | UnresolvableReference;
|
|
15
|
+
type MaybeArray<T> = T | T[];
|
|
16
|
+
export declare class VariableValueContainingReferences {
|
|
17
|
+
parts: VariableValuePart[];
|
|
18
|
+
constructor(parts: MaybeArray<VariableValuePart | VariableValueContainingReferences>);
|
|
19
|
+
toString(options?: EscapeOptions): string;
|
|
20
|
+
}
|
|
21
|
+
export declare const createVariableValueContainingReferencesFromString: (value: string, options: {
|
|
22
|
+
componentName: string;
|
|
23
|
+
}) => VariableValueContainingReferences;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __read = this && this.__read || function (o, n) {
|
|
4
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
5
|
+
if (!m) return o;
|
|
6
|
+
var i = m.call(o),
|
|
7
|
+
r,
|
|
8
|
+
ar = [],
|
|
9
|
+
e;
|
|
10
|
+
try {
|
|
11
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
e = {
|
|
14
|
+
error: error
|
|
15
|
+
};
|
|
16
|
+
} finally {
|
|
17
|
+
try {
|
|
18
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
19
|
+
} finally {
|
|
20
|
+
if (e) throw e.error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", {
|
|
26
|
+
value: true
|
|
27
|
+
});
|
|
28
|
+
exports.createVariableValueContainingReferencesFromString = exports.VariableValueContainingReferences = exports.VariableReference = exports.UnresolvableReference = void 0;
|
|
29
|
+
var BashExpression_1 = require("../bash/BashExpression");
|
|
30
|
+
var bashEscape_1 = require("../bash/bashEscape");
|
|
31
|
+
var UnresolvableReference = /** @class */function () {
|
|
32
|
+
function UnresolvableReference(reference) {
|
|
33
|
+
this.reference = reference;
|
|
34
|
+
}
|
|
35
|
+
UnresolvableReference.prototype.toString = function () {
|
|
36
|
+
return "Unresolvable reference: ".concat(this.reference.toString());
|
|
37
|
+
};
|
|
38
|
+
return UnresolvableReference;
|
|
39
|
+
}();
|
|
40
|
+
exports.UnresolvableReference = UnresolvableReference;
|
|
41
|
+
var VariableReference = /** @class */function () {
|
|
42
|
+
function VariableReference(componentName, variableName) {
|
|
43
|
+
this.componentName = componentName;
|
|
44
|
+
this.variableName = variableName;
|
|
45
|
+
}
|
|
46
|
+
VariableReference.prototype.toString = function () {
|
|
47
|
+
return "${".concat(this.componentName, ":").concat(this.variableName, "}");
|
|
48
|
+
};
|
|
49
|
+
return VariableReference;
|
|
50
|
+
}();
|
|
51
|
+
exports.VariableReference = VariableReference;
|
|
52
|
+
var VariableValueContainingReferences = /** @class */function () {
|
|
53
|
+
function VariableValueContainingReferences(parts) {
|
|
54
|
+
this.parts = (Array.isArray(parts) ? parts : [parts]).flatMap(function (part) {
|
|
55
|
+
return part instanceof VariableValueContainingReferences ? part.parts : part === "" ? [] : [part];
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
VariableValueContainingReferences.prototype.toString = function (options) {
|
|
59
|
+
if (options === void 0) {
|
|
60
|
+
options = {
|
|
61
|
+
quotes: false
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return this.parts.map(function (part) {
|
|
65
|
+
if (typeof part === "string") {
|
|
66
|
+
return (0, bashEscape_1.escapeString)(part, options);
|
|
67
|
+
} else if (part instanceof BashExpression_1.BashExpression) {
|
|
68
|
+
return (0, bashEscape_1.escapeBashExpression)(part, options);
|
|
69
|
+
} else {
|
|
70
|
+
return part.toString();
|
|
71
|
+
}
|
|
72
|
+
}).join("");
|
|
73
|
+
};
|
|
74
|
+
return VariableValueContainingReferences;
|
|
75
|
+
}();
|
|
76
|
+
exports.VariableValueContainingReferences = VariableValueContainingReferences;
|
|
77
|
+
// regex to resolve references in catladder variables
|
|
78
|
+
// those expressions have the pattern ${componentName:variableName}
|
|
79
|
+
var REGEX = /\$\{(([^:}]+):)?([^}]+)}/gm;
|
|
80
|
+
var createVariableValueContainingReferencesFromString = function (value, options) {
|
|
81
|
+
var parts = [];
|
|
82
|
+
var match;
|
|
83
|
+
var lastIndex = 0;
|
|
84
|
+
while ((match = REGEX.exec(value)) !== null) {
|
|
85
|
+
var _a = __read(match, 4),
|
|
86
|
+
fullMatch = _a[0],
|
|
87
|
+
_1 = _a[1],
|
|
88
|
+
otherComponentName = _a[2],
|
|
89
|
+
variableName = _a[3];
|
|
90
|
+
parts.push(value.slice(lastIndex, match.index));
|
|
91
|
+
parts.push(new VariableReference(otherComponentName || options.componentName, variableName));
|
|
92
|
+
lastIndex = REGEX.lastIndex;
|
|
93
|
+
}
|
|
94
|
+
parts.push(value.slice(lastIndex));
|
|
95
|
+
return new VariableValueContainingReferences(parts);
|
|
96
|
+
};
|
|
97
|
+
exports.createVariableValueContainingReferencesFromString = createVariableValueContainingReferencesFromString;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.next(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function step(result) {
|
|
25
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
26
|
+
}
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
31
|
+
var _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function () {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
},
|
|
40
|
+
f,
|
|
41
|
+
y,
|
|
42
|
+
t,
|
|
43
|
+
g;
|
|
44
|
+
return g = {
|
|
45
|
+
next: verb(0),
|
|
46
|
+
"throw": verb(1),
|
|
47
|
+
"return": verb(2)
|
|
48
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
49
|
+
return this;
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function (v) {
|
|
53
|
+
return step([n, v]);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
58
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
59
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
60
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
61
|
+
switch (op[0]) {
|
|
62
|
+
case 0:
|
|
63
|
+
case 1:
|
|
64
|
+
t = op;
|
|
65
|
+
break;
|
|
66
|
+
case 4:
|
|
67
|
+
_.label++;
|
|
68
|
+
return {
|
|
69
|
+
value: op[1],
|
|
70
|
+
done: false
|
|
71
|
+
};
|
|
72
|
+
case 5:
|
|
73
|
+
_.label++;
|
|
74
|
+
y = op[1];
|
|
75
|
+
op = [0];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [6, e];
|
|
107
|
+
y = 0;
|
|
108
|
+
} finally {
|
|
109
|
+
f = t = 0;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] & 5) throw op[1];
|
|
112
|
+
return {
|
|
113
|
+
value: op[0] ? op[1] : void 0,
|
|
114
|
+
done: true
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
Object.defineProperty(exports, "__esModule", {
|
|
119
|
+
value: true
|
|
120
|
+
});
|
|
121
|
+
var VariableValueContainingReferences_1 = require("../VariableValueContainingReferences");
|
|
122
|
+
var resolveAllReferences_1 = require("../resolveAllReferences");
|
|
123
|
+
describe("replaceAllReferences", function () {
|
|
124
|
+
it("should replace all references recursivly", function () {
|
|
125
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
126
|
+
var values, getEnvVars, result;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
values = {
|
|
131
|
+
myVar: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the 2nd component has ${component2:variable1} and self reference ${variable2}", {
|
|
132
|
+
componentName: "component1"
|
|
133
|
+
}),
|
|
134
|
+
myOtherVar: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the third component has ${component3:variable1}, isn't that cool?", {
|
|
135
|
+
componentName: "component1"
|
|
136
|
+
}),
|
|
137
|
+
myThirdVar: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("value from component3: ${component3:variable3}", {
|
|
138
|
+
componentName: "component1"
|
|
139
|
+
})
|
|
140
|
+
};
|
|
141
|
+
getEnvVars = function (componentName) {
|
|
142
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
return [2 /*return*/, {
|
|
145
|
+
variable1: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am variable1 from ".concat(componentName), {
|
|
146
|
+
componentName: componentName
|
|
147
|
+
}),
|
|
148
|
+
variable2: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("foo from ".concat(componentName), {
|
|
149
|
+
componentName: componentName
|
|
150
|
+
}),
|
|
151
|
+
variable3: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am referencing ${component1:variable1}", {
|
|
152
|
+
componentName: componentName
|
|
153
|
+
})
|
|
154
|
+
}];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
return [4 /*yield*/, (0, resolveAllReferences_1.resolveAllReferences)(values, getEnvVars)];
|
|
159
|
+
case 1:
|
|
160
|
+
result = _a.sent();
|
|
161
|
+
expect(result).toEqual({
|
|
162
|
+
myVar: new VariableValueContainingReferences_1.VariableValueContainingReferences(["the 2nd component has ", "i am variable1 from component2", " and self reference ", "foo from component1"]),
|
|
163
|
+
myOtherVar: new VariableValueContainingReferences_1.VariableValueContainingReferences(["the third component has ", "i am variable1 from component3", ", isn't that cool?"]),
|
|
164
|
+
myThirdVar: new VariableValueContainingReferences_1.VariableValueContainingReferences(["value from component3: ", "i am referencing ", "i am variable1 from component1"])
|
|
165
|
+
});
|
|
166
|
+
return [2 /*return*/];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("detects infinte loop", function () {
|
|
173
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
174
|
+
var values, getEnvVars;
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
values = {
|
|
179
|
+
myVar: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am referencing ${component2:variable1}", {
|
|
180
|
+
componentName: "component1"
|
|
181
|
+
})
|
|
182
|
+
};
|
|
183
|
+
getEnvVars = function (componentName) {
|
|
184
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
if (componentName === "component2") {
|
|
187
|
+
return [2 /*return*/, {
|
|
188
|
+
variable1: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am referencing ${component3:variable1}", {
|
|
189
|
+
componentName: componentName
|
|
190
|
+
})
|
|
191
|
+
}];
|
|
192
|
+
} else if (componentName === "component3") {
|
|
193
|
+
return [2 /*return*/, {
|
|
194
|
+
variable1: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am referencing ${component1:variable1}", {
|
|
195
|
+
componentName: componentName
|
|
196
|
+
})
|
|
197
|
+
}];
|
|
198
|
+
} else {
|
|
199
|
+
return [2 /*return*/, {
|
|
200
|
+
variable1: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am referencing ${component2:variable1}", {
|
|
201
|
+
componentName: componentName
|
|
202
|
+
})
|
|
203
|
+
}];
|
|
204
|
+
}
|
|
205
|
+
return [2 /*return*/];
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
// expect to throw an error
|
|
210
|
+
return [4 /*yield*/, expect((0, resolveAllReferences_1.resolveAllReferences)(values, getEnvVars)).rejects.toThrow("Infinite loop detected in these variables: myVar (last reference: ${component1:variable1})")];
|
|
211
|
+
case 1:
|
|
212
|
+
// expect to throw an error
|
|
213
|
+
_a.sent();
|
|
214
|
+
return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
6
|
+
resolve(value);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.next(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function step(result) {
|
|
25
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
26
|
+
}
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
31
|
+
var _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function () {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
},
|
|
40
|
+
f,
|
|
41
|
+
y,
|
|
42
|
+
t,
|
|
43
|
+
g;
|
|
44
|
+
return g = {
|
|
45
|
+
next: verb(0),
|
|
46
|
+
"throw": verb(1),
|
|
47
|
+
"return": verb(2)
|
|
48
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
49
|
+
return this;
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function (v) {
|
|
53
|
+
return step([n, v]);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
58
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
59
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
60
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
61
|
+
switch (op[0]) {
|
|
62
|
+
case 0:
|
|
63
|
+
case 1:
|
|
64
|
+
t = op;
|
|
65
|
+
break;
|
|
66
|
+
case 4:
|
|
67
|
+
_.label++;
|
|
68
|
+
return {
|
|
69
|
+
value: op[1],
|
|
70
|
+
done: false
|
|
71
|
+
};
|
|
72
|
+
case 5:
|
|
73
|
+
_.label++;
|
|
74
|
+
y = op[1];
|
|
75
|
+
op = [0];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [6, e];
|
|
107
|
+
y = 0;
|
|
108
|
+
} finally {
|
|
109
|
+
f = t = 0;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] & 5) throw op[1];
|
|
112
|
+
return {
|
|
113
|
+
value: op[0] ? op[1] : void 0,
|
|
114
|
+
done: true
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
Object.defineProperty(exports, "__esModule", {
|
|
119
|
+
value: true
|
|
120
|
+
});
|
|
121
|
+
var VariableValueContainingReferences_1 = require("../VariableValueContainingReferences");
|
|
122
|
+
var resolveAllReferencesOnce_1 = require("../resolveAllReferencesOnce");
|
|
123
|
+
describe("resolveAllReferencesOnce", function () {
|
|
124
|
+
it("should replace all references", function () {
|
|
125
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
126
|
+
var values, getEnvVars, result;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
values = {
|
|
131
|
+
myVar: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the 2nd component has ${component2:variable1} and self reference ${variable2}", {
|
|
132
|
+
componentName: "component1"
|
|
133
|
+
}),
|
|
134
|
+
myOtherVar: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("the third component has ${component3:variable1}, isn't that cool?", {
|
|
135
|
+
componentName: "component1"
|
|
136
|
+
}),
|
|
137
|
+
myThirdVar: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("value from component3: ${component3:variable3}", {
|
|
138
|
+
componentName: "component1"
|
|
139
|
+
})
|
|
140
|
+
};
|
|
141
|
+
getEnvVars = function (componentName) {
|
|
142
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
return [2 /*return*/, {
|
|
145
|
+
variable1: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am variable1 from ".concat(componentName), {
|
|
146
|
+
componentName: componentName
|
|
147
|
+
}),
|
|
148
|
+
variable2: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("foo from ".concat(componentName), {
|
|
149
|
+
componentName: componentName
|
|
150
|
+
}),
|
|
151
|
+
variable3: (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)("i am referencing ${component1:variable1}", {
|
|
152
|
+
componentName: componentName
|
|
153
|
+
})
|
|
154
|
+
}];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
return [4 /*yield*/, (0, resolveAllReferencesOnce_1.resolveAllReferencesOnce)(values, getEnvVars)];
|
|
159
|
+
case 1:
|
|
160
|
+
result = _a.sent();
|
|
161
|
+
expect(result).toEqual({
|
|
162
|
+
myVar: new VariableValueContainingReferences_1.VariableValueContainingReferences(["the 2nd component has ", "i am variable1 from component2", " and self reference ", "foo from component1"]),
|
|
163
|
+
myOtherVar: new VariableValueContainingReferences_1.VariableValueContainingReferences(["the third component has ", "i am variable1 from component3", ", isn't that cool?"]),
|
|
164
|
+
myThirdVar: new VariableValueContainingReferences_1.VariableValueContainingReferences(["value from component3: ", "i am referencing ", new VariableValueContainingReferences_1.VariableReference("component1", "variable1")])
|
|
165
|
+
});
|
|
166
|
+
return [2 /*return*/];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|