create-plasmic-app 0.0.151 → 0.0.153

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 (153) hide show
  1. package/cpa-out/.gitignore +4 -2
  2. package/cpa-out/gatsby-codegen-js/package.json +2 -2
  3. package/cpa-out/gatsby-codegen-js/plasmic.json +2 -2
  4. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  5. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +61 -26
  6. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  7. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
  8. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  9. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  10. package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  11. package/cpa-out/gatsby-codegen-js/src/components/plasmic/plasmic__default_style.module.css +363 -0
  12. package/cpa-out/gatsby-codegen-ts/package.json +2 -2
  13. package/cpa-out/gatsby-codegen-ts/plasmic.json +2 -2
  14. package/cpa-out/gatsby-codegen-ts/src/components/RandomDynamicPageButton.tsx +1 -2
  15. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  16. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  17. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +74 -28
  18. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  19. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
  20. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  21. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  22. package/cpa-out/gatsby-codegen-ts/src/components/plasmic/plasmic__default_style.module.css +363 -0
  23. package/cpa-out/gatsby-loader-js/package.json +1 -1
  24. package/cpa-out/gatsby-loader-js/src/templates/defaultPlasmicPage.jsx +1 -0
  25. package/cpa-out/gatsby-loader-ts/package.json +1 -1
  26. package/cpa-out/gatsby-loader-ts/src/templates/defaultPlasmicPage.tsx +1 -0
  27. package/cpa-out/nextjs-app-codegen-js/app/dynamic/[slug]/page.jsx +13 -3
  28. package/cpa-out/nextjs-app-codegen-js/app/globals.css +10 -0
  29. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  30. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +62 -27
  31. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  32. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.jsx +103 -2
  33. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
  34. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  35. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  36. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  37. package/cpa-out/nextjs-app-codegen-js/components/plasmic/plasmic__default_style.module.css +363 -0
  38. package/cpa-out/nextjs-app-codegen-js/eslint.config.mjs +16 -0
  39. package/cpa-out/nextjs-app-codegen-js/jsconfig.json +7 -0
  40. package/cpa-out/nextjs-app-codegen-js/package.json +4 -4
  41. package/cpa-out/nextjs-app-codegen-js/plasmic.json +2 -2
  42. package/cpa-out/nextjs-app-codegen-ts/app/dynamic/[slug]/page.tsx +13 -3
  43. package/cpa-out/nextjs-app-codegen-ts/app/globals.css +10 -0
  44. package/cpa-out/nextjs-app-codegen-ts/components/RandomDynamicPageButton.tsx +1 -2
  45. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  46. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  47. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +69 -29
  48. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.tsx +110 -2
  49. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  50. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
  51. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  52. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  53. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/plasmic__default_style.module.css +363 -0
  54. package/cpa-out/nextjs-app-codegen-ts/eslint.config.mjs +18 -0
  55. package/cpa-out/nextjs-app-codegen-ts/package.json +4 -4
  56. package/cpa-out/nextjs-app-codegen-ts/plasmic.json +2 -2
  57. package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +1 -0
  58. package/cpa-out/nextjs-app-loader-js/app/globals.css +10 -0
  59. package/cpa-out/nextjs-app-loader-js/eslint.config.mjs +16 -0
  60. package/cpa-out/nextjs-app-loader-js/jsconfig.json +7 -0
  61. package/cpa-out/nextjs-app-loader-js/package.json +3 -3
  62. package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +1 -0
  63. package/cpa-out/nextjs-app-loader-ts/app/globals.css +10 -0
  64. package/cpa-out/nextjs-app-loader-ts/eslint.config.mjs +18 -0
  65. package/cpa-out/nextjs-app-loader-ts/package.json +3 -3
  66. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  67. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +62 -27
  68. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  69. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
  70. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  71. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  72. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  73. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/plasmic__default_style.module.css +363 -0
  74. package/cpa-out/nextjs-pages-codegen-js/eslint.config.mjs +16 -0
  75. package/cpa-out/nextjs-pages-codegen-js/jsconfig.json +7 -0
  76. package/cpa-out/nextjs-pages-codegen-js/package.json +4 -4
  77. package/cpa-out/nextjs-pages-codegen-js/pages/dynamic/[slug].jsx +24 -2
  78. package/cpa-out/nextjs-pages-codegen-js/plasmic.json +2 -2
  79. package/cpa-out/nextjs-pages-codegen-js/styles/Home.module.css +141 -0
  80. package/cpa-out/nextjs-pages-codegen-js/styles/globals.css +10 -0
  81. package/cpa-out/nextjs-pages-codegen-ts/components/RandomDynamicPageButton.tsx +1 -2
  82. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  83. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  84. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +75 -29
  85. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  86. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
  87. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  88. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  89. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/plasmic__default_style.module.css +363 -0
  90. package/cpa-out/nextjs-pages-codegen-ts/eslint.config.mjs +18 -0
  91. package/cpa-out/nextjs-pages-codegen-ts/package.json +4 -4
  92. package/cpa-out/nextjs-pages-codegen-ts/pages/dynamic/[slug].tsx +25 -2
  93. package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +2 -2
  94. package/cpa-out/nextjs-pages-codegen-ts/styles/Home.module.css +141 -0
  95. package/cpa-out/nextjs-pages-codegen-ts/styles/globals.css +10 -0
  96. package/cpa-out/nextjs-pages-loader-js/eslint.config.mjs +16 -0
  97. package/cpa-out/nextjs-pages-loader-js/jsconfig.json +7 -0
  98. package/cpa-out/nextjs-pages-loader-js/package.json +3 -3
  99. package/cpa-out/nextjs-pages-loader-js/pages/[[...catchall]].jsx +1 -0
  100. package/cpa-out/nextjs-pages-loader-js/styles/Home.module.css +141 -0
  101. package/cpa-out/nextjs-pages-loader-js/styles/globals.css +10 -0
  102. package/cpa-out/nextjs-pages-loader-ts/eslint.config.mjs +18 -0
  103. package/cpa-out/nextjs-pages-loader-ts/package.json +3 -3
  104. package/cpa-out/nextjs-pages-loader-ts/pages/[[...catchall]].tsx +1 -0
  105. package/cpa-out/nextjs-pages-loader-ts/styles/Home.module.css +141 -0
  106. package/cpa-out/nextjs-pages-loader-ts/styles/globals.css +10 -0
  107. package/cpa-out/react-codegen-js/package.json +2 -2
  108. package/cpa-out/react-codegen-js/plasmic.json +2 -2
  109. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  110. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +61 -26
  111. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  112. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
  113. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  114. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  115. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  116. package/cpa-out/react-codegen-js/src/components/plasmic/plasmic__default_style.module.css +363 -0
  117. package/cpa-out/react-codegen-js/src/index.css +68 -0
  118. package/cpa-out/react-codegen-ts/package.json +2 -2
  119. package/cpa-out/react-codegen-ts/plasmic.json +2 -2
  120. package/cpa-out/react-codegen-ts/src/components/RandomDynamicPageButton.tsx +1 -2
  121. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
  122. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
  123. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +74 -28
  124. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
  125. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
  126. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
  127. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
  128. package/cpa-out/react-codegen-ts/src/components/plasmic/plasmic__default_style.module.css +363 -0
  129. package/cpa-out/react-codegen-ts/src/index.css +68 -0
  130. package/cpa-out/tanstack-codegen-ts/package.json +3 -3
  131. package/cpa-out/tanstack-codegen-ts/plasmic.json +2 -2
  132. package/cpa-out/tanstack-codegen-ts/src/components/RandomDynamicPageButton.tsx +1 -2
  133. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.css +495 -0
  134. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.css +44 -0
  135. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +74 -28
  136. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.css +43 -0
  137. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
  138. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.css +16 -0
  139. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.css +354 -0
  140. package/cpa-out/tanstack-codegen-ts/src/components/plasmic/plasmic__default_style.css +363 -0
  141. package/cpa-out/tanstack-codegen-ts/src/routes/dynamic/$slug/index.tsx +31 -8
  142. package/cpa-out/tanstack-codegen-ts/src/styles.css +17 -0
  143. package/dist/nextjs/nextjs.js +80 -8
  144. package/dist/nextjs/templates/app-codegen/layout.d.ts +2 -2
  145. package/dist/nextjs/templates/app-codegen/layout.js +8 -2
  146. package/dist/nextjs/templates/pages-codegen/app.d.ts +2 -2
  147. package/dist/nextjs/templates/pages-codegen/app.js +8 -2
  148. package/dist/utils/types.d.ts +4 -0
  149. package/package.json +3 -3
  150. package/src/nextjs/nextjs.ts +110 -18
  151. package/src/nextjs/templates/app-codegen/layout.ts +16 -3
  152. package/src/nextjs/templates/pages-codegen/app.ts +16 -3
  153. package/src/utils/types.ts +5 -0
