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

fix(create-turbo): Hard code default example. #4974

Merged
merged 2 commits into from
May 16, 2023
Merged
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
113 changes: 61 additions & 52 deletions packages/turbo-utils/src/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,60 +37,69 @@ export async function createProject({
let repoInfo: RepoInfo | undefined;
let repoUrl: URL | undefined;

try {
repoUrl = new URL(example);
} catch (err: any) {
if (err.code !== "ERR_INVALID_URL") {
error(err);
process.exit(1);
}
}

if (repoUrl) {
if (repoUrl.origin !== "https://github.com") {
error(
`Invalid URL: ${chalk.red(
`"${example}"`
)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`
);
process.exit(1);
}

repoInfo = await getRepoInfo(repoUrl, examplePath);

if (!repoInfo) {
error(
`Unable to fetch repository information from: ${chalk.red(
`"${example}"`
)}. Please fix the URL and try again.`
);
process.exit(1);
if (isDefaultExample) {
repoInfo = {
username: "vercel",
name: "turbo",
branch: "main",
filePath: "examples/basic",
};
} else {
try {
repoUrl = new URL(example);
} catch (err: any) {
if (err.code !== "ERR_INVALID_URL") {
error(err);
process.exit(1);
}
}

const found = await hasRepo(repoInfo);

if (!found) {
error(
`Could not locate the repository for ${chalk.red(
`"${example}"`
)}. Please check that the repository exists and try again.`
);
process.exit(1);
}
} else {
const found = await existsInRepo(example);

if (!found) {
error(
`Could not locate an example named ${chalk.red(
`"${example}"`
)}. It could be due to the following:\n`,
`1. Your spelling of example ${chalk.red(
`"${example}"`
)} might be incorrect.\n`,
`2. You might not be connected to the internet or you are behind a proxy.`
);
process.exit(1);
if (repoUrl) {
if (repoUrl.origin !== "https://github.com") {
error(
`Invalid URL: ${chalk.red(
`"${example}"`
)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`
);
process.exit(1);
}

repoInfo = await getRepoInfo(repoUrl, examplePath);

if (!repoInfo) {
error(
`Unable to fetch repository information from: ${chalk.red(
`"${example}"`
)}. Please fix the URL and try again.`
);
process.exit(1);
}

const found = await hasRepo(repoInfo);

if (!found) {
error(
`Could not locate the repository for ${chalk.red(
`"${example}"`
)}. Please check that the repository exists and try again.`
);
process.exit(1);
}
} else {
const found = await existsInRepo(example);

if (!found) {
error(
`Could not locate an example named ${chalk.red(
`"${example}"`
)}. It could be due to the following:\n`,
`1. Your spelling of example ${chalk.red(
`"${example}"`
)} might be incorrect.\n`,
`2. You might not be connected to the internet or you are behind a proxy.`
);
process.exit(1);
}
}
}

Expand Down