create-plasmic-app 0.0.141 → 0.0.143

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.
@@ -0,0 +1,17 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { PlasmicRootProvider } from "@plasmicapp/react-web";
5
+ import Link from "next/link";
6
+
7
+ /**
8
+ * ClientPlasmicRootProvider is a Client Component that passes Next's Link to PlasmicRootProvider.
9
+ *
10
+ * Props passed from a Server Component to a Client Component must be serializable.
11
+ * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
12
+ */
13
+ export function ClientPlasmicRootProvider(
14
+ props
15
+ ) {
16
+ return <PlasmicRootProvider Link={Link} {...props} />;
17
+ }
@@ -0,0 +1,17 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { PlasmicRootProvider } from "@plasmicapp/react-web";
5
+ import Link from "next/link";
6
+
7
+ /**
8
+ * ClientPlasmicRootProvider is a Client Component that passes Next's Link to PlasmicRootProvider.
9
+ *
10
+ * Props passed from a Server Component to a Client Component must be serializable.
11
+ * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
12
+ */
13
+ export function ClientPlasmicRootProvider(
14
+ props: Omit<React.ComponentProps<typeof PlasmicRootProvider>, "Link">
15
+ ) {
16
+ return <PlasmicRootProvider Link={Link} {...props} />;
17
+ }
@@ -13,48 +13,10 @@ import { PLASMIC } from "@/plasmic-init";
13
13
  // PLASMIC.registerComponent(...);
14
14
 
15
15
  /**
16
- * ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
16
+ * ClientPlasmicRootProvider is a Client Component that passes the loader to PlasmicRootProvider.
17
17
  *
18
- * Why? Props passed from Server to Client Components must be serializable.
18
+ * Props passed from a Server Component to a Client Component must be serializable.
19
19
  * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
20
- * However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
21
- *
22
- * In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
23
- *
24
- * ```tsx
25
- * import { PLASMIC } from "@/plasmic-init";
26
- * import { PlasmicRootProvider } from "plasmicapp/loader-nextjs";
27
- * export default function MyPage() {
28
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
29
- * return (
30
- * <PlasmicRootProvider
31
- * loader={PLASMIC} // ERROR: loader is not serializable
32
- * prefetchedData={prefetchedData}
33
- * >
34
- * {yourContent()}
35
- * </PlasmicRootProvider>;
36
- * );
37
- * }
38
- * ```
39
- *
40
- * Therefore, we define ClientPlasmicRootProvider as a Client Component (this file is marked "use client").
41
- * ClientPlasmicRootProvider wraps the PlasmicRootProvider and passes in the loader for you,
42
- * while allowing your Server Component to pass in prefetched data and other serializable props:
43
- *
44
- * ```tsx
45
- * import { PLASMIC } from "@/plasmic-init";
46
- * import { ClientPlasmicRootProvider } from "@/plasmic-init-client"; // changed
47
- * export default function MyPage() {
48
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
49
- * return (
50
- * <ClientPlasmicRootProvider // don't pass in loader
51
- * prefetchedData={prefetchedData}
52
- * >
53
- * {yourContent()}
54
- * </ClientPlasmicRootProvider>;
55
- * );
56
- * }
57
- * ```
58
20
  */
