-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge dev-next-release pull request #1124
- Loading branch information
Showing
67 changed files
with
1,969 additions
and
343 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
55 changes: 55 additions & 0 deletions
55
packages/adapter-next/src/hooks/sliceTemplateLibrary-read.ts
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,55 @@ | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
import { SharedSlice } from "@prismicio/types-internal/lib/customtypes"; | ||
import type { SliceTemplateLibraryReadHook } from "@slicemachine/plugin-kit"; | ||
|
||
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject"; | ||
|
||
import * as CallToAction from "../sliceTemplates/CallToAction"; | ||
import type { PluginOptions } from "../types"; | ||
|
||
const initialTemplates = [CallToAction]; | ||
|
||
export const sliceTemplateLibraryRead: SliceTemplateLibraryReadHook< | ||
PluginOptions | ||
> = async ({ templateIDs }, { helpers, options }) => { | ||
const isTypeScriptProject = await checkIsTypeScriptProject({ | ||
helpers, | ||
options, | ||
}); | ||
const templates = | ||
templateIDs && templateIDs.length | ||
? initialTemplates.filter((t) => templateIDs?.includes(t.model.id)) | ||
: initialTemplates; | ||
|
||
const templatesPromises = templates.map(async (t) => { | ||
const { mocks, model, createComponentContents, screenshotPaths } = t; | ||
|
||
const screenshotEntries = Object.entries(screenshotPaths); | ||
const screenshotPromises = screenshotEntries.map(([key, filePath]) => { | ||
return fs | ||
.readFile( | ||
fileURLToPath(new URL(path.join("..", filePath), import.meta.url)), | ||
) | ||
.then((data) => [key, data]); | ||
}); | ||
const readScreenshots = await Promise.all(screenshotPromises); | ||
const screenshots = Object.fromEntries(readScreenshots); | ||
|
||
return { | ||
mocks, | ||
model, | ||
createComponentContents: (model: SharedSlice) => | ||
createComponentContents(model, isTypeScriptProject), | ||
screenshots, | ||
}; | ||
}); | ||
|
||
const resolvedTemplates = await Promise.all(templatesPromises); | ||
|
||
return { | ||
templates: resolvedTemplates, | ||
}; | ||
}; |
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.