- Enable generating the new & minimal TS setup by default when generating the `ts` preset with CNW. The existing `NX_ADD_TS_PLUGIN` environment variable is kept with its default value inverted and set to `true`. It can be used to opt out of the new TS setup by running CNW with `NX_ADD_TS_PLUGIN=false`. - Throw an error when running generators that don't yet support the new TS setup. - We'll add support for those generators incrementally in follow-up PRs. <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> <!-- Fixes NXC-1066 --> <!-- Fixes NXC-1068 --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
130 lines
3.6 KiB
TypeScript
130 lines
3.6 KiB
TypeScript
import {
|
|
addDependenciesToPackageJson,
|
|
formatFiles,
|
|
GeneratorCallback,
|
|
joinPathFragments,
|
|
runTasksInSerial,
|
|
Tree,
|
|
} from '@nx/devkit';
|
|
import { initGenerator as jsInitGenerator } from '@nx/js';
|
|
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
|
import { setupTailwindGenerator } from '@nx/react';
|
|
import {
|
|
testingLibraryReactVersion,
|
|
typesReactDomVersion,
|
|
typesReactVersion,
|
|
} from '@nx/react/src/utils/versions';
|
|
|
|
import { normalizeOptions } from './lib/normalize-options';
|
|
import { Schema } from './schema';
|
|
import { addE2e } from './lib/add-e2e';
|
|
import { addJest } from './lib/add-jest';
|
|
import { addProject } from './lib/add-project';
|
|
import { createApplicationFiles } from './lib/create-application-files';
|
|
import { setDefaults } from './lib/set-defaults';
|
|
import { updateJestConfig } from './lib/update-jest-config';
|
|
import { nextInitGenerator } from '../init/init';
|
|
import { addStyleDependencies } from '../../utils/styles';
|
|
import { addLinting } from './lib/add-linting';
|
|
import { customServerGenerator } from '../custom-server/custom-server';
|
|
import { updateCypressTsConfig } from './lib/update-cypress-tsconfig';
|
|
import { showPossibleWarnings } from './lib/show-possible-warnings';
|
|
import { tsLibVersion } from '../../utils/versions';
|
|
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
|
|
|
export async function applicationGenerator(host: Tree, schema: Schema) {
|
|
return await applicationGeneratorInternal(host, {
|
|
addPlugin: false,
|
|
...schema,
|
|
});
|
|
}
|
|
|
|
export async function applicationGeneratorInternal(host: Tree, schema: Schema) {
|
|
assertNotUsingTsSolutionSetup(host, 'next', 'application');
|
|
|
|
const tasks: GeneratorCallback[] = [];
|
|
const options = await normalizeOptions(host, schema);
|
|
|
|
showPossibleWarnings(host, options);
|
|
|
|
const jsInitTask = await jsInitGenerator(host, {
|
|
js: options.js,
|
|
skipPackageJson: options.skipPackageJson,
|
|
skipFormat: true,
|
|
});
|
|
tasks.push(jsInitTask);
|
|
|
|
const nextTask = await nextInitGenerator(host, {
|
|
...options,
|
|
skipFormat: true,
|
|
});
|
|
tasks.push(nextTask);
|
|
|
|
createApplicationFiles(host, options);
|
|
|
|
addProject(host, options);
|
|
|
|
const e2eTask = await addE2e(host, options);
|
|
tasks.push(e2eTask);
|
|
|
|
const jestTask = await addJest(host, options);
|
|
tasks.push(jestTask);
|
|
|
|
const lintTask = await addLinting(host, options);
|
|
tasks.push(lintTask);
|
|
|
|
if (options.style === 'tailwind') {
|
|
const tailwindTask = await setupTailwindGenerator(host, {
|
|
project: options.projectName,
|
|
});
|
|
|
|
tasks.push(tailwindTask);
|
|
}
|
|
|
|
const styledTask = addStyleDependencies(host, {
|
|
style: options.style,
|
|
swc: !host.exists(joinPathFragments(options.appProjectRoot, '.babelrc')),
|
|
});
|
|
tasks.push(styledTask);
|
|
|
|
updateJestConfig(host, options);
|
|
updateCypressTsConfig(host, options);
|
|
setDefaults(host, options);
|
|
|
|
if (options.customServer) {
|
|
await customServerGenerator(host, {
|
|
project: options.projectName,
|
|
compiler: options.swc ? 'swc' : 'tsc',
|
|
});
|
|
}
|
|
|
|
if (!options.skipPackageJson) {
|
|
const devDependencies: Record<string, string> = {
|
|
'@types/react': typesReactVersion,
|
|
'@types/react-dom': typesReactDomVersion,
|
|
};
|
|
|
|
if (schema.unitTestRunner && schema.unitTestRunner !== 'none') {
|
|
devDependencies['@testing-library/react'] = testingLibraryReactVersion;
|
|
}
|
|
|
|
tasks.push(
|
|
addDependenciesToPackageJson(
|
|
host,
|
|
{ tslib: tsLibVersion },
|
|
devDependencies
|
|
)
|
|
);
|
|
}
|
|
|
|
if (!options.skipFormat) {
|
|
await formatFiles(host);
|
|
}
|
|
|
|
tasks.push(() => {
|
|
logShowProjectCommand(options.projectName);
|
|
});
|
|
|
|
return runTasksInSerial(...tasks);
|
|
}
|