From 96d583c21b24262b9eb21b57ee3267854ed235c2 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Thu, 9 Jan 2020 14:53:18 +0800 Subject: [PATCH 1/3] Support @[scope] template prefix --- packages/create-react-app/createReactApp.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index bd60bed0d76..1ae658a24f1 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -640,10 +640,23 @@ function getTemplateInstallPackage(template, originalDirectory) { const scope = packageMatch[1] || ''; const templateName = packageMatch[2]; - const name = templateName.startsWith(templateToInstall) - ? templateName - : `${templateToInstall}-${templateName}`; - templateToInstall = `${scope}${name}`; + if ( + templateName === templateToInstall || + templateName.startsWith(`${templateToInstall}-`) + ) { + // cra-template + // @SCOPE/cra-template + // cra-template-NAME + // @SCOPE/cra-template-NAME + templateToInstall = `${scope}${templateName}`; + } else if (templateName.startsWith('@')) { + // @SCOPE + templateToInstall = `${templateName}/${templateToInstall}`; + } else { + // NAME + // @SCOPE/NAME + templateToInstall = `${scope}${templateToInstall}-${templateName}`; + } } } From cb3e5be44a23c5dd94f55effd1244ac0a2d1083e Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Thu, 9 Jan 2020 15:21:49 +0800 Subject: [PATCH 2/3] Update template documentation --- docusaurus/docs/custom-templates.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docusaurus/docs/custom-templates.md b/docusaurus/docs/custom-templates.md index 98acb9b1a75..7c43de98ccd 100644 --- a/docusaurus/docs/custom-templates.md +++ b/docusaurus/docs/custom-templates.md @@ -9,6 +9,8 @@ Custom Templates enable you to select a template to create your project from, wh You'll notice that Custom Templates are always named in the format `cra-template-[template-name]`, however you only need to provide the `[template-name]` to the creation command. +Scoped templates are also supported, under the name `@[scope-name]/cra-template` or `@[scope-name]/cra-template-[template-name]`, which can be installed via `@[scope]` and `@[scope]/[template-name]` respectively. + ### npm ```sh From cb007f48e56ef414552586acfa578deebe00b877 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Thu, 9 Jan 2020 20:00:50 +0800 Subject: [PATCH 3/3] Update comments wording Co-Authored-By: Brody McKee --- packages/create-react-app/createReactApp.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 1ae658a24f1..4d39b208767 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -644,17 +644,19 @@ function getTemplateInstallPackage(template, originalDirectory) { templateName === templateToInstall || templateName.startsWith(`${templateToInstall}-`) ) { - // cra-template - // @SCOPE/cra-template - // cra-template-NAME - // @SCOPE/cra-template-NAME + // Covers: + // - cra-template + // - @SCOPE/cra-template + // - cra-template-NAME + // - @SCOPE/cra-template-NAME templateToInstall = `${scope}${templateName}`; } else if (templateName.startsWith('@')) { - // @SCOPE + // Covers using @SCOPE only templateToInstall = `${templateName}/${templateToInstall}`; } else { - // NAME - // @SCOPE/NAME + // Covers templates without the `cra-template` prefix: + // - NAME + // - @SCOPE/NAME templateToInstall = `${scope}${templateToInstall}-${templateName}`; } }