@nx/next 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.
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/babel.d.ts +0 -0
- package/babel.js +12 -0
- package/executors.json +20 -0
- package/generators.json +47 -0
- package/index.d.ts +8 -0
- package/index.js +19 -0
- package/migrations.json +106 -0
- package/package.json +60 -0
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/plugins/component-testing.d.ts +2 -0
- package/plugins/component-testing.js +96 -0
- package/plugins/with-less.d.ts +3 -0
- package/plugins/with-less.js +79 -0
- package/plugins/with-nx.d.ts +25 -0
- package/plugins/with-nx.js +297 -0
- package/plugins/with-stylus.d.ts +3 -0
- package/plugins/with-stylus.js +12 -0
- package/src/executors/build/build.impl.d.ts +5 -0
- package/src/executors/build/build.impl.js +106 -0
- package/src/executors/build/lib/check-project.d.ts +1 -0
- package/src/executors/build/lib/check-project.js +12 -0
- package/src/executors/build/lib/create-next-config-file.d.ts +14 -0
- package/src/executors/build/lib/create-next-config-file.js +162 -0
- package/src/executors/build/lib/test-fixtures/ensure-exts/baz.json +1 -0
- package/src/executors/build/lib/update-package-json.d.ts +3 -0
- package/src/executors/build/lib/update-package-json.js +30 -0
- package/src/executors/build/schema.json +76 -0
- package/src/executors/export/export.impl.d.ts +17 -0
- package/src/executors/export/export.impl.js +58 -0
- package/src/executors/export/schema.json +30 -0
- package/src/executors/server/custom-server.impl.d.ts +6 -0
- package/src/executors/server/custom-server.impl.js +36 -0
- package/src/executors/server/schema.json +63 -0
- package/src/executors/server/server.impl.d.ts +6 -0
- package/src/executors/server/server.impl.js +66 -0
- package/src/generators/application/application.d.ts +4 -0
- package/src/generators/application/application.js +85 -0
- package/src/generators/application/files/app/api/hello/route.ts__tmpl__ +4 -0
- package/src/generators/application/files/app/global.__stylesExt____tmpl__ +1 -0
- package/src/generators/application/files/app/page.module.__style__ +1 -0
- package/src/generators/application/files/app/page.tsx__tmpl__ +30 -0
- package/src/generators/application/files/app-default-layout/layout.tsx__tmpl__ +18 -0
- package/src/generators/application/files/app-styled-components/layout.tsx__tmpl__ +21 -0
- package/src/generators/application/files/app-styled-components/registry.tsx__tmpl__ +33 -0
- package/src/generators/application/files/app-styled-jsx/layout.tsx__tmpl__ +16 -0
- package/src/generators/application/files/app-styled-jsx/registry.tsx__tmpl__ +23 -0
- package/src/generators/application/files/common/__dot__babelrc +21 -0
- package/src/generators/application/files/common/index.d.ts__tmpl__ +13 -0
- package/src/generators/application/files/common/next-env.d.ts__tmpl__ +5 -0
- package/src/generators/application/files/common/next.config.js__tmpl__ +82 -0
- package/src/generators/application/files/common/public/.gitkeep +0 -0
- package/src/generators/application/files/common/public/favicon.ico +0 -0
- package/src/generators/application/files/common/specs/__fileName__.spec.tsx__tmpl__ +18 -0
- package/src/generators/application/files/common/tsconfig.json__tmpl__ +29 -0
- package/src/generators/application/files/pages/__fileName__.module.__style__ +1 -0
- package/src/generators/application/files/pages/__fileName__.tsx__tmpl__ +30 -0
- package/src/generators/application/files/pages/_app.tsx__tmpl__ +18 -0
- package/src/generators/application/files/pages/_document.tsx__tmpl__ +33 -0
- package/src/generators/application/files/pages/styles.__stylesExt____tmpl__ +1 -0
- package/src/generators/application/lib/add-e2e.d.ts +3 -0
- package/src/generators/application/lib/add-e2e.js +72 -0
- package/src/generators/application/lib/add-jest.d.ts +3 -0
- package/src/generators/application/lib/add-jest.js +38 -0
- package/src/generators/application/lib/add-linting.d.ts +3 -0
- package/src/generators/application/lib/add-linting.js +62 -0
- package/src/generators/application/lib/add-plugin.d.ts +2 -0
- package/src/generators/application/lib/add-plugin.js +25 -0
- package/src/generators/application/lib/add-project.d.ts +3 -0
- package/src/generators/application/lib/add-project.js +66 -0
- package/src/generators/application/lib/create-application-files.d.ts +3 -0
- package/src/generators/application/lib/create-application-files.helpers.d.ts +2 -0
- package/src/generators/application/lib/create-application-files.helpers.js +846 -0
- package/src/generators/application/lib/create-application-files.js +114 -0
- package/src/generators/application/lib/normalize-options.d.ts +14 -0
- package/src/generators/application/lib/normalize-options.js +56 -0
- package/src/generators/application/lib/set-defaults.d.ts +3 -0
- package/src/generators/application/lib/set-defaults.js +14 -0
- package/src/generators/application/lib/show-possible-warnings.d.ts +3 -0
- package/src/generators/application/lib/show-possible-warnings.js +10 -0
- package/src/generators/application/lib/update-cypress-tsconfig.d.ts +3 -0
- package/src/generators/application/lib/update-cypress-tsconfig.js +16 -0
- package/src/generators/application/lib/update-jest-config.d.ts +3 -0
- package/src/generators/application/lib/update-jest-config.js +15 -0
- package/src/generators/application/schema.d.ts +24 -0
- package/src/generators/application/schema.json +146 -0
- package/src/generators/component/component.d.ts +28 -0
- package/src/generators/component/component.js +66 -0
- package/src/generators/component/schema.json +125 -0
- package/src/generators/custom-server/custom-server.d.ts +3 -0
- package/src/generators/custom-server/custom-server.js +104 -0
- package/src/generators/custom-server/files/server/main.ts__tmpl__ +46 -0
- package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +17 -0
- package/src/generators/custom-server/schema.d.ts +4 -0
- package/src/generators/custom-server/schema.json +30 -0
- package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +5 -0
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +87 -0
- package/src/generators/cypress-component-configuration/schema.d.ts +6 -0
- package/src/generators/cypress-component-configuration/schema.json +42 -0
- package/src/generators/init/init.d.ts +5 -0
- package/src/generators/init/init.js +46 -0
- package/src/generators/init/lib/add-plugin.d.ts +2 -0
- package/src/generators/init/lib/add-plugin.js +26 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +34 -0
- package/src/generators/library/lib/normalize-options.d.ts +7 -0
- package/src/generators/library/lib/normalize-options.js +26 -0
- package/src/generators/library/library.d.ts +5 -0
- package/src/generators/library/library.js +92 -0
- package/src/generators/library/schema.d.ts +28 -0
- package/src/generators/library/schema.json +156 -0
- package/src/generators/page/page.d.ts +5 -0
- package/src/generators/page/page.js +96 -0
- package/src/generators/page/schema.d.ts +20 -0
- package/src/generators/page/schema.json +111 -0
- package/src/migrations/update-15-8-8/add-style-packages.d.ts +3 -0
- package/src/migrations/update-15-8-8/add-style-packages.js +23 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-3-0/remove-root-build-option.d.ts +2 -0
- package/src/migrations/update-16-3-0/remove-root-build-option.js +17 -0
- package/src/migrations/update-16-4-0/update-nx-next-dependency.d.ts +2 -0
- package/src/migrations/update-16-4-0/update-nx-next-dependency.js +17 -0
- package/src/migrations/update-17-2-7/remove-eslint-rules-patch.d.ts +2 -0
- package/src/migrations/update-17-2-7/remove-eslint-rules-patch.js +15 -0
- package/src/plugins/plugin.d.ts +11 -0
- package/src/plugins/plugin.js +182 -0
- package/src/utils/add-gitignore-entry.d.ts +2 -0
- package/src/utils/add-gitignore-entry.js +17 -0
- package/src/utils/add-swc-to-custom-server.d.ts +2 -0
- package/src/utils/add-swc-to-custom-server.js +37 -0
- package/src/utils/compose-plugins.d.ts +3 -0
- package/src/utils/compose-plugins.js +22 -0
- package/src/utils/config-invalid-function.fixture.d.ts +0 -0
- package/src/utils/config-invalid-function.fixture.js +1 -0
- package/src/utils/config-not-a-function.fixture.d.ts +0 -0
- package/src/utils/config-not-a-function.fixture.js +1 -0
- package/src/utils/config.d.ts +13 -0
- package/src/utils/config.js +24 -0
- package/src/utils/constants.d.ts +1 -0
- package/src/utils/constants.js +4 -0
- package/src/utils/create-cli-options.d.ts +1 -0
- package/src/utils/create-cli-options.js +13 -0
- package/src/utils/create-copy-plugin.d.ts +2 -0
- package/src/utils/create-copy-plugin.js +64 -0
- package/src/utils/generate-globs.d.ts +5 -0
- package/src/utils/generate-globs.js +29 -0
- package/src/utils/styles.d.ts +67 -0
- package/src/utils/styles.js +67 -0
- package/src/utils/types.d.ts +57 -0
- package/src/utils/types.js +2 -0
- package/src/utils/versions.d.ts +12 -0
- package/src/utils/versions.js +15 -0
- package/tailwind.d.ts +2 -0
- package/tailwind.js +6 -0
- package/typings/image.d.ts +12 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createApplicationFiles = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const js_1 = require("@nx/js");
|
|
7
|
+
const create_application_files_helpers_1 = require("./create-application-files.helpers");
|
|
8
|
+
function createApplicationFiles(host, options) {
|
|
9
|
+
const offsetFromRoot = (0, devkit_1.offsetFromRoot)(options.appProjectRoot);
|
|
10
|
+
const layoutTypeSrcPath = (0, devkit_1.joinPathFragments)(offsetFromRoot, options.appProjectRoot, '.next/types/**/*.ts');
|
|
11
|
+
const layoutTypeDistPath = (0, devkit_1.joinPathFragments)(offsetFromRoot, options.outputPath, '.next/types/**/*.ts');
|
|
12
|
+
// scope tsconfig to the project directory so that it doesn't include other projects/libs
|
|
13
|
+
const rootPath = options.rootProject
|
|
14
|
+
? options.src
|
|
15
|
+
? 'src/'
|
|
16
|
+
: options.appDir
|
|
17
|
+
? 'app/'
|
|
18
|
+
: 'pages/'
|
|
19
|
+
: '';
|
|
20
|
+
const templateVariables = {
|
|
21
|
+
...(0, devkit_1.names)(options.name),
|
|
22
|
+
...options,
|
|
23
|
+
dot: '.',
|
|
24
|
+
tmpl: '',
|
|
25
|
+
offsetFromRoot,
|
|
26
|
+
layoutTypeSrcPath,
|
|
27
|
+
rootPath,
|
|
28
|
+
layoutTypeDistPath,
|
|
29
|
+
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot),
|
|
30
|
+
appContent: (0, create_application_files_helpers_1.createAppJsx)(options.projectName),
|
|
31
|
+
styleContent: (0, create_application_files_helpers_1.createStyleRules)(),
|
|
32
|
+
pageStyleContent: `.page {}`,
|
|
33
|
+
stylesExt: options.style === 'less' ? options.style : 'css',
|
|
34
|
+
};
|
|
35
|
+
const generatedAppFilePath = options.src
|
|
36
|
+
? (0, path_1.join)(options.appProjectRoot, 'src')
|
|
37
|
+
: options.appProjectRoot;
|
|
38
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/common'), options.appProjectRoot, templateVariables);
|
|
39
|
+
if (options.appDir) {
|
|
40
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
|
|
41
|
+
if (options.unitTestRunner === 'none') {
|
|
42
|
+
host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'specs', `index.spec.${options.js ? 'jsx' : 'tsx'}`));
|
|
43
|
+
}
|
|
44
|
+
if (options.style === 'styled-components') {
|
|
45
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-styled-components'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
|
|
46
|
+
}
|
|
47
|
+
else if (options.style === 'styled-jsx') {
|
|
48
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-styled-jsx'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-default-layout'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/pages'), (0, path_1.join)(generatedAppFilePath, 'pages'), templateVariables);
|
|
56
|
+
}
|
|
57
|
+
if (options.rootProject) {
|
|
58
|
+
(0, devkit_1.updateJson)(host, 'tsconfig.base.json', (json) => {
|
|
59
|
+
const appJSON = (0, devkit_1.readJson)(host, 'tsconfig.json');
|
|
60
|
+
let { extends: _, ...updatedJson } = json;
|
|
61
|
+
// Don't generate the `paths` object or else workspace libs will not work later.
|
|
62
|
+
// It'll be generated as needed when a lib is first added.
|
|
63
|
+
delete json.compilerOptions.paths;
|
|
64
|
+
updatedJson = {
|
|
65
|
+
...devkit_1.updateJson,
|
|
66
|
+
compilerOptions: {
|
|
67
|
+
...updatedJson.compilerOptions,
|
|
68
|
+
...appJSON.compilerOptions,
|
|
69
|
+
},
|
|
70
|
+
include: [
|
|
71
|
+
...new Set([
|
|
72
|
+
...(updatedJson.include || []),
|
|
73
|
+
...(appJSON.include || []),
|
|
74
|
+
]),
|
|
75
|
+
],
|
|
76
|
+
exclude: [
|
|
77
|
+
...new Set([
|
|
78
|
+
...(updatedJson.exclude || []),
|
|
79
|
+
...(appJSON.exclude || []),
|
|
80
|
+
`dist/${options.projectName}/**/*`,
|
|
81
|
+
]),
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
return updatedJson;
|
|
85
|
+
});
|
|
86
|
+
host.delete('tsconfig.json');
|
|
87
|
+
host.rename('tsconfig.base.json', 'tsconfig.json');
|
|
88
|
+
}
|
|
89
|
+
if (options.unitTestRunner === 'none') {
|
|
90
|
+
host.delete(`${options.appProjectRoot}/specs/${options.fileName}.spec.tsx`);
|
|
91
|
+
}
|
|
92
|
+
// SWC will be disabled if custom babelrc is provided.
|
|
93
|
+
// Check for `!== false` because `create-nx-workspace` is not passing default values.
|
|
94
|
+
if (options.swc !== false) {
|
|
95
|
+
host.delete(`${options.appProjectRoot}/.babelrc`);
|
|
96
|
+
}
|
|
97
|
+
if (options.styledModule) {
|
|
98
|
+
if (options.appDir) {
|
|
99
|
+
host.delete(`${generatedAppFilePath}/app/page.module.${options.style}`);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
host.delete(`${generatedAppFilePath}/pages/${options.fileName}.module.${options.style}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (options.style !== 'styled-components') {
|
|
106
|
+
host.delete(`${generatedAppFilePath}/pages/_document.tsx`);
|
|
107
|
+
}
|
|
108
|
+
if (options.js) {
|
|
109
|
+
host.delete(`${options.appProjectRoot}/index.d.ts`);
|
|
110
|
+
(0, devkit_1.toJS)(host);
|
|
111
|
+
host.delete(`${options.appProjectRoot}/next-env.d.js`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.createApplicationFiles = createApplicationFiles;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from '../schema';
|
|
3
|
+
export interface NormalizedSchema extends Schema {
|
|
4
|
+
projectName: string;
|
|
5
|
+
appProjectRoot: string;
|
|
6
|
+
outputPath: string;
|
|
7
|
+
e2eProjectName: string;
|
|
8
|
+
e2eProjectRoot: string;
|
|
9
|
+
parsedTags: string[];
|
|
10
|
+
fileName: string;
|
|
11
|
+
styledModule: null | string;
|
|
12
|
+
js?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = 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 assertion_1 = require("@nx/react/src/utils/assertion");
|
|
8
|
+
async function normalizeOptions(host, options) {
|
|
9
|
+
const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
10
|
+
name: options.name,
|
|
11
|
+
projectType: 'application',
|
|
12
|
+
directory: options.directory,
|
|
13
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
14
|
+
rootProject: options.rootProject,
|
|
15
|
+
callingGenerator: '@nx/next:application',
|
|
16
|
+
});
|
|
17
|
+
options.rootProject = appProjectRoot === '.';
|
|
18
|
+
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
19
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
20
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
21
|
+
nxJson.useInferencePlugins !== false;
|
|
22
|
+
options.addPlugin ??= addPlugin;
|
|
23
|
+
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
|
24
|
+
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
|
25
|
+
const name = (0, devkit_1.names)(options.name).fileName;
|
|
26
|
+
const outputPath = (0, devkit_1.joinPathFragments)('dist', appProjectRoot, ...(options.rootProject ? [name] : []));
|
|
27
|
+
const parsedTags = options.tags
|
|
28
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
29
|
+
: [];
|
|
30
|
+
const fileName = 'index';
|
|
31
|
+
const appDir = options.appDir ?? true;
|
|
32
|
+
const src = options.src ?? true;
|
|
33
|
+
const styledModule = /^(css|scss|less)$/.test(options.style)
|
|
34
|
+
? null
|
|
35
|
+
: options.style;
|
|
36
|
+
(0, assertion_1.assertValidStyle)(options.style);
|
|
37
|
+
return {
|
|
38
|
+
...options,
|
|
39
|
+
appDir,
|
|
40
|
+
src,
|
|
41
|
+
appProjectRoot,
|
|
42
|
+
e2eProjectName,
|
|
43
|
+
e2eProjectRoot,
|
|
44
|
+
e2eTestRunner: options.e2eTestRunner || 'cypress',
|
|
45
|
+
fileName,
|
|
46
|
+
linter: options.linter || eslint_1.Linter.EsLint,
|
|
47
|
+
name,
|
|
48
|
+
outputPath,
|
|
49
|
+
parsedTags,
|
|
50
|
+
projectName: appProjectName,
|
|
51
|
+
style: options.style || 'css',
|
|
52
|
+
styledModule,
|
|
53
|
+
unitTestRunner: options.unitTestRunner || 'jest',
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.normalizeOptions = normalizeOptions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDefaults = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function setDefaults(host, options) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
7
|
+
nxJson.generators ??= {};
|
|
8
|
+
nxJson.generators['@nx/next'] ??= {};
|
|
9
|
+
nxJson.generators['@nx/next'].application ??= {};
|
|
10
|
+
nxJson.generators['@nx/next'].application.style ??= options.style;
|
|
11
|
+
nxJson.generators['@nx/next'].application.linter ??= options.linter;
|
|
12
|
+
(0, devkit_1.updateNxJson)(host, nxJson);
|
|
13
|
+
}
|
|
14
|
+
exports.setDefaults = setDefaults;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.showPossibleWarnings = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function showPossibleWarnings(tree, options) {
|
|
6
|
+
if (options.style === '@emotion/styled' && options.appDir) {
|
|
7
|
+
devkit_1.logger.warn(`Emotion may not work with the App Router. See: https://nextjs.org/docs/app/building-your-application/styling/css-in-js`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.showPossibleWarnings = showPossibleWarnings;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateCypressTsConfig = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function updateCypressTsConfig(host, options) {
|
|
6
|
+
if (options.e2eTestRunner !== 'cypress' || !options.rootProject) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
(0, devkit_1.updateJson)(host, `${options.e2eProjectRoot}/tsconfig.json`, (json) => {
|
|
10
|
+
return {
|
|
11
|
+
...json,
|
|
12
|
+
exclude: [],
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
exports.updateCypressTsConfig = updateCypressTsConfig;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateJestConfig = void 0;
|
|
4
|
+
function updateJestConfig(host, options) {
|
|
5
|
+
if (options.unitTestRunner !== 'jest') {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const configPath = `${options.appProjectRoot}/jest.config.${options.js ? 'js' : 'ts'}`;
|
|
9
|
+
const originalContent = host.read(configPath, 'utf-8');
|
|
10
|
+
const content = originalContent
|
|
11
|
+
.replace('transform: {', "transform: {\n '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',")
|
|
12
|
+
.replace(`'babel-jest'`, `['babel-jest', { presets: ['@nx/next/babel'] }]`);
|
|
13
|
+
host.write(configPath, content);
|
|
14
|
+
}
|
|
15
|
+
exports.updateJestConfig = updateJestConfig;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
|
+
import type { SupportedStyles } from '@nx/react';
|
|
4
|
+
|
|
5
|
+
export interface Schema {
|
|
6
|
+
name: string;
|
|
7
|
+
style?: SupportedStyles;
|
|
8
|
+
skipFormat?: boolean;
|
|
9
|
+
directory?: string;
|
|
10
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
11
|
+
tags?: string;
|
|
12
|
+
unitTestRunner?: 'jest' | 'none';
|
|
13
|
+
e2eTestRunner?: 'cypress' | 'playwright' | 'none';
|
|
14
|
+
linter?: Linter;
|
|
15
|
+
js?: boolean;
|
|
16
|
+
setParserOptionsProject?: boolean;
|
|
17
|
+
swc?: boolean;
|
|
18
|
+
customServer?: boolean;
|
|
19
|
+
skipPackageJson?: boolean;
|
|
20
|
+
appDir?: boolean;
|
|
21
|
+
src?: boolean;
|
|
22
|
+
rootProject?: boolean;
|
|
23
|
+
addPlugin?: boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxNextApp",
|
|
5
|
+
"title": "Create a Next.js Application for Nx",
|
|
6
|
+
"description": "Create a Next.js Application for Nx.",
|
|
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 application?",
|
|
17
|
+
"pattern": "^[a-zA-Z][^:]*$",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"directory": {
|
|
21
|
+
"description": "The directory of the new application.",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"alias": "dir",
|
|
24
|
+
"x-priority": "important"
|
|
25
|
+
},
|
|
26
|
+
"projectNameAndRootFormat": {
|
|
27
|
+
"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`).",
|
|
28
|
+
"type": "string",
|
|
29
|
+
"enum": ["as-provided", "derived"]
|
|
30
|
+
},
|
|
31
|
+
"style": {
|
|
32
|
+
"description": "The file extension to be used for style files.",
|
|
33
|
+
"type": "string",
|
|
34
|
+
"default": "css",
|
|
35
|
+
"alias": "s",
|
|
36
|
+
"x-prompt": {
|
|
37
|
+
"message": "Which stylesheet format would you like to use?",
|
|
38
|
+
"type": "list",
|
|
39
|
+
"items": [
|
|
40
|
+
{ "value": "css", "label": "CSS" },
|
|
41
|
+
{
|
|
42
|
+
"value": "scss",
|
|
43
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"value": "less",
|
|
47
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"value": "styled-components",
|
|
51
|
+
"label": "styled-components [ https://styled-components.com ]"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"value": "@emotion/styled",
|
|
55
|
+
"label": "emotion [ https://emotion.sh ]"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"value": "styled-jsx",
|
|
59
|
+
"label": "styled-jsx [ https://www.npmjs.com/package/styled-jsx ]"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"value": "none",
|
|
63
|
+
"label": "None"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"linter": {
|
|
69
|
+
"description": "The tool to use for running lint checks.",
|
|
70
|
+
"type": "string",
|
|
71
|
+
"enum": ["eslint"],
|
|
72
|
+
"default": "eslint"
|
|
73
|
+
},
|
|
74
|
+
"skipFormat": {
|
|
75
|
+
"description": "Skip formatting files.",
|
|
76
|
+
"type": "boolean",
|
|
77
|
+
"default": false,
|
|
78
|
+
"x-priority": "internal"
|
|
79
|
+
},
|
|
80
|
+
"unitTestRunner": {
|
|
81
|
+
"type": "string",
|
|
82
|
+
"enum": ["jest", "none"],
|
|
83
|
+
"description": "Test runner to use for unit tests.",
|
|
84
|
+
"default": "jest"
|
|
85
|
+
},
|
|
86
|
+
"e2eTestRunner": {
|
|
87
|
+
"type": "string",
|
|
88
|
+
"enum": ["cypress", "playwright", "none"],
|
|
89
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
90
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
91
|
+
"default": "cypress"
|
|
92
|
+
},
|
|
93
|
+
"tags": {
|
|
94
|
+
"type": "string",
|
|
95
|
+
"description": "Add tags to the application (used for linting).",
|
|
96
|
+
"alias": "t"
|
|
97
|
+
},
|
|
98
|
+
"js": {
|
|
99
|
+
"type": "boolean",
|
|
100
|
+
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
101
|
+
"default": false
|
|
102
|
+
},
|
|
103
|
+
"setParserOptionsProject": {
|
|
104
|
+
"type": "boolean",
|
|
105
|
+
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
|
106
|
+
"default": false
|
|
107
|
+
},
|
|
108
|
+
"swc": {
|
|
109
|
+
"description": "Enable the Rust-based compiler SWC to compile JS/TS files.",
|
|
110
|
+
"type": "boolean",
|
|
111
|
+
"default": true
|
|
112
|
+
},
|
|
113
|
+
"customServer": {
|
|
114
|
+
"description": "Use a custom Express server for the Next.js application.",
|
|
115
|
+
"type": "boolean",
|
|
116
|
+
"default": false
|
|
117
|
+
},
|
|
118
|
+
"skipPackageJson": {
|
|
119
|
+
"type": "boolean",
|
|
120
|
+
"default": false,
|
|
121
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
122
|
+
"x-priority": "internal"
|
|
123
|
+
},
|
|
124
|
+
"appDir": {
|
|
125
|
+
"type": "boolean",
|
|
126
|
+
"default": true,
|
|
127
|
+
"description": "Enable the App Router for this project.",
|
|
128
|
+
"x-prompt": "Would you like to use the App Router (recommended)?"
|
|
129
|
+
},
|
|
130
|
+
"src": {
|
|
131
|
+
"type": "boolean",
|
|
132
|
+
"default": true,
|
|
133
|
+
"description": "Generate a `src` directory for the project.",
|
|
134
|
+
"x-prompt": "Would you like to use `src/` directory?"
|
|
135
|
+
},
|
|
136
|
+
"rootProject": {
|
|
137
|
+
"description": "Create an application at the root of the workspace.",
|
|
138
|
+
"type": "boolean",
|
|
139
|
+
"default": false,
|
|
140
|
+
"hidden": true,
|
|
141
|
+
"x-priority": "internal"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"required": [],
|
|
145
|
+
"examplesFile": "../../../docs/application-examples.md"
|
|
146
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import type { SupportedStyles } from '@nx/react';
|
|
3
|
+
interface Schema {
|
|
4
|
+
name: string;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19.
|
|
7
|
+
*/
|
|
8
|
+
project?: string;
|
|
9
|
+
style: SupportedStyles;
|
|
10
|
+
directory?: string;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
13
|
+
*/
|
|
14
|
+
flat?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
|
|
17
|
+
*/
|
|
18
|
+
pascalCaseFiles?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
|
|
21
|
+
*/
|
|
22
|
+
pascalCaseDirectory?: boolean;
|
|
23
|
+
nameAndDirectoryFormat?: 'as-provided' | 'derived';
|
|
24
|
+
skipFormat?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function componentGenerator(host: Tree, schema: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
27
|
+
export declare function componentGeneratorInternal(host: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
28
|
+
export default componentGenerator;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentGeneratorInternal = exports.componentGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const react_1 = require("@nx/react");
|
|
6
|
+
const styles_1 = require("../../utils/styles");
|
|
7
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
8
|
+
// TODO(v19): Remove this logic once we no longer derive directory.
|
|
9
|
+
function maybeGetDerivedDirectory(host, options) {
|
|
10
|
+
if (!options.project)
|
|
11
|
+
return options.directory;
|
|
12
|
+
const workspace = (0, devkit_1.getProjects)(host);
|
|
13
|
+
const projectType = workspace.get(options.project).projectType;
|
|
14
|
+
return options.directory
|
|
15
|
+
? options.directory
|
|
16
|
+
: projectType === 'application'
|
|
17
|
+
? 'components'
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
async function componentGenerator(host, schema) {
|
|
21
|
+
return componentGeneratorInternal(host, {
|
|
22
|
+
nameAndDirectoryFormat: 'derived',
|
|
23
|
+
...schema,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.componentGenerator = componentGenerator;
|
|
27
|
+
/*
|
|
28
|
+
* This schematic is basically the React one, but for Next we need
|
|
29
|
+
* extra dependencies for css, sass, less style options.
|
|
30
|
+
*/
|
|
31
|
+
async function componentGeneratorInternal(host, options) {
|
|
32
|
+
const { artifactName: name, directory, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
|
33
|
+
artifactType: 'component',
|
|
34
|
+
callingGenerator: '@nx/next:component',
|
|
35
|
+
name: options.name,
|
|
36
|
+
directory: options.directory,
|
|
37
|
+
derivedDirectory: maybeGetDerivedDirectory(host, options),
|
|
38
|
+
flat: options.flat,
|
|
39
|
+
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
|
40
|
+
project: options.project,
|
|
41
|
+
fileExtension: 'tsx',
|
|
42
|
+
pascalCaseFile: options.pascalCaseFiles,
|
|
43
|
+
pascalCaseDirectory: options.pascalCaseDirectory,
|
|
44
|
+
});
|
|
45
|
+
const componentInstall = await (0, react_1.componentGenerator)(host, {
|
|
46
|
+
...options,
|
|
47
|
+
name,
|
|
48
|
+
nameAndDirectoryFormat: 'as-provided', // already determined the directory so use as is
|
|
49
|
+
project: undefined,
|
|
50
|
+
directory,
|
|
51
|
+
classComponent: false,
|
|
52
|
+
routing: false,
|
|
53
|
+
skipFormat: true,
|
|
54
|
+
});
|
|
55
|
+
const project = (0, devkit_1.readProjectConfiguration)(host, projectName);
|
|
56
|
+
const styledInstall = (0, styles_1.addStyleDependencies)(host, {
|
|
57
|
+
style: options.style,
|
|
58
|
+
swc: !host.exists((0, devkit_1.joinPathFragments)(project.root, '.babelrc')),
|
|
59
|
+
});
|
|
60
|
+
if (!options.skipFormat) {
|
|
61
|
+
await (0, devkit_1.formatFiles)(host);
|
|
62
|
+
}
|
|
63
|
+
return (0, devkit_1.runTasksInSerial)(styledInstall, componentInstall);
|
|
64
|
+
}
|
|
65
|
+
exports.componentGeneratorInternal = componentGeneratorInternal;
|
|
66
|
+
exports.default = componentGenerator;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxNextReactComponent",
|
|
5
|
+
"title": "Create a React Component for Next",
|
|
6
|
+
"description": "Create a React Component for Next.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The name of the project.",
|
|
12
|
+
"alias": "p",
|
|
13
|
+
"$default": {
|
|
14
|
+
"$source": "projectName"
|
|
15
|
+
},
|
|
16
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19."
|
|
17
|
+
},
|
|
18
|
+
"name": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The name of the component.",
|
|
21
|
+
"$default": {
|
|
22
|
+
"$source": "argv",
|
|
23
|
+
"index": 0
|
|
24
|
+
},
|
|
25
|
+
"x-prompt": "What name would you like to use for the component?",
|
|
26
|
+
"x-priority": "important"
|
|
27
|
+
},
|
|
28
|
+
"style": {
|
|
29
|
+
"description": "The file extension to be used for style files.",
|
|
30
|
+
"type": "string",
|
|
31
|
+
"alias": "s",
|
|
32
|
+
"default": "css",
|
|
33
|
+
"x-prompt": {
|
|
34
|
+
"message": "Which stylesheet format would you like to use?",
|
|
35
|
+
"type": "list",
|
|
36
|
+
"items": [
|
|
37
|
+
{
|
|
38
|
+
"value": "css",
|
|
39
|
+
"label": "CSS"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"value": "scss",
|
|
43
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"value": "less",
|
|
47
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"value": "styled-components",
|
|
51
|
+
"label": "styled-components [ https://styled-components.com ]"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"value": "@emotion/styled",
|
|
55
|
+
"label": "emotion [ https://emotion.sh ]"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"value": "styled-jsx",
|
|
59
|
+
"label": "styled-jsx [ https://www.npmjs.com/package/styled-jsx ]"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"value": "none",
|
|
63
|
+
"label": "None"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"skipTests": {
|
|
69
|
+
"type": "boolean",
|
|
70
|
+
"description": "When true, does not create `spec.ts` test files for the new component.",
|
|
71
|
+
"default": false,
|
|
72
|
+
"x-priority": "internal"
|
|
73
|
+
},
|
|
74
|
+
"directory": {
|
|
75
|
+
"type": "string",
|
|
76
|
+
"description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
|
|
77
|
+
"alias": "dir",
|
|
78
|
+
"x-priority": "important"
|
|
79
|
+
},
|
|
80
|
+
"nameAndDirectoryFormat": {
|
|
81
|
+
"description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
|
|
82
|
+
"type": "string",
|
|
83
|
+
"enum": ["as-provided", "derived"]
|
|
84
|
+
},
|
|
85
|
+
"export": {
|
|
86
|
+
"type": "boolean",
|
|
87
|
+
"description": "When true, the component is exported from the project index.ts (if it exists).",
|
|
88
|
+
"alias": "e",
|
|
89
|
+
"default": false
|
|
90
|
+
},
|
|
91
|
+
"js": {
|
|
92
|
+
"type": "boolean",
|
|
93
|
+
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
94
|
+
"default": false
|
|
95
|
+
},
|
|
96
|
+
"flat": {
|
|
97
|
+
"type": "boolean",
|
|
98
|
+
"description": "Create component at the source root rather than its own directory.",
|
|
99
|
+
"default": false,
|
|
100
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
|
|
101
|
+
},
|
|
102
|
+
"pascalCaseFiles": {
|
|
103
|
+
"type": "boolean",
|
|
104
|
+
"description": "Use pascal case component file name (e.g. `App.tsx`).",
|
|
105
|
+
"alias": "P",
|
|
106
|
+
"default": false,
|
|
107
|
+
"x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
108
|
+
},
|
|
109
|
+
"pascalCaseDirectory": {
|
|
110
|
+
"type": "boolean",
|
|
111
|
+
"description": "Use pascal case directory name (e.g. `App/App.tsx`).",
|
|
112
|
+
"alias": "R",
|
|
113
|
+
"default": false,
|
|
114
|
+
"x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
115
|
+
},
|
|
116
|
+
"skipFormat": {
|
|
117
|
+
"description": "Skip formatting files.",
|
|
118
|
+
"type": "boolean",
|
|
119
|
+
"default": false,
|
|
120
|
+
"x-priority": "internal"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"required": ["name"],
|
|
124
|
+
"examplesFile": "../../../docs/component-examples.md"
|
|
125
|
+
}
|