-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(turbo-gen): support TS config files
- Loading branch information
Showing
13 changed files
with
397 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { PlopTypes } from "@turbo/gen"; | ||
|
||
// helpers | ||
const dateToday = (): string => | ||
new Date().toISOString().split("T")[0].replace(/-/g, "/"); | ||
|
||
const majorMinor = (version: string): string => | ||
version.split(".").slice(0, 2).join("."); | ||
|
||
export function init(plop: PlopTypes.NodePlopAPI): void { | ||
// add helpers for use in templates | ||
plop.setHelper("dateToday", dateToday); | ||
plop.setHelper("majorMinor", majorMinor); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import fetch from "node-fetch"; | ||
|
||
interface Answers extends Object { | ||
turboStars: string; | ||
turboDownloads: string; | ||
turboYearsSaved: string; | ||
} | ||
|
||
const PUBLIC_TB_TOKEN = | ||
"p.eyJ1IjogIjAzYzA0Y2MyLTM1YTAtNDhhNC05ZTZjLThhMWE0NGNhNjhkZiIsICJpZCI6ICJmOWIzMTU5Yi0wOTVjLTQyM2UtOWIwNS04ZDZlNzIyNjEwNzIifQ.A3TOPdm3Lhmn-1x5m6jNvulCQbbgUeQfAIO3IaaAt5k"; | ||
|
||
export async function releasePostStats(answers: Answers): Promise<string> { | ||
const [starsResponse, downloadsResponse, timeSavedResponse] = | ||
await Promise.all([ | ||
fetch("https://api.github.com/repos/vercel/turbo"), | ||
fetch("https://api.npmjs.org/versions/turbo/last-week"), | ||
fetch( | ||
`https://api.us-east.tinybird.co/v0/pipes/turborepo_time_saved_ticker.json?token=${PUBLIC_TB_TOKEN}` | ||
), | ||
]); | ||
|
||
const [starsData, downloadsData, timeSavedData] = await Promise.all([ | ||
starsResponse.json() as { stargazers_count: number }, | ||
downloadsResponse.json() as { | ||
downloads: Array<{ [key: string]: number }>; | ||
}, | ||
timeSavedResponse.json() as { | ||
data: [ | ||
{ | ||
remote_cache_minutes_saved: number; | ||
local_cache_minutes_saved: number; | ||
} | ||
]; | ||
}, | ||
]); | ||
|
||
const totalMinutesSaved: number = | ||
timeSavedData.data[0].remote_cache_minutes_saved + | ||
timeSavedData.data[0].local_cache_minutes_saved; | ||
const totalYearsSaved: number = Math.floor(totalMinutesSaved / 60 / 24 / 365); | ||
const weeklyDownloads: number = Object.keys(downloadsData.downloads).reduce( | ||
(sum, version) => sum + downloadsData.downloads[version], | ||
0 | ||
); | ||
|
||
console.log(JSON.stringify(weeklyDownloads)); | ||
|
||
const prettyRound = (num: number): string => { | ||
if (num < 1000) { | ||
return num.toString(); | ||
} else if (num < 1000000) { | ||
return (num / 1000).toFixed(1) + "k"; | ||
} else { | ||
return (num / 1000000).toFixed(1) + "M"; | ||
} | ||
}; | ||
|
||
// extend answers | ||
answers.turboStars = prettyRound(starsData.stargazers_count); | ||
answers.turboDownloads = prettyRound(weeklyDownloads); | ||
answers.turboYearsSaved = prettyRound(totalYearsSaved); | ||
|
||
return "Fetched stats for release post"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.