UNPKG

@nx/next

Version:

The Next.js plugin for Nx contains executors and generators for managing Next.js applications and libraries within an Nx workspace. It provides: - Scaffolding for creating, building, serving, linting, and testing Next.js applications. - Integration wit

111 lines (110 loc) 5.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.applicationGenerator = applicationGenerator; exports.applicationGeneratorInternal = applicationGeneratorInternal; const internal_1 = require("@nx/devkit/internal"); const devkit_1 = require("@nx/devkit"); const assert_supported_next_version_1 = require("../../utils/assert-supported-next-version"); const js_1 = require("@nx/js"); const internal_2 = require("@nx/react/internal"); const internal_3 = require("@nx/react/internal"); const normalize_options_1 = require("./lib/normalize-options"); const add_e2e_1 = require("./lib/add-e2e"); const add_jest_1 = require("./lib/add-jest"); const add_project_1 = require("./lib/add-project"); const create_application_files_1 = require("./lib/create-application-files"); const set_defaults_1 = require("./lib/set-defaults"); const init_1 = require("../init/init"); const styles_1 = require("../../utils/styles"); const add_linting_1 = require("./lib/add-linting"); const custom_server_1 = require("../custom-server/custom-server"); const update_cypress_tsconfig_1 = require("./lib/update-cypress-tsconfig"); const versions_1 = require("../../utils/versions"); const internal_4 = require("@nx/js/internal"); const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server"); const jest_config_util_1 = require("../../utils/jest-config-util"); async function applicationGenerator(host, schema) { return await applicationGeneratorInternal(host, { addPlugin: false, useProjectJson: true, ...schema, }); } async function applicationGeneratorInternal(host, schema) { (0, assert_supported_next_version_1.assertSupportedNextVersion)(host); const tasks = []; const addTsPlugin = (0, internal_4.shouldConfigureTsSolutionSetup)(host, schema.addPlugin, schema.useTsSolution); const jsInitTask = await (0, js_1.initGenerator)(host, { js: schema.js, skipPackageJson: schema.skipPackageJson, skipFormat: true, addTsPlugin, formatter: schema.formatter, platform: 'web', }); tasks.push(jsInitTask); const options = await (0, normalize_options_1.normalizeOptions)(host, schema); const nextTask = await (0, init_1.nextInitGenerator)(host, { ...options, skipFormat: true, }); tasks.push(nextTask); await (0, create_application_files_1.createApplicationFiles)(host, options); (0, add_project_1.addProject)(host, options); // If we are using the new TS solution // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project if (options.isTsSolutionSetup) { await (0, internal_4.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot); } const lintTask = await (0, add_linting_1.addLinting)(host, options); tasks.push(lintTask); const e2eTask = await (0, add_e2e_1.addE2e)(host, options); tasks.push(e2eTask); const jestTask = await (0, add_jest_1.addJest)(host, options); tasks.push(jestTask); const styledTask = (0, styles_1.addStyleDependencies)(host, { style: options.style, swc: !host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, '.babelrc')), }); tasks.push(styledTask); (0, jest_config_util_1.updateJestConfig)(host, { ...options, projectRoot: options.appProjectRoot }); (0, update_cypress_tsconfig_1.updateCypressTsConfig)(host, options); (0, set_defaults_1.setDefaults)(host, options); if (options.swc) { const swcTask = (0, add_swc_to_custom_server_1.configureForSwc)(host, options.appProjectRoot); tasks.push(swcTask); } if (options.customServer) { await (0, custom_server_1.customServerGenerator)(host, { project: options.projectName, compiler: options.swc ? 'swc' : 'tsc', }); } if (!options.skipPackageJson) { const reactVersions = await (0, internal_3.getReactDependenciesVersionsToInstall)(host); const devDependencies = { '@types/react': reactVersions['@types/react'], '@types/react-dom': reactVersions['@types/react-dom'], }; if (options.unitTestRunner && options.unitTestRunner !== 'none') { devDependencies['@testing-library/react'] = internal_2.testingLibraryReactVersion; devDependencies['@testing-library/dom'] = internal_2.testingLibraryDomVersion; } tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { tslib: versions_1.tsLibVersion }, devDependencies, undefined, true)); } (0, internal_4.updateTsconfigFiles)(host, options.appProjectRoot, 'tsconfig.json', { jsx: 'preserve', module: 'esnext', moduleResolution: 'bundler', }, options.linter === 'eslint' ? ['.next', 'eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs'] : ['.next'], options.src ? 'src' : '.'); (0, internal_4.sortPackageJsonFields)(host, options.appProjectRoot); if (!options.skipFormat) { await (0, devkit_1.formatFiles)(host); } tasks.push(() => { (0, internal_1.logShowProjectCommand)(options.projectName); }); return (0, devkit_1.runTasksInSerial)(...tasks); }