Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --local-template-path / --localTemplatePath option to rnv new #1664

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/engine-core/src/taskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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`);
}
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions packages/engine-core/src/tasks/bootstrap/taskNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default createTask({
TaskOptions.projectName,
TaskOptions.projectTemplate,
TaskOptions.templateVersion,
TaskOptions.localTemplatePath,
TaskOptions.title,
TaskOptions.appVersion,
TaskOptions.id,
Expand Down
Loading