Add a `useProjectJson` option to project generators to allow users to opt in/out of generating the Nx configuration in a `project.json` file. ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes #
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { readNxJson, Tree } from '@nx/devkit';
|
|
import {
|
|
determineProjectNameAndRootOptions,
|
|
ensureRootProjectName,
|
|
} from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
import { Schema } from '../schema';
|
|
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
|
|
|
export interface NormalizedSchema extends Schema {
|
|
importPath: string;
|
|
projectRoot: string;
|
|
isUsingTsSolutionConfig: boolean;
|
|
}
|
|
|
|
export async function normalizeOptions(
|
|
host: Tree,
|
|
options: Schema
|
|
): Promise<NormalizedSchema> {
|
|
await ensureRootProjectName(options, 'library');
|
|
const { projectRoot, importPath } = await determineProjectNameAndRootOptions(
|
|
host,
|
|
{
|
|
name: options.name,
|
|
projectType: 'library',
|
|
directory: options.directory,
|
|
importPath: options.importPath,
|
|
}
|
|
);
|
|
|
|
const nxJson = readNxJson(host);
|
|
const addPlugin =
|
|
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
nxJson.useInferencePlugins !== false;
|
|
options.addPlugin ??= addPlugin;
|
|
const isUsingTsSolutionConfig = isUsingTsSolutionSetup(host);
|
|
|
|
return {
|
|
...options,
|
|
importPath,
|
|
projectRoot,
|
|
isUsingTsSolutionConfig,
|
|
useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
|
|
};
|
|
}
|