@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,10 @@
1
+ {
2
+ "extends": "<%= rootTsConfigPath %>",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.app.json"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,35 @@
1
+ <% if (webpackPluginOptions) { %>
2
+ const { NxWebpackPlugin } = require('@nx/webpack');
3
+ const { join } = require('path');
4
+
5
+ module.exports = {
6
+ output: {
7
+ path: join(__dirname, '<%= offset %><%= webpackPluginOptions.outputPath %>'),
8
+ },
9
+ plugins: [
10
+ new NxWebpackPlugin({
11
+ target: 'node',
12
+ compiler: 'tsc',
13
+ main: '<%= webpackPluginOptions.main %>',
14
+ tsConfig: '<%= webpackPluginOptions.tsConfig %>',
15
+ assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
16
+ optimization: false,
17
+ outputHashing: 'none',
18
+ })
19
+ ],
20
+ };
21
+ <% } else { %>
22
+ const { composePlugins, withNx} = require('@nx/webpack');
23
+
24
+ // Nx plugins for webpack.
25
+ module.exports = composePlugins(
26
+ withNx({
27
+ target: 'node',
28
+ }),
29
+ (config) => {
30
+ // Update the webpack config as needed here.
31
+ // e.g. `config.plugins.push(new MyPlugin())`
32
+ return config;
33
+ }
34
+ );
35
+ <% } %>
@@ -0,0 +1,14 @@
1
+ import express from 'express';
2
+
3
+ const host = process.env.HOST ?? 'localhost';
4
+ const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>;
5
+
6
+ const app = express();
7
+
8
+ app.get('/', (req, res) => {
9
+ res.send({ 'message': 'Hello API'});
10
+ });
11
+
12
+ app.listen(port, host, () => {
13
+ console.log(`[ ready ] http://${host}:${port}`);
14
+ });
@@ -0,0 +1,20 @@
1
+ import Fastify, { FastifyInstance } from 'fastify';
2
+ import { app } from './app';
3
+
4
+ describe('GET /', () => {
5
+ let server: FastifyInstance;
6
+
7
+ beforeEach(() => {
8
+ server = Fastify();
9
+ server.register(app);
10
+ });
11
+
12
+ it('should respond with a message', async () => {
13
+ const response = await server.inject({
14
+ method: 'GET',
15
+ url: '/'
16
+ });
17
+
18
+ expect(response.json()).toEqual({ message: 'Hello API' })
19
+ });
20
+ });
@@ -0,0 +1,27 @@
1
+ import * as path from 'path';
2
+ import { FastifyInstance } from 'fastify';
3
+ import AutoLoad from '@fastify/autoload';
4
+
5
+ /* eslint-disable-next-line */
6
+ export interface AppOptions { }
7
+
8
+ export async function app(fastify: FastifyInstance, opts: AppOptions) {
9
+ // Place here your custom code!
10
+
11
+ // Do not touch the following lines
12
+
13
+ // This loads all plugins defined in plugins
14
+ // those should be support plugins that are reused
15
+ // through your application
16
+ fastify.register(AutoLoad, {
17
+ dir: path.join(__dirname, 'plugins'),
18
+ options: { ...opts },
19
+ });
20
+
21
+ // This loads all plugins defined in routes
22
+ // define your routes in one of these
23
+ fastify.register(AutoLoad, {
24
+ dir: path.join(__dirname, 'routes'),
25
+ options: { ...opts },
26
+ });
27
+ }
@@ -0,0 +1,12 @@
1
+ import { FastifyInstance } from 'fastify';
2
+ import fp from 'fastify-plugin';
3
+ import sensible from '@fastify/sensible';
4
+
5
+ /**
6
+ * This plugins adds some utilities to handle http errors
7
+ *
8
+ * @see https://github.com/fastify/fastify-sensible
9
+ */
10
+ export default fp(async function(fastify: FastifyInstance) {
11
+ fastify.register(sensible);
12
+ });
@@ -0,0 +1,7 @@
1
+ import { FastifyInstance } from 'fastify';
2
+
3
+ export default async function(fastify: FastifyInstance) {
4
+ fastify.get('/', async function() {
5
+ return { message: 'Hello API' };
6
+ });
7
+ }
@@ -0,0 +1,23 @@
1
+ import Fastify from 'fastify';
2
+ import { app } from './app/app';
3
+
4
+ const host = process.env.HOST ?? 'localhost';
5
+ const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>;
6
+
7
+ // Instantiate Fastify with some config
8
+ const server = Fastify({
9
+ logger: true,
10
+ });
11
+
12
+ // Register your application as a normal plugin.
13
+ server.register(app);
14
+
15
+ // Start listening.
16
+ server.listen({ port, host }, (err) => {
17
+ if (err) {
18
+ server.log.error(err);
19
+ process.exit(1);
20
+ } else {
21
+ console.log(`[ ready ] http://${host}:${port}`);
22
+ }
23
+ });
@@ -0,0 +1,14 @@
1
+ import koa from 'koa';
2
+
3
+ const host = process.env.HOST ?? 'localhost';
4
+ const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>;
5
+
6
+ const app = new koa();
7
+
8
+ app.use(async ctx =>{
9
+ ctx.body = { 'message': 'Hello API'};
10
+ });
11
+
12
+ app.listen(port, host, () => {
13
+ console.log(`[ ready ] http://${host}:${port}`);
14
+ });
@@ -0,0 +1,31 @@
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
+ skipFormat?: boolean;
7
+ skipPackageJson?: boolean;
8
+ directory?: string;
9
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
10
+ unitTestRunner?: 'jest' | 'none';
11
+ e2eTestRunner?: 'jest' | 'none';
12
+ linter?: Linter;
13
+ tags?: string;
14
+ frontendProject?: string;
15
+ swcJest?: boolean;
16
+ /** @deprecated use `swcJest` instead */
17
+ babelJest?: boolean;
18
+ js?: boolean;
19
+ pascalCaseFiles?: boolean;
20
+ setParserOptionsProject?: boolean;
21
+ standaloneConfig?: boolean;
22
+ bundler?: 'esbuild' | 'webpack';
23
+ framework?: NodeJsFrameWorks;
24
+ port?: number;
25
+ rootProject?: boolean;
26
+ docker?: boolean;
27
+ isNest?: boolean;
28
+ addPlugin?: boolean;
29
+ }
30
+
31
+ export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'nest' | 'none';
@@ -0,0 +1,136 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "SchematicsNxNodeApp",
5
+ "title": "Nx Application Options Schema",
6
+ "description": "Nx Application Options Schema.",
7
+ "type": "object",
8
+ "properties": {
9
+ "name": {
10
+ "description": "The name of the application.",
11
+ "type": "string",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-prompt": "What name would you like to use for the node application?",
17
+ "x-priority": "important",
18
+ "pattern": "^[a-zA-Z][^:]*$"
19
+ },
20
+ "directory": {
21
+ "description": "The directory of the new application.",
22
+ "type": "string",
23
+ "x-priority": "important"
24
+ },
25
+ "projectNameAndRootFormat": {
26
+ "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`).",
27
+ "type": "string",
28
+ "enum": ["as-provided", "derived"]
29
+ },
30
+ "skipFormat": {
31
+ "description": "Skip formatting files",
32
+ "type": "boolean",
33
+ "default": false,
34
+ "x-priority": "internal"
35
+ },
36
+ "skipPackageJson": {
37
+ "type": "boolean",
38
+ "default": false,
39
+ "description": "Do not add dependencies to `package.json`.",
40
+ "x-priority": "internal"
41
+ },
42
+ "linter": {
43
+ "description": "The tool to use for running lint checks.",
44
+ "type": "string",
45
+ "enum": ["eslint"],
46
+ "default": "eslint"
47
+ },
48
+ "unitTestRunner": {
49
+ "type": "string",
50
+ "enum": ["jest", "none"],
51
+ "description": "Test runner to use for unit tests.",
52
+ "default": "jest"
53
+ },
54
+ "tags": {
55
+ "type": "string",
56
+ "description": "Add tags to the application (used for linting)."
57
+ },
58
+ "frontendProject": {
59
+ "type": "string",
60
+ "description": "Frontend project that needs to access this application. This sets up proxy configuration.",
61
+ "x-priority": "important",
62
+ "x-dropdown": "projects"
63
+ },
64
+ "swcJest": {
65
+ "type": "boolean",
66
+ "description": "Use `@swc/jest` instead `ts-jest` for faster test compilation.",
67
+ "default": false
68
+ },
69
+ "babelJest": {
70
+ "type": "boolean",
71
+ "description": "Use `babel` instead `ts-jest`.",
72
+ "default": false,
73
+ "x-deprecated": "Use --swcJest instead for faster compilation"
74
+ },
75
+ "pascalCaseFiles": {
76
+ "type": "boolean",
77
+ "description": "Use pascal case file names.",
78
+ "alias": "P",
79
+ "default": false
80
+ },
81
+ "js": {
82
+ "type": "boolean",
83
+ "description": "Generate JavaScript files rather than TypeScript files.",
84
+ "default": false
85
+ },
86
+ "setParserOptionsProject": {
87
+ "type": "boolean",
88
+ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
89
+ "default": false
90
+ },
91
+ "standaloneConfig": {
92
+ "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
93
+ "type": "boolean",
94
+ "default": true,
95
+ "x-deprecated": "Nx only supports standaloneConfig"
96
+ },
97
+ "bundler": {
98
+ "description": "Bundler which is used to package the application",
99
+ "type": "string",
100
+ "enum": ["esbuild", "webpack"],
101
+ "default": "esbuild",
102
+ "x-priority": "important"
103
+ },
104
+ "framework": {
105
+ "description": "Generate the node application using a framework",
106
+ "type": "string",
107
+ "enum": ["express", "fastify", "koa", "nest", "none"],
108
+ "default": "none",
109
+ "x-prompt": "Which framework do you want to use?",
110
+ "x-priority": "important"
111
+ },
112
+ "port": {
113
+ "description": "The port which the server will be run on",
114
+ "type": "number",
115
+ "default": 3000
116
+ },
117
+ "rootProject": {
118
+ "description": "Create node application at the root of the workspace",
119
+ "type": "boolean",
120
+ "default": false,
121
+ "hidden": true,
122
+ "x-priority": "internal"
123
+ },
124
+ "e2eTestRunner": {
125
+ "type": "string",
126
+ "enum": ["jest", "none"],
127
+ "description": "Test runner to use for end to end (e2e) tests",
128
+ "default": "jest"
129
+ },
130
+ "docker": {
131
+ "type": "boolean",
132
+ "description": "Add a docker build target"
133
+ }
134
+ },
135
+ "required": ["name"]
136
+ }
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function e2eProjectGenerator(host: Tree, options: Schema): Promise<GeneratorCallback>;
4
+ export declare function e2eProjectGeneratorInternal(host: Tree, _options: Schema): Promise<GeneratorCallback>;
5
+ export default e2eProjectGenerator;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.e2eProjectGeneratorInternal = exports.e2eProjectGenerator = 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 eslint_1 = require("@nx/eslint");
7
+ const global_eslint_config_1 = require("@nx/eslint/src/generators/init/global-eslint-config");
8
+ const path = require("path");
9
+ const versions_1 = require("../../utils/versions");
10
+ const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
11
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
12
+ async function e2eProjectGenerator(host, options) {
13
+ return await e2eProjectGeneratorInternal(host, {
14
+ addPlugin: false,
15
+ projectNameAndRootFormat: 'derived',
16
+ ...options,
17
+ });
18
+ }
19
+ exports.e2eProjectGenerator = e2eProjectGenerator;
20
+ async function e2eProjectGeneratorInternal(host, _options) {
21
+ const tasks = [];
22
+ const options = await normalizeOptions(host, _options);
23
+ const appProject = (0, devkit_1.readProjectConfiguration)(host, options.project);
24
+ // TODO(@ndcunningham): This is broken.. the outputs are wrong.. and this isn't using the jest generator
25
+ (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
26
+ root: options.e2eProjectRoot,
27
+ implicitDependencies: [options.project],
28
+ projectType: 'application',
29
+ targets: {
30
+ e2e: {
31
+ executor: '@nx/jest:jest',
32
+ outputs: ['{workspaceRoot}/coverage/{e2eProjectRoot}'],
33
+ options: {
34
+ jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
35
+ passWithNoTests: true,
36
+ },
37
+ },
38
+ },
39
+ });
40
+ if (options.projectType === 'server') {
41
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/server/common'), options.e2eProjectRoot, {
42
+ ...options,
43
+ ...(0, devkit_1.names)(options.rootProject ? 'server' : options.project),
44
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
45
+ tmpl: '',
46
+ });
47
+ if (options.isNest) {
48
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/server/nest'), options.e2eProjectRoot, {
49
+ ...options,
50
+ ...(0, devkit_1.names)(options.rootProject ? 'server' : options.project),
51
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
52
+ tmpl: '',
53
+ });
54
+ }
55
+ }
56
+ else if (options.projectType === 'cli') {
57
+ const mainFile = appProject.targets.build?.options?.outputPath;
58
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/cli'), options.e2eProjectRoot, {
59
+ ...options,
60
+ ...(0, devkit_1.names)(options.rootProject ? 'cli' : options.project),
61
+ mainFile,
62
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
63
+ tmpl: '',
64
+ });
65
+ }
66
+ // axios is more than likely used in the application code, so install it as a regular dependency.
67
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, { axios: versions_1.axiosVersion }, {});
68
+ tasks.push(installTask);
69
+ if (options.linter === eslint_1.Linter.EsLint) {
70
+ const linterTask = await (0, eslint_1.lintProjectGenerator)(host, {
71
+ project: options.e2eProjectName,
72
+ linter: eslint_1.Linter.EsLint,
73
+ skipFormat: true,
74
+ tsConfigPaths: [
75
+ (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'tsconfig.json'),
76
+ ],
77
+ setParserOptionsProject: false,
78
+ skipPackageJson: false,
79
+ rootProject: options.rootProject,
80
+ addPlugin: options.addPlugin,
81
+ });
82
+ tasks.push(linterTask);
83
+ if (options.rootProject && (0, eslint_file_1.isEslintConfigSupported)(host)) {
84
+ (0, eslint_file_1.addPluginsToLintConfig)(host, options.e2eProjectRoot, '@nx');
85
+ (0, eslint_file_1.replaceOverridesInLintConfig)(host, options.e2eProjectRoot, [
86
+ global_eslint_config_1.typeScriptOverride,
87
+ global_eslint_config_1.javaScriptOverride,
88
+ ]);
89
+ }
90
+ }
91
+ if (!options.skipFormat) {
92
+ await (0, devkit_1.formatFiles)(host);
93
+ }
94
+ tasks.push(() => {
95
+ (0, log_show_project_command_1.logShowProjectCommand)(options.e2eProjectName);
96
+ });
97
+ return (0, devkit_1.runTasksInSerial)(...tasks);
98
+ }
99
+ exports.e2eProjectGeneratorInternal = e2eProjectGeneratorInternal;
100
+ async function normalizeOptions(tree, options) {
101
+ const { projectName: e2eProjectName, projectRoot: e2eProjectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
102
+ name: options.name ?? `${options.project}-e2e`,
103
+ projectType: 'library',
104
+ directory: options.rootProject ? 'e2e' : options.directory,
105
+ projectNameAndRootFormat: options.rootProject
106
+ ? 'as-provided'
107
+ : options.projectNameAndRootFormat,
108
+ // this is an internal generator, don't save defaults
109
+ callingGenerator: null,
110
+ });
111
+ const nxJson = (0, devkit_1.readNxJson)(tree);
112
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
113
+ nxJson.useInferencePlugins !== false;
114
+ return {
115
+ addPlugin,
116
+ ...options,
117
+ e2eProjectRoot,
118
+ e2eProjectName,
119
+ port: options.port ?? 3000,
120
+ rootProject: !!options.rootProject,
121
+ };
122
+ }
123
+ exports.default = e2eProjectGenerator;
@@ -0,0 +1,14 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: '<%= e2eProjectName %>',
4
+ preset: '<%= offsetFromRoot %>/jest.preset.js',
5
+ setupFiles: ['<rootDir>/src/test-setup.ts'],
6
+ testEnvironment: 'node',
7
+ transform: {
8
+ '^.+\\.[tj]s$': ['ts-jest', {
9
+ tsconfig: '<rootDir>/tsconfig.spec.json',
10
+ }],
11
+ },
12
+ moduleFileExtensions: ['ts', 'js', 'html'],
13
+ coverageDirectory: '<%= offsetFromRoot %>/coverage/<%= e2eProjectName %>',
14
+ };
@@ -0,0 +1,13 @@
1
+ import { execSync } from 'child_process';
2
+ import { join } from 'path';
3
+
4
+ describe('CLI tests', () => {
5
+ it('should print a message', () => {
6
+ const cliPath = join(process.cwd(), "<%= mainFile %>");
7
+
8
+ const output = execSync(`node ${cliPath}`).toString();
9
+
10
+ expect(output).toMatch(/Hello World/);
11
+ });
12
+ });
13
+
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "<%= offsetFromRoot %><% if (rootProject) { %>tsconfig.json<% } else { %>tsconfig.base.json<% } %>",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.spec.json"
8
+ }
9
+ ],
10
+ "compilerOptions": {
11
+ "esModuleInterop": true
12
+ }
13
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "<%= offsetFromRoot %>/dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": [
9
+ "jest.config.ts",
10
+ "src/**/*.ts"
11
+ ]
12
+ }
@@ -0,0 +1,16 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: '<%= e2eProjectName %>',
4
+ preset: '<%= offsetFromRoot %>jest.preset.js',
5
+ globalSetup: '<rootDir>/src/support/global-setup.ts',
6
+ globalTeardown: '<rootDir>/src/support/global-teardown.ts',
7
+ setupFiles: ['<rootDir>/src/support/test-setup.ts'],
8
+ testEnvironment: 'node',
9
+ transform: {
10
+ '^.+\\.[tj]s$': ['ts-jest', {
11
+ tsconfig: '<rootDir>/tsconfig.spec.json',
12
+ }],
13
+ },
14
+ moduleFileExtensions: ['ts', 'js', 'html'],
15
+ coverageDirectory: '<%= offsetFromRoot %>coverage/<%= e2eProjectName %>',
16
+ };
@@ -0,0 +1,10 @@
1
+ import axios from 'axios';
2
+
3
+ describe('GET /', () => {
4
+ it('should return a message', async () => {
5
+ const res = await axios.get(`/`);
6
+
7
+ expect(res.status).toBe(200);
8
+ expect(res.data).toEqual({ message: 'Hello API' });
9
+ });
10
+ })
@@ -0,0 +1,11 @@
1
+ /* eslint-disable */
2
+ var __TEARDOWN_MESSAGE__: string;
3
+
4
+ module.exports = async function() {
5
+ // Start services that that the app needs to run (e.g. database, docker-compose, etc.).
6
+ console.log('\nSetting up...\n');
7
+
8
+ // Hint: Use `globalThis` to pass variables to global teardown.
9
+ globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
10
+ };
11
+
@@ -0,0 +1,7 @@
1
+ /* eslint-disable */
2
+
3
+ module.exports = async function() {
4
+ // Put clean up logic here (e.g. stopping services, docker-compose, etc.).
5
+ // Hint: `globalThis` is shared between setup and teardown.
6
+ console.log(globalThis.__TEARDOWN_MESSAGE__);
7
+ };
@@ -0,0 +1,10 @@
1
+ /* eslint-disable */
2
+
3
+ import axios from 'axios';
4
+
5
+ module.exports = async function() {
6
+ // Configure axios for tests to use.
7
+ const host = process.env.HOST ?? 'localhost';
8
+ const port = process.env.PORT ?? '<%= port %>';
9
+ axios.defaults.baseURL = `http://${host}:${port}`;
10
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "<%= offsetFromRoot %><% if (rootProject) { %>tsconfig.json<% } else { %>tsconfig.base.json<% } %>",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.spec.json"
8
+ }
9
+ ],
10
+ "compilerOptions": {
11
+ "esModuleInterop": true
12
+ }
13
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": [
9
+ "jest.config.ts",
10
+ "src/**/*.ts"
11
+ ]
12
+ }
@@ -0,0 +1,10 @@
1
+ import axios from 'axios';
2
+
3
+ describe('GET /api', () => {
4
+ it('should return a message', async () => {
5
+ const res = await axios.get(`/api`);
6
+
7
+ expect(res.status).toBe(200);
8
+ expect(res.data).toEqual({ message: 'Hello API' });
9
+ });
10
+ })
@@ -0,0 +1,15 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+
3
+ export interface Schema {
4
+ project: string;
5
+ projectType: 'server' | 'cli';
6
+ directory?: string;
7
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
8
+ name?: string;
9
+ port?: number;
10
+ linter?: 'eslint' | 'none';
11
+ rootProject?: boolean;
12
+ isNest?: boolean;
13
+ skipFormat?: boolean;
14
+ addPlugin?: boolean;
15
+ }