Skip to content

Commit ef5384c

Browse files
feat: move and rename destination folder
1 parent e580251 commit ef5384c

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {red} from 'kleur';
22
import prompts from 'prompts';
33
import {installCliIfNecessary} from './services/cli.services';
44
import {generate} from './services/generate.services';
5-
import {promptProjectName, promptStarter, promptTemplate} from './services/prompt.services';
5+
import {promptProjectDestination, promptStarter, promptTemplate} from './services/prompt.services';
66
import type {GeneratorInput} from './types/generator';
77
import {checkNodeVersion} from './utils/env.utils';
88
import {assertAnswerCtrlC} from './utils/prompts.utils';
@@ -27,6 +27,8 @@ export const run = async () => {
2727

2828
console.log(WELCOME);
2929

30+
const destination = await promptProjectDestination();
31+
3032
const {action}: Pick<GeneratorInput, 'action'> = await prompts({
3133
type: 'select',
3234
name: 'action',
@@ -42,15 +44,14 @@ export const run = async () => {
4244
if (action === 'website') {
4345
console.warn('🚧 This feature is not yet implemented. Please try again later.');
4446
return;
45-
}
4647

48+
}
4749
const template = await promptTemplate(action);
4850
const starter = action === 'app' ? await promptStarter() : null;
49-
const name = await promptProjectName();
5051

5152
await generate({
5253
action,
53-
name,
54+
destination,
5455
template,
5556
starter
5657
});

src/services/generate.services.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {createDirectory, getLocalFiles, type LocalFileDescriptor} from '../utils
1717

1818
type PopulateInput = {
1919
where: string | null;
20-
} & Omit<GeneratorInput, 'name'>;
20+
} & Omit<GeneratorInput, 'destination'>;
2121

22-
export const generate = async ({name, ...rest}: GeneratorInput) => {
22+
export const generate = async ({destination, ...rest}: GeneratorInput) => {
2323
await populate({
24-
where: ['.', ''].includes(name) ? null : name,
24+
where: ['.', ''].includes(destination) ? null : destination,
2525
...rest
2626
});
2727
};

src/services/prompt.services.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ export const promptStarter = async () => {
5252
return starter;
5353
};
5454

55-
export const promptProjectName = async (): Promise<string> => {
56-
const {name}: {name: string} = await prompts({
55+
export const promptProjectDestination = async (): Promise<string | ""> => {
56+
const {destination}: {destination?: string} = await prompts({
5757
type: 'text',
58-
name: 'name',
59-
message: 'What is the name of your project?'
58+
name: 'destination',
59+
message: 'Where should we create your project?'
6060
});
6161

62-
assertAnswerCtrlC(name);
62+
// We do not use assertAnswerCtrlC here because we allow Return
63+
if (isNullish(destination)) {
64+
process.exit(1);
65+
}
6366

64-
return name;
67+
return destination;
6568
};

src/types/generator.ts

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

33
export interface GeneratorInput {
44
action: 'website' | 'app';
5-
name: string;
5+
destination: string | "";
66
template: Template;
77
starter: TemplateStarter | null;
88
}

0 commit comments

Comments
 (0)