create-plasmic-app 0.0.63 → 0.0.64

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.
Files changed (209) hide show
  1. package/README.internal.md +6 -2
  2. package/cpa-out/.gitignore +15 -0
  3. package/cpa-out/gatsby-codegen-js/gatsby-browser.jsx +11 -0
  4. package/cpa-out/gatsby-codegen-js/gatsby-config.js +9 -0
  5. package/cpa-out/gatsby-codegen-js/gatsby-node.js +0 -0
  6. package/cpa-out/gatsby-codegen-js/gatsby-ssr.jsx +11 -0
  7. package/cpa-out/gatsby-codegen-js/package.json +26 -0
  8. package/cpa-out/gatsby-codegen-js/plasmic.json +79 -0
  9. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
  10. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +206 -0
  11. package/cpa-out/gatsby-codegen-js/src/pages/404.js +4 -0
  12. package/cpa-out/gatsby-codegen-js/src/pages/index.jsx +39 -0
  13. package/cpa-out/gatsby-codegen-ts/gatsby-browser.tsx +11 -0
  14. package/cpa-out/gatsby-codegen-ts/gatsby-config.ts +14 -0
  15. package/cpa-out/gatsby-codegen-ts/gatsby-node.ts +0 -0
  16. package/cpa-out/gatsby-codegen-ts/gatsby-ssr.tsx +11 -0
  17. package/cpa-out/gatsby-codegen-ts/package.json +34 -0
  18. package/cpa-out/gatsby-codegen-ts/plasmic.json +79 -0
  19. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
  20. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +290 -0
  21. package/cpa-out/gatsby-codegen-ts/src/pages/404.js +4 -0
  22. package/cpa-out/gatsby-codegen-ts/src/pages/index.tsx +41 -0
  23. package/cpa-out/gatsby-codegen-ts/tsconfig.json +102 -0
  24. package/cpa-out/gatsby-loader-js/gatsby-config.js +25 -0
  25. package/cpa-out/gatsby-loader-js/gatsby-node.js +0 -0
  26. package/cpa-out/gatsby-loader-js/gatsby-ssr.jsx +44 -0
  27. package/cpa-out/gatsby-loader-js/package.json +24 -0
  28. package/cpa-out/gatsby-loader-js/src/pages/404.js +4 -0
  29. package/cpa-out/gatsby-loader-js/src/pages/plasmic-host.jsx +19 -0
  30. package/cpa-out/gatsby-loader-js/src/plasmic-init.js +18 -0
  31. package/cpa-out/gatsby-loader-js/src/templates/defaultPlasmicPage.jsx +44 -0
  32. package/cpa-out/gatsby-loader-ts/gatsby-config.ts +31 -0
  33. package/cpa-out/gatsby-loader-ts/gatsby-node.ts +0 -0
  34. package/cpa-out/gatsby-loader-ts/gatsby-ssr.tsx +44 -0
  35. package/cpa-out/gatsby-loader-ts/package.json +32 -0
  36. package/cpa-out/gatsby-loader-ts/src/pages/404.ts +4 -0
  37. package/cpa-out/gatsby-loader-ts/src/pages/plasmic-host.tsx +24 -0
  38. package/cpa-out/gatsby-loader-ts/src/plasmic-init.ts +19 -0
  39. package/cpa-out/gatsby-loader-ts/src/templates/defaultPlasmicPage.tsx +52 -0
  40. package/cpa-out/gatsby-loader-ts/tsconfig.json +102 -0
  41. package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +56 -0
  42. package/cpa-out/nextjs-app-loader-js/app/head.js +10 -0
  43. package/cpa-out/nextjs-app-loader-js/app/layout.js +14 -0
  44. package/cpa-out/nextjs-app-loader-js/app/plasmic-host/page.jsx +6 -0
  45. package/cpa-out/nextjs-app-loader-js/next.config.js +13 -0
  46. package/cpa-out/nextjs-app-loader-js/package.json +20 -0
  47. package/cpa-out/nextjs-app-loader-js/pages/api/hello.js +5 -0
  48. package/cpa-out/nextjs-app-loader-js/plasmic-init-client.jsx +65 -0
  49. package/cpa-out/nextjs-app-loader-js/plasmic-init.js +16 -0
  50. package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +59 -0
  51. package/cpa-out/nextjs-app-loader-ts/app/head.tsx +10 -0
  52. package/cpa-out/nextjs-app-loader-ts/app/layout.tsx +18 -0
  53. package/cpa-out/nextjs-app-loader-ts/app/plasmic-host/page.tsx +6 -0
  54. package/cpa-out/nextjs-app-loader-ts/next.config.js +13 -0
  55. package/cpa-out/nextjs-app-loader-ts/package.json +24 -0
  56. package/cpa-out/nextjs-app-loader-ts/pages/api/hello.ts +13 -0
  57. package/cpa-out/nextjs-app-loader-ts/plasmic-init-client.tsx +65 -0
  58. package/cpa-out/nextjs-app-loader-ts/plasmic-init.ts +16 -0
  59. package/cpa-out/nextjs-app-loader-ts/tsconfig.json +29 -0
  60. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
  61. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +205 -0
  62. package/cpa-out/nextjs-pages-codegen-js/next.config.js +10 -0
  63. package/cpa-out/nextjs-pages-codegen-js/package.json +22 -0
  64. package/cpa-out/nextjs-pages-codegen-js/pages/_app.jsx +11 -0
  65. package/cpa-out/nextjs-pages-codegen-js/pages/api/hello.js +5 -0
  66. package/cpa-out/nextjs-pages-codegen-js/pages/index.jsx +35 -0
  67. package/cpa-out/nextjs-pages-codegen-js/pages/plasmic-host.jsx +15 -0
  68. package/cpa-out/nextjs-pages-codegen-js/plasmic.json +79 -0
  69. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
  70. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +287 -0
  71. package/cpa-out/nextjs-pages-codegen-ts/next.config.js +10 -0
  72. package/cpa-out/nextjs-pages-codegen-ts/package.json +26 -0
  73. package/cpa-out/nextjs-pages-codegen-ts/pages/_app.tsx +12 -0
  74. package/cpa-out/nextjs-pages-codegen-ts/pages/api/hello.ts +13 -0
  75. package/cpa-out/nextjs-pages-codegen-ts/pages/index.tsx +37 -0
  76. package/cpa-out/nextjs-pages-codegen-ts/pages/plasmic-host.tsx +15 -0
  77. package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +79 -0
  78. package/cpa-out/nextjs-pages-codegen-ts/tsconfig.json +24 -0
  79. package/cpa-out/nextjs-pages-loader-js/next.config.js +10 -0
  80. package/cpa-out/nextjs-pages-loader-js/package.json +20 -0
  81. package/cpa-out/nextjs-pages-loader-js/pages/[[...catchall]].jsx +66 -0
  82. package/cpa-out/nextjs-pages-loader-js/pages/api/hello.js +5 -0
  83. package/cpa-out/nextjs-pages-loader-js/pages/plasmic-host.jsx +7 -0
  84. package/cpa-out/nextjs-pages-loader-js/plasmic-init.js +25 -0
  85. package/cpa-out/nextjs-pages-loader-ts/next.config.js +10 -0
  86. package/cpa-out/nextjs-pages-loader-ts/package.json +24 -0
  87. package/cpa-out/nextjs-pages-loader-ts/pages/[[...catchall]].tsx +70 -0
  88. package/cpa-out/nextjs-pages-loader-ts/pages/api/hello.ts +13 -0
  89. package/cpa-out/nextjs-pages-loader-ts/pages/plasmic-host.tsx +7 -0
  90. package/cpa-out/nextjs-pages-loader-ts/plasmic-init.ts +25 -0
  91. package/cpa-out/nextjs-pages-loader-ts/tsconfig.json +24 -0
  92. package/cpa-out/react-codegen-js/package.json +41 -0
  93. package/cpa-out/react-codegen-js/plasmic.json +76 -0
  94. package/cpa-out/react-codegen-js/src/App.jsx +9 -0
  95. package/cpa-out/react-codegen-js/src/components/Homepage.jsx +26 -0
  96. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
  97. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +196 -0
  98. package/cpa-out/react-codegen-js/src/index.js +17 -0
  99. package/cpa-out/react-codegen-js/src/reportWebVitals.js +13 -0
  100. package/cpa-out/react-codegen-js/src/setupTests.js +5 -0
  101. package/cpa-out/react-codegen-ts/package.json +46 -0
  102. package/cpa-out/react-codegen-ts/plasmic.json +76 -0
  103. package/cpa-out/react-codegen-ts/src/App.tsx +9 -0
  104. package/cpa-out/react-codegen-ts/src/components/Homepage.tsx +45 -0
  105. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
  106. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +280 -0
  107. package/cpa-out/react-codegen-ts/src/index.tsx +19 -0
  108. package/cpa-out/react-codegen-ts/src/react-app-env.d.ts +1 -0
  109. package/cpa-out/react-codegen-ts/src/reportWebVitals.ts +15 -0
  110. package/cpa-out/react-codegen-ts/src/setupTests.ts +5 -0
  111. package/cpa-out/react-codegen-ts/tsconfig.json +26 -0
  112. package/cpa-out/react-loader-js/package.json +41 -0
  113. package/cpa-out/react-loader-js/plasmic.json +76 -0
  114. package/cpa-out/react-loader-js/src/App.jsx +9 -0
  115. package/cpa-out/react-loader-js/src/components/Homepage.jsx +26 -0
  116. package/cpa-out/react-loader-js/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.jsx +29 -0
  117. package/cpa-out/react-loader-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +196 -0
  118. package/cpa-out/react-loader-js/src/index.js +17 -0
  119. package/cpa-out/react-loader-js/src/reportWebVitals.js +13 -0
  120. package/cpa-out/react-loader-js/src/setupTests.js +5 -0
  121. package/cpa-out/react-loader-ts/package.json +46 -0
  122. package/cpa-out/react-loader-ts/plasmic.json +76 -0
  123. package/cpa-out/react-loader-ts/src/App.tsx +9 -0
  124. package/cpa-out/react-loader-ts/src/components/Homepage.tsx +45 -0
  125. package/cpa-out/react-loader-ts/src/components/plasmic/create_plasmic_app/PlasmicGlobalVariant__Screen.tsx +30 -0
  126. package/cpa-out/react-loader-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +280 -0
  127. package/cpa-out/react-loader-ts/src/index.tsx +19 -0
  128. package/cpa-out/react-loader-ts/src/react-app-env.d.ts +1 -0
  129. package/cpa-out/react-loader-ts/src/reportWebVitals.ts +15 -0
  130. package/cpa-out/react-loader-ts/src/setupTests.ts +5 -0
  131. package/cpa-out/react-loader-ts/tsconfig.json +26 -0
  132. package/dist/gatsby/gatsby.d.ts +6 -0
  133. package/dist/{strategies → gatsby}/gatsby.js +26 -29
  134. package/dist/gatsby/template.d.ts +11 -0
  135. package/dist/{templates/gatsby.js → gatsby/template.js} +34 -42
  136. package/dist/index.d.ts +1 -1
  137. package/dist/index.js +57 -27
  138. package/dist/lib.d.ts +3 -4
  139. package/dist/lib.js +22 -12
  140. package/dist/nextjs/nextjs.d.ts +2 -0
  141. package/dist/nextjs/nextjs.js +155 -0
  142. package/dist/nextjs/templates/app-loader/catchall-page.d.ts +2 -0
  143. package/dist/nextjs/templates/app-loader/catchall-page.js +67 -0
  144. package/dist/nextjs/templates/app-loader/plasmic-host.d.ts +1 -0
  145. package/dist/nextjs/templates/app-loader/plasmic-host.js +13 -0
  146. package/dist/nextjs/templates/app-loader/plasmic-init-client.d.ts +2 -0
  147. package/dist/nextjs/templates/app-loader/plasmic-init-client.js +73 -0
  148. package/dist/nextjs/templates/app-loader/plasmic-init.d.ts +1 -0
  149. package/dist/nextjs/templates/app-loader/plasmic-init.js +23 -0
  150. package/dist/nextjs/templates/pages-codegen/app.d.ts +2 -0
  151. package/dist/nextjs/templates/pages-codegen/app.js +20 -0
  152. package/dist/nextjs/templates/pages-codegen/plasmic-host.d.ts +1 -0
  153. package/dist/nextjs/templates/pages-codegen/plasmic-host.js +22 -0
  154. package/dist/nextjs/templates/pages-loader/catchall-page.d.ts +2 -0
  155. package/dist/nextjs/templates/pages-loader/catchall-page.js +77 -0
  156. package/dist/nextjs/templates/pages-loader/plasmic-host.d.ts +1 -0
  157. package/dist/nextjs/templates/pages-loader/plasmic-host.js +14 -0
  158. package/dist/nextjs/templates/pages-loader/plasmic-init.d.ts +1 -0
  159. package/dist/nextjs/templates/pages-loader/plasmic-init.js +32 -0
  160. package/dist/react/react.d.ts +2 -0
  161. package/dist/{strategies → react}/react.js +10 -10
  162. package/dist/templates/readme.d.ts +2 -2
  163. package/dist/templates/readme.js +5 -4
  164. package/dist/templates/welcomePage.d.ts +2 -2
  165. package/dist/templates/welcomePage.js +5 -5
  166. package/dist/{strategies/common.d.ts → utils/codegen.d.ts} +0 -0
  167. package/dist/{strategies/common.js → utils/codegen.js} +0 -0
  168. package/dist/utils/file-utils.d.ts +2 -2
  169. package/dist/utils/file-utils.js +3 -3
  170. package/dist/{strategies/types.d.ts → utils/strategy.d.ts} +16 -14
  171. package/dist/{strategies/types.js → utils/strategy.js} +0 -0
  172. package/dist/utils/types.d.ts +9 -0
  173. package/dist/utils/types.js +7 -0
  174. package/package.json +4 -3
  175. package/run-cpa.ts +151 -0
  176. package/src/{strategies → gatsby}/gatsby.ts +28 -46
  177. package/src/{templates/gatsby.ts → gatsby/template.ts} +41 -51
  178. package/src/index.ts +86 -56
  179. package/src/lib.ts +30 -15
  180. package/src/nextjs/nextjs.ts +180 -0
  181. package/src/nextjs/templates/app-loader/catchall-page.ts +71 -0
  182. package/src/nextjs/templates/app-loader/plasmic-host.ts +9 -0
  183. package/src/nextjs/templates/app-loader/plasmic-init-client.ts +74 -0
  184. package/src/nextjs/templates/app-loader/plasmic-init.ts +22 -0
  185. package/src/nextjs/templates/pages-codegen/app.ts +24 -0
  186. package/src/nextjs/templates/pages-codegen/plasmic-host.ts +18 -0
  187. package/src/nextjs/templates/pages-loader/catchall-page.ts +81 -0
  188. package/src/nextjs/templates/pages-loader/plasmic-host.ts +10 -0
  189. package/src/nextjs/templates/pages-loader/plasmic-init.ts +31 -0
  190. package/src/{strategies → react}/react.ts +8 -10
  191. package/src/templates/readme.ts +5 -5
  192. package/src/templates/welcomePage.ts +6 -7
  193. package/src/{strategies/common.ts → utils/codegen.ts} +0 -0
  194. package/src/utils/file-utils.ts +4 -4
  195. package/src/utils/strategy.ts +48 -0
  196. package/src/utils/types.ts +12 -0
  197. package/dist/strategies/gatsby.d.ts +0 -7
  198. package/dist/strategies/index.d.ts +0 -2
  199. package/dist/strategies/index.js +0 -22
  200. package/dist/strategies/nextjs.d.ts +0 -3
  201. package/dist/strategies/nextjs.js +0 -104
  202. package/dist/strategies/react.d.ts +0 -3
  203. package/dist/templates/gatsby.d.ts +0 -11
  204. package/dist/templates/nextjs.d.ts +0 -5
  205. package/dist/templates/nextjs.js +0 -162
  206. package/src/strategies/index.ts +0 -21
  207. package/src/strategies/nextjs.ts +0 -131
  208. package/src/strategies/types.ts +0 -42
  209. package/src/templates/nextjs.ts +0 -170
