create-plasmic-app 0.0.152 → 0.0.154

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 (71) hide show
  1. package/cpa-out/nextjs-app-codegen-js/app/layout.jsx +1 -0
  2. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.jsx +11 -12
  3. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +15 -16
  4. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.jsx +1 -1
  5. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +11 -16
  6. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.jsx +1 -2
  7. package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/{plasmic.module.css → plasmic.css} +73 -73
  8. package/cpa-out/nextjs-app-codegen-js/package.json +4 -4
  9. package/cpa-out/nextjs-app-codegen-js/plasmic.json +4 -4
  10. package/cpa-out/nextjs-app-codegen-ts/app/layout.tsx +1 -0
  11. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.tsx +11 -12
  12. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +15 -16
  13. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.tsx +1 -1
  14. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +11 -16
  15. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +0 -1
  16. package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.tsx +1 -3
  17. package/cpa-out/{nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/plasmic.module.css → nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/plasmic.css} +73 -73
  18. package/cpa-out/nextjs-app-codegen-ts/package.json +4 -4
  19. package/cpa-out/nextjs-app-codegen-ts/plasmic.json +4 -4
  20. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.jsx +11 -12
  21. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +15 -16
  22. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +11 -16
  23. package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.jsx +1 -2
  24. package/cpa-out/{nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/plasmic.module.css → nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/plasmic.css} +73 -73
  25. package/cpa-out/nextjs-pages-codegen-js/package.json +4 -4
  26. package/cpa-out/nextjs-pages-codegen-js/pages/_app.jsx +1 -0
  27. package/cpa-out/nextjs-pages-codegen-js/plasmic.json +4 -4
  28. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.tsx +11 -12
  29. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +15 -16
  30. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +11 -16
  31. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +0 -1
  32. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.tsx +1 -3
  33. package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/{plasmic.module.css → plasmic.css} +73 -73
  34. package/cpa-out/nextjs-pages-codegen-ts/package.json +4 -4
  35. package/cpa-out/nextjs-pages-codegen-ts/pages/_app.tsx +1 -0
  36. package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +4 -4
  37. package/cpa-out/react-codegen-js/package.json +2 -2
  38. package/cpa-out/react-codegen-js/plasmic.json +4 -4
  39. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.jsx +12 -12
  40. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +16 -16
  41. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +12 -16
  42. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.jsx +1 -0
  43. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.jsx +2 -2
  44. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/plasmic.css +702 -0
  45. package/cpa-out/react-codegen-ts/package.json +2 -2
  46. package/cpa-out/react-codegen-ts/plasmic.json +4 -4
  47. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.tsx +12 -12
  48. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +16 -16
  49. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +12 -16
  50. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.tsx +1 -1
  51. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicStyleTokensProvider.tsx +2 -2
  52. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.css +702 -0
  53. package/dist/nextjs/nextjs.js +50 -8
  54. package/dist/nextjs/templates/app-codegen/layout.d.ts +2 -2
  55. package/dist/nextjs/templates/app-codegen/layout.js +8 -2
  56. package/dist/nextjs/templates/pages-codegen/app.d.ts +2 -2
  57. package/dist/nextjs/templates/pages-codegen/app.js +8 -2
  58. package/dist/utils/types.d.ts +4 -0
  59. package/package.json +3 -3
  60. package/src/nextjs/nextjs.ts +76 -17
  61. package/src/nextjs/templates/app-codegen/layout.ts +16 -3
  62. package/src/nextjs/templates/pages-codegen/app.ts +16 -3
  63. package/src/utils/types.ts +5 -0
  64. package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/plasmic.module.css +0 -702
  65. package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.module.css +0 -702
  66. /package/cpa-out/nextjs-app-codegen-js/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +0 -0
  67. /package/cpa-out/nextjs-app-codegen-ts/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +0 -0
  68. /package/cpa-out/nextjs-pages-codegen-js/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +0 -0
  69. /package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +0 -0
  70. /package/cpa-out/react-codegen-js/src/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +0 -0
  71. /package/cpa-out/react-codegen-ts/src/components/plasmic/{plasmic__default_style.module.css → plasmic__default_style.css} +0 -0
@@ -137,10 +137,6 @@ function generateFilesAppDir(args) {
137
137
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "[[...catchall]]", `page.${jsOrTs}x`), (0, catchall_page_1.makeCatchallPage_app_loader)(jsOrTs));
138
138
  }
139
139
  else {
140
- // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
141
- (0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "app", "layout.*"));
142
- // ./app/layout.tsx
143
- yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`), (0, layout_1.makeLayout_app_codegen)(jsOrTs));
144
140
  // ./plasmic-init-client.tsx
145
141
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init-client.${jsOrTs}x`), (0, plasmic_init_client_1.makePlasmicInitClient_app_codegen)(jsOrTs));
146
142
  // ./app/plasmic-host/page.tsx
@@ -155,8 +151,20 @@ function generateFilesAppDir(args) {
155
151
  projectApiToken,
156
152
  projectPath,
157
153
  });
158
- // Make an index (/) page if the project didn't have one.
154
+ // Read plasmic.json so we can wire each top-level project's plasmic.css
155
+ // import directly into the root layout template.
159
156
  const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
