Skip to content

Commit d46d857

Browse files
committed
un-factorize, extract askSwizzlePreferredLanguage(), remove cliUtils
1 parent 19b494d commit d46d857

File tree

4 files changed

+36
-70
lines changed

4 files changed

+36
-70
lines changed

packages/docusaurus-utils/src/cliUtils.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

packages/docusaurus-utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export {
119119
} from './dataFileUtils';
120120
export {isDraft, isUnlisted} from './contentVisibilityUtils';
121121
export {escapeRegexp} from './regExpUtils';
122-
export {askPreferredLanguage} from './cliUtils';
123122
export {flattenRoutes} from './routeUtils';
124123

125124
export {

packages/docusaurus/src/commands/swizzle/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import fs from 'fs-extra';
99
import logger from '@docusaurus/logger';
10-
import {askPreferredLanguage} from '@docusaurus/utils';
1110
import {
1211
getThemeName,
1312
getThemePath,
@@ -19,7 +18,10 @@ import {helpTables, themeComponentsTable} from './tables';
1918
import {normalizeOptions} from './common';
2019
import {eject, getAction, wrap} from './actions';
2120
import {getThemeSwizzleConfig} from './config';
22-
import {askSwizzleDangerousComponent} from './prompts';
21+
import {
22+
askSwizzleDangerousComponent,
23+
askSwizzlePreferredLanguage,
24+
} from './prompts';
2325
import {initSwizzleContext} from './context';
2426
import type {SwizzleAction, SwizzleComponentConfig} from '@docusaurus/types';
2527
import type {SwizzleCLIOptions, SwizzlePlugin} from './common';
@@ -54,7 +56,7 @@ async function getLanguageForThemeName({
5456

5557
// It's only useful to prompt the user for themes that support both JS/TS
5658
if (supportsTS) {
57-
return askPreferredLanguage({exit: true});
59+
return askSwizzlePreferredLanguage();
5860
}
5961

6062
return 'javascript';

packages/docusaurus/src/commands/swizzle/prompts.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import logger from '@docusaurus/logger';
9-
import prompts from 'prompts';
9+
import prompts, {type Choice} from 'prompts';
1010
import {actionStatusSuffix, PartiallySafeHint} from './common';
1111
import type {ThemeComponents} from './components';
1212
import type {SwizzleAction, SwizzleComponentConfig} from '@docusaurus/types';
@@ -125,3 +125,33 @@ export async function askSwizzleAction(
125125

126126
return action;
127127
}
128+
129+
export async function askSwizzlePreferredLanguage(): Promise<
130+
'javascript' | 'typescript'
131+
> {
132+
const choices: Choice[] = [
133+
{title: logger.bold('JavaScript'), value: 'javascript'},
134+
{title: logger.bold('TypeScript'), value: 'typescript'},
135+
{title: logger.yellow('[Exit]'), value: '[Exit]'},
136+
];
137+
138+
const {language} = await prompts(
139+
{
140+
type: 'select',
141+
name: 'language',
142+
message: 'Which language do you want to use?',
143+
choices,
144+
},
145+
{
146+
onCancel() {
147+
process.exit(0);
148+
},
149+
},
150+
);
151+
152+
if (typeof language === 'undefined' || language === '[Exit]') {
153+
process.exit(0);
154+
}
155+
156+
return language;
157+
}

0 commit comments

Comments
 (0)