Skip to content

Commit

Permalink
feat(create-turbo): fix official examples (#9837)
Browse files Browse the repository at this point in the history
### Description

Fixes some logic that was introduced
#9708 that allows classifying
official examples.

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
tknickman authored Jan 29, 2025
1 parent ebc4075 commit 4a5d9dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions packages/create-turbo/src/transforms/official-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { isDefaultExample } from "../utils/isDefaultExample";
import type { TransformInput, TransformResult, MetaJson } from "./types";
import { TransformError } from "./errors";

const REPO_NAMES = ["turbo", "turborepo"];

const meta = {
name: "official-starter",
};
Expand All @@ -18,10 +20,10 @@ export async function transform(args: TransformInput): TransformResult {
const { prompts, example, opts } = args;

const defaultExample = isDefaultExample(example.name);
const isThisRepo =
example.repo &&
(example.repo.name === "turborepo" || example.repo.name === "turbo");
const isOfficialStarter = example.repo?.username === "vercel" && isThisRepo;
const isOfficialStarter =
!example.repo ||
(example.repo.username === "vercel" &&
REPO_NAMES.includes(example.repo.name));

if (!isOfficialStarter) {
return { result: "not-applicable", ...meta };
Expand All @@ -43,7 +45,7 @@ export async function transform(args: TransformInput): TransformResult {
}

if (hasPackageJson) {
let packageJsonContent;
let packageJsonContent: PackageJson | undefined;
try {
packageJsonContent = fs.readJsonSync(rootPackageJsonPath) as
| PackageJson
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-utils/src/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function createProject({
if (isDefaultExample) {
repoInfo = {
username: "vercel",
name: "turbo",
name: "turborepo",
branch: "main",
filePath: "examples/basic",
};
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-utils/src/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function existsInRepo(nameOrUrl: string): Promise<boolean> {
return isUrlOk(url.href);
} catch {
return isUrlOk(
`https://api.github.com/repos/vercel/turbo/contents/examples/${encodeURIComponent(
`https://api.github.com/repos/vercel/turborepo/contents/examples/${encodeURIComponent(
nameOrUrl
)}`
);
Expand Down

0 comments on commit 4a5d9dd

Please sign in to comment.