fix(core): do not prompt, only warn when projectNameAndRootLayout is … (#19037)
This commit is contained in:
parent
214b53134d
commit
850cdb3d20
@ -63,6 +63,10 @@ type ProjectNameAndRootFormats = {
|
|||||||
derived?: ProjectNameAndRootOptions;
|
derived?: ProjectNameAndRootOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deprecationWarning = stripIndents`
|
||||||
|
In Nx 18, generating projects will no longer derive the name and root.
|
||||||
|
Please provide the exact project name and root in the future.`;
|
||||||
|
|
||||||
export async function determineProjectNameAndRootOptions(
|
export async function determineProjectNameAndRootOptions(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
options: ProjectGenerationOptions
|
options: ProjectGenerationOptions
|
||||||
@ -73,11 +77,18 @@ export async function determineProjectNameAndRootOptions(
|
|||||||
> {
|
> {
|
||||||
validateName(options.name, options.projectNameAndRootFormat);
|
validateName(options.name, options.projectNameAndRootFormat);
|
||||||
const formats = getProjectNameAndRootFormats(tree, options);
|
const formats = getProjectNameAndRootFormats(tree, options);
|
||||||
|
const configuredDefault = getDefaultProjectNameAndRootFormat(tree);
|
||||||
|
|
||||||
|
if (configuredDefault === 'derived') {
|
||||||
|
logger.warn(
|
||||||
|
deprecationWarning + '\n' + getExample(options.callingGenerator, formats)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const format =
|
const format =
|
||||||
options.projectNameAndRootFormat ??
|
options.projectNameAndRootFormat ??
|
||||||
(getDefaultProjectNameAndRootFormat(tree) === 'as-provided'
|
configuredDefault ??
|
||||||
? 'as-provided'
|
(await determineFormat(tree, formats, options.callingGenerator));
|
||||||
: await determineFormat(tree, formats, options.callingGenerator));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...formats[format],
|
...formats[format],
|
||||||
@ -115,6 +126,13 @@ function validateName(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getExample(
|
||||||
|
callingGenerator: string,
|
||||||
|
formats: ProjectNameAndRootFormats
|
||||||
|
) {
|
||||||
|
return `Example: nx g ${callingGenerator} ${formats['as-provided'].projectName} --directory ${formats['as-provided'].projectRoot}`;
|
||||||
|
}
|
||||||
|
|
||||||
async function determineFormat(
|
async function determineFormat(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
formats: ProjectNameAndRootFormats,
|
formats: ProjectNameAndRootFormats,
|
||||||
@ -157,10 +175,6 @@ async function determineFormat(
|
|||||||
format === asProvidedSelectedValue ? 'as-provided' : 'derived'
|
format === asProvidedSelectedValue ? 'as-provided' : 'derived'
|
||||||
);
|
);
|
||||||
|
|
||||||
const deprecationWarning = stripIndents`
|
|
||||||
In Nx 18, generating projects will no longer derive the name and root.
|
|
||||||
Please provide the exact project name and root in the future.`;
|
|
||||||
|
|
||||||
if (result === 'as-provided' && callingGenerator) {
|
if (result === 'as-provided' && callingGenerator) {
|
||||||
const { saveDefault } = await prompt<{ saveDefault: boolean }>({
|
const { saveDefault } = await prompt<{ saveDefault: boolean }>({
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
@ -174,7 +188,7 @@ async function determineFormat(
|
|||||||
logger.warn(deprecationWarning);
|
logger.warn(deprecationWarning);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const example = `Example: nx g ${callingGenerator} ${formats[result].projectName} --directory ${formats[result].projectRoot}`;
|
const example = getExample(callingGenerator, formats);
|
||||||
logger.warn(deprecationWarning + '\n' + example);
|
logger.warn(deprecationWarning + '\n' + example);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +204,7 @@ function setProjectNameAndRootFormatDefault(tree: Tree) {
|
|||||||
|
|
||||||
function getDefaultProjectNameAndRootFormat(tree: Tree) {
|
function getDefaultProjectNameAndRootFormat(tree: Tree) {
|
||||||
const nxJson = readNxJson(tree);
|
const nxJson = readNxJson(tree);
|
||||||
return nxJson.workspaceLayout?.projectNameAndRootFormat ?? 'derived';
|
return nxJson.workspaceLayout?.projectNameAndRootFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProjectNameAndRootFormats(
|
function getProjectNameAndRootFormats(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user