157
+ const layoutAbsPath = path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`);
158
+ const cssImports = getPlasmicCssImports({
159
+ projectPath,
160
+ rootFileAbsPath: layoutAbsPath,
161
+ config,
162
+ });
163
+ // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
164
+ (0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "app", "layout.*"));
165
+ // ./app/layout.tsx
166
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`), (0, layout_1.makeLayout_app_codegen)(jsOrTs, cssImports));
167
+ // Make an index (/) page if the project didn't have one.
160
168
  const plasmicFiles = lodash_1.default.map(lodash_1.default.flatMap(config.projects, (p) => p.components), (c) => c.importSpec.modulePath);
161
169
  if (!plasmicFiles.find((f) => f.includes("app/page."))) {
162
170
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `page.${jsOrTs}x`), (0, file_utils_1.generateWelcomePage)(config, "nextjs"));
@@ -178,8 +186,6 @@ function generateFilesPagesDir(args) {
178
186
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `[[...catchall]].${jsOrTs}x`), (0, catchall_page_2.makeCatchallPage_pages_loader)(jsOrTs));
179
187
  }
180
188
  else {
181
- // ./pages/_app.tsx
182
- yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `_app.${jsOrTs}x`), (0, app_1.makeCustomApp_pages_codegen)(jsOrTs));
183
189
  // ./pages/plasmic-host.tsx
