@nx/docker 22.0.0 → 22.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/plugins/plugin.d.ts +10 -2
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +91 -14
- package/src/release/version-pattern-utils.d.ts +2 -0
- package/src/release/version-pattern-utils.d.ts.map +1 -1
- package/src/release/version-pattern-utils.js +3 -39
- package/src/release/version-utils.d.ts +1 -1
- package/src/release/version-utils.d.ts.map +1 -1
- package/src/release/version-utils.js +4 -3
- package/src/utils/interpolate-pattern.d.ts +23 -0
- package/src/utils/interpolate-pattern.d.ts.map +1 -0
- package/src/utils/interpolate-pattern.js +81 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/docker",
|
|
3
3
|
"description": "The Nx Plugin for Docker to aid in containerizing projects.",
|
|
4
|
-
"version": "22.0.0",
|
|
4
|
+
"version": "22.1.0-beta.0",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"executors": "./executors.json",
|
|
48
48
|
"generators": "./generators.json",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@nx/devkit": "22.0.0",
|
|
50
|
+
"@nx/devkit": "22.1.0-beta.0",
|
|
51
51
|
"enquirer": "~2.3.6",
|
|
52
52
|
"tslib": "^2.3.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"nx": "22.0.0"
|
|
55
|
+
"nx": "22.1.0-beta.0"
|
|
56
56
|
},
|
|
57
57
|
"types": "./src/index.d.ts"
|
|
58
58
|
}
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type CreateNodesV2 } from '@nx/devkit';
|
|
2
|
+
export interface DockerTargetOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
args?: string[];
|
|
5
|
+
env?: Record<string, string>;
|
|
6
|
+
envFile?: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
configurations?: Record<string, Omit<DockerTargetOptions, 'configurations' | 'name'>>;
|
|
9
|
+
}
|
|
2
10
|
export interface DockerPluginOptions {
|
|
3
|
-
buildTarget?: string;
|
|
4
|
-
runTarget?: string;
|
|
11
|
+
buildTarget?: string | DockerTargetOptions;
|
|
12
|
+
runTarget?: string | DockerTargetOptions;
|
|
5
13
|
}
|
|
6
14
|
export declare const createNodesV2: CreateNodesV2<DockerPluginOptions>;
|
|
7
15
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAOnB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAOnB,MAAM,YAAY,CAAC;AAUpB,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CACrB,MAAM,EACN,IAAI,CAAC,mBAAmB,EAAE,gBAAgB,GAAG,MAAM,CAAC,CACrD,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;CAC1C;AAsBD,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAmC5D,CAAC"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -8,6 +8,8 @@ const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
11
|
+
const git_utils_1 = require("nx/src/utils/git-utils");
|
|
12
|
+
const interpolate_pattern_1 = require("../utils/interpolate-pattern");
|
|
11
13
|
function readTargetsCache(cachePath) {
|
|
12
14
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
13
15
|
}
|
|
@@ -47,26 +49,91 @@ async function createNodesInternal(configFilePath, hash, normalizedOptions, cont
|
|
|
47
49
|
},
|
|
48
50
|
};
|
|
49
51
|
}
|
|
52
|
+
function interpolateDockerTargetOptions(options, projectRoot, imageRef, context) {
|
|
53
|
+
const commitSha = (0, git_utils_1.getLatestCommitSha)();
|
|
54
|
+
const projectName = getProjectName(projectRoot, context.workspaceRoot);
|
|
55
|
+
const tokens = {
|
|
56
|
+
projectRoot,
|
|
57
|
+
projectName,
|
|
58
|
+
imageRef,
|
|
59
|
+
currentDate: new Date(),
|
|
60
|
+
commitSha,
|
|
61
|
+
shortCommitSha: commitSha.slice(0, 7),
|
|
62
|
+
};
|
|
63
|
+
return (0, interpolate_pattern_1.interpolateObject)(options, tokens);
|
|
64
|
+
}
|
|
65
|
+
function getProjectName(projectRoot, workspaceRoot) {
|
|
66
|
+
const projectJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'project.json');
|
|
67
|
+
if ((0, fs_1.existsSync)(projectJsonPath)) {
|
|
68
|
+
const projectJson = (0, devkit_1.readJsonFile)(projectJsonPath);
|
|
69
|
+
if (projectJson.name) {
|
|
70
|
+
return projectJson.name;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
|
|
74
|
+
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
75
|
+
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
76
|
+
if (packageJson.name) {
|
|
77
|
+
return packageJson.name;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return projectRoot.replace(/^[\\/]/, '').replace(/[\\/\s]+/g, '-');
|
|
81
|
+
}
|
|
82
|
+
function buildTargetOptions(interpolatedTarget, projectRoot, imageRef, isRunTarget = false) {
|
|
83
|
+
const options = {
|
|
84
|
+
cwd: interpolatedTarget.cwd ?? projectRoot,
|
|
85
|
+
};
|
|
86
|
+
if (isRunTarget) {
|
|
87
|
+
// Run target doesn't have default args
|
|
88
|
+
if (interpolatedTarget.args) {
|
|
89
|
+
options.args = interpolatedTarget.args;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Build target always includes --tag default
|
|
94
|
+
options.args = [`--tag ${imageRef}`, ...(interpolatedTarget.args ?? [])];
|
|
95
|
+
}
|
|
96
|
+
if (interpolatedTarget.env) {
|
|
97
|
+
options.env = interpolatedTarget.env;
|
|
98
|
+
}
|
|
99
|
+
if (interpolatedTarget.envFile) {
|
|
100
|
+
options.envFile = interpolatedTarget.envFile;
|
|
101
|
+
}
|
|
102
|
+
return options;
|
|
103
|
+
}
|
|
104
|
+
function buildTargetConfigurations(interpolatedTarget, projectRoot, imageRef, isRunTarget = false) {
|
|
105
|
+
if (!interpolatedTarget.configurations) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const configurations = {};
|
|
109
|
+
for (const [configName, configOptions] of Object.entries(interpolatedTarget.configurations)) {
|
|
110
|
+
// Each configuration gets the full treatment with defaults
|
|
111
|
+
configurations[configName] = buildTargetOptions({ ...configOptions, name: interpolatedTarget.name }, projectRoot, imageRef, isRunTarget);
|
|
112
|
+
}
|
|
113
|
+
return configurations;
|
|
114
|
+
}
|
|
50
115
|
async function createDockerTargets(projectRoot, options, context) {
|
|
51
116
|
const imageRef = projectRoot.replace(/^[\\/]/, '').replace(/[\\/\s]+/g, '-');
|
|
117
|
+
const interpolatedBuildTarget = interpolateDockerTargetOptions(options.buildTarget, projectRoot, imageRef, context);
|
|
118
|
+
const interpolatedRunTarget = interpolateDockerTargetOptions(options.runTarget, projectRoot, imageRef, context);
|
|
52
119
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
53
120
|
const targets = {};
|
|
54
121
|
const metadata = {
|
|
55
122
|
targetGroups: {
|
|
56
123
|
['Docker']: [
|
|
57
|
-
|
|
58
|
-
|
|
124
|
+
interpolatedBuildTarget.name,
|
|
125
|
+
interpolatedRunTarget.name,
|
|
59
126
|
'nx-release-publish',
|
|
60
127
|
],
|
|
61
128
|
},
|
|
62
129
|
};
|
|
63
|
-
|
|
130
|
+
const buildOptions = buildTargetOptions(interpolatedBuildTarget, projectRoot, imageRef, false);
|
|
131
|
+
const buildConfigurations = buildTargetConfigurations(interpolatedBuildTarget, projectRoot, imageRef, false);
|
|
132
|
+
targets[interpolatedBuildTarget.name] = {
|
|
64
133
|
dependsOn: ['build', '^build'],
|
|
65
134
|
command: `docker build .`,
|
|
66
|
-
options:
|
|
67
|
-
|
|
68
|
-
args: [`--tag ${imageRef}`],
|
|
69
|
-
},
|
|
135
|
+
options: buildOptions,
|
|
136
|
+
...(buildConfigurations && { configurations: buildConfigurations }),
|
|
70
137
|
inputs: [
|
|
71
138
|
...('production' in namedInputs
|
|
72
139
|
? ['production', '^production']
|
|
@@ -86,12 +153,13 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
86
153
|
},
|
|
87
154
|
},
|
|
88
155
|
};
|
|
89
|
-
|
|
90
|
-
|
|
156
|
+
const runOptions = buildTargetOptions(interpolatedRunTarget, projectRoot, imageRef, true);
|
|
157
|
+
const runConfigurations = buildTargetConfigurations(interpolatedRunTarget, projectRoot, imageRef, true);
|
|
158
|
+
targets[interpolatedRunTarget.name] = {
|
|
159
|
+
dependsOn: [interpolatedBuildTarget.name],
|
|
91
160
|
command: `docker run {args} ${imageRef}`,
|
|
92
|
-
options:
|
|
93
|
-
|
|
94
|
-
},
|
|
161
|
+
options: runOptions,
|
|
162
|
+
...(runConfigurations && { configurations: runConfigurations }),
|
|
95
163
|
inputs: [
|
|
96
164
|
...('production' in namedInputs
|
|
97
165
|
? ['production', '^production']
|
|
@@ -116,8 +184,17 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
116
184
|
return { targets, metadata };
|
|
117
185
|
}
|
|
118
186
|
function normalizePluginOptions(options) {
|
|
187
|
+
const normalizeTarget = (target, defaultName) => {
|
|
188
|
+
if (typeof target === 'string') {
|
|
189
|
+
return { name: target };
|
|
190
|
+
}
|
|
191
|
+
if (target && typeof target === 'object') {
|
|
192
|
+
return { ...target, name: target.name ?? defaultName };
|
|
193
|
+
}
|
|
194
|
+
return { name: defaultName };
|
|
195
|
+
};
|
|
119
196
|
return {
|
|
120
|
-
buildTarget: options.buildTarget
|
|
121
|
-
runTarget: options.runTarget
|
|
197
|
+
buildTarget: normalizeTarget(options.buildTarget, 'docker:build'),
|
|
198
|
+
runTarget: normalizeTarget(options.runTarget, 'docker:run'),
|
|
122
199
|
};
|
|
123
200
|
}
|
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
* {commitSha} - The full commit sha for the current commit
|
|
7
7
|
* {shortCommitSha} - The seven character commit sha for the current commit
|
|
8
8
|
* {env.VAR_NAME} - The value of the environment variable VAR_NAME
|
|
9
|
+
* {versionActionsVersion} - The version generated during the version actions such as "1.2.3"
|
|
9
10
|
*/
|
|
10
11
|
export interface PatternTokens {
|
|
11
12
|
projectName: string;
|
|
12
13
|
currentDate: Date;
|
|
13
14
|
commitSha: string;
|
|
14
15
|
shortCommitSha: string;
|
|
16
|
+
versionActionsVersion: string;
|
|
15
17
|
}
|
|
16
18
|
export declare function interpolateVersionPattern(versionPattern: string, data: Partial<PatternTokens>): string;
|
|
17
19
|
//# sourceMappingURL=version-pattern-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-pattern-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-pattern-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version-pattern-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-pattern-utils.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,UAY7B"}
|
|
@@ -2,23 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.interpolateVersionPattern = interpolateVersionPattern;
|
|
4
4
|
const git_utils_1 = require("nx/src/utils/git-utils");
|
|
5
|
-
const
|
|
6
|
-
function formatDate(date, format) {
|
|
7
|
-
const year = String(date.getUTCFullYear());
|
|
8
|
-
const month = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
9
|
-
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
10
|
-
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
11
|
-
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
12
|
-
const seconds = String(date.getUTCSeconds()).padStart(2, '0');
|
|
13
|
-
return format
|
|
14
|
-
.replace(/YYYY/g, year)
|
|
15
|
-
.replace(/YY/g, year.slice(-2))
|
|
16
|
-
.replace(/MM/g, month)
|
|
17
|
-
.replace(/DD/g, day)
|
|
18
|
-
.replace(/HH/g, hours)
|
|
19
|
-
.replace(/mm/g, minutes)
|
|
20
|
-
.replace(/ss/g, seconds);
|
|
21
|
-
}
|
|
5
|
+
const interpolate_pattern_1 = require("../utils/interpolate-pattern");
|
|
22
6
|
function interpolateVersionPattern(versionPattern, data) {
|
|
23
7
|
const commitSha = (0, git_utils_1.getLatestCommitSha)();
|
|
24
8
|
const substitutions = {
|
|
@@ -26,27 +10,7 @@ function interpolateVersionPattern(versionPattern, data) {
|
|
|
26
10
|
currentDate: data.currentDate ?? new Date(),
|
|
27
11
|
commitSha: data.commitSha ?? commitSha,
|
|
28
12
|
shortCommitSha: data.shortCommitSha ?? commitSha.slice(0, 7),
|
|
13
|
+
versionActionsVersion: data.versionActionsVersion ?? '',
|
|
29
14
|
};
|
|
30
|
-
return
|
|
31
|
-
// Handle environment variables
|
|
32
|
-
if (envVarName) {
|
|
33
|
-
const envValue = process.env[envVarName];
|
|
34
|
-
return envValue !== undefined ? envValue : match;
|
|
35
|
-
}
|
|
36
|
-
// Handle other tokens
|
|
37
|
-
const value = substitutions[identifier];
|
|
38
|
-
if (value === undefined) {
|
|
39
|
-
return match; // Keep original token if no data
|
|
40
|
-
}
|
|
41
|
-
// Handle date formatting
|
|
42
|
-
if (identifier === 'currentDate') {
|
|
43
|
-
if (format) {
|
|
44
|
-
return formatDate(value, format);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return value.toISOString();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return value;
|
|
51
|
-
});
|
|
15
|
+
return (0, interpolate_pattern_1.interpolatePattern)(versionPattern, substitutions);
|
|
52
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
2
|
import type { FinalConfigForProject } from 'nx/src/command-line/release/utils/release-graph';
|
|
3
3
|
export declare const getDockerVersionPath: (workspaceRoot: string, projectRoot: string) => string;
|
|
4
|
-
export declare function handleDockerVersion(workspaceRoot: string, projectGraphNode: ProjectGraphProjectNode, finalConfigForProject: FinalConfigForProject, dockerVersionScheme?: string, dockerVersion?: string): Promise<{
|
|
4
|
+
export declare function handleDockerVersion(workspaceRoot: string, projectGraphNode: ProjectGraphProjectNode, finalConfigForProject: FinalConfigForProject, dockerVersionScheme?: string, dockerVersion?: string, versionActionsVersion?: string): Promise<{
|
|
5
5
|
newVersion: string;
|
|
6
6
|
logs: string[];
|
|
7
7
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAQ7F,eAAO,MAAM,oBAAoB,GAC/B,eAAe,MAAM,EACrB,aAAa,MAAM,WAGpB,CAAC;AAEF,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,uBAAuB,EACzC,qBAAqB,EAAE,qBAAqB,EAC5C,mBAAmB,CAAC,EAAE,MAAM,EAC5B,aAAa,CAAC,EAAE,MAAM;;;
|
|
1
|
+
{"version":3,"file":"version-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/release/version-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAQ7F,eAAO,MAAM,oBAAoB,GAC/B,eAAe,MAAM,EACrB,aAAa,MAAM,WAGpB,CAAC;AAEF,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,uBAAuB,EACzC,qBAAqB,EAAE,qBAAqB,EAC5C,mBAAmB,CAAC,EAAE,MAAM,EAC5B,aAAa,CAAC,EAAE,MAAM,EACtB,qBAAqB,CAAC,EAAE,MAAM;;;GA6C/B"}
|
|
@@ -15,7 +15,7 @@ const getDockerVersionPath = (workspaceRoot, projectRoot) => {
|
|
|
15
15
|
return (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, '.docker-version');
|
|
16
16
|
};
|
|
17
17
|
exports.getDockerVersionPath = getDockerVersionPath;
|
|
18
|
-
async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigForProject, dockerVersionScheme, dockerVersion) {
|
|
18
|
+
async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigForProject, dockerVersionScheme, dockerVersion, versionActionsVersion) {
|
|
19
19
|
// If the full docker image reference is provided, use it directly
|
|
20
20
|
const nxDockerImageRefEnvOverride = process.env.NX_DOCKER_IMAGE_REF?.trim() || undefined;
|
|
21
21
|
// If an explicit dockerVersion is provided, use it directly
|
|
@@ -30,7 +30,7 @@ async function handleDockerVersion(workspaceRoot, projectGraphNode, finalConfigF
|
|
|
30
30
|
const versionScheme = dockerVersionScheme && dockerVersionScheme in availableVersionSchemes
|
|
31
31
|
? dockerVersionScheme
|
|
32
32
|
: await promptForNewVersion(availableVersionSchemes, projectGraphNode.name);
|
|
33
|
-
newVersion = calculateNewVersion(projectGraphNode.name, versionScheme, availableVersionSchemes);
|
|
33
|
+
newVersion = calculateNewVersion(projectGraphNode.name, versionScheme, availableVersionSchemes, versionActionsVersion);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
const logs = updateProjectVersion(newVersion, nxDockerImageRefEnvOverride, workspaceRoot, projectGraphNode.data.root, finalConfigForProject.dockerOptions.repositoryName, finalConfigForProject.dockerOptions.registryUrl);
|
|
@@ -53,12 +53,13 @@ async function promptForNewVersion(versionSchemes, projectName) {
|
|
|
53
53
|
});
|
|
54
54
|
return versionScheme;
|
|
55
55
|
}
|
|
56
|
-
function calculateNewVersion(projectName, versionScheme, versionSchemes) {
|
|
56
|
+
function calculateNewVersion(projectName, versionScheme, versionSchemes, versionActionsVersion) {
|
|
57
57
|
if (!(versionScheme in versionSchemes)) {
|
|
58
58
|
throw new Error(`Could not find version scheme '${versionScheme}'. Available options are: ${Object.keys(versionSchemes).join(', ')}.`);
|
|
59
59
|
}
|
|
60
60
|
return (0, version_pattern_utils_1.interpolateVersionPattern)(versionSchemes[versionScheme], {
|
|
61
61
|
projectName,
|
|
62
|
+
versionActionsVersion,
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
function updateProjectVersion(newVersion, nxDockerImageRefEnvOverride, workspaceRoot, projectRoot, repositoryName, registry) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpolates pattern tokens in a string.
|
|
3
|
+
*
|
|
4
|
+
* Supported tokens:
|
|
5
|
+
* - {tokenName} - Simple token replacement
|
|
6
|
+
* - {currentDate} - Current date in ISO format
|
|
7
|
+
* - {currentDate|FORMAT} - Current date with custom format (YYYY, YY, MM, DD, HH, mm, ss)
|
|
8
|
+
* - {env.VAR_NAME} - Environment variable value
|
|
9
|
+
*
|
|
10
|
+
* @param pattern - String containing tokens to interpolate
|
|
11
|
+
* @param tokens - Record of token values
|
|
12
|
+
* @returns Interpolated string
|
|
13
|
+
*/
|
|
14
|
+
export declare function interpolatePattern(pattern: string, tokens: Record<string, any>): string;
|
|
15
|
+
/**
|
|
16
|
+
* Recursively interpolates pattern tokens in all string values within an object or array.
|
|
17
|
+
*
|
|
18
|
+
* @param obj - Object or array to process
|
|
19
|
+
* @param tokens - Record of token values
|
|
20
|
+
* @returns New object/array with interpolated values
|
|
21
|
+
*/
|
|
22
|
+
export declare function interpolateObject<T>(obj: T, tokens: Record<string, any>): T;
|
|
23
|
+
//# sourceMappingURL=interpolate-pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpolate-pattern.d.ts","sourceRoot":"","sources":["../../../../../packages/docker/src/utils/interpolate-pattern.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,MAAM,CA6BR;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAkB3E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolatePattern = interpolatePattern;
|
|
4
|
+
exports.interpolateObject = interpolateObject;
|
|
5
|
+
const tokenRegex = /\{(env\.([^}]+)|([^|{}]+)(?:\|([^{}]+))?)\}/g;
|
|
6
|
+
function formatDate(date, format) {
|
|
7
|
+
const year = String(date.getUTCFullYear());
|
|
8
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
9
|
+
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
10
|
+
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
11
|
+
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
12
|
+
const seconds = String(date.getUTCSeconds()).padStart(2, '0');
|
|
13
|
+
return format
|
|
14
|
+
.replace(/YYYY/g, year)
|
|
15
|
+
.replace(/YY/g, year.slice(-2))
|
|
16
|
+
.replace(/MM/g, month)
|
|
17
|
+
.replace(/DD/g, day)
|
|
18
|
+
.replace(/HH/g, hours)
|
|
19
|
+
.replace(/mm/g, minutes)
|
|
20
|
+
.replace(/ss/g, seconds);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Interpolates pattern tokens in a string.
|
|
24
|
+
*
|
|
25
|
+
* Supported tokens:
|
|
26
|
+
* - {tokenName} - Simple token replacement
|
|
27
|
+
* - {currentDate} - Current date in ISO format
|
|
28
|
+
* - {currentDate|FORMAT} - Current date with custom format (YYYY, YY, MM, DD, HH, mm, ss)
|
|
29
|
+
* - {env.VAR_NAME} - Environment variable value
|
|
30
|
+
*
|
|
31
|
+
* @param pattern - String containing tokens to interpolate
|
|
32
|
+
* @param tokens - Record of token values
|
|
33
|
+
* @returns Interpolated string
|
|
34
|
+
*/
|
|
35
|
+
function interpolatePattern(pattern, tokens) {
|
|
36
|
+
return pattern.replace(tokenRegex, (match, fullMatch, envVarName, identifier, format) => {
|
|
37
|
+
// Handle environment variables
|
|
38
|
+
if (envVarName) {
|
|
39
|
+
const envValue = process.env[envVarName];
|
|
40
|
+
return envValue !== undefined ? envValue : match;
|
|
41
|
+
}
|
|
42
|
+
// Handle other tokens
|
|
43
|
+
const value = tokens[identifier];
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
return match; // Keep original token if no data
|
|
46
|
+
}
|
|
47
|
+
// Handle date formatting
|
|
48
|
+
if (identifier === 'currentDate') {
|
|
49
|
+
if (format) {
|
|
50
|
+
return formatDate(value, format);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return value.toISOString();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Recursively interpolates pattern tokens in all string values within an object or array.
|
|
61
|
+
*
|
|
62
|
+
* @param obj - Object or array to process
|
|
63
|
+
* @param tokens - Record of token values
|
|
64
|
+
* @returns New object/array with interpolated values
|
|
65
|
+
*/
|
|
66
|
+
function interpolateObject(obj, tokens) {
|
|
67
|
+
if (typeof obj === 'string') {
|
|
68
|
+
return interpolatePattern(obj, tokens);
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(obj)) {
|
|
71
|
+
return obj.map((item) => interpolateObject(item, tokens));
|
|
72
|
+
}
|
|
73
|
+
if (obj !== null && typeof obj === 'object') {
|
|
74
|
+
const result = {};
|
|
75
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
76
|
+
result[key] = interpolateObject(value, tokens);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
return obj;
|
|
81
|
+
}
|