59
21
  export function ClientPlasmicRootProvider(
60
22
  props
@@ -13,48 +13,10 @@ import { PLASMIC } from "@/plasmic-init";
13
13
  // PLASMIC.registerComponent(...);
14
14
 
15
15
  /**
16
- * ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
16
+ * ClientPlasmicRootProvider is a Client Component that passes the loader to PlasmicRootProvider.
17
17
  *
18
- * Why? Props passed from Server to Client Components must be serializable.
18
+ * Props passed from a Server Component to a Client Component must be serializable.
19
19
  * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
20
- * However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
21
- *
22
- * In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
23
- *
24
- * ```tsx
25
- * import { PLASMIC } from "@/plasmic-init";
26
- * import { PlasmicRootProvider } from "plasmicapp/loader-nextjs";
27
- * export default function MyPage() {
28
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
29
- * return (
30
- * <PlasmicRootProvider
31
- * loader={PLASMIC} // ERROR: loader is not serializable
32
- * prefetchedData={prefetchedData}
33
- * >
34
- * {yourContent()}
35
- * </PlasmicRootProvider>;
36
- * );
37
- * }
38
- * ```
39
- *
40
- * Therefore, we define ClientPlasmicRootProvider as a Client Component (this file is marked "use client").
41
- * ClientPlasmicRootProvider wraps the PlasmicRootProvider and passes in the loader for you,
42
- * while allowing your Server Component to pass in prefetched data and other serializable props:
43
- *
44
- * ```tsx
45
- * import { PLASMIC } from "@/plasmic-init";
46
- * import { ClientPlasmicRootProvider } from "@/plasmic-init-client"; // changed
47
- * export default function MyPage() {
48
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
49
- * return (
50
- * <ClientPlasmicRootProvider // don't pass in loader
51
- * prefetchedData={prefetchedData}
52
- * >
53
- * {yourContent()}
54
- * </ClientPlasmicRootProvider>;
55
- * );
56
- * }
57
- * ```
58
20
  */
59
21
  export function ClientPlasmicRootProvider(
60
22
  props: Omit<React.ComponentProps<typeof PlasmicRootProvider>, "loader">
@@ -22,10 +22,11 @@ const file_utils_1 = require("../utils/file-utils");
22
22
  const lang_utils_1 = require("../utils/lang-utils");
23
23
  const npm_utils_1 = require("../utils/npm-utils");
24
24
  const layout_1 = require("./templates/app-codegen/layout");
25
+ const plasmic_init_client_1 = require("./templates/app-codegen/plasmic-init-client");
25
26
  const catchall_page_1 = require("./templates/app-loader/catchall-page");
26
27
  const plasmic_host_1 = require("./templates/app-loader/plasmic-host");
27
28
  const plasmic_init_1 = require("./templates/app-loader/plasmic-init");
28
- const plasmic_init_client_1 = require("./templates/app-loader/plasmic-init-client");
29
+ const plasmic_init_client_2 = require("./templates/app-loader/plasmic-init-client");
29
30
  const app_1 = require("./templates/pages-codegen/app");
30
31
  const plasmic_host_2 = require("./templates/pages-codegen/plasmic-host");
31
32
  const catchall_page_2 = require("./templates/pages-loader/catchall-page");
@@ -97,7 +98,7 @@ function generateFilesAppDir(args) {
97
98
  // ./plasmic-init.ts
98
99
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init.${jsOrTs}`), (0, plasmic_init_1.makePlasmicInit_app_loader)(projectId, (0, lang_utils_1.ensure)(projectApiToken, "Missing projectApiToken")));
99
100
  // ./plasmic-init-client.ts
100
- yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init-client.${jsOrTs}x`), (0, plasmic_init_client_1.makePlasmicInitClient_app_loader)(jsOrTs));
101
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init-client.${jsOrTs}x`), (0, plasmic_init_client_2.makePlasmicInitClient_app_loader)(jsOrTs));
101
102
  // ./app/plasmic-host/page.tsx
102
103
  yield fs_1.promises.mkdir(path_1.default.join(projectPath, "app", "plasmic-host"));
103
104
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "plasmic-host", `page.${jsOrTs}x`), (0, plasmic_host_1.makePlasmicHostPage_app_loader)());
@@ -108,6 +109,8 @@ function generateFilesAppDir(args) {
108
109
  else {
109
110
  // ./app/layout.tsx
110
111
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`), (0, layout_1.makeLayout_app_codegen)(jsOrTs));
112
+ // ./plasmic-init-client.tsx
113
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init-client.${jsOrTs}x`), (0, plasmic_init_client_1.makePlasmicInitClient_app_codegen)(jsOrTs));
111
114
  // ./app/plasmic-host/page.tsx
112
115
  yield fs_1.promises.mkdir(path_1.default.join(projectPath, "app", "plasmic-host"));
113
116
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "plasmic-host", `page.${jsOrTs}x`), (0, plasmic_host_2.makePlasmicHostPage_pages_codegen)() // plasmic-host page contents are the same as the pages router
@@ -4,8 +4,7 @@ exports.makeLayout_app_codegen = void 0;
4
4
  const file_utils_1 = require("../../../utils/file-utils");
5
5
  function makeLayout_app_codegen(jsOrTs) {
6
6
  return `import '@/app/globals.css'
