@nx/docker 0.0.0-pr-32918-04e1c21 → 0.0.0-pr-32892-1cb8488
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 +9 -2
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +68 -14
- package/src/release/version-pattern-utils.d.ts.map +1 -1
- package/src/release/version-pattern-utils.js +2 -39
- 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": "0.0.0-pr-
|
|
4
|
+
"version": "0.0.0-pr-32892-1cb8488",
|
|
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": "0.0.0-pr-
|
|
50
|
+
"@nx/devkit": "0.0.0-pr-32892-1cb8488",
|
|
51
51
|
"enquirer": "~2.3.6",
|
|
52
52
|
"tslib": "^2.3.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"nx": "0.0.0-pr-
|
|
55
|
+
"nx": "0.0.0-pr-32892-1cb8488"
|
|
56
56
|
},
|
|
57
57
|
"types": "./src/index.d.ts"
|
|
58
58
|
}
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
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
|
+
}
|
|
2
9
|
export interface DockerPluginOptions {
|
|
3
|
-
buildTarget?: string;
|
|
4
|
-
runTarget?: string;
|
|
10
|
+
buildTarget?: string | DockerTargetOptions;
|
|
11
|
+
runTarget?: string | DockerTargetOptions;
|
|
5
12
|
}
|
|
6
13
|
export declare const createNodesV2: CreateNodesV2<DockerPluginOptions>;
|
|
7
14
|
//# 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;CACd;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,63 @@ 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
|
+
}
|
|
50
82
|
async function createDockerTargets(projectRoot, options, context) {
|
|
51
83
|
const imageRef = projectRoot.replace(/^[\\/]/, '').replace(/[\\/\s]+/g, '-');
|
|
84
|
+
const interpolatedBuildTarget = interpolateDockerTargetOptions(options.buildTarget, projectRoot, imageRef, context);
|
|
85
|
+
const interpolatedRunTarget = interpolateDockerTargetOptions(options.runTarget, projectRoot, imageRef, context);
|
|
52
86
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
53
87
|
const targets = {};
|
|
54
88
|
const metadata = {
|
|
55
89
|
targetGroups: {
|
|
56
90
|
['Docker']: [
|
|
57
|
-
|
|
58
|
-
|
|
91
|
+
interpolatedBuildTarget.name,
|
|
92
|
+
interpolatedRunTarget.name,
|
|
59
93
|
'nx-release-publish',
|
|
60
94
|
],
|
|
61
95
|
},
|
|
62
96
|
};
|
|
63
|
-
|
|
97
|
+
const buildOptions = {
|
|
98
|
+
cwd: interpolatedBuildTarget.cwd ?? projectRoot,
|
|
99
|
+
args: [`--tag ${imageRef}`, ...(interpolatedBuildTarget.args ?? [])],
|
|
100
|
+
...(interpolatedBuildTarget.env && { env: interpolatedBuildTarget.env }),
|
|
101
|
+
...(interpolatedBuildTarget.envFile && {
|
|
102
|
+
envFile: interpolatedBuildTarget.envFile,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
targets[interpolatedBuildTarget.name] = {
|
|
64
106
|
dependsOn: ['build', '^build'],
|
|
65
107
|
command: `docker build .`,
|
|
66
|
-
options:
|
|
67
|
-
cwd: projectRoot,
|
|
68
|
-
args: [`--tag ${imageRef}`],
|
|
69
|
-
},
|
|
108
|
+
options: buildOptions,
|
|
70
109
|
inputs: [
|
|
71
110
|
...('production' in namedInputs
|
|
72
111
|
? ['production', '^production']
|
|
@@ -86,12 +125,18 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
86
125
|
},
|
|
87
126
|
},
|
|
88
127
|
};
|
|
89
|
-
|
|
90
|
-
|
|
128
|
+
const runOptions = {
|
|
129
|
+
cwd: interpolatedRunTarget.cwd ?? projectRoot,
|
|
130
|
+
...(interpolatedRunTarget.args && { args: interpolatedRunTarget.args }),
|
|
131
|
+
...(interpolatedRunTarget.env && { env: interpolatedRunTarget.env }),
|
|
132
|
+
...(interpolatedRunTarget.envFile && {
|
|
133
|
+
envFile: interpolatedRunTarget.envFile,
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
targets[interpolatedRunTarget.name] = {
|
|
137
|
+
dependsOn: [interpolatedBuildTarget.name],
|
|
91
138
|
command: `docker run {args} ${imageRef}`,
|
|
92
|
-
options:
|
|
93
|
-
cwd: projectRoot,
|
|
94
|
-
},
|
|
139
|
+
options: runOptions,
|
|
95
140
|
inputs: [
|
|
96
141
|
...('production' in namedInputs
|
|
97
142
|
? ['production', '^production']
|
|
@@ -116,8 +161,17 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
116
161
|
return { targets, metadata };
|
|
117
162
|
}
|
|
118
163
|
function normalizePluginOptions(options) {
|
|
164
|
+
const normalizeTarget = (target, defaultName) => {
|
|
165
|
+
if (typeof target === 'string') {
|
|
166
|
+
return { name: target };
|
|
167
|
+
}
|
|
168
|
+
if (target && typeof target === 'object') {
|
|
169
|
+
return { ...target, name: target.name ?? defaultName };
|
|
170
|
+
}
|
|
171
|
+
return { name: defaultName };
|
|
172
|
+
};
|
|
119
173
|
return {
|
|
120
|
-
buildTarget: options.buildTarget
|
|
121
|
-
runTarget: options.runTarget
|
|
174
|
+
buildTarget: normalizeTarget(options.buildTarget, 'docker:build'),
|
|
175
|
+
runTarget: normalizeTarget(options.runTarget, 'docker:run'),
|
|
122
176
|
};
|
|
123
177
|
}
|
|
@@ -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;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,IAAI,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,UAW7B"}
|
|
@@ -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 = {
|
|
@@ -27,26 +11,5 @@ function interpolateVersionPattern(versionPattern, data) {
|
|
|
27
11
|
commitSha: data.commitSha ?? commitSha,
|
|
28
12
|
shortCommitSha: data.shortCommitSha ?? commitSha.slice(0, 7),
|
|
29
13
|
};
|
|
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
|
-
});
|
|
14
|
+
return (0, interpolate_pattern_1.interpolatePattern)(versionPattern, substitutions);
|
|
52
15
|
}
|
|
@@ -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
|
+
}
|