@@ -0,0 +1,22 @@
1
+ export function makePlasmicInit_app_loader(
2
+ projectId: string,
3
+ projectApiToken: string
4
+ ): string {
5
+ return `import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
6
+
7
+ export const PLASMIC = initPlasmicLoader({
8
+ projects: [
9
+ {
10
+ id: "${projectId}",
11
+ token: "${projectApiToken}",
12
+ },
13
+ ],
14
+
15
+ // By default Plasmic will use the last published version of your project.
16
+ // For development, you can set preview to true, which will use the unpublished
17
+ // project, allowing you to see your designs without publishing. Please
18
+ // only use this for development, as this is significantly slower.
19
+ preview: false,
20
+ });
21
+ `;
22
+ }
@@ -0,0 +1,24 @@
1
+ import { ifTs } from "../../../utils/file-utils";
2
+ import { JsOrTs } from "../../../utils/types";
3
+
4
+ export function makeCustomApp_pages_codegen(jsOrTs: JsOrTs): string {
5
+ return `import 'styles/globals.css'
6
+ import { PlasmicRootProvider } from "@plasmicapp/react-web";${ifTs(
7
+ jsOrTs,
8
+ `
9
+ import type { AppProps } from "next/app";`
10
+ )}
11
+ import Head from "next/head";
12
+
13
+ export default function MyApp({ Component, pageProps }${ifTs(
14
+ jsOrTs,
15
+ `: AppProps`
16
+ )}) {
17
+ return (
18
+ <PlasmicRootProvider Head={Head}>
19
+ <Component {...pageProps} />
20
+ </PlasmicRootProvider>
21
+ );
22
+ }
23
+ `;
24
+ }
@@ -0,0 +1,18 @@
1
+ export function makePlasmicHostPage_pages_codegen(): string {
2
+ return `import * as React from 'react';
3
+ import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/host';
4
+
5
+ // You can register any code components that you want to use here; see
6
+ // https://docs.plasmic.app/learn/code-components-ref/
7
+ // And configure your Plasmic project to use the host url pointing at
8
+ // the /plasmic-host page of your nextjs app (for example,
9
+ // http://localhost:3000/plasmic-host). See
10
+ // https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
11
+
12
+ // registerComponent(...)
13
+
14
+ export default function PlasmicHost() {
15
+ return <PlasmicCanvasHost />;
16
+ }
17
+ `;
18
+ }
@@ -0,0 +1,81 @@
1
+ import { ifTs } from "../../../utils/file-utils";
2
+ import { JsOrTs } from "../../../utils/types";
3
+
4
+ export function makeCatchallPage_pages_loader(jsOrTs: JsOrTs): string {
5
+ return `import * as React from "react";
6
+ import {
7
+ PlasmicComponent,
8
+ extractPlasmicQueryData,
9
+ ComponentRenderData,
10
+ PlasmicRootProvider,
11
+ } from "@plasmicapp/loader-nextjs";
12
+ ${ifTs(jsOrTs, `import type { GetStaticPaths, GetStaticProps } from "next";\n`)}
13
+ import Error from "next/error";
14
+ import { useRouter } from "next/router";
15
+ import { PLASMIC } from "plasmic-init";
16
+
17
+ export default function PlasmicLoaderPage(props${ifTs(
18
+ jsOrTs,
19
+ `: {
20
+ plasmicData?: ComponentRenderData;
21
+ queryCache?: Record<string, any>;
22
+ }`
23
+ )}) {
24
+ const { plasmicData, queryCache } = props;
25
+ const router = useRouter();
26
+ if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
27
+ return <Error statusCode={404} />;
28
+ }
29
+ const pageMeta = plasmicData.entryCompMetas[0];
30
+ return (
31
+ <PlasmicRootProvider
32
+ loader={PLASMIC}
33
+ prefetchedData={plasmicData}
34
+ prefetchedQueryData={queryCache}
35
+ pageParams={pageMeta.params}
36
+ pageQuery={router.query}
37
+ >
38
+ <PlasmicComponent component={pageMeta.displayName} />
39
+ </PlasmicRootProvider>
40
+ );
41
+ }
42
+
43
+ export const getStaticProps${ifTs(
44
+ jsOrTs,
45
+ `: GetStaticProps`
46
+ )} = async (context) => {
47
+ const { catchall } = context.params ?? {};
48
+ const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
49
+ const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
50
+ if (!plasmicData) {
51
+ // non-Plasmic catch-all
52
+ return { props: {} };
53
+ }
54
+ const pageMeta = plasmicData.entryCompMetas[0];
55
+ // Cache the necessary data fetched for the page
56
+ const queryCache = await extractPlasmicQueryData(
57
+ <PlasmicRootProvider
58
+ loader={PLASMIC}
59
+ prefetchedData={plasmicData}
60
+ pageParams={pageMeta.params}
61
+ >
62
+ <PlasmicComponent component={pageMeta.displayName} />
63
+ </PlasmicRootProvider>
64
+ );
65
+ // Use revalidate if you want incremental static regeneration
66
+ return { props: { plasmicData, queryCache }, revalidate: 60 };
67
+ }
68
+
69
+ export const getStaticPaths${ifTs(jsOrTs, `: GetStaticPaths`)} = async () => {
70
+ const pageModules = await PLASMIC.fetchPages();
71
+ return {
72
+ paths: pageModules.map((mod) => ({
73
+ params: {
74
+ catchall: mod.path.substring(1).split("/"),
75
+ },
76
+ })),
77
+ fallback: "blocking",
78
+ };
79
+ }
80
+ `;
81
+ }
@@ -0,0 +1,10 @@
1
+ export function makePlasmicHostPage_pages_loader(): string {
2
+ return `import * as React from 'react';
3
+ import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs';
4
+ import { PLASMIC } from 'plasmic-init';
5
+
6
+ export default function PlasmicHost() {
7
+ return PLASMIC && <PlasmicCanvasHost />;
8
+ }
9
+ `;
10
+ }
@@ -0,0 +1,31 @@
1
+ export function makePlasmicInit_pages_loader(
2
+ projectId: string,
3
+ projectApiToken: string
4
+ ): string {
5
+ return `import { initPlasmicLoader } from "@plasmicapp/loader-nextjs";
6
+
7
+ export const PLASMIC = initPlasmicLoader({
8
+ projects: [
9
+ {
10
+ id: "${projectId}",
11
+ token: "${projectApiToken}",
12
+ },
13
+ ],
14
+
15
+ // By default Plasmic will use the last published version of your project.
16
+ // For development, you can set preview to true, which will use the unpublished
17
+ // project, allowing you to see your designs without publishing. Please
18
+ // only use this for development, as this is significantly slower.
19
+ preview: false,
20
+ });
21
+
22
+ // You can register any code components that you want to use here; see
23
+ // https://docs.plasmic.app/learn/code-components-ref/
24
+ // And configure your Plasmic project to use the host url pointing at
25
+ // the /plasmic-host page of your nextjs app (for example,
26
+ // http://localhost:3000/plasmic-host). See
27
+ // https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
28
+
29
+ // PLASMIC.registerComponent(...);
30
+ `;
31
+ }
@@ -1,18 +1,18 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { spawnOrFail } from "../utils/cmd-utils";
4
+ import { installCodegenDeps, runCodegenSync } from "../utils/codegen";
4
5
  import { overwriteIndex } from "../utils/file-utils";