@@ -1,4 +1,5 @@
1
- import { promises as fs } from "fs";
1
+ import { PlasmicConfig } from "@plasmicapp/cli/dist/utils/config-utils";
2
+ import { existsSync, promises as fs } from "fs";
2
3
  import L from "lodash";
3
4
  import path from "path";
4
5
  import { spawnOrFail } from "../utils/cmd-utils";
@@ -11,6 +12,7 @@ import {
11
12
  import { ensure } from "../utils/lang-utils";
12
13
  import { installUpgrade } from "../utils/npm-utils";
13
14
  import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
15
+ import { PlasmicCssImport } from "../utils/types";
14
16
  import { makeLayout_app_codegen } from "./templates/app-codegen/layout";
15
17
  import { makePlasmicHostPage_app_codegen } from "./templates/app-codegen/plasmic-host";
16
18
  import { makePlasmicInitClient_app_codegen } from "./templates/app-codegen/plasmic-init-client";
@@ -52,6 +54,21 @@ export const nextjsStrategy: CPAStrategy = {
52
54
  },
53
55
  overwriteConfig: async (args) => {
54
56
  const { projectPath, scheme, jsOrTs } = args;
57
+
58
+ // create-next-app's globals.css forces a dark background with `prefers-color-scheme: dark`.
59
+ // It's imported by the /plasmic-host layout/_app and paints the Studio canvas black.
60
+ const globalsCssCandidates = [
61
+ path.join(projectPath, "app", "globals.css"),
62
+ path.join(projectPath, "src", "app", "globals.css"),
63
+ path.join(projectPath, "styles", "globals.css"),
64
+ path.join(projectPath, "src", "styles", "globals.css"),
65
+ ];
66
+ for (const globalsCssPath of globalsCssCandidates) {
67
+ if (existsSync(globalsCssPath)) {
68
+ await fs.writeFile(globalsCssPath, makeNeutralGlobalsCss());
69
+ }
70
+ }
71
+
55
72
  if (scheme === "codegen") {
56
73
  const isTs = jsOrTs === "ts";
57
74
  const typePragma = isTs
@@ -83,6 +100,24 @@ export default nextConfig;`
83
100
  },
84
101
  };
85
102
 
103
+ /**
104
+ * Canvas-safe globals.css: no body background/color or dark `color-scheme`,
105
+ * since it's loaded by /plasmic-host (for Studio canvas).
106
+ */
107
+ function makeNeutralGlobalsCss(): string {
108
+ return `* {
109
+ box-sizing: border-box;
110
+ padding: 0;
111
+ margin: 0;
112
+ }
113
+
114
+ a {
115
+ color: inherit;
116
+ text-decoration: none;
117
+ }
118
+ `;
119
+ }
120
+
86
121
  async function generateFilesAppDir(args: GenerateFilesArgs) {
87
122
  const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
88
123
 
@@ -119,15 +154,6 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
119
154
  makeCatchallPage_app_loader(jsOrTs)
120
155
  );
121
156
  } else {
122
- // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
123
- deleteGlob(path.join(projectPath, "app", "layout.*"));
124
-
125
- // ./app/layout.tsx
126
- await fs.writeFile(
127
- path.join(projectPath, "app", `layout.${jsOrTs}x`),
128
- makeLayout_app_codegen(jsOrTs)
129
- );
130
-
131
157
  // ./plasmic-init-client.tsx
132
158
  await fs.writeFile(
133
159
  path.join(projectPath, `plasmic-init-client.${jsOrTs}x`),
@@ -151,8 +177,26 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
151
177
  projectPath,
152
178
  });
153
179
 
154
- // Make an index (/) page if the project didn't have one.
180
+ // Read plasmic.json so we can wire each top-level project's plasmic.css
181
+ // import directly into the root layout template.
155
182
  const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
183
+ const layoutAbsPath = path.join(projectPath, "app", `layout.${jsOrTs}x`);
184
+ const cssImports = getPlasmicCssImports({
185
+ projectPath,
186
+ rootFileAbsPath: layoutAbsPath,
187
+ config,
188
+ });
189
+
190
+ // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
191
+ deleteGlob(path.join(projectPath, "app", "layout.*"));
192
+
193
+ // ./app/layout.tsx
194
+ await fs.writeFile(
195
+ path.join(projectPath, "app", `layout.${jsOrTs}x`),
196
+ makeLayout_app_codegen(jsOrTs, cssImports)
197
+ );
198
+
199
+ // Make an index (/) page if the project didn't have one.
156
200
  const plasmicFiles = L.map(
157
201
  L.flatMap(config.projects, (p) => p.components),
158
202
  (c) => c.importSpec.modulePath
@@ -194,12 +238,6 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
194
238
  makeCatchallPage_pages_loader(jsOrTs)
195
239
  );
196
240
  } else {
197
- // ./pages/_app.tsx
198
- await fs.writeFile(
199
- path.join(projectPath, "pages", `_app.${jsOrTs}x`),
200
- makeCustomApp_pages_codegen(jsOrTs)
201
- );
202
-
203
241
  // ./pages/plasmic-host.tsx
204
242
  await fs.writeFile(
205
243
  path.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`),
@@ -216,8 +254,23 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
216
254
  projectPath,
217
255
  });
