create-plasmic-app 0.0.45 → 0.0.48

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.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
-
2
1
  # Create Plasmic App
2
+
3
3
  The easiest way to get started with Plasmic for a new code base is with `create-plasmic-app`. Under the hood, we'll use `create-next-app`, `create-gatsby`, or `create-react-app` to help create a new app, and set it up with Plasmic.
4
4
 
5
5
  ## Quickstart
package/dist/index.js CHANGED
@@ -203,7 +203,7 @@ function run() {
203
203
  name: "projectId",
204
204
  message: `What is the URL of your project?
205
205
  If you don't have a project yet, create one by going to
206
- https://studio.plasmic.app/starters/simple-light
206
+ https://studio.plasmic.app/starters/blank
207
207
  `,
208
208
  });
209
209
  projectId = rawProjectId
package/dist/lib.js CHANGED
@@ -102,6 +102,7 @@ function create(args) {
102
102
  const installResult = yield cpaStrategy.installDeps({
103
103
  scheme,
104
104
  projectPath: resolvedProjectPath,
105
+ useTypescript,
105
106
  });
106
107
  if (!installResult) {
107
108
  throw new Error("Failed to install the Plasmic dependency");
@@ -49,16 +49,38 @@ const npm_utils_1 = require("../utils/npm-utils");
49
49
  const common_1 = require("./common");
50
50
  const gatsbyStrategy = {
51
51
  create: (args) => __awaiter(void 0, void 0, void 0, function* () {
52
- const { projectPath, template } = args;
53
- const createCommand = `npx -p gatsby gatsby new ${projectPath}`;
54
- const templateArg = template ? ` ${template}` : "";
55
- yield cmd_utils_1.spawnOrFail(`${createCommand}${templateArg}`);
52
+ const { projectPath, template, useTypescript } = args;
53
+ if (template) {
54
+ console.log(`Warning: Ignoring template '${template}' (argument is not supported by Gatsby).`);
55
+ }
56
+ // create-gatsby does not support absolute paths as of 2022-08-12
57
+ // (see https://github.com/gatsbyjs/gatsby/issues/36381).
58
+ const parent = path_1.default.dirname(projectPath);
59
+ yield fs_1.promises.mkdir(parent, { recursive: true });
60
+ const dir = path_1.default.basename(projectPath);
61
+ const createCommand = `npx -p create-gatsby create-gatsby ${useTypescript ? "-ts" : ""} -y ${dir}`;
62
+ yield cmd_utils_1.spawnOrFail(`${createCommand}`, parent);
56
63
  }),
57
- installDeps: ({ projectPath, scheme }) => __awaiter(void 0, void 0, void 0, function* () {
64
+ installDeps: ({ projectPath, scheme, useTypescript }) => __awaiter(void 0, void 0, void 0, function* () {
58
65
  if (scheme === "loader") {
59
- return yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
66
+ const installedLoader = yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
67
+ workingDir: projectPath,
68
+ });
69
+ const installedHelmet = yield npm_utils_1.installUpgrade("react-helmet", {
70
+ workingDir: projectPath,
71
+ });
72
+ const installedHelmetTypes = !useTypescript ||
73
+ (yield npm_utils_1.installUpgrade("@types/react-helmet", {
74
+ workingDir: projectPath,
75
+ dev: true,
76
+ }));
77
+ const installedHelmetPlugin = yield npm_utils_1.installUpgrade("gatsby-plugin-react-helmet", {
60
78
  workingDir: projectPath,
61
79
  });
80
+ return (installedLoader &&
81
+ installedHelmet &&
82
+ installedHelmetPlugin &&
83
+ installedHelmetTypes);
62
84
  }
63
85
  else {
64
86
  return yield common_1.installCodegenDeps({ projectPath });
@@ -67,21 +89,29 @@ const gatsbyStrategy = {
67
89
  overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
68
90
  var e_1, _a;
69
91
  const { projectId, projectPath, projectApiToken, useTypescript, scheme, } = args;
92
+ const extension = useTypescript ? "ts" : "js";
70
93
  if (scheme === "loader") {
71
- // create-gatsby will create a default gatsby-config.js that we need to modify
72
- const gatsbyConfigFile = path_1.default.join(projectPath, "gatsby-config.js");
94
+ // create-gatsby will create a default gatsby-config that we need to modify
95
+ const gatsbyConfigFile = path_1.default.join(projectPath, `gatsby-config.${extension}`);
73
96
  const rl = readline.createInterface({
74
97
  input: fs_1.createReadStream(gatsbyConfigFile),
75
98
  crlfDelay: Infinity,
76
99
  });
77
- let result = "";
100
+ // Typescript doesn't accept require.resolve
101
+ // https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/#requireresolve
102
+ let result = useTypescript ? `import path from "path";\n` : "";
103
+ const pluginConfig = gatsby_1.GATSBY_PLUGIN_CONFIG(projectId, lang_utils_1.ensure(projectApiToken), useTypescript);
78
104
  try {
79
105
  for (var rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), !rl_1_1.done;) {
80
106
  const line = rl_1_1.value;
81
- result += line + "\n";
82
- // Prepend PlasmicLoader to list of plugins
83
- if (line.includes("plugins:")) {
84
- result += gatsby_1.GATSBY_PLUGIN_CONFIG(projectId, lang_utils_1.ensure(projectApiToken), useTypescript);
107
+ if (line.includes("plugins: []")) {
108
+ result += " plugins: [" + pluginConfig + "]\n";
109
+ }
110
+ else if (line.includes("plugins: [")) {
111
+ result += line + pluginConfig + "\n";
112
+ }
113
+ else {
114
+ result += line + "\n";
85
115
  }
86
116
  }
87
117
  }
@@ -102,16 +132,16 @@ const gatsbyStrategy = {
102
132
  const extension = useTypescript ? "ts" : "js";
103
133
  file_utils_1.deleteGlob(path_1.default.join(projectPath, "src/@(pages|components|templates)/*.*"));
104
134
  // Create a very basic 404 page - `gatsby build` fails without it.
105
- yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/404.js`), gatsby_1.GATSBY_404);
135
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/404.${extension}`), gatsby_1.GATSBY_404);
106
136
  // Add plasmic-host page
107
137
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/plasmic-host.${extension}x`), gatsby_1.makeGatsbyHostPage({
108
138
  useTypescript,
109
139
  scheme,
110
140
  }));
111
- // Start with an empty gatsby-node.js
112
- yield fs_1.promises.writeFile(path_1.default.join(projectPath, "gatsby-node.js"), "");
141
+ // Start with an empty gatsby-node
142
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, `gatsby-node.${extension}`), "");
113
143
  // Updates `gatsby-ssr` to include script tag for preamble
114
- yield fs_1.promises.writeFile(path_1.default.join(projectPath, "gatsby-ssr.js"), gatsby_1.GATSBY_SSR_CONFIG);
144
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, `gatsby-ssr.${extension}x`), gatsby_1.GATSBY_SSR_CONFIG);
115
145
  if (scheme === "loader") {
116
146
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/plasmic-init.${extension}`), gatsby_1.makeGatsbyPlasmicInit(extension));
117
147
  const templatesFolder = path_1.default.join(projectPath, "src/templates");
@@ -131,9 +161,9 @@ const gatsbyStrategy = {
131
161
  yield file_utils_1.overwriteIndex(projectPath, "gatsby", scheme);
132
162
  // Overwrite the wrapper files to wrap PlasmicRootProvider
133
163
  const wrapperContent = gatsby_1.wrapAppRootForCodegen();
134
- const browserFilePath = path_1.default.join(projectPath, "gatsby-browser.js");
164
+ const browserFilePath = path_1.default.join(projectPath, `gatsby-browser.${extension}x`);
135
165
  yield fs_1.promises.writeFile(browserFilePath, wrapperContent);
136
- const ssrFilePath = path_1.default.join(projectPath, "gatsby-ssr.js");
166
+ const ssrFilePath = path_1.default.join(projectPath, `gatsby-ssr.${extension}x`);
137
167
  yield fs_1.promises.writeFile(ssrFilePath, wrapperContent);
138
168
  }
139
169
  }),
@@ -25,6 +25,7 @@ interface BuildArgs {
25
25
  interface InstallArgs {
26
26
  scheme: CodeScheme;
27
27
  projectPath: string;
28
+ useTypescript: boolean;
28
29
  }
29
30
  export interface CPAStrategy {
30
31
  create: (args: CreateArgs) => Promise<void>;
@@ -13,7 +13,7 @@ import {
13
13
  InitOptions,
14
14
  ComponentRenderData,`)}
15
15
  } from "@plasmicapp/loader-gatsby";
16
- import { graphql } from "gatsby";
16
+ import { graphql${file_utils_1.ifTs(ts, ", PageProps")} } from "gatsby";
17
17
  import { initPlasmicLoaderWithRegistrations } from "../plasmic-init";
18
18
 
19
19
  export const query = graphql\`
@@ -23,14 +23,14 @@ export const query = graphql\`
23
23
  }
24
24
  \`;
25
25
 
26
- ${file_utils_1.ifTs(ts, `interface PlasmicGatsbyPageProps {
26
+ ${file_utils_1.ifTs(ts, `interface PlasmicGatsbyPageProps extends PageProps {
27
27
  data: {
28
28
  plasmicOptions: InitOptions
29
29
  plasmicComponents: ComponentRenderData
30
30
  }
31
31
  }
32
32
  `)}
33
- const PlasmicGatsbyPage = ({ data }${file_utils_1.ifTs(ts, ": PlasmicGatsbyPageProps")}) => {
33
+ const PlasmicGatsbyPage = ({ data, location }${file_utils_1.ifTs(ts, ": PlasmicGatsbyPageProps")}) => {
34
34
  const {
35
35
  plasmicComponents,
36
36
  plasmicOptions,
@@ -41,12 +41,14 @@ const PlasmicGatsbyPage = ({ data }${file_utils_1.ifTs(ts, ": PlasmicGatsbyPageP
41
41
  <PlasmicRootProvider
42
42
  loader={initPlasmicLoaderWithRegistrations(plasmicOptions)}
43
43
  prefetchedData={plasmicComponents}
44
+ pageParams={pageMeta.params}
45
+ pageQuery={Object.fromEntries(new URLSearchParams(location.search))}
44
46
  >
45
47
  <Helmet>
46
- {pageMetadata.title && <title>{pageMetadata.title}</title>}
47
- {pageMetadata.title && <meta property="og:title" content={pageMetadata.title} /> }
48
- {pageMetadata.description && <meta property="og:description" content={pageMetadata.description} />}
49
- {pageMetadata.openGraphImageUrl && <meta property="og:image" content={pageMetadata.openGraphImageUrl} />}
48
+ {pageMetadata?.title && <title>{pageMetadata.title}</title>}
49
+ {pageMetadata?.title && <meta property="og:title" content={pageMetadata.title} /> }
50
+ {pageMetadata?.description && <meta property="og:description" content={pageMetadata.description} />}
51
+ {pageMetadata?.openGraphImageUrl && <meta property="og:image" content={pageMetadata.openGraphImageUrl} />}
50
52
  </Helmet>
51
53
  <PlasmicComponent component={pageMeta.displayName} />
52
54
  </PlasmicRootProvider>
@@ -73,9 +75,13 @@ const GATSBY_PLUGIN_CONFIG = (projectId, projectApiToken, useTypescript) => `
73
75
  token: "${projectApiToken}",
74
76
  },
75
77
  ], // An array of project ids.
76
- defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage.${useTypescript ? "tsx" : "jsx"}"),
78
+ preview: false,
79
+ defaultPlasmicPage: ${useTypescript ? "path" : "require"}.resolve("./src/templates/defaultPlasmicPage.${useTypescript ? "tsx" : "jsx"}"),
77
80
  },
78
81
  },
82
+ {
83
+ resolve: "gatsby-plugin-react-helmet",
84
+ }
79
85
  `;
80
86
  exports.GATSBY_PLUGIN_CONFIG = GATSBY_PLUGIN_CONFIG;
81
87
  const makeGatsbyHostPage = (opts) => {
@@ -40,8 +40,9 @@ import {
40
40
  ComponentRenderData,
41
41
  PlasmicRootProvider,
42
42
  } from "@plasmicapp/loader-nextjs";
43
- ${file_utils_1.ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
43
+ ${file_utils_1.ifTs(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
44
44
  import Error from "next/error";
45
+ import { useRouter } from "next/router";
45
46
  import { PLASMIC } from "../plasmic-init";
46
47
 
47
48
  export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
@@ -49,16 +50,20 @@ export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
49
50
  queryCache?: Record<string, any>;
50
51
  }`)}) {
51
52
  const { plasmicData, queryCache } = props;
53
+ const router = useRouter();
52
54
  if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
53
55
  return <Error statusCode={404} />;
54
56
  }
57
+ const pageMeta = plasmicData.entryCompMetas[0];
55
58
  return (
56
59
  <PlasmicRootProvider
57
60
  loader={PLASMIC}
58
61
  prefetchedData={plasmicData}
59
62
  prefetchedQueryData={queryCache}
63
+ pageParams={pageMeta.params}
64
+ pageQuery={router.query}
60
65
  >
61
- <PlasmicComponent component={plasmicData.entryCompMetas[0].displayName} />
66
+ <PlasmicComponent component={pageMeta.displayName} />
62
67
  </PlasmicRootProvider>
63
68
  );
64
69
  }
@@ -71,10 +76,15 @@ export const getStaticProps${file_utils_1.ifTs(ts, `: GetStaticProps`)} = async
71
76
  // non-Plasmic catch-all
72
77
  return { props: {} };
73
78
  }
79
+ const pageMeta = plasmicData.entryCompMetas[0];
74
80
  // Cache the necessary data fetched for the page
75
81
  const queryCache = await extractPlasmicQueryData(
76
- <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
77
- <PlasmicComponent component={plasmicData.entryCompMetas[0].displayName} />
82
+ <PlasmicRootProvider
83
+ loader={PLASMIC}
84
+ prefetchedData={plasmicData}
85
+ pageParams={pageMeta.params}
86
+ >
87
+ <PlasmicComponent component={pageMeta.displayName} />
78
88
  </PlasmicRootProvider>
79
89
  );
80
90
  // Use revalidate if you want incremental static regeneration
@@ -89,10 +99,7 @@ export const getStaticPaths${file_utils_1.ifTs(ts, `: GetStaticPaths`)} = async
89
99
  catchall: mod.path.substring(1).split("/"),
90
100
  },
91
101
  })),
92
-
93
- // Turn on "fallback: 'blocking'" if you would like new paths created
94
- // in Plasmic to be automatically available
95
- fallback: false,
102
+ fallback: "blocking",
96
103
  };
97
104
  }
98
105
  `.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.45",
3
+ "version": "0.0.48",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
@@ -17,7 +17,7 @@
17
17
  "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
18
18
  "build": "eslint 'src/**' && tsc",
19
19
  "create-plasmic-app": "ts-node src/index.ts",
20
- "prepare": "yarn build"
20
+ "prepare": "if-env PREPARE_NO_BUILD=true || yarn build"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/findup-sync": "^2.0.2",
@@ -40,7 +40,7 @@
40
40
  "typescript": "^4.2.3"
41
41
  },
42
42
  "dependencies": {
43
- "@plasmicapp/cli": "^0.1.166",
43
+ "@plasmicapp/cli": "^0.1.185",
44
44
  "@sentry/node": "^6.2.2",
45
45
  "chalk": "^4.1.0",
46
46
  "execa": "^5.0.0",
package/src/index.ts CHANGED
@@ -186,7 +186,7 @@ async function run(): Promise<void> {
186
186
  name: "projectId",
187
187
  message: `What is the URL of your project?
188
188
  If you don't have a project yet, create one by going to
189
- https://studio.plasmic.app/starters/simple-light
189
+ https://studio.plasmic.app/starters/blank
190
190
  `,
191
191
  });
192
192
  projectId = rawProjectId
package/src/lib.ts CHANGED
@@ -97,6 +97,7 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
97
97
  const installResult = await cpaStrategy.installDeps({
98
98
  scheme,
99
99
  projectPath: resolvedProjectPath,
100
+ useTypescript,
100
101
  });
101
102
 
102
103
  if (!installResult) {
@@ -19,17 +19,52 @@ import { CPAStrategy } from "./types";
19
19
 
20
20
  const gatsbyStrategy: CPAStrategy = {
21
21
  create: async (args) => {
22
- const { projectPath, template } = args;
23
- const createCommand = `npx -p gatsby gatsby new ${projectPath}`;
24
- const templateArg = template ? ` ${template}` : "";
22
+ const { projectPath, template, useTypescript } = args;
23
+ if (template) {
24
+ console.log(
25
+ `Warning: Ignoring template '${template}' (argument is not supported by Gatsby).`
26
+ );
27
+ }
25
28
 
26
- await spawnOrFail(`${createCommand}${templateArg}`);
29
+ // create-gatsby does not support absolute paths as of 2022-08-12
30
+ // (see https://github.com/gatsbyjs/gatsby/issues/36381).
31
+ const parent = path.dirname(projectPath);
32
+ await fs.mkdir(parent, { recursive: true });
33
+ const dir = path.basename(projectPath);
34
+ const createCommand = `npx -p create-gatsby create-gatsby ${
35
+ useTypescript ? "-ts" : ""
36
+ } -y ${dir}`;
37
+ await spawnOrFail(`${createCommand}`, parent);
27
38
  },
28
- installDeps: async ({ projectPath, scheme }) => {
39
+ installDeps: async ({ projectPath, scheme, useTypescript }) => {
29
40
  if (scheme === "loader") {
30
- return await installUpgrade("@plasmicapp/loader-gatsby", {
41
+ const installedLoader = await installUpgrade(
42
+ "@plasmicapp/loader-gatsby",
43
+ {
44
+ workingDir: projectPath,
45
+ }
46
+ );
47
+ const installedHelmet = await installUpgrade("react-helmet", {
31
48
  workingDir: projectPath,
32
49
  });
50
+ const installedHelmetTypes =
51
+ !useTypescript ||
52
+ (await installUpgrade("@types/react-helmet", {
53
+ workingDir: projectPath,
54
+ dev: true,
55
+ }));
56
+ const installedHelmetPlugin = await installUpgrade(
57
+ "gatsby-plugin-react-helmet",
58
+ {
59
+ workingDir: projectPath,
60
+ }
61
+ );
62
+ return (
63
+ installedLoader &&
64
+ installedHelmet &&
65
+ installedHelmetPlugin &&
66
+ installedHelmetTypes
67
+ );
33
68
  } else {
34
69
  return await installCodegenDeps({ projectPath });
35
70
  }
@@ -42,24 +77,33 @@ const gatsbyStrategy: CPAStrategy = {
42
77
  useTypescript,
43
78
  scheme,
44
79
  } = args;
80
+ const extension = useTypescript ? "ts" : "js";
45
81
 
46
82
  if (scheme === "loader") {
47
- // create-gatsby will create a default gatsby-config.js that we need to modify
48
- const gatsbyConfigFile = path.join(projectPath, "gatsby-config.js");
83
+ // create-gatsby will create a default gatsby-config that we need to modify
84
+ const gatsbyConfigFile = path.join(
85
+ projectPath,
86
+ `gatsby-config.${extension}`
87
+ );
49
88
  const rl = readline.createInterface({
50
89
  input: createReadStream(gatsbyConfigFile),
51
90
  crlfDelay: Infinity,
52
91
  });
53
- let result = "";
92
+ // Typescript doesn't accept require.resolve
93
+ // https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/#requireresolve
94
+ let result = useTypescript ? `import path from "path";\n` : "";
95
+ const pluginConfig = GATSBY_PLUGIN_CONFIG(
96
+ projectId,
97
+ ensure(projectApiToken),
98
+ useTypescript
99
+ );
54
100
  for await (const line of rl) {
55
- result += line + "\n";
56
- // Prepend PlasmicLoader to list of plugins
57
- if (line.includes("plugins:")) {
58
- result += GATSBY_PLUGIN_CONFIG(
59
- projectId,
60
- ensure(projectApiToken),
61
- useTypescript
62
- );
101
+ if (line.includes("plugins: []")) {
102
+ result += " plugins: [" + pluginConfig + "]\n";
103
+ } else if (line.includes("plugins: [")) {
104
+ result += line + pluginConfig + "\n";
105
+ } else {
106
+ result += line + "\n";
63
107
  }
64
108
  }
65
109
  await fs.writeFile(gatsbyConfigFile, result);
@@ -81,7 +125,10 @@ const gatsbyStrategy: CPAStrategy = {
81
125
  deleteGlob(path.join(projectPath, "src/@(pages|components|templates)/*.*"));
82
126
 
83
127
  // Create a very basic 404 page - `gatsby build` fails without it.
84
- await fs.writeFile(path.join(projectPath, `src/pages/404.js`), GATSBY_404);
128
+ await fs.writeFile(
129
+ path.join(projectPath, `src/pages/404.${extension}`),
130
+ GATSBY_404
131
+ );
85
132
 
86
133
  // Add plasmic-host page
87
134
  await fs.writeFile(
@@ -92,12 +139,12 @@ const gatsbyStrategy: CPAStrategy = {
92
139
  })
93
140
  );
94
141
 
95
- // Start with an empty gatsby-node.js
96
- await fs.writeFile(path.join(projectPath, "gatsby-node.js"), "");
142
+ // Start with an empty gatsby-node
143
+ await fs.writeFile(path.join(projectPath, `gatsby-node.${extension}`), "");
97
144
 
98
145
  // Updates `gatsby-ssr` to include script tag for preamble
99
146
  await fs.writeFile(
100
- path.join(projectPath, "gatsby-ssr.js"),
147
+ path.join(projectPath, `gatsby-ssr.${extension}x`),
101
148
  GATSBY_SSR_CONFIG
102
149
  );
103
150
 
@@ -128,10 +175,13 @@ const gatsbyStrategy: CPAStrategy = {
128
175
 
129
176
  // Overwrite the wrapper files to wrap PlasmicRootProvider
130
177
  const wrapperContent = wrapAppRootForCodegen();
131
- const browserFilePath = path.join(projectPath, "gatsby-browser.js");
178
+ const browserFilePath = path.join(
179
+ projectPath,
180
+ `gatsby-browser.${extension}x`
181
+ );
132
182
  await fs.writeFile(browserFilePath, wrapperContent);
133
183
 
134
- const ssrFilePath = path.join(projectPath, "gatsby-ssr.js");
184
+ const ssrFilePath = path.join(projectPath, `gatsby-ssr.${extension}x`);
135
185
  await fs.writeFile(ssrFilePath, wrapperContent);
136
186
  }
137
187
  },
@@ -30,6 +30,7 @@ interface BuildArgs {
30
30
  interface InstallArgs {
31
31
  scheme: CodeScheme;
32
32
  projectPath: string;
33
+ useTypescript: boolean;
33
34
  }
34
35
 
35
36
  export interface CPAStrategy {
@@ -15,7 +15,7 @@ import {
15
15
  ComponentRenderData,`
16
16
  )}
17
17
  } from "@plasmicapp/loader-gatsby";
18
- import { graphql } from "gatsby";
18
+ import { graphql${ifTs(ts, ", PageProps")} } from "gatsby";
19
19
  import { initPlasmicLoaderWithRegistrations } from "../plasmic-init";
20
20
 
21
21
  export const query = graphql\`
@@ -27,7 +27,7 @@ export const query = graphql\`
27
27
 
28
28
  ${ifTs(
29
29
  ts,
30
- `interface PlasmicGatsbyPageProps {
30
+ `interface PlasmicGatsbyPageProps extends PageProps {
31
31
  data: {
32
32
  plasmicOptions: InitOptions
33
33
  plasmicComponents: ComponentRenderData
@@ -35,7 +35,10 @@ ${ifTs(
35
35
  }
36
36
  `
37
37
  )}
38
- const PlasmicGatsbyPage = ({ data }${ifTs(ts, ": PlasmicGatsbyPageProps")}) => {
38
+ const PlasmicGatsbyPage = ({ data, location }${ifTs(
39
+ ts,
40
+ ": PlasmicGatsbyPageProps"
41
+ )}) => {
39
42
  const {
40
43
  plasmicComponents,
41
44
  plasmicOptions,
@@ -46,12 +49,14 @@ const PlasmicGatsbyPage = ({ data }${ifTs(ts, ": PlasmicGatsbyPageProps")}) => {
46
49
  <PlasmicRootProvider
47
50
  loader={initPlasmicLoaderWithRegistrations(plasmicOptions)}
48
51
  prefetchedData={plasmicComponents}
52
+ pageParams={pageMeta.params}
53
+ pageQuery={Object.fromEntries(new URLSearchParams(location.search))}
49
54
  >
50
55
  <Helmet>
51
- {pageMetadata.title && <title>{pageMetadata.title}</title>}
52
- {pageMetadata.title && <meta property="og:title" content={pageMetadata.title} /> }
53
- {pageMetadata.description && <meta property="og:description" content={pageMetadata.description} />}
54
- {pageMetadata.openGraphImageUrl && <meta property="og:image" content={pageMetadata.openGraphImageUrl} />}
56
+ {pageMetadata?.title && <title>{pageMetadata.title}</title>}
57
+ {pageMetadata?.title && <meta property="og:title" content={pageMetadata.title} /> }
58
+ {pageMetadata?.description && <meta property="og:description" content={pageMetadata.description} />}
59
+ {pageMetadata?.openGraphImageUrl && <meta property="og:image" content={pageMetadata.openGraphImageUrl} />}
55
60
  </Helmet>
56
61
  <PlasmicComponent component={pageMeta.displayName} />
57
62
  </PlasmicRootProvider>
@@ -83,11 +88,17 @@ export const GATSBY_PLUGIN_CONFIG = (
83
88
  token: "${projectApiToken}",
84
89
  },
85
90
  ], // An array of project ids.
86
- defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage.${
87
- useTypescript ? "tsx" : "jsx"
88
- }"),
91
+ preview: false,
92
+ defaultPlasmicPage: ${
93
+ useTypescript ? "path" : "require"
94
+ }.resolve("./src/templates/defaultPlasmicPage.${
95
+ useTypescript ? "tsx" : "jsx"
96
+ }"),
89
97
  },
90
98
  },
99
+ {
100
+ resolve: "gatsby-plugin-react-helmet",
101
+ }
91
102
  `;
92
103
 
93
104
  export const makeGatsbyHostPage = (opts: {
@@ -43,8 +43,9 @@ import {
43
43
  ComponentRenderData,
44
44
  PlasmicRootProvider,
45
45
  } from "@plasmicapp/loader-nextjs";
46
- ${ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
46
+ ${ifTs(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
47
47
  import Error from "next/error";
48
+ import { useRouter } from "next/router";
48
49
  import { PLASMIC } from "../plasmic-init";
49
50
 
50
51
  export default function PlasmicLoaderPage(props${ifTs(
@@ -55,16 +56,20 @@ export default function PlasmicLoaderPage(props${ifTs(
55
56
  }`
56
57
  )}) {
57
58
  const { plasmicData, queryCache } = props;
59
+ const router = useRouter();
58
60
  if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
59
61
  return <Error statusCode={404} />;
60
62
  }
63
+ const pageMeta = plasmicData.entryCompMetas[0];
61
64
  return (
62
65
  <PlasmicRootProvider
63
66
  loader={PLASMIC}
64
67
  prefetchedData={plasmicData}
65
68
  prefetchedQueryData={queryCache}
69
+ pageParams={pageMeta.params}
70
+ pageQuery={router.query}
66
71
  >
67
- <PlasmicComponent component={plasmicData.entryCompMetas[0].displayName} />
72
+ <PlasmicComponent component={pageMeta.displayName} />
68
73
  </PlasmicRootProvider>
69
74
  );
70
75
  }
@@ -80,10 +85,15 @@ export const getStaticProps${ifTs(
80
85
  // non-Plasmic catch-all
81
86
  return { props: {} };
82
87
  }
88
+ const pageMeta = plasmicData.entryCompMetas[0];
83
89
  // Cache the necessary data fetched for the page
84
90
  const queryCache = await extractPlasmicQueryData(
85
- <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
86
- <PlasmicComponent component={plasmicData.entryCompMetas[0].displayName} />
91
+ <PlasmicRootProvider
92
+ loader={PLASMIC}
93
+ prefetchedData={plasmicData}
94
+ pageParams={pageMeta.params}
95
+ >
96
+ <PlasmicComponent component={pageMeta.displayName} />
87
97
  </PlasmicRootProvider>
88
98
  );
89
99
  // Use revalidate if you want incremental static regeneration
@@ -98,10 +108,7 @@ export const getStaticPaths${ifTs(ts, `: GetStaticPaths`)} = async () => {
98
108
  catchall: mod.path.substring(1).split("/"),
99
109
  },
100
110
  })),
101
-
102
- // Turn on "fallback: 'blocking'" if you would like new paths created
103
- // in Plasmic to be automatically available
104
- fallback: false,
111
+ fallback: "blocking",
105
112
  };
106
113
  }
107
114
  `.trim();