create-plasmic-app 0.0.133 → 0.0.135
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/cpa-out/nextjs-app-codegen-js/app/dynamic/[slug]/page-client.jsx +7 -0
- package/cpa-out/nextjs-app-codegen-js/app/dynamic/[slug]/page.jsx +45 -0
- package/cpa-out/nextjs-app-codegen-js/app/layout.js +28 -0
- package/cpa-out/nextjs-app-codegen-js/app/layout.jsx +17 -0
- package/cpa-out/nextjs-app-codegen-js/app/page-client.jsx +7 -0
- package/cpa-out/nextjs-app-codegen-js/app/page.jsx +45 -0
- package/cpa-out/nextjs-app-codegen-js/app/plasmic-host/page.jsx +15 -0
- package/cpa-out/nextjs-app-codegen-js/components/Button.jsx +11 -0
- package/cpa-out/nextjs-app-codegen-js/components/RandomDynamicPageButton.jsx +24 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.jsx +595 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +216 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.jsx +56 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +26 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +251 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepageServer.jsx +56 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +159 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.jsx +15 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/icons/PlasmicIcon__CheckSvg.jsx +39 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.jsx +37 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/plasmic.jsx +11 -0
- package/cpa-out/nextjs-app-codegen-js/package.json +22 -0
- package/cpa-out/nextjs-app-codegen-js/plasmic.json +148 -0
- package/cpa-out/nextjs-app-codegen-ts/app/dynamic/[slug]/page-client.tsx +11 -0
- package/cpa-out/nextjs-app-codegen-ts/app/dynamic/[slug]/page.tsx +57 -0
- package/cpa-out/nextjs-app-codegen-ts/app/layout.tsx +19 -0
- package/cpa-out/nextjs-app-codegen-ts/app/page-client.tsx +11 -0
- package/cpa-out/nextjs-app-codegen-ts/app/page.tsx +54 -0
- package/cpa-out/nextjs-app-codegen-ts/app/plasmic-host/page.tsx +15 -0
- package/cpa-out/nextjs-app-codegen-ts/components/Button.tsx +35 -0
- package/cpa-out/nextjs-app-codegen-ts/components/RandomDynamicPageButton.tsx +44 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.tsx +776 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +329 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.tsx +77 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +366 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepageServer.tsx +75 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +274 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.tsx +19 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/icons/PlasmicIcon__CheckSvg.tsx +44 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/icons/PlasmicIcon__Icon.tsx +41 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/plasmic.tsx +14 -0
- package/cpa-out/nextjs-app-codegen-ts/package.json +26 -0
- package/cpa-out/nextjs-app-codegen-ts/plasmic.json +148 -0
- package/cpa-out/nextjs-app-codegen-ts/tsconfig.json +26 -0
- package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +80 -0
- package/cpa-out/nextjs-app-loader-js/app/layout.js +28 -0
- package/cpa-out/nextjs-app-loader-js/app/plasmic-host/page.jsx +6 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init-client.jsx +65 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init.js +5 -10
- package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +85 -0
- package/cpa-out/nextjs-app-loader-ts/app/layout.tsx +33 -0
- package/cpa-out/nextjs-app-loader-ts/app/plasmic-host/page.tsx +6 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init-client.tsx +65 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init.ts +5 -10
- package/cpa-out/nextjs-app-loader-ts/tsconfig.json +6 -1
- package/dist/index.js +31 -30
- package/dist/nextjs/nextjs.js +37 -11
- package/dist/nextjs/templates/app-codegen/layout.d.ts +2 -0
- package/dist/nextjs/templates/app-codegen/layout.js +27 -0
- package/dist/nextjs/templates/app-loader/catchall-page.js +63 -38
- package/dist/nextjs/templates/app-loader/plasmic-init-client.js +1 -1
- package/dist/nextjs/templates/app-loader/plasmic-init.js +4 -0
- package/package.json +2 -2
- package/run-cpa.ts +8 -9
- package/src/index.ts +31 -36
- package/src/nextjs/nextjs.ts +67 -28
- package/src/nextjs/templates/app-codegen/layout.ts +28 -0
- package/src/nextjs/templates/app-loader/catchall-page.ts +80 -43
- package/src/nextjs/templates/app-loader/plasmic-init-client.ts +1 -1
- package/src/nextjs/templates/app-loader/plasmic-init.ts +4 -0
- package/cpa-out/nextjs-app-loader-js/pages/[[...catchall]].jsx +0 -68
- package/cpa-out/nextjs-app-loader-js/pages/api/hello.js +0 -5
- package/cpa-out/nextjs-app-loader-js/pages/plasmic-host.jsx +0 -7
- package/cpa-out/nextjs-app-loader-ts/pages/[[...catchall]].tsx +0 -72
- package/cpa-out/nextjs-app-loader-ts/pages/api/hello.ts +0 -13
- package/cpa-out/nextjs-app-loader-ts/pages/plasmic-host.tsx +0 -7
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { PlasmicRootProvider } from "@plasmicapp/loader-nextjs";
|
|
4
|
+
import { PLASMIC } from "@/plasmic-init";
|
|
5
|
+
|
|
6
|
+
// You can register any code components that you want to use here; see
|
|
7
|
+
// https://docs.plasmic.app/learn/code-components-ref/
|
|
8
|
+
// And configure your Plasmic project to use the host url pointing at
|
|
9
|
+
// the /plasmic-host page of your nextjs app (for example,
|
|
10
|
+
// http://localhost:3000/plasmic-host). See
|
|
11
|
+
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
12
|
+
|
|
13
|
+
// PLASMIC.registerComponent(...);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
|
|
17
|
+
*
|
|
18
|
+
* Why? Props passed from Server to Client Components must be serializable.
|
|
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
|
+
*/
|
|
59
|
+
export function ClientPlasmicRootProvider(
|
|
60
|
+
props: Omit<React.ComponentProps<typeof PlasmicRootProvider>, "loader">
|
|
61
|
+
) {
|
|
62
|
+
return (
|
|
63
|
+
<PlasmicRootProvider loader={PLASMIC} {...props}></PlasmicRootProvider>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs";
|
|
1
|
+
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
|
|
2
|
+
import * as NextNavigation from "next/navigation";
|
|
2
3
|
|
|
3
4
|
export const PLASMIC = initPlasmicLoader({
|
|
4
5
|
projects: [
|
|
@@ -13,13 +14,7 @@ export const PLASMIC = initPlasmicLoader({
|
|
|
13
14
|
// project, allowing you to see your designs without publishing. Please
|
|
14
15
|
// only use this for development, as this is significantly slower.
|
|
15
16
|
preview: false,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// You can register any code components that you want to use here; see
|
|
19
|
-
// https://docs.plasmic.app/learn/code-components-ref/
|
|
20
|
-
// And configure your Plasmic project to use the host url pointing at
|
|
21
|
-
// the /plasmic-host page of your nextjs app (for example,
|
|
22
|
-
// http://localhost:3000/plasmic-host). See
|
|
23
|
-
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
24
17
|
|
|
25
|
-
//
|
|
18
|
+
// Needed for Next.js app router support.
|
|
19
|
+
nextNavigation: NextNavigation,
|
|
20
|
+
});
|
|
@@ -12,10 +12,15 @@
|
|
|
12
12
|
"isolatedModules": true,
|
|
13
13
|
"jsx": "preserve",
|
|
14
14
|
"incremental": true,
|
|
15
|
+
"plugins": [
|
|
16
|
+
{
|
|
17
|
+
"name": "next"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
15
20
|
"paths": {
|
|
16
21
|
"@/*": ["./*"]
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
|
-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
|
24
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
20
25
|
"exclude": ["node_modules"]
|
|
21
26
|
}
|
package/dist/index.js
CHANGED
|
@@ -96,10 +96,6 @@ const argv = yargs_1.default
|
|
|
96
96
|
!(argv2.platform === "nextjs" || argv2.platform === "gatsby")) {
|
|
97
97
|
throw new Error(`Loader scheme may only be used with Next.js or Gatsby`);
|
|
98
98
|
}
|
|
99
|
-
if (argv2.appDir &&
|
|
100
|
-
!(argv2.platform === "nextjs" && argv2.scheme === "loader")) {
|
|
101
|
-
throw new Error(`App dir may only be used with Next.js and loader scheme`);
|
|
102
|
-
}
|
|
103
99
|
return true;
|
|
104
100
|
}).argv;
|
|
105
101
|
// Initialize Sentry
|
|
@@ -222,34 +218,39 @@ function run() {
|
|
|
222
218
|
default: "loader",
|
|
223
219
|
})
|
|
224
220
|
: "codegen";
|
|
225
|
-
// TODO: Support nextjs + codegen
|
|
226
221
|
const platformOptions = {};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
222
|
+
if (platform === "nextjs") {
|
|
223
|
+
// TODO: re-enable when app dir is released
|
|
224
|
+
const showAppDirQuestion = false;
|
|
225
|
+
if (showAppDirQuestion) {
|
|
226
|
+
platformOptions.nextjs = {
|
|
227
|
+
appDir: yield maybePrompt({
|
|
228
|
+
name: "appDir",
|
|
229
|
+
message: "Do you want to use the app/ directory and React Server Components? (see https://nextjs.org/docs/app)",
|
|
230
|
+
type: "list",
|
|
231
|
+
choices: () => [
|
|
232
|
+
{
|
|
233
|
+
name: "Yes, use app/ directory",
|
|
234
|
+
short: "Yes",
|
|
235
|
+
value: true,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: "No, use pages/ directory",
|
|
239
|
+
short: "No",
|
|
240
|
+
value: false,
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
default: true,
|
|
244
|
+
}),
|
|
245
|
+
};
|
|
246
|
+
// Respect appDir flag for e2e tests
|
|
247
|
+
}
|
|
248
|
+
else if (argv["appDir"] !== undefined) {
|
|
249
|
+
platformOptions.nextjs = {
|
|
250
|
+
appDir: argv["appDir"],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
250
253
|
}
|
|
251
|
-
// Get the projectId
|
|
252
|
-
console.log();
|
|
253
254
|
const projectInput = yield maybePrompt({
|
|
254
255
|
name: "projectId",
|
|
255
256
|
message: `If you don't have a project yet, create one by going to https://studio.plasmic.app/starters/blank
|
package/dist/nextjs/nextjs.js
CHANGED
|
@@ -21,6 +21,7 @@ const codegen_1 = require("../utils/codegen");
|
|
|
21
21
|
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
|
+
const layout_1 = require("./templates/app-codegen/layout");
|
|
24
25
|
const catchall_page_1 = require("./templates/app-loader/catchall-page");
|
|
25
26
|
const plasmic_host_1 = require("./templates/app-loader/plasmic-host");
|
|
26
27
|
const plasmic_init_1 = require("./templates/app-loader/plasmic-init");
|
|
@@ -89,19 +90,44 @@ export default nextConfig;`);
|
|
|
89
90
|
};
|
|
90
91
|
function generateFilesAppDir(args) {
|
|
91
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
const { projectPath, jsOrTs, projectId, projectApiToken } = args;
|
|
93
|
+
const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
|
|
93
94
|
// Delete existing pages
|
|
94
95
|
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "app", "page.*"));
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
if (scheme === "loader") {
|
|
97
|
+
// ./plasmic-init.ts
|
|
98
|
+
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
|
+
// ./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
|
+
// ./app/plasmic-host/page.tsx
|
|
102
|
+
yield fs_1.promises.mkdir(path_1.default.join(projectPath, "app", "plasmic-host"));
|
|
103
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "plasmic-host", `page.${jsOrTs}x`), (0, plasmic_host_1.makePlasmicHostPage_app_loader)());
|
|
104
|
+
// ./app/[[...catchall]]/page.tsx
|
|
105
|
+
yield fs_1.promises.mkdir(path_1.default.join(projectPath, "app", "[[...catchall]]"));
|
|
106
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "[[...catchall]]", `page.${jsOrTs}x`), (0, catchall_page_1.makeCatchallPage_app_loader)(jsOrTs));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// ./app/layout.tsx
|
|
110
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`), (0, layout_1.makeLayout_app_codegen)(jsOrTs));
|
|
111
|
+
// ./app/plasmic-host/page.tsx
|
|
112
|
+
yield fs_1.promises.mkdir(path_1.default.join(projectPath, "app", "plasmic-host"));
|
|
113
|
+
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
|
|
114
|
+
);
|
|
115
|
+
// This should generate
|
|
116
|
+
// ./plasmic.json
|
|
117
|
+
// ./app/page.tsx
|
|
118
|
+
// ./components/plasmic/**
|
|
119
|
+
yield (0, codegen_1.runCodegenSync)({
|
|
120
|
+
projectId,
|
|
121
|
+
projectApiToken,
|
|
122
|
+
projectPath,
|
|
123
|
+
});
|
|
124
|
+
// Make an index (/) page if the project didn't have one.
|
|
125
|
+
const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
|
|
126
|
+
const plasmicFiles = lodash_1.default.map(lodash_1.default.flatMap(config.projects, (p) => p.components), (c) => c.importSpec.modulePath);
|
|
127
|
+
if (!plasmicFiles.find((f) => f.includes("app/page."))) {
|
|
128
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `page.${jsOrTs}x`), (0, file_utils_1.generateWelcomePage)(config, "nextjs"));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
105
131
|
});
|
|
106
132
|
}
|
|
107
133
|
function generateFilesPagesDir(args) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeLayout_app_codegen = void 0;
|
|
4
|
+
const file_utils_1 = require("../../../utils/file-utils");
|
|
5
|
+
function makeLayout_app_codegen(jsOrTs) {
|
|
6
|
+
return `import '@/app/globals.css'
|
|
7
|
+
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
8
|
+
import Link from "next/link";
|
|
9
|
+
|
|
10
|
+
export default function RootLayout({
|
|
11
|
+
children,
|
|
12
|
+
}${(0, file_utils_1.ifTs)(jsOrTs, `: Readonly<{
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}>`)}) {
|
|
15
|
+
return (
|
|
16
|
+
<html lang="en">
|
|
17
|
+
<body>
|
|
18
|
+
<PlasmicRootProvider Link={Link}>
|
|
19
|
+
{children}
|
|
20
|
+
</PlasmicRootProvider>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
exports.makeLayout_app_codegen = makeLayout_app_codegen;
|
|
@@ -3,65 +3,90 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.makeCatchallPage_app_loader = void 0;
|
|
4
4
|
const file_utils_1 = require("../../../utils/file-utils");
|
|
5
5
|
function makeCatchallPage_app_loader(jsOrTs) {
|
|
6
|
-
return `import {
|
|
7
|
-
import { notFound } from "next/navigation";
|
|
8
|
-
import { PLASMIC } from "@/plasmic-init";
|
|
6
|
+
return `import { PLASMIC } from "@/plasmic-init";
|
|
9
7
|
import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
|
|
8
|
+
import { ${(0, file_utils_1.ifTs)(jsOrTs, `ComponentRenderData,`)}PlasmicComponent } from "@plasmicapp/loader-nextjs";${(0, file_utils_1.ifTs)(jsOrTs, `
|
|
9
|
+
import { Metadata, ResolvingMetadata } from "next";`)}
|
|
10
|
+
import { notFound } from "next/navigation";
|
|
10
11
|
|
|
11
12
|
// Use revalidate if you want incremental static regeneration
|
|
12
13
|
export const revalidate = 60;
|
|
14
|
+
${(0, file_utils_1.ifTs)(jsOrTs, `interface Params {
|
|
15
|
+
catchall: string[] | undefined;
|
|
16
|
+
}`)}
|
|
17
|
+
export async function generateStaticParams()${(0, file_utils_1.ifTs)(jsOrTs, ": Promise<Params[]>")} {
|
|
18
|
+
const pageModules = await PLASMIC.fetchPages();
|
|
19
|
+
return pageModules.map((mod) => {
|
|
20
|
+
const catchall =
|
|
21
|
+
mod.path === "/" ? undefined : mod.path.substring(1).split("/");
|
|
22
|
+
return {
|
|
23
|
+
catchall,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
${(0, file_utils_1.ifTs)(jsOrTs, `interface LoaderPageProps {
|
|
28
|
+
params: Promise<Params>;
|
|
29
|
+
}`)}
|
|
30
|
+
export async function generateMetadata(
|
|
31
|
+
{ params }${(0, file_utils_1.ifTs)(jsOrTs, `: LoaderPageProps`)},
|
|
32
|
+
parent${(0, file_utils_1.ifTs)(jsOrTs, `: ResolvingMetadata`)}
|
|
33
|
+
)${(0, file_utils_1.ifTs)(jsOrTs, `: Promise<Metadata>`)} {
|
|
34
|
+
const { componentData } = await getPlasmicData(params);
|
|
35
|
+
|
|
36
|
+
if (!componentData) {
|
|
37
|
+
return parent${(0, file_utils_1.ifTs)(jsOrTs, ` as Promise<Metadata>`)};
|
|
38
|
+
}
|
|
39
|
+
const pageMeta = componentData.entryCompMetas[0];
|
|
40
|
+
const metadata = await PLASMIC.unstable__generateMetadata(componentData, {
|
|
41
|
+
params: pageMeta.params ?? {},
|
|
42
|
+
query: {},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return { ...(await parent), ...metadata };
|
|
46
|
+
}
|
|
13
47
|
|
|
14
48
|
export default async function PlasmicLoaderPage({
|
|
15
49
|
params,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
params?: { catchall: string[] | undefined };
|
|
19
|
-
searchParams?: Record<string, string | string[]>;
|
|
20
|
-
}`)}) {
|
|
21
|
-
const plasmicComponentData = await fetchPlasmicComponentData(params?.catchall);
|
|
22
|
-
if (!plasmicComponentData) {
|
|
23
|
-
notFound();
|
|
24
|
-
}
|
|
50
|
+
}${(0, file_utils_1.ifTs)(jsOrTs, `: LoaderPageProps`)}) {
|
|
51
|
+
const { pagePath, componentData } = await getPlasmicData(params);
|
|
25
52
|
|
|
26
|
-
|
|
27
|
-
if (prefetchedData.entryCompMetas.length === 0) {
|
|
53
|
+
if (!componentData) {
|
|
28
54
|
notFound();
|
|
29
55
|
}
|
|
56
|
+
const pageMeta = componentData.entryCompMetas[0];
|
|
57
|
+
const prefetchedQueryData = await PLASMIC.unstable__getServerQueriesData(
|
|
58
|
+
componentData,
|
|
59
|
+
{
|
|
60
|
+
pagePath,
|
|
61
|
+
params: pageMeta.params,
|
|
62
|
+
query: {},
|
|
63
|
+
}
|
|
64
|
+
);
|
|
30
65
|
|
|
31
|
-
const pageMeta = prefetchedData.entryCompMetas[0];
|
|
32
66
|
return (
|
|
33
67
|
<ClientPlasmicRootProvider
|
|
34
|
-
prefetchedData={
|
|
35
|
-
|
|
68
|
+
prefetchedData={componentData}
|
|
69
|
+
prefetchedQueryData={prefetchedQueryData}
|
|
36
70
|
pageParams={pageMeta.params}
|
|
37
|
-
|
|
71
|
+
pageRoute={pageMeta.path}
|
|
38
72
|
>
|
|
39
|
-
<PlasmicComponent
|
|
40
|
-
component={pageMeta.displayName}
|
|
41
|
-
/>
|
|
73
|
+
<PlasmicComponent component={pageMeta.displayName} />
|
|
42
74
|
</ClientPlasmicRootProvider>
|
|
43
75
|
);
|
|
44
76
|
}
|
|
45
77
|
|
|
46
|
-
async function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
78
|
+
async function getPlasmicData(
|
|
79
|
+
params${(0, file_utils_1.ifTs)(jsOrTs, ": Promise<Params>")}
|
|
80
|
+
)${(0, file_utils_1.ifTs)(jsOrTs, ": Promise<{ pagePath: string; componentData?: ComponentRenderData }>")} {
|
|
81
|
+
const catchall = (await params).catchall;
|
|
82
|
+
const pagePath = catchall ? \`/\${catchall.join("/")}\` : "/";
|
|
52
83
|
|
|
53
|
-
|
|
54
|
-
}
|
|
84
|
+
const componentData = await PLASMIC.maybeFetchComponentData(pagePath);
|
|
55
85
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
mod.path === "/" ? undefined : mod.path.substring(1).split("/");
|
|
61
|
-
return {
|
|
62
|
-
catchall,
|
|
63
|
-
};
|
|
64
|
-
});
|
|
86
|
+
if (!componentData || componentData.entryCompMetas.length === 0) {
|
|
87
|
+
return { pagePath };
|
|
88
|
+
}
|
|
89
|
+
return { pagePath, componentData };
|
|
65
90
|
}
|
|
66
91
|
`;
|
|
67
92
|
}
|
|
@@ -21,7 +21,7 @@ import { PLASMIC } from "@/plasmic-init";
|
|
|
21
21
|
* ClientPlasmicRootProvider is a Client Component that passes in the loader for you.
|
|
22
22
|
*
|
|
23
23
|
* Why? Props passed from Server to Client Components must be serializable.
|
|
24
|
-
* https://
|
|
24
|
+
* https://nextjs.org/docs/app/getting-started/server-and-client-components#passing-data-from-server-to-client-components
|
|
25
25
|
* However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
|
|
26
26
|
*
|
|
27
27
|
* In a Server Component like app/<your-path>/path.tsx, rendering the following would not work:
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.makePlasmicInit_app_loader = void 0;
|
|
4
4
|
function makePlasmicInit_app_loader(projectId, projectApiToken) {
|
|
5
5
|
return `import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
|
|
6
|
+
import * as NextNavigation from "next/navigation";
|
|
6
7
|
|
|
7
8
|
export const PLASMIC = initPlasmicLoader({
|
|
8
9
|
projects: [
|
|
@@ -17,6 +18,9 @@ export const PLASMIC = initPlasmicLoader({
|
|
|
17
18
|
// project, allowing you to see your designs without publishing. Please
|
|
18
19
|
// only use this for development, as this is significantly slower.
|
|
19
20
|
preview: false,
|
|
21
|
+
|
|
22
|
+
// Needed for Next.js app router support.
|
|
23
|
+
nextNavigation: NextNavigation,
|
|
20
24
|
});
|
|
21
25
|
`;
|
|
22
26
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-plasmic-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.135",
|
|
4
4
|
"description": "Create Plasmic-powered React apps",
|
|
5
5
|
"main": "./dist/lib.js",
|
|
6
6
|
"types": "./dist/lib.d.ts",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"validate-npm-package-name": "^3.0.0",
|
|
48
48
|
"yargs": "^16.2.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "7bdae76d262e9a939b16d46be2b806ae68b374ca"
|
|
51
51
|
}
|
package/run-cpa.ts
CHANGED
|
@@ -30,6 +30,12 @@ async function run() {
|
|
|
30
30
|
scheme,
|
|
31
31
|
typescript,
|
|
32
32
|
});
|
|
33
|
+
allArgSets.push({
|
|
34
|
+
platform: "nextjs",
|
|
35
|
+
appDir: true,
|
|
36
|
+
scheme,
|
|
37
|
+
typescript,
|
|
38
|
+
});
|
|
33
39
|
if (scheme === "codegen") {
|
|
34
40
|
if (typescript) {
|
|
35
41
|
allArgSets.push({
|
|
@@ -46,22 +52,15 @@ async function run() {
|
|
|
46
52
|
});
|
|
47
53
|
}
|
|
48
54
|
});
|
|
49
|
-
|
|
50
|
-
allArgSets.push({
|
|
51
|
-
platform: "nextjs",
|
|
52
|
-
appDir: true,
|
|
53
|
-
scheme: "loader", // TODO: support codegen with appDir
|
|
54
|
-
typescript,
|
|
55
|
-
});
|
|
56
55
|
});
|
|
57
56
|
const allArgSetNames = allArgSets.map(getProjectName).sort();
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
const yargsCommand = yargs.command(
|
|
60
59
|
"$0 [arg-sets..]",
|
|
61
60
|
`Runs create-plasmic-app with predefined sets of args for you.
|
|
62
61
|
|
|
63
62
|
Valid arg sets:\n\tall\n\t${allArgSetNames.join("\n\t")}`,
|
|
64
|
-
(
|
|
63
|
+
(yargs2) => yargs2
|
|
65
64
|
);
|
|
66
65
|
|
|
67
66
|
const cliArgSetNames = yargsCommand.strict().argv["arg-sets"] as
|
package/src/index.ts
CHANGED
|
@@ -75,15 +75,6 @@ const argv = yargs
|
|
|
75
75
|
throw new Error(`Loader scheme may only be used with Next.js or Gatsby`);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
if (
|
|
79
|
-
argv2.appDir &&
|
|
80
|
-
!(argv2.platform === "nextjs" && argv2.scheme === "loader")
|
|
81
|
-
) {
|
|
82
|
-
throw new Error(
|
|
83
|
-
`App dir may only be used with Next.js and loader scheme`
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
78
|
return true;
|
|
88
79
|
}).argv;
|
|
89
80
|
|
|
@@ -219,36 +210,40 @@ async function run(): Promise<void> {
|
|
|
219
210
|
})
|
|
220
211
|
: "codegen";
|
|
221
212
|
|
|
222
|
-
// TODO: Support nextjs + codegen
|
|
223
213
|
const platformOptions: PlatformOptions = {};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
214
|
+
if (platform === "nextjs") {
|
|
215
|
+
// TODO: re-enable when app dir is released
|
|
216
|
+
const showAppDirQuestion = false;
|
|
217
|
+
if (showAppDirQuestion) {
|
|
218
|
+
platformOptions.nextjs = {
|
|
219
|
+
appDir: await maybePrompt({
|
|
220
|
+
name: "appDir",
|
|
221
|
+
message:
|
|
222
|
+
"Do you want to use the app/ directory and React Server Components? (see https://nextjs.org/docs/app)",
|
|
223
|
+
type: "list",
|
|
224
|
+
choices: () => [
|
|
225
|
+
{
|
|
226
|
+
name: "Yes, use app/ directory",
|
|
227
|
+
short: "Yes",
|
|
228
|
+
value: true,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: "No, use pages/ directory",
|
|
232
|
+
short: "No",
|
|
233
|
+
value: false,
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
default: true,
|
|
237
|
+
}),
|
|
238
|
+
};
|
|
239
|
+
// Respect appDir flag for e2e tests
|
|
240
|
+
} else if (argv["appDir"] !== undefined) {
|
|
241
|
+
platformOptions.nextjs = {
|
|
242
|
+
appDir: argv["appDir"],
|
|
243
|
+
};
|
|
244
|
+
}
|
|
248
245
|
}
|
|
249
246
|
|
|
250
|
-
// Get the projectId
|
|
251
|
-
console.log();
|
|
252
247
|
const projectInput = await maybePrompt<string>({
|
|
253
248
|
name: "projectId",
|
|
254
249
|
message: `If you don't have a project yet, create one by going to https://studio.plasmic.app/starters/blank
|