create-plasmic-app 0.0.37 → 0.0.40
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/index.js +0 -0
- package/dist/strategies/nextjs.js +6 -6
- package/dist/templates/gatsby.js +21 -0
- package/dist/templates/nextjs.js +18 -13
- package/package.json +1 -1
- package/src/strategies/nextjs.ts +1 -1
- package/src/templates/gatsby.ts +21 -0
- package/src/templates/nextjs.ts +18 -13
- package/n/.cache/redux/redux.node.state_0 +0 -0
- package/n/.cache/redux/redux.page.state_0 +0 -0
- package/n/.cache/redux/redux.rest.state +0 -0
package/dist/index.js
CHANGED
|
File without changes
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
15
|
+
const fs_1 = require("fs");
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const nextjs_1 = require("../templates/nextjs");
|
|
18
18
|
const cmd_utils_1 = require("../utils/cmd-utils");
|
|
@@ -43,7 +43,7 @@ const nextjsStrategy = {
|
|
|
43
43
|
const { projectPath, scheme } = args;
|
|
44
44
|
if (scheme === "codegen") {
|
|
45
45
|
const nextjsConfigFile = path_1.default.join(projectPath, "next.config.js");
|
|
46
|
-
yield
|
|
46
|
+
yield fs_1.promises.writeFile(nextjsConfigFile, `
|
|
47
47
|
module.exports = {
|
|
48
48
|
eslint: {
|
|
49
49
|
ignoreDuringBuilds: true,
|
|
@@ -62,13 +62,13 @@ module.exports = {
|
|
|
62
62
|
const pagesPath = path_1.default.join(projectPath, "pages");
|
|
63
63
|
file_utils_1.deleteGlob(path_1.default.join(pagesPath, `*.*`));
|
|
64
64
|
const hostPage = path_1.default.join(pagesPath, `plasmic-host.${useTypescript ? "tsx" : "jsx"}`);
|
|
65
|
-
yield
|
|
65
|
+
yield fs_1.promises.writeFile(hostPage, nextjs_1.makeNextjsHostPage(scheme));
|
|
66
66
|
if (scheme === "loader") {
|
|
67
67
|
const initFile = path_1.default.join(projectPath, `plasmic-init.${useTypescript ? "ts" : "js"}`);
|
|
68
|
-
yield
|
|
68
|
+
yield fs_1.promises.writeFile(initFile, nextjs_1.makeNextjsInitPage(projectId, lang_utils_1.ensure(projectApiToken)));
|
|
69
69
|
// Write catch-all page for loader
|
|
70
70
|
const loaderPage = path_1.default.join(pagesPath, `[[...catchall]].${useTypescript ? "tsx" : "jsx"}`);
|
|
71
|
-
yield
|
|
71
|
+
yield fs_1.promises.writeFile(loaderPage, nextjs_1.makeNextjsCatchallPage(useTypescript ? "ts" : "js"));
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
74
74
|
yield common_1.runCodegenSync({
|
|
@@ -80,7 +80,7 @@ module.exports = {
|
|
|
80
80
|
yield file_utils_1.overwriteIndex(projectPath, "nextjs", scheme);
|
|
81
81
|
// Overwrite the wrapper files to wrap PlasmicRootProvider
|
|
82
82
|
const appFilePath = path_1.default.join(projectPath, "pages", `_app.js`);
|
|
83
|
-
yield
|
|
83
|
+
yield fs_1.promises.writeFile(appFilePath, nextjs_1.wrapAppRootForCodegen());
|
|
84
84
|
}
|
|
85
85
|
}),
|
|
86
86
|
build: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
package/dist/templates/gatsby.js
CHANGED
|
@@ -150,6 +150,27 @@ const HeadComponents = [
|
|
|
150
150
|
key="plasmic-preamble"
|
|
151
151
|
src="https://static1.plasmic.app/preamble.js"
|
|
152
152
|
/>,
|
|
153
|
+
<script
|
|
154
|
+
key="plasmic-hmr"
|
|
155
|
+
type="text/javascript"
|
|
156
|
+
dangerouslySetInnerHTML={{
|
|
157
|
+
__html: \`
|
|
158
|
+
if (typeof window !== "undefined" && /\\\\/plasmic-host\\\\/?$/.test(window.location.pathname)) {
|
|
159
|
+
const RealEventSource = window.EventSource;
|
|
160
|
+
window.EventSource = function(url, config) {
|
|
161
|
+
if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {
|
|
162
|
+
console.warn("Plasmic: disabled EventSource request for", url);
|
|
163
|
+
return {
|
|
164
|
+
onerror() {}, onmessage() {}, onopen() {}, close() {}
|
|
165
|
+
};
|
|
166
|
+
} else {
|
|
167
|
+
return new RealEventSource(url, config);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
\`,
|
|
172
|
+
}}
|
|
173
|
+
/>
|
|
153
174
|
]
|
|
154
175
|
|
|
155
176
|
const isProduction = process.env.NODE_ENV === "production"
|
package/dist/templates/nextjs.js
CHANGED
|
@@ -34,7 +34,10 @@ function makeNextjsCatchallPage(format) {
|
|
|
34
34
|
const ts = format === "ts";
|
|
35
35
|
return `
|
|
36
36
|
import * as React from "react";
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
PlasmicComponent,
|
|
39
|
+
extractPlasmicQueryData,
|
|
40
|
+
} from "@plasmicapp/loader-nextjs";
|
|
38
41
|
${file_utils_1.ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
39
42
|
import {
|
|
40
43
|
ComponentRenderData,
|
|
@@ -45,8 +48,9 @@ import { PLASMIC } from "../plasmic-init";
|
|
|
45
48
|
|
|
46
49
|
export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
|
|
47
50
|
plasmicData?: ComponentRenderData;
|
|
51
|
+
queryCache?: Record<string, any>;
|
|
48
52
|
}`)}) {
|
|
49
|
-
const { plasmicData } = props;
|
|
53
|
+
const { plasmicData, queryCache } = props;
|
|
50
54
|
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
51
55
|
return <Error statusCode={404} />;
|
|
52
56
|
}
|
|
@@ -54,6 +58,7 @@ export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
|
|
|
54
58
|
<PlasmicRootProvider
|
|
55
59
|
loader={PLASMIC}
|
|
56
60
|
prefetchedData={plasmicData}
|
|
61
|
+
prefetchedQueryData={queryCache}
|
|
57
62
|
>
|
|
58
63
|
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
59
64
|
</PlasmicRootProvider>
|
|
@@ -64,18 +69,18 @@ export const getStaticProps${file_utils_1.ifTs(ts, `: GetStaticProps`)} = async
|
|
|
64
69
|
const { catchall } = context.params ?? {};
|
|
65
70
|
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
|
|
66
71
|
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
67
|
-
if (plasmicData) {
|
|
68
|
-
return {
|
|
69
|
-
props: { plasmicData },
|
|
70
|
-
|
|
71
|
-
// Use revalidate if you want incremental static regeneration
|
|
72
|
-
revalidate: 60
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
72
|
+
if (!plasmicData) {
|
|
76
73
|
// non-Plasmic catch-all
|
|
77
|
-
props: {}
|
|
78
|
-
}
|
|
74
|
+
return { props: {} };
|
|
75
|
+
}
|
|
76
|
+
// Cache the necessary data fetched for the page
|
|
77
|
+
const queryCache = await extractPlasmicQueryData(
|
|
78
|
+
<PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
|
|
79
|
+
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
80
|
+
</PlasmicRootProvider>
|
|
81
|
+
);
|
|
82
|
+
// Use revalidate if you want incremental static regeneration
|
|
83
|
+
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
export const getStaticPaths${file_utils_1.ifTs(ts, `: GetStaticPaths`)} = async () => {
|
package/package.json
CHANGED
package/src/strategies/nextjs.ts
CHANGED
package/src/templates/gatsby.ts
CHANGED
|
@@ -167,6 +167,27 @@ const HeadComponents = [
|
|
|
167
167
|
key="plasmic-preamble"
|
|
168
168
|
src="https://static1.plasmic.app/preamble.js"
|
|
169
169
|
/>,
|
|
170
|
+
<script
|
|
171
|
+
key="plasmic-hmr"
|
|
172
|
+
type="text/javascript"
|
|
173
|
+
dangerouslySetInnerHTML={{
|
|
174
|
+
__html: \`
|
|
175
|
+
if (typeof window !== "undefined" && /\\\\/plasmic-host\\\\/?$/.test(window.location.pathname)) {
|
|
176
|
+
const RealEventSource = window.EventSource;
|
|
177
|
+
window.EventSource = function(url, config) {
|
|
178
|
+
if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {
|
|
179
|
+
console.warn("Plasmic: disabled EventSource request for", url);
|
|
180
|
+
return {
|
|
181
|
+
onerror() {}, onmessage() {}, onopen() {}, close() {}
|
|
182
|
+
};
|
|
183
|
+
} else {
|
|
184
|
+
return new RealEventSource(url, config);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
\`,
|
|
189
|
+
}}
|
|
190
|
+
/>
|
|
170
191
|
]
|
|
171
192
|
|
|
172
193
|
const isProduction = process.env.NODE_ENV === "production"
|
package/src/templates/nextjs.ts
CHANGED
|
@@ -37,7 +37,10 @@ export function makeNextjsCatchallPage(format: "ts" | "js"): string {
|
|
|
37
37
|
const ts = format === "ts";
|
|
38
38
|
return `
|
|
39
39
|
import * as React from "react";
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
PlasmicComponent,
|
|
42
|
+
extractPlasmicQueryData,
|
|
43
|
+
} from "@plasmicapp/loader-nextjs";
|
|
41
44
|
${ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
42
45
|
import {
|
|
43
46
|
ComponentRenderData,
|
|
@@ -50,9 +53,10 @@ export default function PlasmicLoaderPage(props${ifTs(
|
|
|
50
53
|
ts,
|
|
51
54
|
`: {
|
|
52
55
|
plasmicData?: ComponentRenderData;
|
|
56
|
+
queryCache?: Record<string, any>;
|
|
53
57
|
}`
|
|
54
58
|
)}) {
|
|
55
|
-
const { plasmicData } = props;
|
|
59
|
+
const { plasmicData, queryCache } = props;
|
|
56
60
|
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
57
61
|
return <Error statusCode={404} />;
|
|
58
62
|
}
|
|
@@ -60,6 +64,7 @@ export default function PlasmicLoaderPage(props${ifTs(
|
|
|
60
64
|
<PlasmicRootProvider
|
|
61
65
|
loader={PLASMIC}
|
|
62
66
|
prefetchedData={plasmicData}
|
|
67
|
+
prefetchedQueryData={queryCache}
|
|
63
68
|
>
|
|
64
69
|
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
65
70
|
</PlasmicRootProvider>
|
|
@@ -73,18 +78,18 @@ export const getStaticProps${ifTs(
|
|
|
73
78
|
const { catchall } = context.params ?? {};
|
|
74
79
|
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
|
|
75
80
|
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
76
|
-
if (plasmicData) {
|
|
77
|
-
return {
|
|
78
|
-
props: { plasmicData },
|
|
79
|
-
|
|
80
|
-
// Use revalidate if you want incremental static regeneration
|
|
81
|
-
revalidate: 60
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
81
|
+
if (!plasmicData) {
|
|
85
82
|
// non-Plasmic catch-all
|
|
86
|
-
props: {}
|
|
87
|
-
}
|
|
83
|
+
return { props: {} };
|
|
84
|
+
}
|
|
85
|
+
// Cache the necessary data fetched for the page
|
|
86
|
+
const queryCache = await extractPlasmicQueryData(
|
|
87
|
+
<PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
|
|
88
|
+
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
89
|
+
</PlasmicRootProvider>
|
|
90
|
+
);
|
|
91
|
+
// Use revalidate if you want incremental static regeneration
|
|
92
|
+
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
export const getStaticPaths${ifTs(ts, `: GetStaticPaths`)} = async () => {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|