create-plasmic-app 0.0.63 → 0.0.65
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.internal.md +6 -2
- package/cpa-out/.gitignore +15 -0
- package/cpa-out/gatsby-codegen-js/gatsby-browser.jsx +11 -0
- package/cpa-out/gatsby-codegen-js/gatsby-config.js +9 -0
- package/cpa-out/gatsby-codegen-js/gatsby-node.js +0 -0
- package/cpa-out/gatsby-codegen-js/gatsby-ssr.jsx +11 -0
- package/cpa-out/gatsby-codegen-js/package.json +26 -0
- package/cpa-out/gatsby-codegen-js/plasmic.json +79 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +206 -0
- package/cpa-out/gatsby-codegen-js/src/pages/404.js +4 -0
- package/cpa-out/gatsby-codegen-js/src/pages/index.jsx +39 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-browser.tsx +11 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-config.ts +14 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-node.ts +0 -0
- package/cpa-out/gatsby-codegen-ts/gatsby-ssr.tsx +11 -0
- package/cpa-out/gatsby-codegen-ts/package.json +34 -0
- package/cpa-out/gatsby-codegen-ts/plasmic.json +79 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +290 -0
- package/cpa-out/gatsby-codegen-ts/src/pages/404.js +4 -0
- package/cpa-out/gatsby-codegen-ts/src/pages/index.tsx +41 -0
- package/cpa-out/gatsby-codegen-ts/tsconfig.json +102 -0
- package/cpa-out/gatsby-loader-js/gatsby-config.js +25 -0
- package/cpa-out/gatsby-loader-js/gatsby-node.js +0 -0
- package/cpa-out/gatsby-loader-js/gatsby-ssr.jsx +44 -0
- package/cpa-out/gatsby-loader-js/package.json +24 -0
- package/cpa-out/gatsby-loader-js/src/pages/404.js +4 -0
- package/cpa-out/gatsby-loader-js/src/pages/plasmic-host.jsx +19 -0
- package/cpa-out/gatsby-loader-js/src/plasmic-init.js +18 -0
- package/cpa-out/gatsby-loader-js/src/templates/defaultPlasmicPage.jsx +44 -0
- package/cpa-out/gatsby-loader-ts/gatsby-config.ts +31 -0
- package/cpa-out/gatsby-loader-ts/gatsby-node.ts +0 -0
- package/cpa-out/gatsby-loader-ts/gatsby-ssr.tsx +44 -0
- package/cpa-out/gatsby-loader-ts/package.json +32 -0
- package/cpa-out/gatsby-loader-ts/src/pages/404.ts +4 -0
- package/cpa-out/gatsby-loader-ts/src/pages/plasmic-host.tsx +24 -0
- package/cpa-out/gatsby-loader-ts/src/plasmic-init.ts +19 -0
- package/cpa-out/gatsby-loader-ts/src/templates/defaultPlasmicPage.tsx +52 -0
- package/cpa-out/gatsby-loader-ts/tsconfig.json +102 -0
- package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +56 -0
- package/cpa-out/nextjs-app-loader-js/app/api/hello/route.js +3 -0
- package/cpa-out/nextjs-app-loader-js/app/layout.js +14 -0
- package/cpa-out/nextjs-app-loader-js/app/plasmic-host/page.jsx +6 -0
- package/cpa-out/nextjs-app-loader-js/next.config.js +13 -0
- package/cpa-out/nextjs-app-loader-js/package.json +19 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init-client.jsx +65 -0
- package/cpa-out/nextjs-app-loader-js/plasmic-init.js +16 -0
- package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +59 -0
- package/cpa-out/nextjs-app-loader-ts/app/api/hello/route.ts +3 -0
- package/cpa-out/nextjs-app-loader-ts/app/layout.tsx +18 -0
- package/cpa-out/nextjs-app-loader-ts/app/plasmic-host/page.tsx +6 -0
- package/cpa-out/nextjs-app-loader-ts/next.config.js +13 -0
- package/cpa-out/nextjs-app-loader-ts/package.json +23 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init-client.tsx +65 -0
- package/cpa-out/nextjs-app-loader-ts/plasmic-init.ts +16 -0
- package/cpa-out/nextjs-app-loader-ts/tsconfig.json +28 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +216 -0
- package/cpa-out/nextjs-pages-codegen-js/next.config.js +10 -0
- package/cpa-out/nextjs-pages-codegen-js/package.json +21 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/_app.jsx +11 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/api/hello.js +5 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/index.jsx +35 -0
- package/cpa-out/nextjs-pages-codegen-js/pages/plasmic-host.jsx +15 -0
- package/cpa-out/nextjs-pages-codegen-js/plasmic.json +79 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +297 -0
- package/cpa-out/nextjs-pages-codegen-ts/next.config.js +10 -0
- package/cpa-out/nextjs-pages-codegen-ts/package.json +25 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/_app.tsx +12 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/api/hello.ts +13 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/index.tsx +37 -0
- package/cpa-out/nextjs-pages-codegen-ts/pages/plasmic-host.tsx +15 -0
- package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +79 -0
- package/cpa-out/nextjs-pages-codegen-ts/tsconfig.json +23 -0
- package/cpa-out/nextjs-pages-loader-js/next.config.js +10 -0
- package/cpa-out/nextjs-pages-loader-js/package.json +19 -0
- package/cpa-out/nextjs-pages-loader-js/pages/[[...catchall]].jsx +66 -0
- package/cpa-out/nextjs-pages-loader-js/pages/api/hello.js +5 -0
- package/cpa-out/nextjs-pages-loader-js/pages/plasmic-host.jsx +7 -0
- package/cpa-out/nextjs-pages-loader-js/plasmic-init.js +25 -0
- package/cpa-out/nextjs-pages-loader-ts/next.config.js +10 -0
- package/cpa-out/nextjs-pages-loader-ts/package.json +23 -0
- package/cpa-out/nextjs-pages-loader-ts/pages/[[...catchall]].tsx +70 -0
- package/cpa-out/nextjs-pages-loader-ts/pages/api/hello.ts +13 -0
- package/cpa-out/nextjs-pages-loader-ts/pages/plasmic-host.tsx +7 -0
- package/cpa-out/nextjs-pages-loader-ts/plasmic-init.ts +25 -0
- package/cpa-out/nextjs-pages-loader-ts/tsconfig.json +23 -0
- package/cpa-out/react-codegen-js/package.json +41 -0
- package/cpa-out/react-codegen-js/plasmic.json +76 -0
- package/cpa-out/react-codegen-js/src/App.jsx +9 -0
- package/cpa-out/react-codegen-js/src/components/Homepage.jsx +26 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +196 -0
- package/cpa-out/react-codegen-js/src/index.js +17 -0
- package/cpa-out/react-codegen-js/src/reportWebVitals.js +13 -0
- package/cpa-out/react-codegen-js/src/setupTests.js +5 -0
- package/cpa-out/react-codegen-ts/package.json +46 -0
- package/cpa-out/react-codegen-ts/plasmic.json +76 -0
- package/cpa-out/react-codegen-ts/src/App.tsx +9 -0
- package/cpa-out/react-codegen-ts/src/components/Homepage.tsx +45 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +280 -0
- package/cpa-out/react-codegen-ts/src/index.tsx +19 -0
- package/cpa-out/react-codegen-ts/src/react-app-env.d.ts +1 -0
- package/cpa-out/react-codegen-ts/src/reportWebVitals.ts +15 -0
- package/cpa-out/react-codegen-ts/src/setupTests.ts +5 -0
- package/cpa-out/react-codegen-ts/tsconfig.json +26 -0
- package/cpa-out/react-loader-js/package.json +41 -0
- package/cpa-out/react-loader-js/plasmic.json +76 -0
- package/cpa-out/react-loader-js/src/App.jsx +9 -0
- package/cpa-out/react-loader-js/src/components/Homepage.jsx +26 -0
- package/cpa-out/react-loader-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
- package/cpa-out/react-loader-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +196 -0
- package/cpa-out/react-loader-js/src/index.js +17 -0
- package/cpa-out/react-loader-js/src/reportWebVitals.js +13 -0
- package/cpa-out/react-loader-js/src/setupTests.js +5 -0
- package/cpa-out/react-loader-ts/package.json +46 -0
- package/cpa-out/react-loader-ts/plasmic.json +76 -0
- package/cpa-out/react-loader-ts/src/App.tsx +9 -0
- package/cpa-out/react-loader-ts/src/components/Homepage.tsx +45 -0
- package/cpa-out/react-loader-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
- package/cpa-out/react-loader-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +280 -0
- package/cpa-out/react-loader-ts/src/index.tsx +19 -0
- package/cpa-out/react-loader-ts/src/react-app-env.d.ts +1 -0
- package/cpa-out/react-loader-ts/src/reportWebVitals.ts +15 -0
- package/cpa-out/react-loader-ts/src/setupTests.ts +5 -0
- package/cpa-out/react-loader-ts/tsconfig.json +26 -0
- package/dist/gatsby/gatsby.d.ts +6 -0
- package/dist/{strategies → gatsby}/gatsby.js +26 -29
- package/dist/gatsby/template.d.ts +11 -0
- package/dist/{templates/gatsby.js → gatsby/template.js} +34 -42
- package/dist/index.d.ts +1 -1
- package/dist/index.js +57 -27
- package/dist/lib.d.ts +3 -4
- package/dist/lib.js +22 -12
- package/dist/nextjs/nextjs.d.ts +2 -0
- package/dist/nextjs/nextjs.js +155 -0
- package/dist/nextjs/templates/app-loader/catchall-page.d.ts +2 -0
- package/dist/nextjs/templates/app-loader/catchall-page.js +67 -0
- package/dist/nextjs/templates/app-loader/plasmic-host.d.ts +1 -0
- package/dist/nextjs/templates/app-loader/plasmic-host.js +13 -0
- package/dist/nextjs/templates/app-loader/plasmic-init-client.d.ts +2 -0
- package/dist/nextjs/templates/app-loader/plasmic-init-client.js +73 -0
- package/dist/nextjs/templates/app-loader/plasmic-init.d.ts +1 -0
- package/dist/nextjs/templates/app-loader/plasmic-init.js +23 -0
- package/dist/nextjs/templates/pages-codegen/app.d.ts +2 -0
- package/dist/nextjs/templates/pages-codegen/app.js +20 -0
- package/dist/nextjs/templates/pages-codegen/plasmic-host.d.ts +1 -0
- package/dist/nextjs/templates/pages-codegen/plasmic-host.js +22 -0
- package/dist/nextjs/templates/pages-loader/catchall-page.d.ts +2 -0
- package/dist/nextjs/templates/pages-loader/catchall-page.js +77 -0
- package/dist/nextjs/templates/pages-loader/plasmic-host.d.ts +1 -0
- package/dist/nextjs/templates/pages-loader/plasmic-host.js +14 -0
- package/dist/nextjs/templates/pages-loader/plasmic-init.d.ts +1 -0
- package/dist/nextjs/templates/pages-loader/plasmic-init.js +32 -0
- package/dist/react/react.d.ts +2 -0
- package/dist/{strategies → react}/react.js +10 -10
- package/dist/templates/readme.d.ts +2 -2
- package/dist/templates/readme.js +5 -4
- package/dist/templates/welcomePage.d.ts +2 -2
- package/dist/templates/welcomePage.js +5 -5
- package/dist/utils/file-utils.d.ts +2 -2
- package/dist/utils/file-utils.js +3 -3
- package/dist/{strategies/types.d.ts → utils/strategy.d.ts} +16 -14
- package/dist/utils/types.d.ts +9 -0
- package/dist/utils/types.js +7 -0
- package/package.json +4 -3
- package/run-cpa.ts +151 -0
- package/src/{strategies → gatsby}/gatsby.ts +28 -46
- package/src/{templates/gatsby.ts → gatsby/template.ts} +41 -51
- package/src/index.ts +86 -56
- package/src/lib.ts +30 -15
- package/src/nextjs/nextjs.ts +180 -0
- package/src/nextjs/templates/app-loader/catchall-page.ts +71 -0
- package/src/nextjs/templates/app-loader/plasmic-host.ts +9 -0
- package/src/nextjs/templates/app-loader/plasmic-init-client.ts +74 -0
- package/src/nextjs/templates/app-loader/plasmic-init.ts +22 -0
- package/src/nextjs/templates/pages-codegen/app.ts +24 -0
- package/src/nextjs/templates/pages-codegen/plasmic-host.ts +18 -0
- package/src/nextjs/templates/pages-loader/catchall-page.ts +81 -0
- package/src/nextjs/templates/pages-loader/plasmic-host.ts +10 -0
- package/src/nextjs/templates/pages-loader/plasmic-init.ts +31 -0
- package/src/{strategies → react}/react.ts +8 -10
- package/src/templates/readme.ts +5 -5
- package/src/templates/welcomePage.ts +6 -7
- package/src/utils/file-utils.ts +4 -4
- package/src/utils/strategy.ts +48 -0
- package/src/utils/types.ts +12 -0
- package/dist/strategies/gatsby.d.ts +0 -7
- package/dist/strategies/index.d.ts +0 -2
- package/dist/strategies/index.js +0 -22
- package/dist/strategies/nextjs.d.ts +0 -3
- package/dist/strategies/nextjs.js +0 -104
- package/dist/strategies/react.d.ts +0 -3
- package/dist/templates/gatsby.d.ts +0 -11
- package/dist/templates/nextjs.d.ts +0 -5
- package/dist/templates/nextjs.js +0 -162
- package/src/strategies/index.ts +0 -21
- package/src/strategies/nextjs.ts +0 -131
- package/src/strategies/types.ts +0 -42
- package/src/templates/nextjs.ts +0 -170
- /package/dist/{strategies/common.d.ts → utils/codegen.d.ts} +0 -0
- /package/dist/{strategies/common.js → utils/codegen.js} +0 -0
- /package/dist/{strategies/types.js → utils/strategy.js} +0 -0
- /package/src/{strategies/common.ts → utils/codegen.ts} +0 -0
package/dist/templates/nextjs.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapAppRootForCodegen = exports.makeNextjsHostPage = exports.makeNextjsCatchallPage = exports.makeNextjsInitPage = void 0;
|
|
4
|
-
const file_utils_1 = require("../utils/file-utils");
|
|
5
|
-
const makeNextjsInitPage = (projectId, projectApiToken) => `
|
|
6
|
-
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs";
|
|
7
|
-
|
|
8
|
-
export const PLASMIC = initPlasmicLoader({
|
|
9
|
-
projects: [
|
|
10
|
-
{
|
|
11
|
-
id: "${projectId}",
|
|
12
|
-
token: "${projectApiToken}",
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
|
|
16
|
-
// By default Plasmic will use the last published version of your project.
|
|
17
|
-
// For development, you can set preview to true, which will use the unpublished
|
|
18
|
-
// project, allowing you to see your designs without publishing. Please
|
|
19
|
-
// only use this for development, as this is significantly slower.
|
|
20
|
-
preview: false,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// You can register any code components that you want to use here; see
|
|
24
|
-
// https://docs.plasmic.app/learn/code-components-ref/
|
|
25
|
-
// And configure your Plasmic project to use the host url pointing at
|
|
26
|
-
// the /plasmic-host page of your nextjs app (for example,
|
|
27
|
-
// http://localhost:3000/plasmic-host). See
|
|
28
|
-
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
29
|
-
|
|
30
|
-
// PLASMIC.registerComponent(...);
|
|
31
|
-
`.trim();
|
|
32
|
-
exports.makeNextjsInitPage = makeNextjsInitPage;
|
|
33
|
-
function makeNextjsCatchallPage(format) {
|
|
34
|
-
const ts = format === "ts";
|
|
35
|
-
return `
|
|
36
|
-
import * as React from "react";
|
|
37
|
-
import {
|
|
38
|
-
PlasmicComponent,
|
|
39
|
-
extractPlasmicQueryData,
|
|
40
|
-
ComponentRenderData,
|
|
41
|
-
PlasmicRootProvider,
|
|
42
|
-
} from "@plasmicapp/loader-nextjs";
|
|
43
|
-
${(0, file_utils_1.ifTs)(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
44
|
-
import Error from "next/error";
|
|
45
|
-
import { useRouter } from "next/router";
|
|
46
|
-
import { PLASMIC } from "../plasmic-init";
|
|
47
|
-
|
|
48
|
-
export default function PlasmicLoaderPage(props${(0, file_utils_1.ifTs)(ts, `: {
|
|
49
|
-
plasmicData?: ComponentRenderData;
|
|
50
|
-
queryCache?: Record<string, any>;
|
|
51
|
-
}`)}) {
|
|
52
|
-
const { plasmicData, queryCache } = props;
|
|
53
|
-
const router = useRouter();
|
|
54
|
-
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
55
|
-
return <Error statusCode={404} />;
|
|
56
|
-
}
|
|
57
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
58
|
-
return (
|
|
59
|
-
<PlasmicRootProvider
|
|
60
|
-
loader={PLASMIC}
|
|
61
|
-
prefetchedData={plasmicData}
|
|
62
|
-
prefetchedQueryData={queryCache}
|
|
63
|
-
pageParams={pageMeta.params}
|
|
64
|
-
pageQuery={router.query}
|
|
65
|
-
>
|
|
66
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
67
|
-
</PlasmicRootProvider>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const getStaticProps${(0, file_utils_1.ifTs)(ts, `: GetStaticProps`)} = async (context) => {
|
|
72
|
-
const { catchall } = context.params ?? {};
|
|
73
|
-
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
|
|
74
|
-
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
75
|
-
if (!plasmicData) {
|
|
76
|
-
// non-Plasmic catch-all
|
|
77
|
-
return { props: {} };
|
|
78
|
-
}
|
|
79
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
80
|
-
// Cache the necessary data fetched for the page
|
|
81
|
-
const queryCache = await extractPlasmicQueryData(
|
|
82
|
-
<PlasmicRootProvider
|
|
83
|
-
loader={PLASMIC}
|
|
84
|
-
prefetchedData={plasmicData}
|
|
85
|
-
pageParams={pageMeta.params}
|
|
86
|
-
>
|
|
87
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
88
|
-
</PlasmicRootProvider>
|
|
89
|
-
);
|
|
90
|
-
// Use revalidate if you want incremental static regeneration
|
|
91
|
-
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export const getStaticPaths${(0, file_utils_1.ifTs)(ts, `: GetStaticPaths`)} = async () => {
|
|
95
|
-
const pageModules = await PLASMIC.fetchPages();
|
|
96
|
-
return {
|
|
97
|
-
paths: pageModules.map((mod) => ({
|
|
98
|
-
params: {
|
|
99
|
-
catchall: mod.path.substring(1).split("/"),
|
|
100
|
-
},
|
|
101
|
-
})),
|
|
102
|
-
fallback: "blocking",
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
`.trim();
|
|
106
|
-
}
|
|
107
|
-
exports.makeNextjsCatchallPage = makeNextjsCatchallPage;
|
|
108
|
-
function makeNextjsHostPage(scheme) {
|
|
109
|
-
const commonImports = `
|
|
110
|
-
import * as React from 'react';
|
|
111
|
-
import Script from 'next/script';
|
|
112
|
-
`.trim();
|
|
113
|
-
if (scheme === "loader") {
|
|
114
|
-
return `
|
|
115
|
-
${commonImports}
|
|
116
|
-
import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs';
|
|
117
|
-
import { PLASMIC } from '../plasmic-init';
|
|
118
|
-
|
|
119
|
-
export default function PlasmicHost() {
|
|
120
|
-
return PLASMIC && <PlasmicCanvasHost />;
|
|
121
|
-
}
|
|
122
|
-
`;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
return `
|
|
126
|
-
${commonImports}
|
|
127
|
-
import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/host';
|
|
128
|
-
|
|
129
|
-
// You can register any code components that you want to use here; see
|
|
130
|
-
// https://docs.plasmic.app/learn/code-components-ref/
|
|
131
|
-
// And configure your Plasmic project to use the host url pointing at
|
|
132
|
-
// the /plasmic-host page of your nextjs app (for example,
|
|
133
|
-
// http://localhost:3000/plasmic-host). See
|
|
134
|
-
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
135
|
-
|
|
136
|
-
// registerComponent(...)
|
|
137
|
-
|
|
138
|
-
export default function PlasmicHost() {
|
|
139
|
-
return <PlasmicCanvasHost />;
|
|
140
|
-
}
|
|
141
|
-
`;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.makeNextjsHostPage = makeNextjsHostPage;
|
|
145
|
-
function wrapAppRootForCodegen() {
|
|
146
|
-
return `
|
|
147
|
-
import '../styles/globals.css'
|
|
148
|
-
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
149
|
-
import Head from "next/head";
|
|
150
|
-
|
|
151
|
-
function MyApp({ Component, pageProps }) {
|
|
152
|
-
return (
|
|
153
|
-
<PlasmicRootProvider Head={Head}>
|
|
154
|
-
<Component {...pageProps} />
|
|
155
|
-
</PlasmicRootProvider>
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export default MyApp
|
|
160
|
-
`;
|
|
161
|
-
}
|
|
162
|
-
exports.wrapAppRootForCodegen = wrapAppRootForCodegen;
|
package/src/strategies/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import gatsbyStrategy from "./gatsby";
|
|
2
|
-
import nextjsStrategy from "./nextjs";
|
|
3
|
-
import reactStrategy from "./react";
|
|
4
|
-
import { CPAStrategy } from "./types";
|
|
5
|
-
|
|
6
|
-
const strategies: Record<string, CPAStrategy> = {
|
|
7
|
-
nextjs: nextjsStrategy,
|
|
8
|
-
gatsby: gatsbyStrategy,
|
|
9
|
-
react: reactStrategy,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const getCPAStrategy = (
|
|
13
|
-
platform: string,
|
|
14
|
-
errorMsg?: string
|
|
15
|
-
): CPAStrategy => {
|
|
16
|
-
if (!Object.keys(strategies).includes(platform)) {
|
|
17
|
-
const msg = errorMsg || `Unrecognized platform: ${platform}`;
|
|
18
|
-
throw new Error(msg);
|
|
19
|
-
}
|
|
20
|
-
return strategies[platform];
|
|
21
|
-
};
|
package/src/strategies/nextjs.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import {
|
|
4
|
-
makeNextjsCatchallPage,
|
|
5
|
-
makeNextjsHostPage,
|
|
6
|
-
makeNextjsInitPage,
|
|
7
|
-
wrapAppRootForCodegen,
|
|
8
|
-
} from "../templates/nextjs";
|
|
9
|
-
import { spawnOrFail } from "../utils/cmd-utils";
|
|
10
|
-
import { deleteGlob, overwriteIndex } from "../utils/file-utils";
|
|
11
|
-
import { ensure } from "../utils/lang-utils";
|
|
12
|
-
import { installUpgrade } from "../utils/npm-utils";
|
|
13
|
-
import { installCodegenDeps, runCodegenSync } from "./common";
|
|
14
|
-
import { CPAStrategy } from "./types";
|
|
15
|
-
|
|
16
|
-
const nextjsStrategy: CPAStrategy = {
|
|
17
|
-
create: async (args) => {
|
|
18
|
-
const { projectPath, template, useTypescript } = args;
|
|
19
|
-
const createCommand = `npx create-next-app@latest ${
|
|
20
|
-
useTypescript ? "--ts" : "--js"
|
|
21
|
-
} --eslint --no-src-dir --no-experimental-app --import-alias "@/*" ${projectPath}`;
|
|
22
|
-
const templateArg = template ? ` --template ${template}` : "";
|
|
23
|
-
|
|
24
|
-
// Default Next.js starter already supports Typescript
|
|
25
|
-
// See where we `touch tsconfig.json` later on
|
|
26
|
-
await spawnOrFail(`${createCommand}${templateArg}`);
|
|
27
|
-
},
|
|
28
|
-
installDeps: async ({ scheme, projectPath }) => {
|
|
29
|
-
if (scheme === "loader") {
|
|
30
|
-
return await installUpgrade("@plasmicapp/loader-nextjs", {
|
|
31
|
-
workingDir: projectPath,
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
return await installCodegenDeps({ projectPath });
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
overwriteConfig: async (args) => {
|
|
38
|
-
const { projectPath, scheme } = args;
|
|
39
|
-
const nextjsConfigFile = path.join(projectPath, "next.config.js");
|
|
40
|
-
if (scheme === "codegen") {
|
|
41
|
-
await fs.writeFile(
|
|
42
|
-
nextjsConfigFile,
|
|
43
|
-
`
|
|
44
|
-
module.exports = {
|
|
45
|
-
eslint: {
|
|
46
|
-
ignoreDuringBuilds: true,
|
|
47
|
-
},
|
|
48
|
-
trailingSlash: true,
|
|
49
|
-
// Your NextJS config.
|
|
50
|
-
};
|
|
51
|
-
`
|
|
52
|
-
);
|
|
53
|
-
} else {
|
|
54
|
-
await fs.writeFile(
|
|
55
|
-
nextjsConfigFile,
|
|
56
|
-
`
|
|
57
|
-
/** @type {import('next').NextConfig} */
|
|
58
|
-
const nextConfig = {
|
|
59
|
-
// Turn off React StrictMode for now, as react-aria (used by Plasmic)
|
|
60
|
-
// has some troubles with it. See
|
|
61
|
-
// https://github.com/adobe/react-spectrum/labels/strict%20mode
|
|
62
|
-
reactStrictMode: false,
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = nextConfig
|
|
66
|
-
`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
generateFiles: async (args) => {
|
|
71
|
-
// this is supposed to be called for loader case, so we are supposed to remove
|
|
72
|
-
// all the files from pages/ since we have inserted a optional catch all
|
|
73
|
-
const {
|
|
74
|
-
projectPath,
|
|
75
|
-
scheme,
|
|
76
|
-
useTypescript,
|
|
77
|
-
projectId,
|
|
78
|
-
projectApiToken,
|
|
79
|
-
} = args;
|
|
80
|
-
|
|
81
|
-
// Always start fresh
|
|
82
|
-
const pagesPath = path.join(projectPath, "pages");
|
|
83
|
-
deleteGlob(path.join(pagesPath, `*.*`));
|
|
84
|
-
|
|
85
|
-
const hostPage = path.join(
|
|
86
|
-
pagesPath,
|
|
87
|
-
`plasmic-host.${useTypescript ? "tsx" : "jsx"}`
|
|
88
|
-
);
|
|
89
|
-
await fs.writeFile(hostPage, makeNextjsHostPage(scheme));
|
|
90
|
-
|
|
91
|
-
if (scheme === "loader") {
|
|
92
|
-
const initFile = path.join(
|
|
93
|
-
projectPath,
|
|
94
|
-
`plasmic-init.${useTypescript ? "ts" : "js"}`
|
|
95
|
-
);
|
|
96
|
-
await fs.writeFile(
|
|
97
|
-
initFile,
|
|
98
|
-
makeNextjsInitPage(projectId, ensure(projectApiToken))
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
// Write catch-all page for loader
|
|
102
|
-
const loaderPage = path.join(
|
|
103
|
-
pagesPath,
|
|
104
|
-
`[[...catchall]].${useTypescript ? "tsx" : "jsx"}`
|
|
105
|
-
);
|
|
106
|
-
await fs.writeFile(
|
|
107
|
-
loaderPage,
|
|
108
|
-
makeNextjsCatchallPage(useTypescript ? "ts" : "js")
|
|
109
|
-
);
|
|
110
|
-
} else {
|
|
111
|
-
await runCodegenSync({
|
|
112
|
-
projectId,
|
|
113
|
-
projectApiToken,
|
|
114
|
-
projectPath,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// Overwrite the index file
|
|
118
|
-
await overwriteIndex(projectPath, "nextjs", scheme);
|
|
119
|
-
|
|
120
|
-
// Overwrite the wrapper files to wrap PlasmicRootProvider
|
|
121
|
-
const appFilePath = path.join(projectPath, "pages", `_app.js`);
|
|
122
|
-
await fs.writeFile(appFilePath, wrapAppRootForCodegen());
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
build: async (args) => {
|
|
126
|
-
const { npmRunCmd, projectPath } = args;
|
|
127
|
-
await spawnOrFail(`${npmRunCmd} build`, projectPath);
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export default nextjsStrategy;
|
package/src/strategies/types.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { CodeScheme } from "..";
|
|
2
|
-
|
|
3
|
-
interface CreateArgs {
|
|
4
|
-
projectPath: string;
|
|
5
|
-
template?: string;
|
|
6
|
-
useTypescript: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface ConfigArgs {
|
|
10
|
-
projectId: string;
|
|
11
|
-
projectPath: string;
|
|
12
|
-
useTypescript: boolean;
|
|
13
|
-
scheme: CodeScheme;
|
|
14
|
-
projectApiToken: string | undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface GenerateFilesArgs {
|
|
18
|
-
projectPath: string;
|
|
19
|
-
useTypescript: boolean;
|
|
20
|
-
scheme: CodeScheme;
|
|
21
|
-
projectId: string;
|
|
22
|
-
projectApiToken: string | undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface BuildArgs {
|
|
26
|
-
projectPath: string;
|
|
27
|
-
npmRunCmd: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface InstallArgs {
|
|
31
|
-
scheme: CodeScheme;
|
|
32
|
-
projectPath: string;
|
|
33
|
-
useTypescript: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface CPAStrategy {
|
|
37
|
-
create: (args: CreateArgs) => Promise<void>;
|
|
38
|
-
installDeps: (args: InstallArgs) => Promise<boolean>;
|
|
39
|
-
overwriteConfig: (args: ConfigArgs) => Promise<void>;
|
|
40
|
-
generateFiles: (args: GenerateFilesArgs) => Promise<void>;
|
|
41
|
-
build: (args: BuildArgs) => Promise<void>;
|
|
42
|
-
}
|
package/src/templates/nextjs.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { CodeScheme } from "..";
|
|
2
|
-
import { ifTs } from "../utils/file-utils";
|
|
3
|
-
|
|
4
|
-
export const makeNextjsInitPage = (
|
|
5
|
-
projectId: string,
|
|
6
|
-
projectApiToken: string
|
|
7
|
-
): string =>
|
|
8
|
-
`
|
|
9
|
-
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs";
|
|
10
|
-
|
|
11
|
-
export const PLASMIC = initPlasmicLoader({
|
|
12
|
-
projects: [
|
|
13
|
-
{
|
|
14
|
-
id: "${projectId}",
|
|
15
|
-
token: "${projectApiToken}",
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
|
|
19
|
-
// By default Plasmic will use the last published version of your project.
|
|
20
|
-
// For development, you can set preview to true, which will use the unpublished
|
|
21
|
-
// project, allowing you to see your designs without publishing. Please
|
|
22
|
-
// only use this for development, as this is significantly slower.
|
|
23
|
-
preview: false,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// You can register any code components that you want to use here; see
|
|
27
|
-
// https://docs.plasmic.app/learn/code-components-ref/
|
|
28
|
-
// And configure your Plasmic project to use the host url pointing at
|
|
29
|
-
// the /plasmic-host page of your nextjs app (for example,
|
|
30
|
-
// http://localhost:3000/plasmic-host). See
|
|
31
|
-
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
32
|
-
|
|
33
|
-
// PLASMIC.registerComponent(...);
|
|
34
|
-
`.trim();
|
|
35
|
-
|
|
36
|
-
export function makeNextjsCatchallPage(format: "ts" | "js"): string {
|
|
37
|
-
const ts = format === "ts";
|
|
38
|
-
return `
|
|
39
|
-
import * as React from "react";
|
|
40
|
-
import {
|
|
41
|
-
PlasmicComponent,
|
|
42
|
-
extractPlasmicQueryData,
|
|
43
|
-
ComponentRenderData,
|
|
44
|
-
PlasmicRootProvider,
|
|
45
|
-
} from "@plasmicapp/loader-nextjs";
|
|
46
|
-
${ifTs(ts, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
47
|
-
import Error from "next/error";
|
|
48
|
-
import { useRouter } from "next/router";
|
|
49
|
-
import { PLASMIC } from "../plasmic-init";
|
|
50
|
-
|
|
51
|
-
export default function PlasmicLoaderPage(props${ifTs(
|
|
52
|
-
ts,
|
|
53
|
-
`: {
|
|
54
|
-
plasmicData?: ComponentRenderData;
|
|
55
|
-
queryCache?: Record<string, any>;
|
|
56
|
-
}`
|
|
57
|
-
)}) {
|
|
58
|
-
const { plasmicData, queryCache } = props;
|
|
59
|
-
const router = useRouter();
|
|
60
|
-
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
61
|
-
return <Error statusCode={404} />;
|
|
62
|
-
}
|
|
63
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
64
|
-
return (
|
|
65
|
-
<PlasmicRootProvider
|
|
66
|
-
loader={PLASMIC}
|
|
67
|
-
prefetchedData={plasmicData}
|
|
68
|
-
prefetchedQueryData={queryCache}
|
|
69
|
-
pageParams={pageMeta.params}
|
|
70
|
-
pageQuery={router.query}
|
|
71
|
-
>
|
|
72
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
73
|
-
</PlasmicRootProvider>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const getStaticProps${ifTs(
|
|
78
|
-
ts,
|
|
79
|
-
`: GetStaticProps`
|
|
80
|
-
)} = async (context) => {
|
|
81
|
-
const { catchall } = context.params ?? {};
|
|
82
|
-
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
|
|
83
|
-
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
84
|
-
if (!plasmicData) {
|
|
85
|
-
// non-Plasmic catch-all
|
|
86
|
-
return { props: {} };
|
|
87
|
-
}
|
|
88
|
-
const pageMeta = plasmicData.entryCompMetas[0];
|
|
89
|
-
// Cache the necessary data fetched for the page
|
|
90
|
-
const queryCache = await extractPlasmicQueryData(
|
|
91
|
-
<PlasmicRootProvider
|
|
92
|
-
loader={PLASMIC}
|
|
93
|
-
prefetchedData={plasmicData}
|
|
94
|
-
pageParams={pageMeta.params}
|
|
95
|
-
>
|
|
96
|
-
<PlasmicComponent component={pageMeta.displayName} />
|
|
97
|
-
</PlasmicRootProvider>
|
|
98
|
-
);
|
|
99
|
-
// Use revalidate if you want incremental static regeneration
|
|
100
|
-
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export const getStaticPaths${ifTs(ts, `: GetStaticPaths`)} = async () => {
|
|
104
|
-
const pageModules = await PLASMIC.fetchPages();
|
|
105
|
-
return {
|
|
106
|
-
paths: pageModules.map((mod) => ({
|
|
107
|
-
params: {
|
|
108
|
-
catchall: mod.path.substring(1).split("/"),
|
|
109
|
-
},
|
|
110
|
-
})),
|
|
111
|
-
fallback: "blocking",
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
`.trim();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function makeNextjsHostPage(scheme: CodeScheme): string {
|
|
118
|
-
const commonImports = `
|
|
119
|
-
import * as React from 'react';
|
|
120
|
-
import Script from 'next/script';
|
|
121
|
-
`.trim();
|
|
122
|
-
|
|
123
|
-
if (scheme === "loader") {
|
|
124
|
-
return `
|
|
125
|
-
${commonImports}
|
|
126
|
-
import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs';
|
|
127
|
-
import { PLASMIC } from '../plasmic-init';
|
|
128
|
-
|
|
129
|
-
export default function PlasmicHost() {
|
|
130
|
-
return PLASMIC && <PlasmicCanvasHost />;
|
|
131
|
-
}
|
|
132
|
-
`;
|
|
133
|
-
} else {
|
|
134
|
-
return `
|
|
135
|
-
${commonImports}
|
|
136
|
-
import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/host';
|
|
137
|
-
|
|
138
|
-
// You can register any code components that you want to use here; see
|
|
139
|
-
// https://docs.plasmic.app/learn/code-components-ref/
|
|
140
|
-
// And configure your Plasmic project to use the host url pointing at
|
|
141
|
-
// the /plasmic-host page of your nextjs app (for example,
|
|
142
|
-
// http://localhost:3000/plasmic-host). See
|
|
143
|
-
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
144
|
-
|
|
145
|
-
// registerComponent(...)
|
|
146
|
-
|
|
147
|
-
export default function PlasmicHost() {
|
|
148
|
-
return <PlasmicCanvasHost />;
|
|
149
|
-
}
|
|
150
|
-
`;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function wrapAppRootForCodegen(): string {
|
|
155
|
-
return `
|
|
156
|
-
import '../styles/globals.css'
|
|
157
|
-
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
158
|
-
import Head from "next/head";
|
|
159
|
-
|
|
160
|
-
function MyApp({ Component, pageProps }) {
|
|
161
|
-
return (
|
|
162
|
-
<PlasmicRootProvider Head={Head}>
|
|
163
|
-
<Component {...pageProps} />
|
|
164
|
-
</PlasmicRootProvider>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export default MyApp
|
|
169
|
-
`;
|
|
170
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|