Skip to content

Commit

Permalink
feat(create-umi): 为create-umi新增设置项目名称的步骤 (#12516)
Browse files Browse the repository at this point in the history
* feat(create-umi): 为create-umi新增设置项目名称及路径的步骤

* fix(create-umi): 修复了`.`不能作为项目文件夹的错误

* docs: 修改文档以适配`create-umi`中新增的文件夹名称设置步骤
  • Loading branch information
Redish101 committed Jul 9, 2024
1 parent 68173ec commit b99c617
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
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);

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

0 comments on commit b99c617

Please sign in to comment.