Skip to content

Commit

Permalink
Merge dev-next-release pull request #1124
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire authored Sep 6, 2023
2 parents 1232710 + 4f7fe2a commit 6ac592d
Show file tree
Hide file tree
Showing 67 changed files with 1,969 additions and 343 deletions.
2 changes: 1 addition & 1 deletion e2e-projects/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cimsirp",
"version": "1.11.0",
"version": "1.11.1-dev-next-release.7",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion e2e-projects/sveltekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveltekit",
"version": "1.11.0",
"version": "1.11.1-dev-next-release.7",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"prettier:fix": "prettier --write .",
"prettier:check": "prettier --check .",
"test": "yarn workspaces foreach --parallel --topological-dev --verbose run test",
"test:e2e": "yarn cypress-setup && start-server-and-test 'npm run dev --prefix e2e-projects/cypress-next-app' http://localhost:3000 'SM_ENV=development ENABLE_SENTRY=false npm run slicemachine --prefix e2e-projects/cypress-next-app' http://localhost:9999 'cypress run'",
"test:e2e:dev": "yarn cypress-setup && start-server-and-test 'npm run dev --prefix e2e-projects/cypress-next-app' http://localhost:3000 'SM_ENV=staging ENABLE_SENTRY=false npm run slicemachine --prefix e2e-projects/cypress-next-app' http://localhost:9999 'cypress open'",
"test:e2e": "yarn cypress-setup && start-server-and-test 'npm run dev --prefix e2e-projects/cypress-next-app' http://localhost:3000 'SM_ENV=development VITE_ENABLE_SENTRY=false npm run slicemachine --prefix e2e-projects/cypress-next-app' http://localhost:9999 'cypress run'",
"test:e2e:dev": "yarn cypress-setup && start-server-and-test 'npm run dev --prefix e2e-projects/cypress-next-app' http://localhost:3000 'SM_ENV=staging VITE_ENABLE_SENTRY=false npm run slicemachine --prefix e2e-projects/cypress-next-app' http://localhost:9999 'cypress open'",
"cy:open": "cypress open",
"bump:interactive": "lerna version prerelease --preid alpha --no-push --exact",
"bump:alpha": "lerna version prerelease --preid $npm_config_preid --no-changelog --exact --yes",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-next",
"version": "0.3.13",
"version": "0.3.14-dev-next-release.7",
"description": "Slice Machine adapter for Next.js.",
"keywords": [
"typescript",
Expand Down
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.
4 changes: 3 additions & 1 deletion packages/adapter-next/src/hooks/slice-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const createComponentFile = async ({
options,
});

if (isTypeScriptProject) {
if (data.componentContents) {
contents = data.componentContents;
} else if (isTypeScriptProject) {
contents = stripIndent`
import { Content } from "@prismicio/client";
import { SliceComponentProps } from "@prismicio/react";
Expand Down
55 changes: 55 additions & 0 deletions packages/adapter-next/src/hooks/sliceTemplateLibrary-read.ts
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,
};
};
7 changes: 7 additions & 0 deletions packages/adapter-next/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { documentationRead } from "./hooks/documentation-read";
import { projectInit } from "./hooks/project-init";
import { sliceCreate } from "./hooks/slice-create";
import { sliceSimulatorSetupRead } from "./hooks/sliceSimulator-setup-read";
import { sliceTemplateLibraryRead } from "./hooks/sliceTemplateLibrary-read";
import { snippetRead } from "./hooks/snippet-read";

export const plugin = defineSliceMachinePlugin<PluginOptions>({
Expand Down Expand Up @@ -155,6 +156,12 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
});
});

////////////////////////////////////////////////////////////////
// slice-template-library:*
////////////////////////////////////////////////////////////////

hook("slice-template-library:read", sliceTemplateLibraryRead);

////////////////////////////////////////////////////////////////
// custom-type:*
////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 6ac592d

Please sign in to comment.