@nx/docker 0.0.0-pr-32892-1cb8488 → 0.0.0-pr-32947-7d6ca22
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 +2 -9
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +14 -68
- package/src/release/version-pattern-utils.d.ts.map +1 -1
- package/src/release/version-pattern-utils.js +39 -2
- package/src/utils/interpolate-pattern.d.ts +0 -23
- package/src/utils/interpolate-pattern.d.ts.map +0 -1
- package/src/utils/interpolate-pattern.js +0 -81
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-32947-7d6ca22",
|
|
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-32947-7d6ca22",
|
|
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-32947-7d6ca22"
|
|
56
56
|
},
|
|
57
57
|
"types": "./src/index.d.ts"
|
|
58
58
|
}
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
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
|
-
}
|
|
9
2
|
export interface DockerPluginOptions {
|
|
10
|
-
buildTarget?: string
|
|
11
|
-
runTarget?: string
|
|
3
|
+
buildTarget?: string;
|
|
4
|
+
runTarget?: string;
|
|
12
5
|
}
|
|
13
6
|
export declare const createNodesV2: CreateNodesV2<DockerPluginOptions>;
|
|
14
7
|
//# 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;AAQpB,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAsBD,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAmC5D,CAAC"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -8,8 +8,6 @@ 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");
|
|
13
11
|
function readTargetsCache(cachePath) {
|
|
14
12
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
15
13
|
}
|
|
@@ -49,63 +47,26 @@ async function createNodesInternal(configFilePath, hash, normalizedOptions, cont
|
|
|
49
47
|
},
|
|
50
48
|
};
|
|
51
49
|
}
|
|
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
50
|
async function createDockerTargets(projectRoot, options, context) {
|
|
83
51
|
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);
|
|
86
52
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
87
53
|
const targets = {};
|
|
88
54
|
const metadata = {
|
|
89
55
|
targetGroups: {
|
|
90
56
|
['Docker']: [
|
|
91
|
-
|
|
92
|
-
|
|
57
|
+
`${options.buildTarget}`,
|
|
58
|
+
`${options.runTarget}`,
|
|
93
59
|
'nx-release-publish',
|
|
94
60
|
],
|
|
95
61
|
},
|
|
96
62
|
};
|
|
97
|
-
|
|
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] = {
|
|
63
|
+
targets[options.buildTarget] = {
|
|
106
64
|
dependsOn: ['build', '^build'],
|
|
107
65
|
command: `docker build .`,
|
|
108
|
-
options:
|
|
66
|
+
options: {
|
|
67
|
+
cwd: projectRoot,
|
|
68
|
+
args: [`--tag ${imageRef}`],
|
|
69
|
+
},
|
|
109
70
|
inputs: [
|
|
110
71
|
...('production' in namedInputs
|
|
111
72
|
? ['production', '^production']
|
|
@@ -125,18 +86,12 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
125
86
|
},
|
|
126
87
|
},
|
|
127
88
|
};
|
|
128
|
-
|
|
129
|
-
|
|
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],
|
|
89
|
+
targets[options.runTarget] = {
|
|
90
|
+
dependsOn: [options.buildTarget],
|
|
138
91
|
command: `docker run {args} ${imageRef}`,
|
|
139
|
-
options:
|
|
92
|
+
options: {
|
|
93
|
+
cwd: projectRoot,
|
|
94
|
+
},
|
|
140
95
|
inputs: [
|
|
141
96
|
...('production' in namedInputs
|
|
142
97
|
? ['production', '^production']
|
|
@@ -161,17 +116,8 @@ async function createDockerTargets(projectRoot, options, context) {
|
|
|
161
116
|
return { targets, metadata };
|
|
162
117
|
}
|
|
163
118
|
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
|
-
};
|
|
173
119
|
return {
|
|
174
|
-
buildTarget:
|
|
175
|
-
runTarget:
|
|
120
|
+
buildTarget: options.buildTarget ?? 'docker:build',
|
|
121
|
+
runTarget: options.runTarget ?? 'docker:run',
|
|
176
122
|
};
|
|
177
123
|
}
|
|
@@ -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":"AAEA;;;;;;;;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;AAsBD,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,UAsC7B"}
|
|
@@ -2,7 +2,23 @@
|
|
|
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
|
|
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
|
+
}
|
|
6
22
|
function interpolateVersionPattern(versionPattern, data) {
|
|
7
23
|
const commitSha = (0, git_utils_1.getLatestCommitSha)();
|
|
8
24
|
const substitutions = {
|
|
@@ -11,5 +27,26 @@ function interpolateVersionPattern(versionPattern, data) {
|
|
|
11
27
|
commitSha: data.commitSha ?? commitSha,
|
|
12
28
|
shortCommitSha: data.shortCommitSha ?? commitSha.slice(0, 7),
|
|
13
29
|
};
|
|
14
|
-
return (
|
|
30
|
+
return versionPattern.replace(tokenRegex, (match, fullMatch, envVarName, identifier, format) => {
|
|
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
52
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
}
|