create-plasmic-app 0.0.46 → 0.0.49

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/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");
@@ -61,15 +61,25 @@ const gatsbyStrategy = {
61
61
  const createCommand = `npx -p create-gatsby create-gatsby ${useTypescript ? "-ts" : ""} -y ${dir}`;
62
62
  yield cmd_utils_1.spawnOrFail(`${createCommand}`, parent);
63
63
  }),
64
- installDeps: ({ projectPath, scheme }) => __awaiter(void 0, void 0, void 0, function* () {
64
+ installDeps: ({ projectPath, scheme, useTypescript }) => __awaiter(void 0, void 0, void 0, function* () {
65
+ const installedHelmet = yield npm_utils_1.installUpgrade("react-helmet", {
66
+ workingDir: projectPath,
67
+ });
68
+ const installedHelmetTypes = !useTypescript ||
69
+ (yield npm_utils_1.installUpgrade("@types/react-helmet", {
70
+ workingDir: projectPath,
71
+ dev: true,
72
+ }));
73
+ const installedHelmetPlugin = yield npm_utils_1.installUpgrade("gatsby-plugin-react-helmet", {
74
+ workingDir: projectPath,
75
+ });
76
+ if (!installedHelmet || !installedHelmetPlugin || !installedHelmetTypes) {
77
+ return false;
78
+ }
65
79
  if (scheme === "loader") {
66
- return ((yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
80
+ return yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
67
81
  workingDir: projectPath,
68
- })) &&
69
- (yield npm_utils_1.installUpgrade("react-helmet", { workingDir: projectPath })) &&
70
- (yield npm_utils_1.installUpgrade("gatsby-plugin-react-helmet", {
71
- workingDir: projectPath,
72
- })));
82
+ });
73
83
  }
74
84
  else {
75
85
  return yield common_1.installCodegenDeps({ projectPath });
@@ -86,7 +96,9 @@ const gatsbyStrategy = {
86
96
  input: fs_1.createReadStream(gatsbyConfigFile),
87
97
  crlfDelay: Infinity,
88
98
  });
89
- let result = "";
99
+ // Typescript doesn't accept require.resolve
100
+ // https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/#requireresolve
101
+ let result = useTypescript ? `import path from "path";\n` : "";
90
102
  const pluginConfig = gatsby_1.GATSBY_PLUGIN_CONFIG(projectId, lang_utils_1.ensure(projectApiToken), useTypescript);
91
103
  try {
92
104
  for (var rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), !rl_1_1.done;) {
@@ -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,15 @@ 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))}
46
+ Head={Helmet}
44
47
  >
45
48
  <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} />}
49
+ {pageMetadata?.title && <title>{pageMetadata.title}</title>}
50
+ {pageMetadata?.title && <meta property="og:title" content={pageMetadata.title} /> }
51
+ {pageMetadata?.description && <meta property="og:description" content={pageMetadata.description} />}
52
+ {pageMetadata?.openGraphImageUrl && <meta property="og:image" content={pageMetadata.openGraphImageUrl} />}
50
53
  </Helmet>
51
54
  <PlasmicComponent component={pageMeta.displayName} />
52
55
  </PlasmicRootProvider>
@@ -74,7 +77,7 @@ const GATSBY_PLUGIN_CONFIG = (projectId, projectApiToken, useTypescript) => `
74
77
  },
75
78
  ], // An array of project ids.
76
79
  preview: false,
77
- defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage.${useTypescript ? "tsx" : "jsx"}"),
80
+ defaultPlasmicPage: ${useTypescript ? "path" : "require"}.resolve("./src/templates/defaultPlasmicPage.${useTypescript ? "tsx" : "jsx"}"),
78
81
  },
79
82
  },
80
83
  {
@@ -210,10 +213,11 @@ function wrapAppRootForCodegen() {
210
213
  return `
211
214
  import React from "react";
212
215
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
216
+ import Helmet from "react-helmet";
213
217
 