7
- import { PlasmicRootProvider } from "@plasmicapp/react-web";
8
- import Link from "next/link";
7
+ import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
9
8
 
10
9
  export default function RootLayout({
11
10
  children,
@@ -15,9 +14,9 @@ export default function RootLayout({
15
14
  return (
16
15
  <html lang="en">
17
16
  <body>
18
- <PlasmicRootProvider Link={Link}>
17
+ <ClientPlasmicRootProvider>
19
18
  {children}
20
- </PlasmicRootProvider>
19
+ </ClientPlasmicRootProvider>
21
20
  </body>
22
21
  </html>
23
22
  );
@@ -0,0 +1,2 @@
1
+ import { JsOrTs } from "../../../utils/types";
2
+ export declare function makePlasmicInitClient_app_codegen(jsOrTs: JsOrTs): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makePlasmicInitClient_app_codegen = void 0;
4
+ const file_utils_1 = require("../../../utils/file-utils");
5
+ function makePlasmicInitClient_app_codegen(jsOrTs) {
6
+ return `"use client";
7
+
8
+ import * as React from "react";
9
+ import { PlasmicRootProvider } from "@plasmicapp/react-web";
10
+ import Link from "next/link";
11
+
12
+ /**
13
+ * ClientPlasmicRootProvider is a Client Component that passes Next's Link to PlasmicRootProvider.
14
+ *
15
+ * Props passed from a Server Component to a Client Component must be serializable.
16
+ * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
17
+ */
18
+ export function ClientPlasmicRootProvider(
19
+ props${(0, file_utils_1.ifTs)(jsOrTs, ': Omit<React.ComponentProps<typeof PlasmicRootProvider>, "Link">')}
20
+ ) {
21
+ return <PlasmicRootProvider Link={Link} {...props} />;
22
+ }
23
+ `;
24
+ }
25
+ exports.makePlasmicInitClient_app_codegen = makePlasmicInitClient_app_codegen;
@@ -18,48 +18,10 @@ import { PLASMIC } from "@/plasmic-init";
18
18
  // PLASMIC.registerComponent(...);
19
19
 
20
20
  /**
21
- * ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
21
+ * ClientPlasmicRootProvider is a Client Component that passes the loader to PlasmicRootProvider.
22
22
  *
23
- * Why? Props passed from Server to Client Components must be serializable.
23
+ * Props passed from a Server Component to a Client Component must be serializable.
24
24
  * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
25
- * However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
26
- *
27
- * In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
28
- *
29
- * \`\`\`tsx
30
- * import { PLASMIC } from "@/plasmic-init";
31
- * import { PlasmicRootProvider } from "plasmicapp/loader-nextjs";
32
- * export default function MyPage() {
33
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
34
- * return (
35
- * <PlasmicRootProvider
36
- * loader={PLASMIC} // ERROR: loader is not serializable
37
- * prefetchedData={prefetchedData}
38
- * >
39
- * {yourContent()}
40
- * </PlasmicRootProvider>;
41
- * );
42
- * }
43
- * \`\`\`
44
- *
45
- * Therefore, we define ClientPlasmicRootProvider as a Client Component (this file is marked "use client").
46
- * ClientPlasmicRootProvider wraps the PlasmicRootProvider and passes in the loader for you,
47
- * while allowing your Server Component to pass in prefetched data and other serializable props:
48
- *
49
- * \`\`\`tsx
50
- * import { PLASMIC } from "@/plasmic-init";
51
- * import { ClientPlasmicRootProvider } from "@/plasmic-init-client"; // changed
52
- * export default function MyPage() {
53
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
54
- * return (
55
- * <ClientPlasmicRootProvider // don't pass in loader
56
- * prefetchedData={prefetchedData}
57
- * >
58
- * {yourContent()}
59
- * </ClientPlasmicRootProvider>;
60
- * );
61
- * }
62
- * \`\`\`
63
25
  */
64
26
  export function ClientPlasmicRootProvider(
65
27
  props${(0, file_utils_1.ifTs)(jsOrTs, ': Omit<React.ComponentProps<typeof PlasmicRootProvider>, "loader">')}
@@ -27,11 +27,6 @@ export const PLASMIC = initPlasmicLoader({
27
27
  // Register custom functions here so they are available during SSR.
28
28
  // See https://docs.plasmic.app/learn/registering-custom-functions/
29
29
  //
30
- // IMPORTANT for app-router projects: any custom function used by a server
31
- // query must be registered here, which runs on the server. Registrations in
32
- // plasmic-init-client.tsx are only available in the browser and will cause
33
- // a runtime error if referenced by a server query during SSR.
34
- //
35
30
  // PLASMIC.registerFunction(...);
36
31
  `;
37
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.141",
3
+ "version": "0.0.143",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
@@ -24,16 +24,16 @@
24
24
  "@types/glob": "^7.1.3",
25
25
  "@types/inquirer": "^8.2.5",
26
26
  "@types/jest": "^26.0.20",
27
- "@types/lodash": "^4.14.168",
27
+ "@types/lodash": "^4.17.24",
28
28
  "@types/node": "^14.14.33",
29
- "@types/semver": "^7.3.5",
29
+ "@types/semver": "^7.7.1",
30
30
  "@types/update-notifier": "^5.0.0",
31
31
  "@types/validate-npm-package-name": "^3.0.2",
32
32
  "@types/yargs": "^16.0.0",
33
- "tsx": "^4.20.6"
33
+ "tsx": "^4.21.0"
34
34
  },
35
35
  "dependencies": {
36
- "@plasmicapp/cli": "0.1.360",
36
+ "@plasmicapp/cli": "0.1.361",
37
37
  "@sentry/node": "^6.2.2",
38
38
  "chalk": "^4.1.0",
39
39
  "execa": "^5.0.0",
@@ -47,5 +47,5 @@
47
47
  "validate-npm-package-name": "^3.0.0",
48
48
  "yargs": "^16.2.0"
49
49
  },
50
- "gitHead": "be549e5886ff23b4bb17b986a4a176cdde139dbc"
50
+ "gitHead": "5f674c9df3345496989eb0d1e09ddd30604757a9"
51
51
  }
@@ -12,6 +12,7 @@ import { ensure } from "../utils/lang-utils";
12
12
  import { installUpgrade } from "../utils/npm-utils";
13
13
  import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
14
14
  import { makeLayout_app_codegen } from "./templates/app-codegen/layout";
15
+ import { makePlasmicInitClient_app_codegen } from "./templates/app-codegen/plasmic-init-client";
15
16
  import { makeCatchallPage_app_loader } from "./templates/app-loader/catchall-page";
16
17
  import { makePlasmicHostPage_app_loader } from "./templates/app-loader/plasmic-host";
17
18
  import { makePlasmicInit_app_loader } from "./templates/app-loader/plasmic-init";
@@ -123,6 +124,12 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
123
124
  makeLayout_app_codegen(jsOrTs)
124
125
  );
125
126
 
127
+ // ./plasmic-init-client.tsx
128
+ await fs.writeFile(
129
+ path.join(projectPath, `plasmic-init-client.${jsOrTs}x`),
130
+ makePlasmicInitClient_app_codegen(jsOrTs)
131
+ );
132
+
126
133
  // ./app/plasmic-host/page.tsx
127
134
  await fs.mkdir(path.join(projectPath, "app", "plasmic-host"));
128
135
  await fs.writeFile(
@@ -3,8 +3,7 @@ import { JsOrTs } from "../../../utils/types";
3
3
 
4
4
  export function makeLayout_app_codegen(jsOrTs: JsOrTs): string {
5
5
  return `import '@/app/globals.css'
6
- import { PlasmicRootProvider } from "@plasmicapp/react-web";
7
- import Link from "next/link";
6
+ import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
8
7
 
9
8
  export default function RootLayout({
10
9
  children,
@@ -17,9 +16,9 @@ export default function RootLayout({
17
16
  return (
18
17
  <html lang="en">
19
18
  <body>
20
- <PlasmicRootProvider Link={Link}>
19
+ <ClientPlasmicRootProvider>
21
20
  {children}
22
- </PlasmicRootProvider>
21
+ </ClientPlasmicRootProvider>
23
22
  </body>
24
23
  </html>
25
24
  );
@@ -0,0 +1,26 @@
1
+ import { ifTs } from "../../../utils/file-utils";
2
+ import { JsOrTs } from "../../../utils/types";
3
+
4
+ export function makePlasmicInitClient_app_codegen(jsOrTs: JsOrTs): string {
5
+ return `"use client";
6
+
7
+ import * as React from "react";
8
+ import { PlasmicRootProvider } from "@plasmicapp/react-web";
9
+ import Link from "next/link";
10
+
11
+ /**
12
+ * ClientPlasmicRootProvider is a Client Component that passes Next's Link to PlasmicRootProvider.
13
+ *
14
+ * Props passed from a Server Component to a Client Component must be serializable.
15
+ * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
16
+ */
17
+ export function ClientPlasmicRootProvider(
18
+ props${ifTs(
19
+ jsOrTs,
20
+ ': Omit<React.ComponentProps<typeof PlasmicRootProvider>, "Link">'
21
+ )}
22
+ ) {
23
+ return <PlasmicRootProvider Link={Link} {...props} />;
24
+ }
25
+ `;
26
+ }
@@ -17,48 +17,10 @@ import { PLASMIC } from "@/plasmic-init";
17
17
  // PLASMIC.registerComponent(...);
18
18
 
19
19
  /**
20
- * ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
20
+ * ClientPlasmicRootProvider is a Client Component that passes the loader to PlasmicRootProvider.
21
21
  *
22
- * Why? Props passed from Server to Client Components must be serializable.
22
+ * Props passed from a Server Component to a Client Component must be serializable.
23
23
  * https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
24
- * However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
25
- *
26
- * In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
27
- *
28
- * \`\`\`tsx
29
- * import { PLASMIC } from "@/plasmic-init";
30
- * import { PlasmicRootProvider } from "plasmicapp/loader-nextjs";
31
- * export default function MyPage() {
32
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
33
- * return (
34
- * <PlasmicRootProvider
35
- * loader={PLASMIC} // ERROR: loader is not serializable
36
- * prefetchedData={prefetchedData}
37
- * >
38
- * {yourContent()}
39
- * </PlasmicRootProvider>;
40
- * );
41
- * }
42
- * \`\`\`
43
- *
44
- * Therefore, we define ClientPlasmicRootProvider as a Client Component (this file is marked "use client").
45
- * ClientPlasmicRootProvider wraps the PlasmicRootProvider and passes in the loader for you,
46
- * while allowing your Server Component to pass in prefetched data and other serializable props:
47
- *
48
- * \`\`\`tsx
49
- * import { PLASMIC } from "@/plasmic-init";
50
- * import { ClientPlasmicRootProvider } from "@/plasmic-init-client"; // changed
51
- * export default function MyPage() {
52
- * const prefetchedData = await PLASMIC.fetchComponentData("YourPage");
53
- * return (
54
- * <ClientPlasmicRootProvider // don't pass in loader
55
- * prefetchedData={prefetchedData}
56
- * >
57
- * {yourContent()}
58
- * </ClientPlasmicRootProvider>;
59
- * );
60
- * }
61
- * \`\`\`
62
24
  */
63
25
  export function ClientPlasmicRootProvider(
64
26
  props${ifTs(
@@ -27,11 +27,6 @@ export const PLASMIC = initPlasmicLoader({
27
27
  // Register custom functions here so they are available during SSR.
28
28
  // See https://docs.plasmic.app/learn/registering-custom-functions/
29
29
  //
30
- // IMPORTANT for app-router projects: any custom function used by a server
31
- // query must be registered here, which runs on the server. Registrations in
32
- // plasmic-init-client.tsx are only available in the browser and will cause
33
- // a runtime error if referenced by a server query during SSR.
34
- //
35
30
  // PLASMIC.registerFunction(...);
36
31
  `;
37
32
  }