-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
130 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,5 @@ | |
- 或者,你想通过交互式选择模板创建项目: | ||
|
||
```bash | ||
pure create myproject | ||
pure create | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { log, clg } from './log' | ||
import pc from 'picocolors' | ||
import ora, { Ora, Options } from 'ora' | ||
import { TTemplateName } from '../types' | ||
import { templates } from '../constants' | ||
import simpleGit, { SimpleGit, SimpleGitOptions, SimpleGitProgressEvent } from 'simple-git' | ||
|
||
const oraOptions: Options = { | ||
spinner: 'runner' | ||
} | ||
const spinner: Ora = ora(oraOptions) | ||
|
||
const progress = ({ progress }: SimpleGitProgressEvent) => { | ||
const proText = `进度: ${pc.cyan(progress + '%')}` | ||
spinner.start().text = proText | ||
if (progress === 100) { | ||
spinner.start().text = proText + pc.green(' 下载完成') | ||
} | ||
} | ||
|
||
const gitOptions: Partial<SimpleGitOptions> = { | ||
baseDir: process.cwd(), | ||
binary: 'git', | ||
maxConcurrentProcesses: 6, | ||
progress | ||
} | ||
|
||
// https://git-scm.com/docs/git-clone#Documentation/git-clone.txt | ||
export const clone = async ( | ||
repo: string, | ||
projectName: string, | ||
options: string[], | ||
templateName: TTemplateName | ||
): Promise<any> => { | ||
const git: SimpleGit = simpleGit(gitOptions) | ||
try { | ||
clg(`项目下载自 ${pc.cyan(repo)}`) | ||
await git.clone(repo, projectName, options) | ||
} catch (err) { | ||
spinner.fail() | ||
log.err('请求失败, 请重试') | ||
} | ||
|
||
spinner.succeed() // 下载成功提示 | ||
// 模板使用提示 | ||
clg(`\r\n 已成功创建项目 ${pc.cyan(projectName)}`) | ||
clg(`\r\n cd ${pc.cyan(projectName)}`) | ||
clg(' pnpm install \r\n') | ||
if (templateName === 'tauri') { | ||
return clg(' pnpm tauri:dev \r\n') | ||
} | ||
clg(' pnpm dev \r\n') | ||
} | ||
|
||
/** | ||
* 判断当前模板类型是否存在 | ||
* @param templateName 模板类型 | ||
* @returns { boolean } | ||
*/ | ||
export const hasTemplate = (templateName: TTemplateName): boolean => { | ||
const templateKeys = Reflect.ownKeys(templates) | ||
const hasTemplate = templateKeys.includes(templateName) | ||
if (!hasTemplate) { | ||
log.err(`当前模板类型 ${pc.cyan(`${templateName}`)} 不存在 \r\n `) | ||
log.info(`请输入以下其中一种模板类型: `) | ||
templateKeys.forEach((key) => { | ||
clg( | ||
pc.bold( | ||
pc.green(`${key as string} `) + pc.gray(`${templates[key as TTemplateName].description}`) | ||
) | ||
) | ||
}) | ||
} | ||
return hasTemplate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,2 @@ | ||
import pc from 'picocolors' | ||
import logSymbols from 'log-symbols' | ||
import ora, { Ora, Options } from 'ora' | ||
import { TTemplateName } from '../types' | ||
import simpleGit, { SimpleGit, SimpleGitOptions, SimpleGitProgressEvent } from 'simple-git' | ||
|
||
const oraOptions: Options = { | ||
spinner: 'runner' | ||
} | ||
const spinner: Ora = ora(oraOptions) | ||
|
||
const progress = ({ progress }: SimpleGitProgressEvent) => { | ||
const proText = `Progress: ${pc.cyan(progress + '%')}` | ||
spinner.start().text = proText | ||
if (progress === 100) { | ||
spinner.start().text = proText + pc.green(' Download Completed') | ||
} | ||
} | ||
|
||
const gitOptions: Partial<SimpleGitOptions> = { | ||
baseDir: process.cwd(), | ||
binary: 'git', | ||
maxConcurrentProcesses: 6, | ||
progress | ||
} | ||
|
||
// https://git-scm.com/docs/git-clone#Documentation/git-clone.txt | ||
export const clone = async ( | ||
repo: string, | ||
projectName: string, | ||
options: string[], | ||
templateName: TTemplateName | ||
): Promise<any> => { | ||
const git: SimpleGit = simpleGit(gitOptions) | ||
try { | ||
console.log(`download from ${pc.cyan(repo)}`) | ||
await git.clone(repo, projectName, options) | ||
} catch (err) { | ||
spinner.fail() | ||
console.log(logSymbols.error, pc.red('Request fail, Please try again')) | ||
} | ||
|
||
spinner.succeed() // 下载成功提示 | ||
// 模板使用提示 | ||
console.log(`\r\n Successfully created project ${pc.cyan(projectName)}`) | ||
console.log(`\r\n cd ${pc.cyan(projectName)}`) | ||
console.log(' pnpm install \r\n') | ||
if (templateName === 'tauri') { | ||
return console.log(' pnpm tauri:dev \r\n') | ||
} | ||
console.log(' pnpm dev \r\n') | ||
} | ||
export * from './log' | ||
export * from './clone' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pc from 'picocolors' | ||
import logSymbols from 'log-symbols' | ||
|
||
export const clg = console.log | ||
|
||
export const log = { | ||
err: (msg: string) => { | ||
clg(logSymbols.error, pc.red(msg)) | ||
}, | ||
warning: (msg: string) => { | ||
clg(logSymbols.warning, pc.yellow(msg)) | ||
}, | ||
info: (msg: string) => { | ||
clg(logSymbols.info, pc.bold(msg)) | ||
} | ||
} | ||
|
||
export default log |