218
256
 
219
- // Make an index page if the project didn't have one.
257
+ // Read plasmic.json so we can wire each top-level project's plasmic.css
258
+ // import directly into the _app template.
220
259
  const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
260
+ const appAbsPath = path.join(projectPath, "pages", `_app.${jsOrTs}x`);
261
+ const cssImports = getPlasmicCssImports({
262
+ projectPath,
263
+ rootFileAbsPath: appAbsPath,
264
+ config,
265
+ });
266
+
267
+ // ./pages/_app.tsx
268
+ await fs.writeFile(
269
+ appAbsPath,
270
+ makeCustomApp_pages_codegen(jsOrTs, cssImports)
271
+ );
272
+
273
+ // Make an index page if the project didn't have one.
221
274
  const plasmicFiles = L.map(
222
275
  L.flatMap(config.projects, (p) => p.components),
223
276
  (c) => c.importSpec.modulePath
@@ -230,3 +283,42 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
230
283
  }
231
284
  }
232
285
  }
286
+
287
+ /**
288
+ * Builds the list of `plasmic.css` imports the Next.js root file (Pages Router
289
+ * `_app.{ext}`, App Router `app/layout.{ext}`) needs for every top-level
290
+ * project in `plasmic.json`. Next.js disallows global non-module CSS imports
291
+ * outside of those files.
292
+ *
293
+ * The marker comment in the emitted import (plasmic-import: <id>/projectcss)
294
+ * matches the convention used by @plasmicapp/cli sync, so subsequent syncs
295
+ * can update paths in-place without producing duplicates.
296
+ *
297
+ * @param rootFileAbsPath Absolute path to the Next.js root file (`_app.{ext}`
298
+ * for Pages Router, `app/layout.{ext}` for App Router).
299
+ */
300
+ function getPlasmicCssImports(args: {
301
+ projectPath: string;
302
+ rootFileAbsPath: string;
303
+ config: PlasmicConfig;
304
+ }): PlasmicCssImport[] {
305
+ const { projectPath, rootFileAbsPath, config } = args;
306
+ return (config.projects || [])
307
+ .filter((p) => !p.indirect && !!p.cssFilePath)
308
+ .map((p) => {
309
+ const absoluteCssPath = path.join(
310
+ projectPath,
311
+ config.srcDir,
312
+ p.cssFilePath
313
+ );
314
+ let relPath = path.relative(
315
+ path.dirname(rootFileAbsPath),
316
+ absoluteCssPath
317
+ );
318
+ if (!relPath.startsWith(".")) {
319
+ relPath = `./${relPath}`;
320
+ }
321
+
322
+ return { projectId: p.projectId, importPath: relPath };
323
+ });
324
+ }
@@ -1,8 +1,21 @@
1
1
  import { ifTs } from "../../../utils/file-utils";
