Skip to content
Closed
Changes from all 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
18 changes: 14 additions & 4 deletions packages/cli/src/commands/init/templateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,20 @@ async function tryTemplateShorthand(templateName: string) {
return templateName;
}
try {
const reactNativeTemplatePackage = `react-native-template-${templateName}`;
const response = await fetch(
`https://registry.yarnpkg.com/${reactNativeTemplatePackage}/latest`,
);
const nameTagArray = templateName.split('@');
const name = nameTagArray[0];
const tag = nameTagArray[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's assign a default value here, so we can avoid branching:

Suggested change
const tag = nameTagArray[1];
const tag = nameTagArray[1] || 'latest';

const reactNativeTemplatePackage = `react-native-template-${name}`;
var response;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var response;
const response = await fetch(
`https://registry.yarnpkg.com/${reactNativeTemplatePackage}/${tag}`,
);

if (tag) {
response = await fetch(
`https://registry.yarnpkg.com/${reactNativeTemplatePackage}/${tag}`,
);
} else {
response = await fetch(
`https://registry.yarnpkg.com/${reactNativeTemplatePackage}/latest`,
);
}

if (JSON.parse(response).name) {
return reactNativeTemplatePackage;
Expand Down