Skip to content

Commit

Permalink
Merge pull request #4391 from christlee1989/master
Browse files Browse the repository at this point in the history
feat(cli): taro-init新增clone选项
  • Loading branch information
Chen-jj authored Sep 4, 2019
2 parents 9390598 + 268bf3d commit e76cd6f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ title: 项目模板

* GitHub - github:owner/name
* GitLab - gitlab:owner/name
* Direct - direct:url

```sh
# 初始化项目时可以使用 --clone 选项指定拉取远程模板时使用git clone
taro init --clone
```

#### url 模板源

Expand Down
4 changes: 3 additions & 1 deletion packages/taro-cli/bin/taro-init
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ program
.option('--typescript', '使用TypeScript')
.option('--no-typescript', '不使用TypeScript')
.option('--template-source [templateSource]', '项目模板源')
.option('--clone [clone]', '拉取远程模板时使用git clone')
.option('--template [template]', '项目模板')
.option('--css [css]', 'CSS预处理器(sass/less/stylus/none)')
.parse(process.argv)

const args = program.args
const { template, templateSource, description, name, css } = program
const { template, templateSource, clone, description, name, css } = program
let typescript

/**
Expand All @@ -34,6 +35,7 @@ const project = new Project({
projectName,
projectDir: process.cwd(),
templateSource,
clone,
template,
description,
typescript,
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-cli/src/create/fetchTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getTemplateSourceType, readDirWithFileTypes } from '../util'

const TEMP_DOWNLOAD_FLODER = 'taro-temp'

export default function fetchTemplate (templateSource: string, templateRootPath: string): Promise<any> {
export default function fetchTemplate (templateSource: string, templateRootPath: string, clone?: boolean): Promise<any> {
const type = getTemplateSourceType(templateSource)
const tempPath = path.join(templateRootPath, TEMP_DOWNLOAD_FLODER)
let name: string
Expand All @@ -23,7 +23,7 @@ export default function fetchTemplate (templateSource: string, templateRootPath:

if (type === 'git') {
name = path.basename(templateSource)
download(templateSource, path.join(tempPath, name), async error => {
download(templateSource, path.join(tempPath, name), { clone }, async error => {
if (error) {
spinner.color = 'red'
spinner.fail(chalk.red('拉取远程模板仓库失败!'))
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-cli/src/create/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IProjectConf {
projectName: string,
projectDir: string,
templateSource: string,
clone?: boolean,
template: string,
description?: string,
typescript?: boolean,
Expand Down Expand Up @@ -96,7 +97,7 @@ export default class Project extends Creator {
}

// 从模板源下载模板
return fetchTemplate(this.conf.templateSource, this.templatePath(''))
return fetchTemplate(this.conf.templateSource, this.templatePath(''), this.conf.clone)
}

ask (templateChoices: string[]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ export function getUserHomeDir (): string {
export type TemplateSourceType = 'git' | 'url'

export function getTemplateSourceType (url: string): TemplateSourceType {
if (/^github:/.test(url) || /^gitlab:/.test(url)) {
if (/^github:/.test(url) || /^gitlab:/.test(url) || /^direct:/.test(url)) {
return 'git'
} else {
return 'url'
Expand Down

0 comments on commit e76cd6f

Please sign in to comment.