214
218
  export const wrapRootElement = ({ element }) => {
215
219
  return (
216
- <PlasmicRootProvider>
220
+ <PlasmicRootProvider Head={Helmet}>
217
221
  {element}
218
222
  </PlasmicRootProvider>
219
223
  );
@@ -42,6 +42,7 @@ import {
42
42
  } from "@plasmicapp/loader-nextjs";
43
43
  ${file_utils_1.ifTs(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
44
44
  import Error from "next/error";
45
+ import Head from "next/head";
45
46
  import { useRouter } from "next/router";
46
47
  import { PLASMIC } from "../plasmic-init";
47
48
 
@@ -61,7 +62,8 @@ export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
61
62
  prefetchedData={plasmicData}
62
63
  prefetchedQueryData={queryCache}
63
64
  pageParams={pageMeta.params}
64
- pageQuery={router.query${file_utils_1.ifTs(ts, " as Record<string, string>")}}
65
+ pageQuery={router.query}
66
+ Head={Head}
65
67
  >
66
68
  <PlasmicComponent component={pageMeta.displayName} />
67
69
  </PlasmicRootProvider>
@@ -83,6 +85,7 @@ export const getStaticProps${file_utils_1.ifTs(ts, `: GetStaticProps`)} = async
83
85
  loader={PLASMIC}
84
86
  prefetchedData={plasmicData}
85
87
  pageParams={pageMeta.params}
88
+ Head={Head}
86
89
  >
87
90
  <PlasmicComponent component={pageMeta.displayName} />
88
91
  </PlasmicRootProvider>
@@ -146,10 +149,11 @@ function wrapAppRootForCodegen() {
146
149
  return `
147
150
  import '../styles/globals.css'
148
151
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
152
+ import Head from "next/head";
149
153
 
150
154
  function MyApp({ Component, pageProps }) {
151
155
  return (
152
- <PlasmicRootProvider>
156
+ <PlasmicRootProvider Head={Head}>
153
157
  <Component {...pageProps} />
154
158
  </PlasmicRootProvider>
155
159
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.46",
3
+ "version": "0.0.49",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
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) {
@@ -36,17 +36,30 @@ const gatsbyStrategy: CPAStrategy = {
36
36
  } -y ${dir}`;
37
37
  await spawnOrFail(`${createCommand}`, parent);
38
38
  },
39
- installDeps: async ({ projectPath, scheme }) => {
39
+ installDeps: async ({ projectPath, scheme, useTypescript }) => {
40
+ const installedHelmet = await installUpgrade("react-helmet", {
41
+ workingDir: projectPath,
42
+ });
43
+ const installedHelmetTypes =
44
+ !useTypescript ||
45
+ (await installUpgrade("@types/react-helmet", {
46
+ workingDir: projectPath,
47
+ dev: true,
48
+ }));
49
+ const installedHelmetPlugin = await installUpgrade(
50
+ "gatsby-plugin-react-helmet",
51
+ {
52
+ workingDir: projectPath,
53
+ }
54
+ );
55
+ if (!installedHelmet || !installedHelmetPlugin || !installedHelmetTypes) {
56
+ return false;
57
+ }
58
+
40
59
  if (scheme === "loader") {
41
- return (
42
- (await installUpgrade("@plasmicapp/loader-gatsby", {
43
- workingDir: projectPath,
44
- })) &&
45
- (await installUpgrade("react-helmet", { workingDir: projectPath })) &&
46
- (await installUpgrade("gatsby-plugin-react-helmet", {
47
- workingDir: projectPath,
48
- }))
49
- );
60
+ return await installUpgrade("@plasmicapp/loader-gatsby", {
61
+ workingDir: projectPath,
62
+ });
50
63
  } else {
51
64
  return await installCodegenDeps({ projectPath });
52
65
  }
@@ -71,7 +84,9 @@ const gatsbyStrategy: CPAStrategy = {
71
84
  input: createReadStream(gatsbyConfigFile),
72
85
  crlfDelay: Infinity,
73
86
  });
74
- let result = "";
87
+ // Typescript doesn't accept require.resolve
88
+ // https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/#requireresolve
89
+ let result = useTypescript ? `import path from "path";\n` : "";
75
90
  const pluginConfig = GATSBY_PLUGIN_CONFIG(
76
91
  projectId,
77
92
  ensure(projectApiToken),
@@ -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,15 @@ 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))}
54
+ Head={Helmet}
49
55
  >
50
56
  <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} />}
