create-plasmic-app 0.0.43 → 0.0.46
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 +1 -1
- package/dist/index.js +2 -2
- package/dist/strategies/gatsby.js +35 -18
- package/dist/templates/gatsby.js +4 -0
- package/dist/templates/nextjs.js +15 -8
- package/package.json +3 -3
- package/src/index.ts +2 -2
- package/src/strategies/gatsby.ts +53 -23
- package/src/templates/gatsby.ts +4 -0
- package/src/templates/nextjs.ts +15 -8
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
|
@@ -202,8 +202,8 @@ function run() {
|
|
|
202
202
|
const rawProjectId = yield maybePrompt({
|
|
203
203
|
name: "projectId",
|
|
204
204
|
message: `What is the URL of your project?
|
|
205
|
-
|
|
206
|
-
https://studio.plasmic.app/starters/
|
|
205
|
+
If you don't have a project yet, create one by going to
|
|
206
|
+
https://studio.plasmic.app/starters/blank
|
|
207
207
|
`,
|
|
208
208
|
});
|
|
209
209
|
projectId = rawProjectId
|
|
@@ -49,16 +49,27 @@ 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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
64
|
installDeps: ({ projectPath, scheme }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
65
|
if (scheme === "loader") {
|
|
59
|
-
return yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
|
|
66
|
+
return ((yield npm_utils_1.installUpgrade("@plasmicapp/loader-gatsby", {
|
|
60
67
|
workingDir: projectPath,
|
|
61
|
-
})
|
|
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
|
+
})));
|
|
62
73
|
}
|
|
63
74
|
else {
|
|
64
75
|
return yield common_1.installCodegenDeps({ projectPath });
|
|
@@ -67,21 +78,27 @@ const gatsbyStrategy = {
|
|
|
67
78
|
overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
79
|
var e_1, _a;
|
|
69
80
|
const { projectId, projectPath, projectApiToken, useTypescript, scheme, } = args;
|
|
81
|
+
const extension = useTypescript ? "ts" : "js";
|
|
70
82
|
if (scheme === "loader") {
|
|
71
|
-
// create-gatsby will create a default gatsby-config
|
|
72
|
-
const gatsbyConfigFile = path_1.default.join(projectPath,
|
|
83
|
+
// create-gatsby will create a default gatsby-config that we need to modify
|
|
84
|
+
const gatsbyConfigFile = path_1.default.join(projectPath, `gatsby-config.${extension}`);
|
|
73
85
|
const rl = readline.createInterface({
|
|
74
86
|
input: fs_1.createReadStream(gatsbyConfigFile),
|
|
75
87
|
crlfDelay: Infinity,
|
|
76
88
|
});
|
|
77
89
|
let result = "";
|
|
90
|
+
const pluginConfig = gatsby_1.GATSBY_PLUGIN_CONFIG(projectId, lang_utils_1.ensure(projectApiToken), useTypescript);
|
|
78
91
|
try {
|
|
79
92
|
for (var rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), !rl_1_1.done;) {
|
|
80
93
|
const line = rl_1_1.value;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
if (line.includes("plugins: []")) {
|
|
95
|
+
result += " plugins: [" + pluginConfig + "]\n";
|
|
96
|
+
}
|
|
97
|
+
else if (line.includes("plugins: [")) {
|
|
98
|
+
result += line + pluginConfig + "\n";
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
result += line + "\n";
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
}
|
|
@@ -102,16 +119,16 @@ const gatsbyStrategy = {
|
|
|
102
119
|
const extension = useTypescript ? "ts" : "js";
|
|
103
120
|
file_utils_1.deleteGlob(path_1.default.join(projectPath, "src/@(pages|components|templates)/*.*"));
|
|
104
121
|
// 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
|
|
122
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/404.${extension}`), gatsby_1.GATSBY_404);
|
|
106
123
|
// Add plasmic-host page
|
|
107
124
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/pages/plasmic-host.${extension}x`), gatsby_1.makeGatsbyHostPage({
|
|
108
125
|
useTypescript,
|
|
109
126
|
scheme,
|
|
110
127
|
}));
|
|
111
|
-
// Start with an empty gatsby-node
|
|
112
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
128
|
+
// Start with an empty gatsby-node
|
|
129
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `gatsby-node.${extension}`), "");
|
|
113
130
|
// Updates `gatsby-ssr` to include script tag for preamble
|
|
114
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
131
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `gatsby-ssr.${extension}x`), gatsby_1.GATSBY_SSR_CONFIG);
|
|
115
132
|
if (scheme === "loader") {
|
|
116
133
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `src/plasmic-init.${extension}`), gatsby_1.makeGatsbyPlasmicInit(extension));
|
|
117
134
|
const templatesFolder = path_1.default.join(projectPath, "src/templates");
|
|
@@ -131,9 +148,9 @@ const gatsbyStrategy = {
|
|
|
131
148
|
yield file_utils_1.overwriteIndex(projectPath, "gatsby", scheme);
|
|
132
149
|
// Overwrite the wrapper files to wrap PlasmicRootProvider
|
|
133
150
|
const wrapperContent = gatsby_1.wrapAppRootForCodegen();
|
|
134
|
-
const browserFilePath = path_1.default.join(projectPath,
|
|
151
|
+
const browserFilePath = path_1.default.join(projectPath, `gatsby-browser.${extension}x`);
|
|
135
152
|
yield fs_1.promises.writeFile(browserFilePath, wrapperContent);
|
|
136
|
-
const ssrFilePath = path_1.default.join(projectPath,
|
|
153
|
+
const ssrFilePath = path_1.default.join(projectPath, `gatsby-ssr.${extension}x`);
|
|
137
154
|
yield fs_1.promises.writeFile(ssrFilePath, wrapperContent);
|
|
138
155
|
}
|
|
139
156
|
}),
|
package/dist/templates/gatsby.js
CHANGED
|
@@ -73,9 +73,13 @@ const GATSBY_PLUGIN_CONFIG = (projectId, projectApiToken, useTypescript) => `
|
|
|
73
73
|
token: "${projectApiToken}",
|
|
74
74
|
},
|
|
75
75
|
], // An array of project ids.
|
|
76
|
+
preview: false,
|
|
76
77
|
defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage.${useTypescript ? "tsx" : "jsx"}"),
|
|
77
78
|
},
|
|
78
79
|
},
|
|
80
|
+
{
|
|
81
|
+
resolve: "gatsby-plugin-react-helmet",
|
|
82
|
+
}
|
|
79
83
|
`;
|
|
80
84
|
exports.GATSBY_PLUGIN_CONFIG = GATSBY_PLUGIN_CONFIG;
|
|
81
85
|
const makeGatsbyHostPage = (opts) => {
|
package/dist/templates/nextjs.js
CHANGED
|
@@ -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${file_utils_1.ifTs(ts, " as Record<string, string>")}}
|
|
60
65
|
>
|
|
61
|
-
<PlasmicComponent component={
|
|
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
|
|
77
|
-
|
|
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.
|
|
3
|
+
"version": "0.0.46",
|
|
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.
|
|
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
|
@@ -185,8 +185,8 @@ async function run(): Promise<void> {
|
|
|
185
185
|
const rawProjectId = await maybePrompt({
|
|
186
186
|
name: "projectId",
|
|
187
187
|
message: `What is the URL of your project?
|
|
188
|
-
|
|
189
|
-
https://studio.plasmic.app/starters/
|
|
188
|
+
If you don't have a project yet, create one by going to
|
|
189
|
+
https://studio.plasmic.app/starters/blank
|
|
190
190
|
`,
|
|
191
191
|
});
|
|
192
192
|
projectId = rawProjectId
|
package/src/strategies/gatsby.ts
CHANGED
|
@@ -19,17 +19,34 @@ import { CPAStrategy } from "./types";
|
|
|
19
19
|
|
|
20
20
|
const gatsbyStrategy: CPAStrategy = {
|
|
21
21
|
create: async (args) => {
|
|
22
|
-
const { projectPath, template } = args;
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
39
|
installDeps: async ({ projectPath, scheme }) => {
|
|
29
40
|
if (scheme === "loader") {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
);
|
|
33
50
|
} else {
|
|
34
51
|
return await installCodegenDeps({ projectPath });
|
|
35
52
|
}
|
|
@@ -42,24 +59,31 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
42
59
|
useTypescript,
|
|
43
60
|
scheme,
|
|
44
61
|
} = args;
|
|
62
|
+
const extension = useTypescript ? "ts" : "js";
|
|
45
63
|
|
|
46
64
|
if (scheme === "loader") {
|
|
47
|
-
// create-gatsby will create a default gatsby-config
|
|
48
|
-
const gatsbyConfigFile = path.join(
|
|
65
|
+
// create-gatsby will create a default gatsby-config that we need to modify
|
|
66
|
+
const gatsbyConfigFile = path.join(
|
|
67
|
+
projectPath,
|
|
68
|
+
`gatsby-config.${extension}`
|
|
69
|
+
);
|
|
49
70
|
const rl = readline.createInterface({
|
|
50
71
|
input: createReadStream(gatsbyConfigFile),
|
|
51
72
|
crlfDelay: Infinity,
|
|
52
73
|
});
|
|
53
74
|
let result = "";
|
|
75
|
+
const pluginConfig = GATSBY_PLUGIN_CONFIG(
|
|
76
|
+
projectId,
|
|
77
|
+
ensure(projectApiToken),
|
|
78
|
+
useTypescript
|
|
79
|
+
);
|
|
54
80
|
for await (const line of rl) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (line.includes("plugins:")) {
|
|
58
|
-
result +=
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
useTypescript
|
|
62
|
-
);
|
|
81
|
+
if (line.includes("plugins: []")) {
|
|
82
|
+
result += " plugins: [" + pluginConfig + "]\n";
|
|
83
|
+
} else if (line.includes("plugins: [")) {
|
|
84
|
+
result += line + pluginConfig + "\n";
|
|
85
|
+
} else {
|
|
86
|
+
result += line + "\n";
|
|
63
87
|
}
|
|
64
88
|
}
|
|
65
89
|
await fs.writeFile(gatsbyConfigFile, result);
|
|
@@ -81,7 +105,10 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
81
105
|
deleteGlob(path.join(projectPath, "src/@(pages|components|templates)/*.*"));
|
|
82
106
|
|
|
83
107
|
// Create a very basic 404 page - `gatsby build` fails without it.
|
|
84
|
-
await fs.writeFile(
|
|
108
|
+
await fs.writeFile(
|
|
109
|
+
path.join(projectPath, `src/pages/404.${extension}`),
|
|
110
|
+
GATSBY_404
|
|
111
|
+
);
|
|
85
112
|
|
|
86
113
|
// Add plasmic-host page
|
|
87
114
|
await fs.writeFile(
|
|
@@ -92,12 +119,12 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
92
119
|
})
|
|
93
120
|
);
|
|
94
121
|
|
|
95
|
-
// Start with an empty gatsby-node
|
|
96
|
-
await fs.writeFile(path.join(projectPath,
|
|
122
|
+
// Start with an empty gatsby-node
|
|
123
|
+
await fs.writeFile(path.join(projectPath, `gatsby-node.${extension}`), "");
|
|
97
124
|
|
|
98
125
|
// Updates `gatsby-ssr` to include script tag for preamble
|
|
99
126
|
await fs.writeFile(
|
|
100
|
-
path.join(projectPath,
|
|
127
|
+
path.join(projectPath, `gatsby-ssr.${extension}x`),
|
|
101
128
|
GATSBY_SSR_CONFIG
|
|
102
129
|
);
|
|
103
130
|
|
|
@@ -128,10 +155,13 @@ const gatsbyStrategy: CPAStrategy = {
|
|
|
128
155
|
|
|
129
156
|
// Overwrite the wrapper files to wrap PlasmicRootProvider
|
|
130
157
|
const wrapperContent = wrapAppRootForCodegen();
|
|
131
|
-
const browserFilePath = path.join(
|
|
158
|
+
const browserFilePath = path.join(
|
|
159
|
+
projectPath,
|
|
160
|
+
`gatsby-browser.${extension}x`
|
|
161
|
+
);
|
|
132
162
|
await fs.writeFile(browserFilePath, wrapperContent);
|
|
133
163
|
|
|
134
|
-
const ssrFilePath = path.join(projectPath,
|
|
164
|
+
const ssrFilePath = path.join(projectPath, `gatsby-ssr.${extension}x`);
|
|
135
165
|
await fs.writeFile(ssrFilePath, wrapperContent);
|
|
136
166
|
}
|
|
137
167
|
},
|
package/src/templates/gatsby.ts
CHANGED
|
@@ -83,11 +83,15 @@ export const GATSBY_PLUGIN_CONFIG = (
|
|
|
83
83
|
token: "${projectApiToken}",
|
|
84
84
|
},
|
|
85
85
|
], // An array of project ids.
|
|
86
|
+
preview: false,
|
|
86
87
|
defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage.${
|
|
87
88
|
useTypescript ? "tsx" : "jsx"
|
|
88
89
|
}"),
|
|
89
90
|
},
|
|
90
91
|
},
|
|
92
|
+
{
|
|
93
|
+
resolve: "gatsby-plugin-react-helmet",
|
|
94
|
+
}
|
|
91
95
|
`;
|
|
92
96
|
|
|
93
97
|
export const makeGatsbyHostPage = (opts: {
|
package/src/templates/nextjs.ts
CHANGED
|
@@ -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${ifTs(ts, " as Record<string, string>")}}
|
|
66
71
|
>
|
|
67
|
-
<PlasmicComponent component={
|
|
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
|
|
86
|
-
|
|
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();
|