184
190
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`), (0, plasmic_host_3.makePlasmicHostPage_pages_codegen)());
185
191
  // This should generate
@@ -191,8 +197,18 @@ function generateFilesPagesDir(args) {
191
197
  projectApiToken,
192
198
  projectPath,
193
199
  });
194
- // Make an index page if the project didn't have one.
200
+ // Read plasmic.json so we can wire each top-level project's plasmic.css
201
+ // import directly into the _app template.
195
202
  const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
203
+ const appAbsPath = path_1.default.join(projectPath, "pages", `_app.${jsOrTs}x`);
204
+ const cssImports = getPlasmicCssImports({
205
+ projectPath,
206
+ rootFileAbsPath: appAbsPath,
207
+ config,
208
+ });
209
+ // ./pages/_app.tsx
210
+ yield fs_1.promises.writeFile(appAbsPath, (0, app_1.makeCustomApp_pages_codegen)(jsOrTs, cssImports));
211
+ // Make an index page if the project didn't have one.
196
212
  const plasmicFiles = lodash_1.default.map(lodash_1.default.flatMap(config.projects, (p) => p.components), (c) => c.importSpec.modulePath);
197
213
  if (!plasmicFiles.find((f) => f.includes("/index."))) {
198
214
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `index.${jsOrTs}x`), (0, file_utils_1.generateWelcomePage)(config, "nextjs"));
@@ -200,3 +216,29 @@ function generateFilesPagesDir(args) {
200
216
  }
201
217
  });
202
218
  }
219
+ /**
220
+ * Builds the list of `plasmic.css` imports the Next.js root file (Pages Router
221
+ * `_app.{ext}`, App Router `app/layout.{ext}`) needs for every top-level
222
+ * project in `plasmic.json`. Next.js disallows global non-module CSS imports
223
+ * outside of those files.
224
+ *
225
+ * The marker comment in the emitted import (plasmic-import: <id>/projectcss)
226
+ * matches the convention used by @plasmicapp/cli sync, so subsequent syncs
227
+ * can update paths in-place without producing duplicates.
228
+ *
229
+ * @param rootFileAbsPath Absolute path to the Next.js root file (`_app.{ext}`
230
+ * for Pages Router, `app/layout.{ext}` for App Router).
231
+ */
232
+ function getPlasmicCssImports(args) {
233
+ const { projectPath, rootFileAbsPath, config } = args;
234
+ return (config.projects || [])
235
+ .filter((p) => !p.indirect && !!p.cssFilePath)
236
+ .map((p) => {
237
+ const absoluteCssPath = path_1.default.join(projectPath, config.srcDir, p.cssFilePath);
238
+ let relPath = path_1.default.relative(path_1.default.dirname(rootFileAbsPath), absoluteCssPath);
239
+ if (!relPath.startsWith(".")) {
240
+ relPath = `./${relPath}`;
241
+ }
242
+ return { projectId: p.projectId, importPath: relPath };
243
+ });
244
+ }
@@ -1,2 +1,2 @@
1
- import { JsOrTs } from "../../../utils/types";
2
- export declare function makeLayout_app_codegen(jsOrTs: JsOrTs): string;
1
+ import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
2
+ export declare function makeLayout_app_codegen(jsOrTs: JsOrTs, cssImports?: PlasmicCssImport[]): string;
@@ -2,8 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeLayout_app_codegen = void 0;
4
4
  const file_utils_1 = require("../../../utils/file-utils");
5
- function makeLayout_app_codegen(jsOrTs) {
6
- return `import '@/app/globals.css'
5
+ function makeLayout_app_codegen(jsOrTs, cssImports = []) {
6
+ const plasmicCssImportLines = cssImports
7
+ .map((i) => `import "${i.importPath}"; // plasmic-import: ${i.projectId}/projectcss`)
8
+ .join("\n");
9
+ const plasmicCssImportsBlock = plasmicCssImportLines
10
+ ? `${plasmicCssImportLines}\n`
11
+ : "";
12
+ return `${plasmicCssImportsBlock}import '@/app/globals.css'
7
13
  import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
8
14
 
9
15
  export default function RootLayout({
@@ -1,2 +1,2 @@
1
- import { JsOrTs } from "../../../utils/types";
2
- export declare function makeCustomApp_pages_codegen(jsOrTs: JsOrTs): string;
1
+ import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
2
+ export declare function makeCustomApp_pages_codegen(jsOrTs: JsOrTs, cssImports?: PlasmicCssImport[]): string;
@@ -2,8 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeCustomApp_pages_codegen = void 0;
4
4
  const file_utils_1 = require("../../../utils/file-utils");
5
- function makeCustomApp_pages_codegen(jsOrTs) {
6
- return `import '@/styles/globals.css'
5
+ function makeCustomApp_pages_codegen(jsOrTs, cssImports = []) {
6
+ const plasmicCssImportLines = cssImports
7
+ .map((i) => `import "${i.importPath}"; // plasmic-import: ${i.projectId}/projectcss`)
8
+ .join("\n");
9
+ const plasmicCssImportsBlock = plasmicCssImportLines
10
+ ? `${plasmicCssImportLines}\n`
11
+ : "";
12
+ return `${plasmicCssImportsBlock}import '@/styles/globals.css'
7
13
  import { PlasmicRootProvider } from "@plasmicapp/react-web";${(0, file_utils_1.ifTs)(jsOrTs, `
8
14
  import type { AppProps } from "next/app";`)}
9
15
  import Head from "next/head";
@@ -6,4 +6,8 @@ export type PlatformOptions = {
6
6
  };
7
7
  };
8
8
  export type SchemeType = "codegen" | "loader";
9
+ export type PlasmicCssImport = {
10
+ projectId: string;
11
+ importPath: string;
12
+ };
9
13
  export declare function platformTypeToString(s: PlatformType): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.152",
3
+ "version": "0.0.154",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
@@ -33,7 +33,7 @@
33
33
  "tsx": "^4.21.0"
34
34
  },
35
35
  "dependencies": {
36
- "@plasmicapp/cli": "0.1.363",
36
+ "@plasmicapp/cli": "0.1.364",
37
37
  "@sentry/node": "^6.2.2",
38
38
  "chalk": "^4.1.0",
39
39
  "execa": "^5.0.0",
@@ -47,5 +47,5 @@
47
47
  "validate-npm-package-name": "^3.0.0",
48
48
  "yargs": "^16.2.0"
49
49
  },
50
- "gitHead": "c8685b26363d59652d7a8899ddaa38727680c81c"
50
+ "gitHead": "0298c004ffbb3e047c5ed214fa29cfebda7ec3b6"
51
51
  }
@@ -1,3 +1,4 @@
1
+ import { PlasmicConfig } from "@plasmicapp/cli/dist/utils/config-utils";
1
2
  import { existsSync, promises as fs } from "fs";
2
3
  import L from "lodash";
3
4
  import path from "path";
@@ -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";
@@ -152,15 +154,6 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
152
154
  makeCatchallPage_app_loader(jsOrTs)
153
155
  );
154
156
  } else {
155
- // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
156
- deleteGlob(path.join(projectPath, "app", "layout.*"));
157
-
158
- // ./app/layout.tsx
159
- await fs.writeFile(
160
- path.join(projectPath, "app", `layout.${jsOrTs}x`),
161
- makeLayout_app_codegen(jsOrTs)
162
- );
163
-
164
157
  // ./plasmic-init-client.tsx
165
158
  await fs.writeFile(
166
159
  path.join(projectPath, `plasmic-init-client.${jsOrTs}x`),
@@ -184,8 +177,26 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
184
177
  projectPath,
185
178
  });
186
179
 
187
- // 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.
188
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.
189
200
  const plasmicFiles = L.map(
190
201
  L.flatMap(config.projects, (p) => p.components),
191
202
  (c) => c.importSpec.modulePath
@@ -227,12 +238,6 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
227
238
  makeCatchallPage_pages_loader(jsOrTs)
228
239
  );
229
240
  } else {
230
- // ./pages/_app.tsx
231
- await fs.writeFile(
232
- path.join(projectPath, "pages", `_app.${jsOrTs}x`),
233
- makeCustomApp_pages_codegen(jsOrTs)
234
- );
235
-
236
241
  // ./pages/plasmic-host.tsx
237
242
  await fs.writeFile(
238
243
  path.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`),
@@ -249,8 +254,23 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
249
254
  projectPath,
250
255
  });
251
256
 
252
- // 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.
253
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.
254
274
  const plasmicFiles = L.map(
255
275
  L.flatMap(config.projects, (p) => p.components),
256
276
  (c) => c.importSpec.modulePath
@@ -263,3 +283,42 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
263
283
  }
264
284
  }
265
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"