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
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docs/docs/docs/guides/boilerplate.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ translated_at: '2024-03-17T10:35:15.206Z'
Umi officially provides a scaffold, which allows you to easily and quickly create a project:

```bash
# Create a project in the current folder
# Input the path to the project directory when prompted by the wizard
pnpm create umi
# Create a project under the my-umi-app folder in the current directory
pnpm create umi my-umi-app
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/docs/guides/boilerplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toc: content
Umi 官方提供了一个脚手架 ,可以轻松快速创建一个项目:

```bash
# 在当前文件夹下创建项目
# 在向导中输入文件夹名称
pnpm create umi
# 在当前目录的 my-umi-app 文件夹下创建项目
pnpm create umi my-umi-app
Expand Down
6 changes: 0 additions & 6 deletions docs/docs/docs/guides/getting-started.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ $ pnpm -v

## Create a Project

First, find a place to create a new empty directory.

```bash
$ mkdir myapp && cd myapp
```

Create a project using the official tool,

PNPM
Expand Down
5 changes: 0 additions & 5 deletions docs/docs/docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ $ pnpm -v

## 创建项目

先找个地方建个空目录。

```bash
$ mkdir myapp && cd myapp
```

通过官方工具创建项目,

Expand Down
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