@nx/node 0.0.0-pr-22179-271588f

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.
Files changed (69) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +66 -0
  3. package/generators.json +34 -0
  4. package/index.d.ts +3 -0
  5. package/index.js +9 -0
  6. package/migrations.json +48 -0
  7. package/package.json +44 -0
  8. package/src/generators/application/application.d.ts +10 -0
  9. package/src/generators/application/application.js +412 -0
  10. package/src/generators/application/files/common/src/assets/.gitkeep +0 -0
  11. package/src/generators/application/files/common/src/main.ts__tmpl__ +1 -0
  12. package/src/generators/application/files/common/tsconfig.app.json +10 -0
  13. package/src/generators/application/files/common/tsconfig.json +10 -0
  14. package/src/generators/application/files/common/webpack.config.js__tmpl__ +35 -0
  15. package/src/generators/application/files/express/src/main.ts__tmpl__ +14 -0
  16. package/src/generators/application/files/fastify/src/app/app.spec.ts__tmpl__ +20 -0
  17. package/src/generators/application/files/fastify/src/app/app.ts__tmpl__ +27 -0
  18. package/src/generators/application/files/fastify/src/app/plugins/sensible.ts__tmpl__ +12 -0
  19. package/src/generators/application/files/fastify/src/app/routes/root.ts__tmpl__ +7 -0
  20. package/src/generators/application/files/fastify/src/main.ts__tmpl__ +23 -0
  21. package/src/generators/application/files/koa/src/main.ts__tmpl__ +14 -0
  22. package/src/generators/application/schema.d.ts +31 -0
  23. package/src/generators/application/schema.json +136 -0
  24. package/src/generators/e2e-project/e2e-project.d.ts +5 -0
  25. package/src/generators/e2e-project/e2e-project.js +123 -0
  26. package/src/generators/e2e-project/files/cli/jest.config.ts__tmpl__ +14 -0
  27. package/src/generators/e2e-project/files/cli/src/__fileName__/__fileName__.spec.ts__tmpl__ +13 -0
  28. package/src/generators/e2e-project/files/cli/src/test-setup.ts__tmpl__ +1 -0
  29. package/src/generators/e2e-project/files/cli/tsconfig.json__tmpl__ +13 -0
  30. package/src/generators/e2e-project/files/cli/tsconfig.spec.json__tmpl__ +12 -0
  31. package/src/generators/e2e-project/files/server/common/jest.config.ts__tmpl__ +16 -0
  32. package/src/generators/e2e-project/files/server/common/src/__fileName__/__fileName__.spec.ts__tmpl__ +10 -0
  33. package/src/generators/e2e-project/files/server/common/src/support/global-setup.ts__tmpl__ +11 -0
  34. package/src/generators/e2e-project/files/server/common/src/support/global-teardown.ts__tmpl__ +7 -0
  35. package/src/generators/e2e-project/files/server/common/src/support/test-setup.ts__tmpl__ +10 -0
  36. package/src/generators/e2e-project/files/server/common/tsconfig.json__tmpl__ +13 -0
  37. package/src/generators/e2e-project/files/server/common/tsconfig.spec.json__tmpl__ +12 -0
  38. package/src/generators/e2e-project/files/server/nest/src/__fileName__/__fileName__.spec.ts__tmpl__ +10 -0
  39. package/src/generators/e2e-project/schema.d.ts +15 -0
  40. package/src/generators/e2e-project/schema.json +70 -0
  41. package/src/generators/init/init.d.ts +4 -0
  42. package/src/generators/init/init.js +23 -0
  43. package/src/generators/init/schema.d.ts +5 -0
  44. package/src/generators/init/schema.json +27 -0
  45. package/src/generators/library/files/lib/package.json__tmpl__ +4 -0
  46. package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +7 -0
  47. package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +3 -0
  48. package/src/generators/library/files/lib/tsconfig.lib.json +11 -0
  49. package/src/generators/library/library.d.ts +12 -0
  50. package/src/generators/library/library.js +141 -0
  51. package/src/generators/library/schema.d.ts +27 -0
  52. package/src/generators/library/schema.json +136 -0
  53. package/src/generators/setup-docker/files/Dockerfile__tmpl__ +24 -0
  54. package/src/generators/setup-docker/schema.d.ts +6 -0
  55. package/src/generators/setup-docker/schema.json +29 -0
  56. package/src/generators/setup-docker/setup-docker.d.ts +5 -0
  57. package/src/generators/setup-docker/setup-docker.js +53 -0
  58. package/src/migrations/update-16-0-0/update-webpack-executor.d.ts +2 -0
  59. package/src/migrations/update-16-0-0/update-webpack-executor.js +17 -0
  60. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  61. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  62. package/src/migrations/update-16-3-1/update-webpack-executor.d.ts +2 -0
  63. package/src/migrations/update-16-3-1/update-webpack-executor.js +17 -0
  64. package/src/migrations/update-16-4-0/replace-node-executor.d.ts +2 -0
  65. package/src/migrations/update-16-4-0/replace-node-executor.js +14 -0
  66. package/src/utils/has-webpack-plugin.d.ts +2 -0
  67. package/src/utils/has-webpack-plugin.js +11 -0
  68. package/src/utils/versions.d.ts +12 -0
  69. package/src/utils/versions.js +15 -0
