From 6a32f4c43505e2a445a26c979f6609c12414e948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=91=E5=B3=B0?= Date: Wed, 4 Sep 2019 15:29:36 +0800 Subject: [PATCH 1/2] feat(cli): taro-init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增clone选项,拉取远程模板时可选择使用git clone --- packages/taro-cli/bin/taro-init | 4 +++- packages/taro-cli/src/create/fetchTemplate.ts | 4 ++-- packages/taro-cli/src/create/project.ts | 3 ++- packages/taro-cli/src/util/index.ts | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/taro-cli/bin/taro-init b/packages/taro-cli/bin/taro-init index de3ba194059b..74c02bb5c1fe 100755 --- a/packages/taro-cli/bin/taro-init +++ b/packages/taro-cli/bin/taro-init @@ -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 /** @@ -34,6 +35,7 @@ const project = new Project({ projectName, projectDir: process.cwd(), templateSource, + clone, template, description, typescript, diff --git a/packages/taro-cli/src/create/fetchTemplate.ts b/packages/taro-cli/src/create/fetchTemplate.ts index eaa8cde2b613..54fceb746b66 100644 --- a/packages/taro-cli/src/create/fetchTemplate.ts +++ b/packages/taro-cli/src/create/fetchTemplate.ts @@ -9,7 +9,7 @@ import { getTemplateSourceType, readDirWithFileTypes } from '../util' const TEMP_DOWNLOAD_FLODER = 'taro-temp' -export default function fetchTemplate (templateSource: string, templateRootPath: string): Promise { +export default function fetchTemplate (templateSource: string, templateRootPath: string, clone?: boolean): Promise { const type = getTemplateSourceType(templateSource) const tempPath = path.join(templateRootPath, TEMP_DOWNLOAD_FLODER) let name: string @@ -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('拉取远程模板仓库失败!')) diff --git a/packages/taro-cli/src/create/project.ts b/packages/taro-cli/src/create/project.ts index 394488d4eb7d..92563a838cd3 100644 --- a/packages/taro-cli/src/create/project.ts +++ b/packages/taro-cli/src/create/project.ts @@ -14,6 +14,7 @@ export interface IProjectConf { projectName: string, projectDir: string, templateSource: string, + clone?: boolean, template: string, description?: string, typescript?: boolean, @@ -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[]) { diff --git a/packages/taro-cli/src/util/index.ts b/packages/taro-cli/src/util/index.ts index 58893554eb0b..c753915b6a1b 100644 --- a/packages/taro-cli/src/util/index.ts +++ b/packages/taro-cli/src/util/index.ts @@ -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' From 268bf3dda40ced80f23187149dbd2c5cf2da7403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=91=E5=B3=B0?= Date: Wed, 4 Sep 2019 16:00:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs(template.md):=20clone=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 拉取git模板源时增加direct:url方式和--clone选项的描述 --- docs/template.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/template.md b/docs/template.md index c6db2fe8da0b..1e66e4a6e640 100644 --- a/docs/template.md +++ b/docs/template.md @@ -28,6 +28,12 @@ title: 项目模板 * GitHub - github:owner/name * GitLab - gitlab:owner/name +* Direct - direct:url + +```sh +# 初始化项目时可以使用 --clone 选项指定拉取远程模板时使用git clone +taro init --clone +``` #### url 模板源