From cfb58e62096738531f9681191af6df57f8d88ac3 Mon Sep 17 00:00:00 2001 From: ElenaDiachenko <96205320+ElenaDiachenko@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:57:20 +0300 Subject: [PATCH] Merge pull request #1664 from flexn-io/localTemplatePath_option_added add --local-template-path / --localTemplatePath option to rnv new (cherry picked from commit d703994d4ab849f29242bf5e775607ff14bc801c) --- .github/workflows/e2e-harness-ios.yml | 2 +- .github/workflows/e2e-template-ios.yml | 2 +- packages/engine-core/src/taskOptions.ts | 6 +++ .../bootstrap/questions/installTemplate.ts | 52 +++++++++++-------- .../src/tasks/bootstrap/taskNew.ts | 1 + 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/.github/workflows/e2e-harness-ios.yml b/.github/workflows/e2e-harness-ios.yml index 864448ca5..dadd873b4 100644 --- a/.github/workflows/e2e-harness-ios.yml +++ b/.github/workflows/e2e-harness-ios.yml @@ -34,7 +34,7 @@ jobs: yarn bootstrap - name: Run run: | - cd packages/app-harness && yarn run:ios-test & sleep 540 + cd packages/app-harness && yarn run:ios-test & sleep 600 - name: E2E run: | cd packages/app-harness && yarn e2e:ios && kill $(lsof -t -i:8092) diff --git a/.github/workflows/e2e-template-ios.yml b/.github/workflows/e2e-template-ios.yml index 96d208014..0f5192c2b 100644 --- a/.github/workflows/e2e-template-ios.yml +++ b/.github/workflows/e2e-template-ios.yml @@ -34,7 +34,7 @@ jobs: yarn bootstrap - name: Run run: | - cd packages/template-starter && yarn run:ios-test & sleep 540 + cd packages/template-starter && yarn run:ios-test & sleep 600 - name: E2E run: | cd packages/template-starter && yarn e2e:ios && kill $(lsof -t -i:8082) diff --git a/packages/engine-core/src/taskOptions.ts b/packages/engine-core/src/taskOptions.ts index c25568bdf..2b829bc69 100644 --- a/packages/engine-core/src/taskOptions.ts +++ b/packages/engine-core/src/taskOptions.ts @@ -51,6 +51,12 @@ export const TaskOptions = createTaskOptionsMap([ isValueType: true, description: 'select the template version', }, + { + key: 'local-template-path', + altKey: 'localTemplatePath', + isValueType: true, + description: 'select the local template path (absolute)', + }, { key: 'title', isValueType: true, diff --git a/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts b/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts index 1e2f515d1..65d95b480 100644 --- a/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts +++ b/packages/engine-core/src/tasks/bootstrap/questions/installTemplate.ts @@ -45,34 +45,36 @@ const Question = async (data: NewProjectData) => { const c = getContext(); const { templateVersion, projectTemplate } = c.program.opts(); + let { localTemplatePath } = c.program.opts(); const projectTemplates = c.buildConfig.projectTemplates || {}; // c.files.rnvConfigTemplates.config?.projectTemplates || {}; - - const options: TemplateOption[] = []; - let defaultOverride; - Object.keys(projectTemplates).forEach((k) => { - const value = projectTemplates[k]; - const option: TemplateOption = { - name: `${k} ${chalk().grey(`- ${value.localPath || value.description}`)}`, - value: { ...value, type: 'existing', packageName: value?.packageName || k }, - }; - options.push(option); - if (value.localPath) { - defaultOverride = option.value; - } - }); - - options.push(inquirerSeparator('Advanced:----------------')); - options.push(customTemplate); - options.push(localTemplate); - options.push(noTemplate); - let localTemplatePath: string | undefined; + const projectTemplateKeys = Object.keys(projectTemplates); inputs.template = {}; if (checkInputValue(projectTemplate)) { inputs.template.packageName = projectTemplate; - } else { + } else if (!checkInputValue(localTemplatePath)) { + const options: TemplateOption[] = []; + let defaultOverride; + projectTemplateKeys.forEach((k) => { + const value = projectTemplates[k]; + + const option: TemplateOption = { + name: `${k} ${chalk().grey(`- ${value.localPath || value.description}`)}`, + value: { ...value, type: 'existing', packageName: value?.packageName || k }, + }; + options.push(option); + if (value.localPath) { + defaultOverride = option.value; + } + }); + + options.push(inquirerSeparator('Advanced:----------------')); + options.push(customTemplate); + options.push(localTemplate); + options.push(noTemplate); + const iRes = await inquirerPrompt({ name: 'inputTemplate', type: 'list', @@ -112,7 +114,7 @@ const Question = async (data: NewProjectData) => { const npmCacheDir = path.join(c.paths.project.dir, RnvFolderName.dotRnv, RnvFolderName.npmCache); - if (localTemplatePath) { + if (checkInputValue(localTemplatePath)) { if (!fsExistsSync(localTemplatePath)) { return Promise.reject(`Local template path ${localTemplatePath} does not exist`); } @@ -136,6 +138,12 @@ const Question = async (data: NewProjectData) => { inputs.template.packageName = pkg.name; inputs.template.version = pkg.version; inputs.template.localPath = localTemplatePath; + projectTemplateKeys.find((tpl) => { + const value = projectTemplates[tpl]; + if (value.localPath === localTemplatePath && inputs.template) { + inputs.template.type = 'existing'; + } + }); if (!inputs.template) return; diff --git a/packages/engine-core/src/tasks/bootstrap/taskNew.ts b/packages/engine-core/src/tasks/bootstrap/taskNew.ts index 2bae994ab..9dedbc531 100644 --- a/packages/engine-core/src/tasks/bootstrap/taskNew.ts +++ b/packages/engine-core/src/tasks/bootstrap/taskNew.ts @@ -95,6 +95,7 @@ export default createTask({ TaskOptions.projectName, TaskOptions.projectTemplate, TaskOptions.templateVersion, + TaskOptions.localTemplatePath, TaskOptions.title, TaskOptions.appVersion, TaskOptions.id,