@@ -0,0 +1,70 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "SchematicsNxNodeE2eProject",
5
+ "title": "Node E2E Project Generator",
6
+ "description": "Generate an E2E project for a Node server application.",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "description": "The name of the project.",
12
+ "$default": { "$source": "argv", "index": 0 },
13
+ "x-dropdown": "project",
14
+ "x-prompt": "What project is this for?"
15
+ },
16
+ "directory": {
17
+ "description": "The directory of the e2e project.",
18
+ "type": "string",
19
+ "x-priority": "important"
20
+ },
21
+ "projectNameAndRootFormat": {
22
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
23
+ "type": "string",
24
+ "enum": ["as-provided", "derived"]
25
+ },
26
+ "name": {
27
+ "description": "The name of the e2e project. Defaults to the project name with '-e2e' suffix.",
28
+ "type": "string"
29
+ },
30
+ "projectType": {
31
+ "description": "The type of application that is being tested.",
32
+ "type": "string",
33
+ "enum": ["server", "cli"],
34
+ "default": "server"
35
+ },
36
+ "port": {
37
+ "description": "The port that the server runs on. Only application for server application.",
38
+ "type": "number",
39
+ "default": 3000
40
+ },
41
+ "linter": {
42
+ "description": "Linter to be used for the E2E project",
43
+ "type": "string",
44
+ "enum": ["eslint", "none"],
45
+ "default": "eslint"
46
+ },
47
+ "isNest": {
48
+ "description": "Is the E2E server project nest",
49
+ "type": "boolean",
50
+ "default": false,
51
+ "hidden": true,
52
+ "x-priority": "internal"
53
+ },
54
+ "rootProject": {
55
+ "description": "Create node application at the root of the workspace.",
56
+ "type": "boolean",
57
+ "default": false,
58
+ "hidden": true,
59
+ "x-priority": "internal"
60
+ },
61
+ "skipFormat": {
62
+ "description": "Skip formatting files.",
63
+ "type": "boolean",
64
+ "default": false,
65
+ "hidden": true,
66
+ "x-priority": "internal"
67
+ }
68
+ },
69
+ "required": ["project"]
70
+ }
@@ -0,0 +1,4 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function initGenerator(tree: Tree, options: Schema): Promise<GeneratorCallback>;
4
+ export default initGenerator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../utils/versions");
6
+ function updateDependencies(tree, options) {
7
+ const tasks = [];
8
+ tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx/node'], []));
9
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/node': versions_1.nxVersion }, undefined, options.keepExistingVersions));
10
+ return (0, devkit_1.runTasksInSerial)(...tasks);
11
+ }
12
+ async function initGenerator(tree, options) {
13
+ let installTask = () => { };
14
+ if (!options.skipPackageJson) {
15
+ installTask = updateDependencies(tree, options);
16
+ }
17
+ if (!options.skipFormat) {
18
+ await (0, devkit_1.formatFiles)(tree);
19
+ }
20
+ return installTask;
21
+ }
22
+ exports.initGenerator = initGenerator;
23
+ exports.default = initGenerator;
@@ -0,0 +1,5 @@
1
+ export interface Schema {
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxNodeInit",
5
+ "title": "Init Node Plugin",
6
+ "description": "Init Node Plugin.",
7
+ "type": "object",
8
+ "properties": {
9
+ "skipFormat": {
10
+ "description": "Skip formatting files.",
11
+ "type": "boolean",
12
+ "default": false
13
+ },
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
16
+ "type": "boolean",
17
+ "default": false
18
+ },
19
+ "keepExistingVersions": {
20
+ "type": "boolean",
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
+ }
25
+ },
26
+ "required": []
27
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "<%= importPath %>",
3
+ "version": "0.0.1"
4
+ }
@@ -0,0 +1,7 @@
1
+ import { <%= propertyName %> } from './<%= fileName %>';
2
+
3
+ describe('<%= propertyName %>', () => {
4
+ it('should work', () => {
5
+ expect(<%= propertyName %>()).toEqual('<%= name %>');
6
+ })
7
+ })
@@ -0,0 +1,3 @@
1
+ export function <%= propertyName %>(): string {
2
+ return '<%= name %>';
3
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "<%= offsetFromRoot %>dist/out-tsc",
6
+ "declaration": true,
7
+ "types": ["node"]
8
+ },
9
+ "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
10
+ "include": ["src/**/*.ts"]
11
+ }
@@ -0,0 +1,12 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export interface NormalizedSchema extends Schema {
4
+ fileName: string;
5
+ projectName: string;
6
+ projectRoot: string;
7
+ parsedTags: string[];
8
+ compiler: 'swc' | 'tsc';
9
+ }
10
+ export declare function libraryGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
11
+ export declare function libraryGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
12
+ export default libraryGenerator;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const js_1 = require("@nx/js");
7
+ const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
8
+ const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
9
+ const path_1 = require("path");
10
+ const versions_1 = require("../../utils/versions");
11
+ const init_1 = require("../init/init");
12
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
13
+ async function libraryGenerator(tree, schema) {
14
+ return await libraryGeneratorInternal(tree, {
15
+ addPlugin: false,
16
+ projectNameAndRootFormat: 'derived',
17
+ ...schema,
18
+ });
19
+ }
20
+ exports.libraryGenerator = libraryGenerator;
21
+ async function libraryGeneratorInternal(tree, schema) {
22
+ const options = await normalizeOptions(tree, schema);
23
+ const tasks = [
24
+ await (0, init_1.initGenerator)(tree, {
25
+ ...options,
26
+ skipFormat: true,
27
+ }),
28
+ ];
29
+ if (options.publishable === true && !schema.importPath) {
30
+ throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
31
+ }
32
+ const libraryInstall = await (0, js_1.libraryGenerator)(tree, {
33
+ ...options,
34
+ bundler: schema.buildable ? 'tsc' : 'none',
35
+ includeBabelRc: schema.babelJest,
36
+ importPath: options.importPath,
37
+ testEnvironment: 'node',
38
+ skipFormat: true,
39
+ setParserOptionsProject: options.setParserOptionsProject,
40
+ });
41
+ tasks.push(libraryInstall);
42
+ createFiles(tree, options);
43
+ if (options.js) {
44
+ (0, devkit_1.updateTsConfigsToJs)(tree, options);
45
+ }
46
+ updateProject(tree, options);
47
+ tasks.push(ensureDependencies(tree));
48
+ if (!schema.skipFormat) {
49
+ await (0, devkit_1.formatFiles)(tree);
50
+ }
51
+ return (0, devkit_1.runTasksInSerial)(...tasks);
52
+ }
53
+ exports.libraryGeneratorInternal = libraryGeneratorInternal;
54
+ exports.default = libraryGenerator;
55
+ async function normalizeOptions(tree, options) {
56
+ const { projectName, names: projectNames, projectRoot, importPath, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
57
+ name: options.name,
58
+ projectType: 'library',
59
+ directory: options.directory,
60
+ importPath: options.importPath,
61
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
62
+ callingGenerator: '@nx/node:library',
63
+ });
64
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
65
+ const nxJson = (0, devkit_1.readNxJson)(tree);
66
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
67
+ nxJson.useInferencePlugins !== false;
68
+ options.addPlugin ??= addPluginDefault;
69
+ const fileName = getCaseAwareFileName({
70
+ fileName: options.simpleModuleName
71
+ ? projectNames.projectSimpleName
72
+ : projectNames.projectFileName,
73
+ pascalCaseFiles: options.pascalCaseFiles,
74
+ });
75
+ const parsedTags = options.tags
76
+ ? options.tags.split(',').map((s) => s.trim())
77
+ : [];
78
+ return {
79
+ ...options,
80
+ fileName,
81
+ projectName,
82
+ projectRoot,
83
+ parsedTags,
84
+ importPath,
85
+ };
86
+ }
87
+ function getCaseAwareFileName(options) {
88
+ const normalized = (0, devkit_1.names)(options.fileName);
89
+ return options.pascalCaseFiles ? normalized.className : normalized.fileName;
90
+ }
91
+ function createFiles(tree, options) {
92
+ const { className, name, propertyName } = (0, devkit_1.names)(options.fileName);
93
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/lib'), options.projectRoot, {
94
+ ...options,
95
+ className,
96
+ name,
97
+ propertyName,
98
+ tmpl: '',
99
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
100
+ });
101
+ if (options.unitTestRunner === 'none') {
102
+ tree.delete((0, path_1.join)(options.projectRoot, `./src/lib/${options.fileName}.spec.ts`));
103
+ }
104
+ if (!options.publishable && !options.buildable) {
105
+ tree.delete((0, path_1.join)(options.projectRoot, 'package.json'));
106
+ }
107
+ if (options.js) {
108
+ (0, devkit_1.toJS)(tree);
109
+ }
110
+ }
111
+ function updateProject(tree, options) {
112
+ if (!options.publishable && !options.buildable) {
113
+ return;
114
+ }
115
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
116
+ const rootProject = options.projectRoot === '.' || options.projectRoot === '';
117
+ project.targets = project.targets || {};
118
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, `@nx/js:${options.compiler}`);
119
+ project.targets.build = {
120
+ executor: `@nx/js:${options.compiler}`,
121
+ outputs: ['{options.outputPath}'],
122
+ options: {
123
+ outputPath: (0, devkit_1.joinPathFragments)('dist', rootProject ? options.projectName : options.projectRoot),
124
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
125
+ packageJson: `${options.projectRoot}/package.json`,
126
+ main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
127
+ assets: [`${options.projectRoot}/*.md`],
128
+ },
129
+ };
130
+ if (options.compiler === 'swc') {
131
+ (0, add_swc_dependencies_1.addSwcDependencies)(tree);
132
+ (0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot);
133
+ }
134
+ if (options.rootDir) {
135
+ project.targets.build.options.srcRootForCompilationRoot = options.rootDir;
136
+ }
137
+ (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
138
+ }
139
+ function ensureDependencies(tree) {
140
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, { tslib: versions_1.tslibVersion }, { '@types/node': versions_1.typesNodeVersion });
141
+ }
@@ -0,0 +1,27 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/eslint';
3
+
4
+ export interface Schema {
5
+ name: string;
6
+ directory?: string;
7
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
8
+ simpleModuleName?: boolean;
9
+ skipTsConfig?: boolean;
10
+ skipFormat?: boolean;
11
+ tags?: string;
12
+ unitTestRunner?: 'jest' | 'none';
13
+ linter?: Linter;
14
+ buildable?: boolean;
15
+ publishable?: boolean;
16
+ importPath?: string;
17
+ testEnvironment?: 'jsdom' | 'node';
18
+ rootDir?: string;
19
+ babelJest?: boolean;
20
+ js?: boolean;
21
+ pascalCaseFiles?: boolean;
22
+ strict?: boolean;
23
+ standaloneConfig?: boolean;
24
+ setParserOptionsProject?: boolean;
25
+ compiler: 'tsc' | 'swc';
26
+ addPlugin?: boolean;
27
+ }
@@ -0,0 +1,136 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxNodeLibrary",
5
+ "title": "Create a Node Library for Nx",
6
+ "description": "Create a Node Library for an Nx workspace.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g lib mylib --directory=myapp",
11
+ "description": "Generate `libs/myapp/mylib`"
12
+ }
13
+ ],
14
+ "properties": {
15
+ "name": {
16
+ "type": "string",
17
+ "description": "Library name",
18
+ "$default": {
19
+ "$source": "argv",
20
+ "index": 0
21
+ },
22
+ "x-prompt": "What name would you like to use for the library?",
23
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
24
+ },
25
+ "directory": {
26
+ "type": "string",
27
+ "description": "A directory where the lib is placed",
28
+ "alias": "dir",
29
+ "x-priority": "important"
30
+ },
31
+ "projectNameAndRootFormat": {
32
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
33
+ "type": "string",
34
+ "enum": ["as-provided", "derived"]
35
+ },
36
+ "simpleModuleName": {
37
+ "description": "Keep the module name simple (when using `--directory`).",
38
+ "type": "boolean",
39
+ "default": false
40
+ },
41
+ "linter": {
42
+ "description": "The tool to use for running lint checks.",
43
+ "type": "string",
44
+ "enum": ["eslint"],
45
+ "default": "eslint"
46
+ },
47
+ "unitTestRunner": {
48
+ "type": "string",
49
+ "enum": ["jest", "none"],
50
+ "description": "Test runner to use for unit tests.",
51
+ "default": "jest"
52
+ },
53
+ "tags": {
54
+ "type": "string",
55
+ "description": "Add tags to the library (used for linting).",
56
+ "alias": "t"
57
+ },
58
+ "skipFormat": {
59
+ "description": "Skip formatting files.",
60
+ "type": "boolean",
61
+ "default": false,
62
+ "x-priority": "internal"
63
+ },
64
+ "skipTsConfig": {
65
+ "type": "boolean",
66
+ "default": false,
67
+ "description": "Do not update `tsconfig.base.json` for development experience.",
68
+ "x-priority": "internal"
69
+ },
70
+ "publishable": {
71
+ "type": "boolean",
72
+ "description": "Create a publishable library.",
73
+ "x-priority": "important"
74
+ },
75
+ "buildable": {
76
+ "type": "boolean",
77
+ "default": false,
78
+ "description": "Generate a buildable library.",
79
+ "x-priority": "important"
80
+ },
81
+ "compiler": {
82
+ "type": "string",
83
+ "enum": ["tsc", "swc"],
84
+ "default": "tsc",
85
+ "description": "The compiler used by the build and test targets.",
86
+ "x-priority": "important"
87
+ },
88
+ "importPath": {
89
+ "type": "string",
90
+ "description": "The library name used to import it, like `@myorg/my-awesome-lib`. Must be a valid npm name."
91
+ },
92
+ "rootDir": {
93
+ "type": "string",
94
+ "description": "Sets the `rootDir` for TypeScript compilation. When not defined, it uses the project's root property, or `srcRootForCompilationRoot` if it is defined."
95
+ },
96
+ "testEnvironment": {
97
+ "type": "string",
98
+ "enum": ["jsdom", "node"],
99
+ "description": "The test environment to use if `unitTestRunner` is set to `jest`.",
100
+ "default": "jsdom"
101
+ },
102
+ "babelJest": {
103
+ "type": "boolean",
104
+ "description": "Use `babel` instead of `ts-jest`.",
105
+ "default": false
106
+ },
107
+ "pascalCaseFiles": {
108
+ "type": "boolean",
109
+ "description": "Use pascal case file names.",
110
+ "alias": "P",
111
+ "default": false
112
+ },
113
+ "js": {
114
+ "type": "boolean",
115
+ "description": "Generate JavaScript files rather than TypeScript files.",
116
+ "default": false
117
+ },
118
+ "strict": {
119
+ "type": "boolean",
120
+ "description": "Whether to enable tsconfig strict mode or not.",
121
+ "default": false
122
+ },
123
+ "standaloneConfig": {
124
+ "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
125
+ "type": "boolean",
126
+ "default": true,
127
+ "x-deprecated": "Nx only supports standaloneConfig"
128
+ },
129
+ "setParserOptionsProject": {
130
+ "type": "boolean",
131
+ "description": "Whether or not to configure the ESLint `parserOptions.project`. We do not do this by default for lint performance reasons.",
132
+ "default": false
133
+ }
134
+ },
135
+ "required": ["name"]
136
+ }
@@ -0,0 +1,24 @@
1
+ # This file is generated by Nx.
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
+ #
6
+ # Run the container with `docker run -p 3000:3000 -t <%= project %>`.
7
+ FROM docker.io/node:lts-alpine
8
+
9
+ ENV HOST=0.0.0.0
10
+ ENV PORT=3000
11
+
12
+ WORKDIR /app
13
+
14
+ RUN addgroup --system <%= project %> && \
15
+ adduser --system -G <%= project %> <%= project %>
16
+
17
+ COPY <%= buildLocation %> <%= project %>
18
+ RUN chown -R <%= project %>:<%= project %> .
19
+
20
+ # You can remove this install step if you build with `--bundle` option.
21
+ # The bundled output will include external dependencies.
22
+ RUN npm --prefix <%= project %> --omit=dev -f install
23
+
24
+ CMD [ "node", "<%= project %>" ]
@@ -0,0 +1,6 @@
1
+ export interface SetUpDockerOptions {
2
+ project?: string;
3
+ targetName?: string;
4
+ buildTarget?: string;
5
+ skipFormat?: boolean;
6
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "SchematicsNxSetupDocker",
5
+ "title": "Nx Node Docker Options Schema",
6
+ "description": "Nx Node Docker Options Schema.",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "description": "The name of the project",
11
+ "$default": {
12
+ "$source": "projectName"
13
+ },
14
+ "type": "string",
15
+ "x-prompt": "What project would you like to add a Dockerfile to?",
16
+ "x-priority": "important"
17
+ },
18
+ "targetName": {
19
+ "description": "The name of the target to create",
20
+ "type": "string",
21
+ "default": "docker-build"
22
+ },
23
+ "buildTargetName": {
24
+ "description": "The name of the build target",
25
+ "type": "string",
26
+ "default": "build"
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { SetUpDockerOptions } from './schema';
3
+ export declare function updateProjectConfig(tree: Tree, options: SetUpDockerOptions): void;
4
+ export declare function setupDockerGenerator(tree: Tree, setupOptions: SetUpDockerOptions): Promise<GeneratorCallback>;
5
+ export default setupDockerGenerator;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupDockerGenerator = exports.updateProjectConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ function normalizeOptions(tree, setupOptions) {
7
+ return {
8
+ ...setupOptions,
9
+ project: setupOptions.project ?? (0, devkit_1.readNxJson)(tree).defaultProject,
10
+ targetName: setupOptions.targetName ?? 'docker-build',
11
+ buildTarget: setupOptions.buildTarget ?? 'build',
12
+ };
13
+ }
14
+ function addDocker(tree, options) {
15
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
16
+ if (!project || !options.targetName) {
17
+ return;
18
+ }
19
+ if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'DockerFile'))) {
20
+ devkit_1.logger.info(`Skipping setup since a Dockerfile already exists inside ${project.root}`);
21
+ }
22
+ else {
23
+ const outputPath = project.targets[`${options.buildTarget}`]?.options.outputPath;
24
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), project.root, {
25
+ tmpl: '',
26
+ app: project.sourceRoot,
27
+ buildLocation: outputPath,
28
+ project: options.project,
29
+ });
30
+ }
31
+ }
32
+ function updateProjectConfig(tree, options) {
33
+ let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
34
+ projectConfig.targets[`${options.targetName}`] = {
35
+ dependsOn: [`${options.buildTarget}`],
36
+ command: `docker build -f ${(0, devkit_1.joinPathFragments)(projectConfig.root, 'Dockerfile')} . -t ${options.project}`,
37
+ };
38
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
39
+ }
40
+ exports.updateProjectConfig = updateProjectConfig;
41
+ async function setupDockerGenerator(tree, setupOptions) {
42
+ const tasks = [];
43
+ const options = normalizeOptions(tree, setupOptions);
44
+ // Should check if the node project exists
45
+ addDocker(tree, options);
46
+ updateProjectConfig(tree, options);
47
+ if (!options.skipFormat) {
48
+ await (0, devkit_1.formatFiles)(tree);
49
+ }
50
+ return (0, devkit_1.runTasksInSerial)(...tasks);
51
+ }
52
+ exports.setupDockerGenerator = setupDockerGenerator;
53
+ exports.default = setupDockerGenerator;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
5
+ async function update(tree) {
6
+ const migrateProject = (options, projectName, targetName) => {
7
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
8
+ projectConfig.targets[targetName].executor = '@nx/webpack:webpack';
9
+ projectConfig.targets[targetName].options.compiler = 'tsc';
10
+ projectConfig.targets[targetName].options.target = 'node';
11
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
12
+ };
13
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/node:webpack', migrateProject);
14
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/node:webpack', migrateProject);
15
+ await (0, devkit_1.formatFiles)(tree);
16
+ }
17
+ exports.default = update;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function replacePackage(tree: Tree): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/node', '@nx/node');
7
+ await (0, devkit_1.formatFiles)(tree);
8
+ }
9
+ exports.default = replacePackage;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;