@nx/node 0.0.0-pr-32120-1cb4170 → 0.0.0-pr-32149-2d2cbf3
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 +6 -7
- package/src/generators/application/application.d.ts.map +1 -1
- package/src/generators/application/application.js +0 -1
- package/src/generators/application/schema.d.ts +0 -1
- package/src/generators/application/schema.json +0 -5
- package/src/generators/setup-docker/files/Dockerfile__tmpl__ +5 -7
- package/src/generators/setup-docker/schema.d.ts +0 -1
- package/src/generators/setup-docker/schema.json +1 -6
- package/src/generators/setup-docker/setup-docker.d.ts.map +1 -1
- package/src/generators/setup-docker/setup-docker.js +11 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/node",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-32149-2d2cbf3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Node Plugin for Nx contains generators to manage Node applications within an Nx workspace.",
|
|
6
6
|
"repository": {
|
|
@@ -32,16 +32,15 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"tslib": "^2.3.0",
|
|
35
|
-
"@nx/devkit": "0.0.0-pr-
|
|
36
|
-
"@nx/jest": "0.0.0-pr-
|
|
37
|
-
"@nx/js": "0.0.0-pr-
|
|
38
|
-
"@nx/eslint": "0.0.0-pr-
|
|
39
|
-
"@nx/docker": "0.0.0-pr-32120-1cb4170",
|
|
35
|
+
"@nx/devkit": "0.0.0-pr-32149-2d2cbf3",
|
|
36
|
+
"@nx/jest": "0.0.0-pr-32149-2d2cbf3",
|
|
37
|
+
"@nx/js": "0.0.0-pr-32149-2d2cbf3",
|
|
38
|
+
"@nx/eslint": "0.0.0-pr-32149-2d2cbf3",
|
|
40
39
|
"tcp-port-used": "^1.0.2",
|
|
41
40
|
"kill-port": "^1.6.1"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"nx": "0.0.0-pr-
|
|
43
|
+
"nx": "0.0.0-pr-32149-2d2cbf3"
|
|
45
44
|
},
|
|
46
45
|
"publishConfig": {
|
|
47
46
|
"access": "public"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAIjB,IAAI,EAIL,MAAM,YAAY,CAAC;AAapB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAwClC,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAMpE;AAED,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAIjB,IAAI,EAIL,MAAM,YAAY,CAAC;AAapB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAwClC,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAMpE;AAED,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BA+K5E;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -124,11 +124,6 @@
|
|
|
124
124
|
"type": "boolean",
|
|
125
125
|
"description": "Add a docker build target"
|
|
126
126
|
},
|
|
127
|
-
"skipDockerPlugin": {
|
|
128
|
-
"type": "boolean",
|
|
129
|
-
"description": "Skip the @nx/docker plugin and use the legacy docker build target instead.",
|
|
130
|
-
"default": false
|
|
131
|
-
},
|
|
132
127
|
"useProjectJson": {
|
|
133
128
|
"type": "boolean",
|
|
134
129
|
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# This file is generated by Nx.
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
|
|
2
|
+
#
|
|
3
|
+
# Build the docker image with `npx nx docker-build <%= project %>`.
|
|
4
|
+
# Tip: Modify "docker-build" options in project.json to change docker build args.
|
|
5
|
+
#
|
|
5
6
|
# Run the container with `docker run -p 3000:3000 -t <%= sanitizedProjectName %>`.
|
|
6
|
-
#<% } else { %>
|
|
7
|
-
# Run the container with `nx docker:run <%= project %> -p 3000:3000`.
|
|
8
|
-
#<% } %>
|
|
9
7
|
FROM docker.io/node:lts-alpine
|
|
10
8
|
|
|
11
9
|
ENV HOST=0.0.0.0
|
|
@@ -17,7 +15,7 @@ RUN addgroup --system <%= sanitizedProjectName %> && \
|
|
|
17
15
|
adduser --system -G <%= sanitizedProjectName %> <%= sanitizedProjectName %>
|
|
18
16
|
|
|
19
17
|
COPY <%= buildLocation %> <%= sanitizedProjectName %>/
|
|
20
|
-
|
|
18
|
+
COPY <%= projectPath %>/package.json <%= sanitizedProjectName %>/
|
|
21
19
|
RUN chown -R <%= sanitizedProjectName %>:<%= sanitizedProjectName %> .
|
|
22
20
|
|
|
23
21
|
# You can remove this install step if you build with `--bundle` option.
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"targetName": {
|
|
19
19
|
"description": "The name of the target to create",
|
|
20
20
|
"type": "string",
|
|
21
|
-
"default": "docker
|
|
21
|
+
"default": "docker-build"
|
|
22
22
|
},
|
|
23
23
|
"buildTargetName": {
|
|
24
24
|
"description": "The name of the build target",
|
|
@@ -28,11 +28,6 @@
|
|
|
28
28
|
"outputPath": {
|
|
29
29
|
"description": "The output path for the node application",
|
|
30
30
|
"type": "string"
|
|
31
|
-
},
|
|
32
|
-
"skipDockerPlugin": {
|
|
33
|
-
"type": "boolean",
|
|
34
|
-
"description": "Skip the @nx/docker plugin and use the legacy docker build target instead.",
|
|
35
|
-
"default": false
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-docker.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/setup-docker/setup-docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"setup-docker.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/setup-docker/setup-docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAKjB,IAAI,EAEL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAmD9C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,QAe1E;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,kBAAkB,8BAajC;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -3,15 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateProjectConfig = updateProjectConfig;
|
|
4
4
|
exports.setupDockerGenerator = setupDockerGenerator;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const generators_1 = require("@nx/docker/generators");
|
|
7
6
|
const path_1 = require("path");
|
|
8
7
|
function normalizeOptions(tree, setupOptions) {
|
|
9
8
|
return {
|
|
10
9
|
...setupOptions,
|
|
11
10
|
project: setupOptions.project ?? (0, devkit_1.readNxJson)(tree).defaultProject,
|
|
12
|
-
targetName: setupOptions.targetName ?? 'docker
|
|
11
|
+
targetName: setupOptions.targetName ?? 'docker-build',
|
|
13
12
|
buildTarget: setupOptions.buildTarget ?? 'build',
|
|
14
|
-
skipDockerPlugin: setupOptions.skipDockerPlugin ?? false,
|
|
15
13
|
};
|
|
16
14
|
}
|
|
17
15
|
function sanitizeProjectName(projectName) {
|
|
@@ -22,11 +20,7 @@ function sanitizeProjectName(projectName) {
|
|
|
22
20
|
.replace(/-+/g, '-')
|
|
23
21
|
.replace(/^-|-$/g, '');
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
let installTask = () => { };
|
|
27
|
-
if (!options.skipDockerPlugin) {
|
|
28
|
-
installTask = await (0, generators_1.initGenerator)(tree, { skipFormat: true });
|
|
29
|
-
}
|
|
23
|
+
function addDocker(tree, options) {
|
|
30
24
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
31
25
|
const outputPath = projectConfig.targets[options.buildTarget]?.options['outputPath'];
|
|
32
26
|
if (!projectConfig) {
|
|
@@ -36,58 +30,29 @@ async function addDocker(tree, options) {
|
|
|
36
30
|
throw new Error(`The output path for the project ${options.project} is not defined. Please provide it as an option to the generator.`);
|
|
37
31
|
}
|
|
38
32
|
const sanitizedProjectName = sanitizeProjectName(options.project);
|
|
39
|
-
const finalOutputPath = options.outputPath ?? outputPath;
|
|
40
|
-
// Calculate build location based on skipDockerPlugin flag
|
|
41
|
-
let buildLocation;
|
|
42
|
-
if (options.skipDockerPlugin) {
|
|
43
|
-
// Legacy mode: use workspace-relative paths
|
|
44
|
-
buildLocation = finalOutputPath;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// New mode: use project-relative paths
|
|
48
|
-
// Remove the project root prefix from the output path
|
|
49
|
-
const projectRootWithSlash = projectConfig.root + '/';
|
|
50
|
-
buildLocation = finalOutputPath.startsWith(projectRootWithSlash)
|
|
51
|
-
? finalOutputPath.substring(projectRootWithSlash.length)
|
|
52
|
-
: finalOutputPath.startsWith(projectConfig.root)
|
|
53
|
-
? finalOutputPath.substring(projectConfig.root.length)
|
|
54
|
-
: 'dist';
|
|
55
|
-
}
|
|
56
33
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), projectConfig.root, {
|
|
57
34
|
tmpl: '',
|
|
58
|
-
buildLocation,
|
|
35
|
+
buildLocation: options.outputPath ?? outputPath,
|
|
59
36
|
project: options.project,
|
|
60
37
|
projectPath: projectConfig.root,
|
|
61
38
|
sanitizedProjectName,
|
|
62
|
-
skipDockerPlugin: options.skipDockerPlugin,
|
|
63
39
|
});
|
|
64
|
-
return installTask;
|
|
65
40
|
}
|
|
66
41
|
function updateProjectConfig(tree, options) {
|
|
67
42
|
let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
options: {
|
|
75
|
-
cwd: projectConfig.root,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
projectConfig.targets[`${options.targetName}`] = {
|
|
81
|
-
dependsOn: [`${options.buildTarget}`, 'prune'],
|
|
82
|
-
};
|
|
83
|
-
}
|
|
43
|
+
// Use sanitized project name for Docker image tag
|
|
44
|
+
const sanitizedProjectName = sanitizeProjectName(options.project);
|
|
45
|
+
projectConfig.targets[`${options.targetName}`] = {
|
|
46
|
+
dependsOn: [`${options.buildTarget}`],
|
|
47
|
+
command: `docker build -f ${(0, devkit_1.joinPathFragments)(projectConfig.root, 'Dockerfile')} . -t ${sanitizedProjectName}`,
|
|
48
|
+
};
|
|
84
49
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
|
85
50
|
}
|
|
86
51
|
async function setupDockerGenerator(tree, setupOptions) {
|
|
87
52
|
const tasks = [];
|
|
88
53
|
const options = normalizeOptions(tree, setupOptions);
|
|
89
|
-
|
|
90
|
-
|
|
54
|
+
// Should check if the node project exists
|
|
55
|
+
addDocker(tree, options);
|
|
91
56
|
updateProjectConfig(tree, options);
|
|
92
57
|
if (!options.skipFormat) {
|
|
93
58
|
await (0, devkit_1.formatFiles)(tree);
|