@@ -6,6 +6,12 @@ import recipePackage from "../../packages/recipe/package.json";
66
77const repository = "https://github.com/lynstack/recipe" ;
88
9+ /** An app that runs an example of a package, and the site that hosts it. */
10+ interface ExampleApp {
11+ readonly host : "Snack" | "StackBlitz" ;
12+ readonly url : string ;
13+ }
14+
915/** A package of the repository, as the docs present it. */
1016interface PackageInfo {
1117 /** The npm name of the package. */
@@ -25,30 +31,33 @@ interface PackageInfo {
2531 /** The package's changelog on GitHub. */
2632 readonly changelog : string ;
2733 /** An example of the package that runs in the browser, to edit and try. */
28- readonly playground : string ;
34+ readonly exampleApp : ExampleApp ;
2935 /** The requirements of the package, on its installation page. */
3036 readonly requirements : string ;
3137}
3238
3339/** Opens the example in `examples/<folder>` on StackBlitz. */
34- function stackBlitzUrl ( folder : PackageIconName , file : string ) : string {
40+ function stackBlitzApp ( folder : PackageIconName , file : string ) : ExampleApp {
3541 const query = new URLSearchParams ( { file, title : `${ folder } example` } ) ;
36- return `https://stackblitz.com/github/lynstack/recipe/tree/main/examples/${ folder } ?${ query } ` ;
42+ return {
43+ host : "StackBlitz" ,
44+ url : `https://stackblitz.com/github/lynstack/recipe/tree/main/examples/${ folder } ?${ query } ` ,
45+ } ;
3746}
3847
3948/**
4049 * Opens `code` as the `App.js` of an Expo Snack that installs `dependency`.
4150 * The editor of Snack checks TypeScript with a version too old to read the
4251 * types of the packages, so the example runs as JavaScript.
4352 */
44- function snackUrl ( dependency : string , code : string ) : string {
53+ function snackApp ( dependency : string , code : string ) : ExampleApp {
4554 const query = new URLSearchParams ( {
4655 dependencies : dependency ,
4756 files : JSON . stringify ( { "App.js" : { contents : code , type : "CODE" } } ) ,
4857 name : "native-recipe example" ,
4958 platform : "web" ,
5059 } ) ;
51- return `https://snack.expo.dev/?${ query } ` ;
60+ return { host : "Snack" , url : `https://snack.expo.dev/?${ query } ` } ;
5261}
5362
5463function packageInfo (
@@ -59,15 +68,15 @@ function packageInfo(
5968 readonly description : string ;
6069 readonly license : string ;
6170 } ,
62- { label, playground } : Pick < PackageInfo , "label " | "playground " > ,
71+ { label, exampleApp } : Pick < PackageInfo , "exampleApp " | "label " > ,
6372) : PackageInfo {
6473 return {
6574 changelog : `${ repository } /blob/main/packages/${ folder } /CHANGELOG.md` ,
75+ exampleApp,
6676 label,
6777 license : manifest . license ,
6878 name : manifest . name ,
6979 npm : `https://www.npmjs.com/package/${ manifest . name } ` ,
70- playground,
7180 requirements : `/recipe/${ folder } /installation/#requirements` ,
7281 source : `${ repository } /tree/main/packages/${ folder } ` ,
7382 summary : manifest . description ,
@@ -78,19 +87,19 @@ function packageInfo(
7887/** Each package, by the name of its folder, which is also its sidebar topic. */
7988const packages = {
8089 "class-recipe" : packageInfo ( "class-recipe" , classRecipePackage , {
90+ exampleApp : stackBlitzApp ( "class-recipe" , "src/recipes.ts" ) ,
8191 label : "Class names" ,
82- playground : stackBlitzUrl ( "class-recipe" , "src/recipes.ts" ) ,
8392 } ) ,
8493 "native-recipe" : packageInfo ( "native-recipe" , nativeRecipePackage , {
85- label : "React Native styles" ,
86- playground : snackUrl (
94+ exampleApp : snackApp (
8795 `${ nativeRecipePackage . name } @${ nativeRecipePackage . version } ` ,
8896 nativeRecipeExample ,
8997 ) ,
98+ label : "React Native styles" ,
9099 } ) ,
91100 recipe : packageInfo ( "recipe" , recipePackage , {
101+ exampleApp : stackBlitzApp ( "recipe" , "src/recipes.ts" ) ,
92102 label : "Core engine" ,
93- playground : stackBlitzUrl ( "recipe" , "src/recipes.ts" ) ,
94103 } ) ,
95104} as const satisfies Readonly < Record < PackageIconName , PackageInfo > > ;
96105
0 commit comments