Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(create-umi): 为create-umi新增设置项目名称的步骤 #12516

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/create-umi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,27 @@ export default async ({
// plugin params
let pluginName = `umi-plugin-${name || 'demo'}`;

const target = name ? join(cwd, name) : cwd;
let target = name ? join(cwd, name) : cwd;

const { isCancel, text, select, intro, outro } = clackPrompts;
const exitPrompt = () => {
outro(chalk.red('Exit create-umi'));
process.exit(1);
};
const setName = async () => {
name = (await text({
message: "What's the target folder name?",
initialValue: name || 'my-app',
validate: (value: string) => {
if (!value.length) {
return 'Please input project name';
}
if (value != '.' && fsExtra.existsSync(join(cwd, value))) {
return `Folder ${value} already exists`;
}
},
})) as string;
};
const selectAppTemplate = async () => {
appTemplate = (await select({
message: 'Pick Umi App Template',
Expand Down Expand Up @@ -159,6 +173,13 @@ export default async ({
const internalTemplatePrompts = async () => {
intro(chalk.bgHex('#19BDD2')(' create-umi '));

await setName();
if (isCancel(name)) {
exitPrompt();
}

target = join(cwd, name);
fz6m marked this conversation as resolved.
Show resolved Hide resolved

await selectAppTemplate();
if (isCancel(appTemplate)) {
exitPrompt();
Expand Down
Loading