feat(core): merge None and TS stacks into one since they are both for TS/JS projects (#18108)

This commit is contained in:
Jack Hsu 2023-07-18 09:42:07 -04:00 committed by GitHub
parent 8d160b277e
commit 0040520bb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,13 +36,9 @@ interface BaseArguments extends CreateWorkspaceOptions {
interface NoneArguments extends BaseArguments { interface NoneArguments extends BaseArguments {
stack: 'none'; stack: 'none';
workspaceType: 'package-based' | 'integrated'; workspaceType: 'package-based' | 'integrated' | 'standalone';
}
interface TsArguments extends BaseArguments {
stack: 'ts';
workspaceType: 'standalone' | 'integrated';
js: boolean; js: boolean;
appName: string | undefined;
} }
interface ReactArguments extends BaseArguments { interface ReactArguments extends BaseArguments {
@ -78,7 +74,6 @@ interface UnknownStackArguments extends BaseArguments {
type Arguments = type Arguments =
| NoneArguments | NoneArguments
| TsArguments
| ReactArguments | ReactArguments
| AngularArguments | AngularArguments
| NodeArguments | NodeArguments
@ -316,7 +311,7 @@ async function determineFolder(
async function determineStack( async function determineStack(
parsedArgs: yargs.Arguments<Arguments> parsedArgs: yargs.Arguments<Arguments>
): Promise<'none' | 'ts' | 'react' | 'angular' | 'node' | 'unknown'> { ): Promise<'none' | 'react' | 'angular' | 'node' | 'unknown'> {
if (parsedArgs.preset) { if (parsedArgs.preset) {
switch (parsedArgs.preset) { switch (parsedArgs.preset) {
case Preset.Angular: case Preset.Angular:
@ -338,10 +333,9 @@ async function determineStack(
case Preset.Empty: case Preset.Empty:
case Preset.Apps: case Preset.Apps:
case Preset.NPM: case Preset.NPM:
return 'none';
case Preset.TS: case Preset.TS:
case Preset.TsStandalone: case Preset.TsStandalone:
return 'ts'; return 'none';
case Preset.WebComponents: case Preset.WebComponents:
case Preset.ReactNative: case Preset.ReactNative:
case Preset.Expo: case Preset.Expo:
@ -351,7 +345,7 @@ async function determineStack(
} }
const { stack } = await enquirer.prompt<{ const { stack } = await enquirer.prompt<{
stack: 'none' | 'ts' | 'react' | 'angular' | 'node'; stack: 'none' | 'react' | 'angular' | 'node';
}>([ }>([
{ {
name: 'stack', name: 'stack',
@ -360,23 +354,19 @@ async function determineStack(
choices: [ choices: [
{ {
name: `none`, name: `none`,
message: `None: Configures a minimal structure without specific frameworks or technologies.`, message: `None: Configures a TypeScript/JavaScript project with minimal structure.`,
},
{
name: `ts`,
message: `TS/JS: Configures a TypeScript/JavaScript package without specific frameworks or platforms.`,
}, },
{ {
name: `react`, name: `react`,
message: `React: Configures a React app with your framework of choice.`, message: `React: Configures a React application with your framework of choice.`,
}, },
{ {
name: `angular`, name: `angular`,
message: `Angular: Configures a Angular app with modern tooling.`, message: `Angular: Configures a Angular application with modern tooling.`,
}, },
{ {
name: `node`, name: `node`,
message: `Node: Configures a Node API with your framework of choice.`, message: `Node: Configures a Node API application with your framework of choice.`,
}, },
], ],
}, },
@ -391,8 +381,6 @@ async function determinePresetOptions(
switch (parsedArgs.stack) { switch (parsedArgs.stack) {
case 'none': case 'none':
return determineNoneOptions(parsedArgs); return determineNoneOptions(parsedArgs);
case 'ts':
return determineTsOptions(parsedArgs);
case 'react': case 'react':
return determineReactOptions(parsedArgs); return determineReactOptions(parsedArgs);
case 'angular': case 'angular':
@ -405,56 +393,25 @@ async function determinePresetOptions(
} }
async function determineNoneOptions( async function determineNoneOptions(
parsedArgs: yargs.Arguments<Arguments> parsedArgs: yargs.Arguments<NoneArguments>
): Promise<Partial<Arguments>> { ): Promise<Partial<NoneArguments>> {
if (parsedArgs.preset) return parsedArgs;
const { workspaceType } = await enquirer.prompt<{
workspaceType: 'package-based' | 'integrated';
}>([
{
type: 'autocomplete',
name: 'workspaceType',
message: `Package-based or integrated?`,
initial: 'package-based' as any,
choices: [
{
name: 'package-based',
message:
'Package-based: Nx makes it fast, but lets you run things your way.',
},
{
name: 'integrated',
message:
'Integrated: Nx creates a workspace structure most suitable for building apps.',
},
],
},
]);
if (workspaceType === 'integrated') {
return {
preset: Preset.Apps,
};
} else {
return {
preset: Preset.NPM,
};
}
}
async function determineTsOptions(
parsedArgs: yargs.Arguments<TsArguments>
): Promise<Partial<Arguments>> {
let preset: Preset; let preset: Preset;
let workspaceType: 'standalone' | 'integrated' | undefined = undefined; let workspaceType: 'package-based' | 'standalone' | 'integrated' | undefined =
undefined;
let appName: string | undefined = undefined; let appName: string | undefined = undefined;
let js = false; let js: boolean | undefined;
if (parsedArgs.preset) { if (parsedArgs.preset) {
preset = parsedArgs.preset; preset = parsedArgs.preset;
} else { } else {
workspaceType = await determineStandAloneOrMonorepo(); workspaceType = await determinePackageBasedOrIntegratedOrStandalone();
if (workspaceType === 'standalone') {
preset = Preset.TsStandalone;
} else if (workspaceType === 'integrated') {
preset = Preset.Apps;
} else {
preset = Preset.NPM;
}
preset = workspaceType === 'standalone' ? Preset.TsStandalone : Preset.TS; preset = workspaceType === 'standalone' ? Preset.TsStandalone : Preset.TS;
} }
@ -512,7 +469,7 @@ async function determineReactOptions(
const workspaceType = const workspaceType =
framework === 'react-native' || framework === 'expo' framework === 'react-native' || framework === 'expo'
? 'integrated' ? 'integrated'
: await determineStandAloneOrMonorepo(); : await determineStandaloneOrMonorepo();
if (workspaceType === 'standalone') { if (workspaceType === 'standalone') {
appName = parsedArgs.name; appName = parsedArgs.name;
@ -614,7 +571,7 @@ async function determineAngularOptions(
appName = await determineAppName(parsedArgs); appName = await determineAppName(parsedArgs);
} }
} else { } else {
const workspaceType = await determineStandAloneOrMonorepo(); const workspaceType = await determineStandaloneOrMonorepo();
if (workspaceType === 'standalone') { if (workspaceType === 'standalone') {
preset = Preset.AngularStandalone; preset = Preset.AngularStandalone;
@ -731,7 +688,7 @@ async function determineNodeOptions(
} else { } else {
framework = await determineNodeFramework(parsedArgs); framework = await determineNodeFramework(parsedArgs);
const workspaceType = await determineStandAloneOrMonorepo(); const workspaceType = await determineStandaloneOrMonorepo();
if (workspaceType === 'standalone') { if (workspaceType === 'standalone') {
preset = Preset.NodeStandalone; preset = Preset.NodeStandalone;
appName = parsedArgs.name; appName = parsedArgs.name;
@ -773,7 +730,47 @@ async function determineNodeOptions(
}; };
} }
async function determineStandAloneOrMonorepo(): Promise< async function determinePackageBasedOrIntegratedOrStandalone(): Promise<
'package-based' | 'integrated' | 'standalone'
> {
const { workspaceType } = await enquirer.prompt<{
workspaceType: 'standalone' | 'integrated' | 'package-based';
}>([
{
type: 'autocomplete',
name: 'workspaceType',
message: `Package-based monorepo, integrated monorepo, or standalone project?`,
initial: 'package-based' as any,
choices: [
{
name: 'package-based',
message:
'Package-based Monorepo: Nx makes it fast, but lets you run things your way.',
},
{
name: 'integrated',
message:
'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
},
{
name: 'standalone',
message:
'Standalone: Nx creates a single project and makes it fast.',
},
],
},
]);
invariant(workspaceType, {
title: 'Invalid workspace type',
bodyLines: [
`It must be one of the following: standalone, integrated. Got ${workspaceType}`,
],
});
return workspaceType;
}
async function determineStandaloneOrMonorepo(): Promise<
'integrated' | 'standalone' 'integrated' | 'standalone'
> { > {
const { workspaceType } = await enquirer.prompt<{ const { workspaceType } = await enquirer.prompt<{
@ -782,19 +779,19 @@ async function determineStandAloneOrMonorepo(): Promise<
{ {
type: 'autocomplete', type: 'autocomplete',
name: 'workspaceType', name: 'workspaceType',
message: `Standalone project or integrated monorepo?`, message: `Integrated monorepo, or standalone project?`,
initial: 'standalone' as any, initial: 'standalone' as any,
choices: [ choices: [
{
name: 'standalone',
message:
'Standalone: Nx creates a single project and makes it fast.',
},
{ {
name: 'integrated', name: 'integrated',
message: message:
'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.', 'Integrated Monorepo: Nx creates a monorepo that contains multiple projects.',
}, },
{
name: 'standalone',
message:
'Standalone: Nx creates a single project and makes it fast.',
},
], ],
}, },
]); ]);