@epic-web/workshop-utils 6.59.1 → 6.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4871,6 +4871,14 @@ export declare function getAppFromFile(filePath: string): Promise<{
4871
4871
  epicVideoEmbeds?: string[] | undefined;
4872
4872
  } | undefined>;
4873
4873
  export declare function savePlayground(): Promise<void>;
4874
+ export type SavedPlayground = {
4875
+ id: string;
4876
+ appName: string;
4877
+ createdAt: string;
4878
+ createdAtMs: number;
4879
+ fullPath: string;
4880
+ };
4881
+ export declare function getSavedPlaygrounds(): Promise<Array<SavedPlayground>>;
4874
4882
  export declare function setPlayground(srcDir: string, { reset }?: {
4875
4883
  reset?: boolean;
4876
4884
  }): Promise<void>;
@@ -4895,6 +4903,21 @@ export declare function getWorkshopInstructions({ request, }?: {
4895
4903
  readonly file: string;
4896
4904
  readonly relativePath: "exercises";
4897
4905
  }>;
4906
+ export declare function getExamplesInstructions({ request, }?: {
4907
+ request?: Request;
4908
+ }): Promise<{
4909
+ readonly compiled: {
4910
+ readonly status: "success";
4911
+ readonly code: string;
4912
+ readonly title: string | null;
4913
+ readonly epicVideoEmbeds: Array<string>;
4914
+ } | {
4915
+ readonly status: "error";
4916
+ readonly error: string;
4917
+ };
4918
+ readonly file: string;
4919
+ readonly relativePath: "examples/README.mdx";
4920
+ }>;
4898
4921
  export declare function getWorkshopFinished({ request, }?: {
4899
4922
  request?: Request;
4900
4923
  }): Promise<{
@@ -1049,6 +1049,46 @@ locally and uncheck "Enable saving playground."
1049
1049
  }
1050
1050
  await fsExtra.copy(playgroundDir, path.join(savedPlaygroundsDir, savedPlaygroundDirName));
1051
1051
  }
1052
+ const savedPlaygroundTimestampPattern = /^(\d{4})\.(\d{2})\.(\d{2})_(\d{2})\.(\d{2})\.(\d{2})$/;
1053
+ function parseSavedPlaygroundDirName(dirName) {
1054
+ const parts = dirName.split('_');
1055
+ if (parts.length < 3)
1056
+ return null;
1057
+ const timestampPart = `${parts[0]}_${parts[1]}`;
1058
+ const appName = parts.slice(2).join('_') || dirName;
1059
+ const match = savedPlaygroundTimestampPattern.exec(timestampPart);
1060
+ if (!match)
1061
+ return null;
1062
+ const [, year, month, day, hour, minute, second] = match;
1063
+ const createdAt = new Date(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second));
1064
+ if (Number.isNaN(createdAt.getTime()))
1065
+ return null;
1066
+ return { appName, createdAt };
1067
+ }
1068
+ export async function getSavedPlaygrounds() {
1069
+ const savedPlaygroundsDir = path.join(getWorkshopRoot(), 'saved-playgrounds');
1070
+ if (!(await exists(savedPlaygroundsDir)))
1071
+ return [];
1072
+ const dirEntries = await fsExtra.readdir(savedPlaygroundsDir, {
1073
+ withFileTypes: true,
1074
+ });
1075
+ const savedPlaygrounds = await Promise.all(dirEntries
1076
+ .filter((entry) => entry.isDirectory())
1077
+ .map(async (entry) => {
1078
+ const fullPath = path.join(savedPlaygroundsDir, entry.name);
1079
+ const parsed = parseSavedPlaygroundDirName(entry.name);
1080
+ const stat = await fsExtra.stat(fullPath).catch(() => null);
1081
+ const createdAt = parsed?.createdAt ?? (stat ? new Date(stat.mtimeMs) : new Date(0));
1082
+ return {
1083
+ id: entry.name,
1084
+ appName: parsed?.appName ?? entry.name,
1085
+ createdAt: createdAt.toISOString(),
1086
+ createdAtMs: createdAt.getTime(),
1087
+ fullPath,
1088
+ };
1089
+ }));
1090
+ return savedPlaygrounds.sort((a, b) => b.createdAtMs - a.createdAtMs);
1091
+ }
1052
1092
  export async function setPlayground(srcDir, { reset } = {}) {
1053
1093
  const preferences = await getPreferences();
1054
1094
  const playgroundApp = await getAppByName('playground');
@@ -1219,6 +1259,18 @@ export async function getWorkshopInstructions({ request, } = {}) {
1219
1259
  });
1220
1260
  return { compiled, file: readmeFilepath, relativePath: 'exercises' };
1221
1261
  }
1262
+ export async function getExamplesInstructions({ request, } = {}) {
1263
+ const readmeFilepath = path.join(getWorkshopRoot(), 'examples', 'README.mdx');
1264
+ const compiled = await compileMdx(readmeFilepath, { request }).then((r) => ({ ...r, status: 'success' }), (e) => {
1265
+ console.error(`There was an error compiling the examples README.mdx`, readmeFilepath, e);
1266
+ return { status: 'error', error: getErrorMessage(e) };
1267
+ });
1268
+ return {
1269
+ compiled,
1270
+ file: readmeFilepath,
1271
+ relativePath: 'examples/README.mdx',
1272
+ };
1273
+ }
1222
1274
  export async function getWorkshopFinished({ request, } = {}) {
1223
1275
  const finishedFilepath = path.join(getWorkshopRoot(), 'exercises', 'FINISHED.mdx');
1224
1276
  const compiled = await compileMdx(finishedFilepath, { request }).then((r) => ({ ...r, status: 'success' }), (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epic-web/workshop-utils",
3
- "version": "6.59.1",
3
+ "version": "6.61.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },