@nx/next
Version:
118 lines (117 loc) • 5.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applicationGenerator = applicationGenerator;
exports.applicationGeneratorInternal = applicationGeneratorInternal;
const devkit_1 = require("@nx/devkit");
const js_1 = require("@nx/js");
const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
const versions_1 = require("@nx/react/src/utils/versions");
const version_utils_1 = require("@nx/react/src/utils/version-utils");
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 show_possible_warnings_1 = require("./lib/show-possible-warnings");
const versions_2 = require("../../utils/versions");
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
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) {
const tasks = [];
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
(0, show_possible_warnings_1.showPossibleWarnings)(host, options);
const jsInitTask = await (0, js_1.initGenerator)(host, {
js: options.js,
skipPackageJson: options.skipPackageJson,
skipFormat: true,
addTsPlugin: options.isTsSolutionSetup,
formatter: options.formatter,
platform: 'web',
});
tasks.push(jsInitTask);
const nextTask = await (0, init_1.nextInitGenerator)(host, {
...options,
skipFormat: true,
});
tasks.push(nextTask);
(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, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot);
}
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 lintTask = await (0, add_linting_1.addLinting)(host, options);
tasks.push(lintTask);
if (options.style === 'tailwind') {
const tailwindTask = await (0, setup_tailwind_1.setupTailwindGenerator)(host, {
project: options.projectName,
});
tasks.push(tailwindTask);
}
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, version_utils_1.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'] = versions_1.testingLibraryReactVersion;
devDependencies['@testing-library/dom'] = versions_1.testingLibraryDomVersion;
}
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { tslib: versions_2.tsLibVersion }, devDependencies));
}
(0, ts_solution_setup_1.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, sort_fields_1.sortPackageJsonFields)(host, options.appProjectRoot);
if (!options.skipFormat) {
await (0, devkit_1.formatFiles)(host);
}
tasks.push(() => {
(0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
});
return (0, devkit_1.runTasksInSerial)(...tasks);
}