5
6
  import { installUpgrade } from "../utils/npm-utils";
6
- import { installCodegenDeps, runCodegenSync } from "./common";
7
- import { CPAStrategy } from "./types";
7
+ import { CPAStrategy } from "../utils/strategy";
8
8
 
9
- const reactStrategy: CPAStrategy = {
9
+ export const reactStrategy: CPAStrategy = {
10
10
  create: async (args) => {
11
- const { projectPath, useTypescript } = args;
11
+ const { projectPath, jsOrTs } = args;
12
12
  let { template } = args;
13
13
  const createCommand = `npx create-react-app@latest ${projectPath}`;
14
14
 
15
- if (!template && useTypescript) {
15
+ if (!template && jsOrTs === "ts") {
16
16
  template = "typescript";
17
17
  }
18
18
 
@@ -36,7 +36,7 @@ const reactStrategy: CPAStrategy = {
36
36
  projectApiToken,
37
37
  projectId,
38
38
  projectPath,
39
- useTypescript,
39
+ jsOrTs,
40
40
  }) => {
41
41
  if (scheme === "loader") {
42
42
  // Nothing to do
@@ -51,11 +51,11 @@ const reactStrategy: CPAStrategy = {
51
51
  await overwriteIndex(projectPath, "react", scheme);
52
52
  }
53
53
 
54
- // Deactivate React.StrictMode from index.tsx
54
+ // Deactivate React.StrictMode from index.js or index.tsx
55
55
  const indexFileName = path.join(
56
56
  projectPath,
57
57
  "src",
58
- `index.${useTypescript ? "tsx" : "js"}`
58
+ `index.${jsOrTs === "js" ? "js" : "tsx"}`
59
59
  );
60
60
  let indexFile = fs.readFileSync(indexFileName).toString();
61
61
  indexFile = indexFile.replace("<React.StrictMode>", "");
@@ -69,5 +69,3 @@ const reactStrategy: CPAStrategy = {
69
69
  await spawnOrFail(`${npmRunCmd} build`, projectPath);
70
70
  },
71
71
  };
72
-
73
- export default reactStrategy;
@@ -1,8 +1,7 @@
1
- import { PlatformType, toString } from "../lib";
1
+ import { PlatformType, platformTypeToString } from "../utils/types";
2
2
 
3
- export const README = (platform: PlatformType, buildCommand: string): string =>
4
- `
5
- This is a ${toString(
3
+ export function README(platform: PlatformType, buildCommand: string): string {
4
+ return `This is a ${platformTypeToString(
6
5
  platform
7
6
  )} project bootstrapped with [\`create-plasmic-app\`](https://www.npmjs.com/package/create-plasmic-app).
8
7
 
@@ -29,4 +28,5 @@ To learn more about Plasmic, take a look at the following resources:
29
28
  - [Plasmic Slack Community](https://www.plasmic.app/slack)
30
29
 
31
30
  You can check out [the Plasmic GitHub repository](https://github.com/plasmicapp/plasmic) - your feedback and contributions are welcome!
32
- `.trim();
31
+ `;
32
+ }
@@ -1,5 +1,4 @@
1
- export const PLASMIC_LOGO = `
2
- function PlasmicLogo() {
1
+ export const PLASMIC_LOGO = `function PlasmicLogo() {
3
2
  return (
4
3
  <svg
5
4
  width={40}
@@ -62,13 +61,12 @@ function PlasmicLogo() {
62
61
  }
63
62
  `;
64
63
 
65
- export const WELCOME_PAGE = (
64
+ export function WELCOME_PAGE(
66
65
  hasPages: boolean,
67
66
  platform: string,
68
67
  pageSection: string
69
- ): string =>
70
- `
71
- import React from "react";
68
+ ): string {
69
+ return `import React from "react";
72
70
  ${hasPages && platform === "nextjs" ? `import Link from "next/link";` : ""}
73
71
  ${PLASMIC_LOGO}
74
72
 
@@ -98,4 +96,5 @@ function Index() {
98
96
  }
99
97
 
100
98
  export default Index;
101
- `.trim();
99
+ `;
100
+ }
File without changes
@@ -2,10 +2,10 @@ import { existsSync, promises as fs, unlinkSync } from "fs";
2
2
  import glob from "glob";
3
3
  import L from "lodash";
4
4
  import * as path from "upath";
5
- import { PlatformType } from "../lib";
6
- import { GATSBY_404 } from "../templates/gatsby";
5
+ import { GATSBY_404 } from "../gatsby/template";
7
6
  import { README } from "../templates/readme";
8
7
  import { WELCOME_PAGE } from "../templates/welcomePage";
8
+ import { JsOrTs, PlatformType } from "../utils/types";
9
9
  import { ensure, ensureString } from "./lang-utils";
10
10
  import { installUpgrade } from "./npm-utils";
11
11
 
@@ -270,6 +270,6 @@ export async function ensureTsconfig(projectPath: string): Promise<void> {
270
270
  }
271
271
  }
272
272
 
273
- export function ifTs(ts: boolean, str: string) {
274
- return ts ? str : "";
273
+ export function ifTs(ts: JsOrTs, str: string) {
274
+ return ts === "ts" ? str : "";
275
275
  }
@@ -0,0 +1,48 @@
1
+ import { JsOrTs, PlatformOptions, SchemeType } from "./types";
2
+
3
+ export interface CreateArgs {
4
+ projectPath: string;
5
+ template?: string;
6
+ jsOrTs: JsOrTs;
7
+ platformOptions: PlatformOptions;
8
+ }
9
+
10
+ export interface ConfigArgs {
11
+ projectId: string;
12
+ projectPath: string;
13
+ jsOrTs: JsOrTs;
14
+ scheme: SchemeType;
15
+ projectApiToken: string | undefined;
16
+ platformOptions: PlatformOptions;
17
+ }
18
+
19
+ export interface GenerateFilesArgs {
20
+ projectPath: string;
21
+ jsOrTs: JsOrTs;
22
+ scheme: SchemeType;
23
+ projectId: string;
24
+ projectApiToken: string | undefined;
25
+ platformOptions: PlatformOptions;
26
+ }
27
+
28
+ export interface BuildArgs {
29
+ projectPath: string;
30
+ npmRunCmd: string;
31
+ }
32
+
33
+ export interface InstallArgs {
34
+ scheme: SchemeType;
35
+ projectPath: string;
36
+ jsOrTs: JsOrTs;
37
+ }
38
+
39
+ // TODO: Remove this interface and use a single "create" entry point.
40
+ // It forces us to make all strategies follow the same steps, even though each strategy has its own quirks.
41
+ // For example, this results in platform-specific conditionals in the utils files which is hard to follow.
42
+ export interface CPAStrategy {
43
+ create: (args: CreateArgs) => Promise<void>;
44
+ installDeps: (args: InstallArgs) => Promise<boolean>;
45
+ overwriteConfig: (args: ConfigArgs) => Promise<void>;
46
+ generateFiles: (args: GenerateFilesArgs) => Promise<void>;
47
+ build: (args: BuildArgs) => Promise<void>;
48
+ }
@@ -0,0 +1,12 @@
1
+ export type JsOrTs = "js" | "ts";
2
+ export type PlatformType = "nextjs" | "gatsby" | "react";
3
+ export type PlatformOptions = {
4
+ nextjs?: {
5
+ appDir: boolean;
6
+ };
7
+ };
8
+ export type SchemeType = "codegen" | "loader";
9
+
10
+ export function platformTypeToString(s: PlatformType): string {
11
+ return s === "nextjs" ? "Next.js" : s === "gatsby" ? "Gatsby" : "React";
12
+ }
@@ -1,7 +0,0 @@
1
- import { CPAStrategy } from "./types";
2
- export declare const GATSBY_TEMPLATES: {
3
- js: string;
4
- ts: string;
5
- };
6
- declare const gatsbyStrategy: CPAStrategy;
7
- export default gatsbyStrategy;
@@ -1,2 +0,0 @@
1
- import { CPAStrategy } from "./types";
2
- export declare const getCPAStrategy: (platform: string, errorMsg?: string) => CPAStrategy;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getCPAStrategy = void 0;
7
- const gatsby_1 = __importDefault(require("./gatsby"));
8
- const nextjs_1 = __importDefault(require("./nextjs"));
9
- const react_1 = __importDefault(require("./react"));
10
- const strategies = {
11
- nextjs: nextjs_1.default,
12
- gatsby: gatsby_1.default,
13
- react: react_1.default,
14
- };
15
- const getCPAStrategy = (platform, errorMsg) => {
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
- };
22
- exports.getCPAStrategy = getCPAStrategy;
@@ -1,3 +0,0 @@
1
- import { CPAStrategy } from "./types";
2
- declare const nextjsStrategy: CPAStrategy;
3
- export default nextjsStrategy;
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const fs_1 = require("fs");
16
- const path_1 = __importDefault(require("path"));
17
- const nextjs_1 = require("../templates/nextjs");
18
- const cmd_utils_1 = require("../utils/cmd-utils");
19
- const file_utils_1 = require("../utils/file-utils");
20
- const lang_utils_1 = require("../utils/lang-utils");
21
- const npm_utils_1 = require("../utils/npm-utils");
22
- const common_1 = require("./common");
23
- const nextjsStrategy = {
24
- create: (args) => __awaiter(void 0, void 0, void 0, function* () {
25
- const { projectPath, template, useTypescript } = args;
26
- const createCommand = `npx create-next-app@latest ${useTypescript ? "--ts" : "--js"} --eslint --no-src-dir --no-experimental-app --import-alias "@/*" ${projectPath}`;
27
- const templateArg = template ? ` --template ${template}` : "";
28
- // Default Next.js starter already supports Typescript
29
- // See where we `touch tsconfig.json` later on
30
- yield (0, cmd_utils_1.spawnOrFail)(`${createCommand}${templateArg}`);
31
- }),
32
- installDeps: ({ scheme, projectPath }) => __awaiter(void 0, void 0, void 0, function* () {
33
- if (scheme === "loader") {
34
- return yield (0, npm_utils_1.installUpgrade)("@plasmicapp/loader-nextjs", {
35
- workingDir: projectPath,
36
- });
37
- }
38
- else {
39
- return yield (0, common_1.installCodegenDeps)({ projectPath });
40
- }
41
- }),
42
- overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
43
- const { projectPath, scheme } = args;
44
- const nextjsConfigFile = path_1.default.join(projectPath, "next.config.js");
45
- if (scheme === "codegen") {
46
- yield fs_1.promises.writeFile(nextjsConfigFile, `
47
- module.exports = {
48
- eslint: {
49
- ignoreDuringBuilds: true,
50
- },
51
- trailingSlash: true,
52
- // Your NextJS config.
53
- };
54
- `);
55
- }
56
- else {
57
- yield fs_1.promises.writeFile(nextjsConfigFile, `
58
- /** @type {import('next').NextConfig} */
59
- const nextConfig = {
60
- // Turn off React StrictMode for now, as react-aria (used by Plasmic)
61
- // has some troubles with it. See
62
- // https://github.com/adobe/react-spectrum/labels/strict%20mode
63
- reactStrictMode: false,
64
- }
65
-
66
- module.exports = nextConfig
67
- `);
68
- }
69
- }),
70
- generateFiles: (args) => __awaiter(void 0, void 0, void 0, function* () {
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 { projectPath, scheme, useTypescript, projectId, projectApiToken, } = args;
74
- // Always start fresh
75
- const pagesPath = path_1.default.join(projectPath, "pages");
76
- (0, file_utils_1.deleteGlob)(path_1.default.join(pagesPath, `*.*`));
77
- const hostPage = path_1.default.join(pagesPath, `plasmic-host.${useTypescript ? "tsx" : "jsx"}`);
78
- yield fs_1.promises.writeFile(hostPage, (0, nextjs_1.makeNextjsHostPage)(scheme));
79
- if (scheme === "loader") {
80
- const initFile = path_1.default.join(projectPath, `plasmic-init.${useTypescript ? "ts" : "js"}`);
81
- yield fs_1.promises.writeFile(initFile, (0, nextjs_1.makeNextjsInitPage)(projectId, (0, lang_utils_1.ensure)(projectApiToken)));
82
- // Write catch-all page for loader
83
- const loaderPage = path_1.default.join(pagesPath, `[[...catchall]].${useTypescript ? "tsx" : "jsx"}`);
84
- yield fs_1.promises.writeFile(loaderPage, (0, nextjs_1.makeNextjsCatchallPage)(useTypescript ? "ts" : "js"));
85
- }
86
- else {
87
- yield (0, common_1.runCodegenSync)({
88
- projectId,
89
- projectApiToken,
90
- projectPath,
91
- });
92
- // Overwrite the index file
93
- yield (0, file_utils_1.overwriteIndex)(projectPath, "nextjs", scheme);
94
- // Overwrite the wrapper files to wrap PlasmicRootProvider
95
- const appFilePath = path_1.default.join(projectPath, "pages", `_app.js`);
96
- yield fs_1.promises.writeFile(appFilePath, (0, nextjs_1.wrapAppRootForCodegen)());
97
- }
98
- }),
99
- build: (args) => __awaiter(void 0, void 0, void 0, function* () {
100
- const { npmRunCmd, projectPath } = args;
101
- yield (0, cmd_utils_1.spawnOrFail)(`${npmRunCmd} build`, projectPath);
102
- }),
103
- };
104
- exports.default = nextjsStrategy;
@@ -1,3 +0,0 @@
1
- import { CPAStrategy } from "./types";
2
- declare const reactStrategy: CPAStrategy;
3
- export default reactStrategy;
@@ -1,11 +0,0 @@
1
- import { CodeScheme } from "..";
2
- export declare const makeGatsbyDefaultPage: (format: "ts" | "js") => string;
3
- export declare const GATSBY_404: string;
4
- export declare const GATSBY_PLUGIN_CONFIG: (projectId: string, projectApiToken: string, useTypescript: boolean) => string;
5
- export declare const makeGatsbyHostPage: (opts: {
6
- useTypescript: boolean;
7
- scheme: CodeScheme;
8
- }) => string;
9
- export declare const GATSBY_SSR_CONFIG: string;
10
- export declare const makeGatsbyPlasmicInit: (format: "ts" | "js") => string;
11
- export declare function wrapAppRootForCodegen(): string;
@@ -1,5 +0,0 @@
1
- import { CodeScheme } from "..";
2
- export declare const makeNextjsInitPage: (projectId: string, projectApiToken: string) => string;
3
- export declare function makeNextjsCatchallPage(format: "ts" | "js"): string;
4
- export declare function makeNextjsHostPage(scheme: CodeScheme): string;
5
- export declare function wrapAppRootForCodegen(): string;