Skip to content

Commit 71a9f90

Browse files
refactor: rename and extract prompt kind
1 parent 8027b71 commit 71a9f90

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

src/index.ts

+13-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import {red} from 'kleur';
2-
import prompts from 'prompts';
1+
import {grey, red} from 'kleur';
2+
import {version} from '../package.json';
33
import {installCliIfNecessary} from './services/cli.services';
44
import {generate} from './services/generate.services';
5-
import {promptDestination, promptStarter, promptTemplate} from './services/prompt.services';
6-
import type {GeneratorInput} from './types/generator';
5+
import {
6+
promptDestination,
7+
promptKind,
8+
promptStarter,
9+
promptTemplate
10+
} from './services/prompt.services';
711
import {checkNodeVersion} from './utils/env.utils';
8-
import {assertAnswerCtrlC} from './utils/prompts.utils';
9-
import {grey} from 'kleur';
10-
import {version} from '../package.json';
1112

1213
const JUNO_LOGO = ` __ __ __ __ _ ____
1314
__) || | || \\| |/ \\
@@ -29,28 +30,17 @@ export const run = async () => {
2930

3031
const {destination} = await promptDestination();
3132

32-
const {action}: Pick<GeneratorInput, 'action'> = await prompts({
33-
type: 'select',
34-
name: 'action',
35-
message: 'What kind of project are you starting?',
36-
choices: [
37-
{title: `A static website`, value: `website`},
38-
{title: `An application`, value: `app`}
39-
]
40-
});
33+
const {kind} = await promptKind();
4134

42-
assertAnswerCtrlC(action);
43-
44-
if (action === 'website') {
35+
if (kind === 'website') {
4536
console.warn('🚧 This feature is not yet implemented. Please try again later.');
4637
return;
47-
4838
}
49-
const template = await promptTemplate(action);
50-
const starter = action === 'app' ? await promptStarter() : null;
39+
const template = await promptTemplate(kind);
40+
const starter = kind === 'app' ? await promptStarter() : null;
5141

5242
await generate({
53-
action,
43+
kind: kind,
5444
destination,
5545
template,
5646
starter

src/services/prompt.services.ts

+16
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,19 @@ export const promptDestination = async (): Promise<Pick<GeneratorInput, 'destina
6767

6868
return {destination};
6969
};
70+
71+
export const promptKind = async (): Promise<Pick<GeneratorInput, 'kind'>> => {
72+
const {kind}: Pick<GeneratorInput, 'kind'> = await prompts({
73+
type: 'select',
74+
name: 'kind',
75+
message: 'What kind of project are you starting?',
76+
choices: [
77+
{title: `Website`, value: `website`},
78+
{title: `Application`, value: `app`}
79+
]
80+
});
81+
82+
assertAnswerCtrlC(kind);
83+
84+
return {kind};
85+
};

src/types/generator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {Template, TemplateStarter} from './template';
22

33
export interface GeneratorInput {
4-
action: 'website' | 'app';
4+
kind: 'website' | 'app';
55
destination: string | "";
66
template: Template;
77
starter: TemplateStarter | null;

src/utils/fs.utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ export const getRelativeTemplatePath = (params: {
2424
}) => join(TEMPLATE_PATH, getTemplateName(params));
2525

2626
export const getLocalTemplatePath = ({
27-
action,
27+
kind,
2828
...rest
2929
}: {
3030
template: Template;
3131
starter: TemplateStarter | null;
32-
} & Pick<GeneratorInput, 'action'>) =>
32+
} & Pick<GeneratorInput, 'kind'>) =>
3333
join(__dirname, '..', TEMPLATE_PATH, action, getTemplateName(rest));
3434

3535
export const createParentFolders = (target: string) => {

0 commit comments

Comments
 (0)