2
- import { JsOrTs } from "../../../utils/types";
2
+ import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
3
3
 
4
- export function makeLayout_app_codegen(jsOrTs: JsOrTs): string {
5
- return `import '@/app/globals.css'
4
+ export function makeLayout_app_codegen(
5
+ jsOrTs: JsOrTs,
6
+ cssImports: PlasmicCssImport[] = []
7
+ ): string {
8
+ const plasmicCssImportLines = cssImports
9
+ .map(
10
+ (i) =>
11
+ `import "${i.importPath}"; // plasmic-import: ${i.projectId}/projectcss`
12
+ )
13
+ .join("\n");
14
+ const plasmicCssImportsBlock = plasmicCssImportLines
15
+ ? `${plasmicCssImportLines}\n`
16
+ : "";
17
+
18
+ return `${plasmicCssImportsBlock}import '@/app/globals.css'
6
19
  import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
7
20
 
8
21
  export default function RootLayout({
@@ -1,8 +1,21 @@
1
1
  import { ifTs } from "../../../utils/file-utils";
2
- import { JsOrTs } from "../../../utils/types";
2
+ import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
3
3
 
4
- export function makeCustomApp_pages_codegen(jsOrTs: JsOrTs): string {
5
- return `import '@/styles/globals.css'
4
+ export function makeCustomApp_pages_codegen(
5
+ jsOrTs: JsOrTs,
6
+ cssImports: PlasmicCssImport[] = []
7
+ ): string {
8
+ const plasmicCssImportLines = cssImports
9
+ .map(
10
+ (i) =>
11
+ `import "${i.importPath}"; // plasmic-import: ${i.projectId}/projectcss`
12
+ )
13
+ .join("\n");
14
+ const plasmicCssImportsBlock = plasmicCssImportLines
15
+ ? `${plasmicCssImportLines}\n`
16
+ : "";
17
+
18
+ return `${plasmicCssImportsBlock}import '@/styles/globals.css'
6
19
  import { PlasmicRootProvider } from "@plasmicapp/react-web";${ifTs(
7
20
  jsOrTs,
8
21
  `
@@ -7,6 +7,11 @@ export type PlatformOptions = {
7
7
  };
8
8
  export type SchemeType = "codegen" | "loader";
9
9
 
10
+ export type PlasmicCssImport = {
11
+ projectId: string;
12
+ importPath: string;
13
+ };
14
+
10
15
  export function platformTypeToString(s: PlatformType): string {
11
16
  return s === "nextjs"
12
17
  ? "Next.js"