57
+ {pageMetadata?.title && <title>{pageMetadata.title}</title>}
58
+ {pageMetadata?.title && <meta property="og:title" content={pageMetadata.title} /> }
59
+ {pageMetadata?.description && <meta property="og:description" content={pageMetadata.description} />}
60
+ {pageMetadata?.openGraphImageUrl && <meta property="og:image" content={pageMetadata.openGraphImageUrl} />}
55
61
  </Helmet>
56
62
  <PlasmicComponent component={pageMeta.displayName} />
57
63
  </PlasmicRootProvider>
@@ -84,9 +90,11 @@ export const GATSBY_PLUGIN_CONFIG = (
84
90
  },
85
91
  ], // An array of project ids.
86
92
  preview: false,
87
- defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage.${
88
- useTypescript ? "tsx" : "jsx"
89
- }"),
93
+ defaultPlasmicPage: ${
94
+ useTypescript ? "path" : "require"
95
+ }.resolve("./src/templates/defaultPlasmicPage.${
96
+ useTypescript ? "tsx" : "jsx"
97
+ }"),
90
98
  },
91
99
  },
92
100
  {
@@ -234,10 +242,11 @@ export function wrapAppRootForCodegen(): string {
234
242
  return `
235
243
  import React from "react";
236
244
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
245
+ import Helmet from "react-helmet";
237
246
 
238
247
  export const wrapRootElement = ({ element }) => {
239
248
  return (
240
- <PlasmicRootProvider>
249
+ <PlasmicRootProvider Head={Helmet}>
241
250
  {element}
242
251
  </PlasmicRootProvider>
243
252
  );
@@ -45,6 +45,7 @@ import {
45
45
  } from "@plasmicapp/loader-nextjs";
46
46
  ${ifTs(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
47
47
  import Error from "next/error";
48
+ import Head from "next/head";
48
49
  import { useRouter } from "next/router";
49
50
  import { PLASMIC } from "../plasmic-init";
50
51
 
@@ -67,7 +68,8 @@ export default function PlasmicLoaderPage(props${ifTs(
67
68
  prefetchedData={plasmicData}
68
69
  prefetchedQueryData={queryCache}
69
70
  pageParams={pageMeta.params}
70
- pageQuery={router.query${ifTs(ts, " as Record<string, string>")}}
71
+ pageQuery={router.query}
72
+ Head={Head}
71
73
  >
72
74
  <PlasmicComponent component={pageMeta.displayName} />
73
75
  </PlasmicRootProvider>
@@ -92,6 +94,7 @@ export const getStaticProps${ifTs(
92
94
  loader={PLASMIC}
93
95
  prefetchedData={plasmicData}
94
96
  pageParams={pageMeta.params}
97
+ Head={Head}
95
98
  >
96
99
  <PlasmicComponent component={pageMeta.displayName} />
97
100
  </PlasmicRootProvider>
@@ -155,10 +158,11 @@ export function wrapAppRootForCodegen(): string {
155
158
  return `
156
159
  import '../styles/globals.css'
157
160
  import { PlasmicRootProvider } from "@plasmicapp/react-web";
161
+ import Head from "next/head";
158
162
 
159
163
  function MyApp({ Component, pageProps }) {
160
164
  return (
161
- <PlasmicRootProvider>
165
+ <PlasmicRootProvider Head={Head}>
162
166
  <Component {...pageProps} />
163
167
  </PlasmicRootProvider>
164
168
  );