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.
- package/cpa-out/.gitignore +4 -2
- package/cpa-out/gatsby-codegen-js/package.json +2 -2
- package/cpa-out/gatsby-codegen-js/plasmic.json +2 -2
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +61 -26
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/gatsby-codegen-js/src/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/gatsby-codegen-ts/package.json +2 -2
- package/cpa-out/gatsby-codegen-ts/plasmic.json +2 -2
- package/cpa-out/gatsby-codegen-ts/src/components/RandomDynamicPageButton.tsx +1 -2
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +74 -28
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/gatsby-codegen-ts/src/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/gatsby-loader-js/package.json +1 -1
- package/cpa-out/gatsby-loader-js/src/templates/defaultPlasmicPage.jsx +1 -0
- package/cpa-out/gatsby-loader-ts/package.json +1 -1
- package/cpa-out/gatsby-loader-ts/src/templates/defaultPlasmicPage.tsx +1 -0
- package/cpa-out/nextjs-app-codegen-js/app/dynamic/[slug]/page.jsx +13 -3
- package/cpa-out/nextjs-app-codegen-js/app/globals.css +10 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +62 -27
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.jsx +103 -2
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/nextjs-app-codegen-js/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/nextjs-app-codegen-js/eslint.config.mjs +16 -0
- package/cpa-out/nextjs-app-codegen-js/jsconfig.json +7 -0
- package/cpa-out/nextjs-app-codegen-js/package.json +4 -4
- package/cpa-out/nextjs-app-codegen-js/plasmic.json +2 -2
- package/cpa-out/nextjs-app-codegen-ts/app/dynamic/[slug]/page.tsx +13 -3
- package/cpa-out/nextjs-app-codegen-ts/app/globals.css +10 -0
- package/cpa-out/nextjs-app-codegen-ts/components/RandomDynamicPageButton.tsx +1 -2
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +69 -29
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPageServer.tsx +110 -2
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/nextjs-app-codegen-ts/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/nextjs-app-codegen-ts/eslint.config.mjs +18 -0
- package/cpa-out/nextjs-app-codegen-ts/package.json +4 -4
- package/cpa-out/nextjs-app-codegen-ts/plasmic.json +2 -2
- package/cpa-out/nextjs-app-loader-js/app/[[...catchall]]/page.jsx +1 -0
- package/cpa-out/nextjs-app-loader-js/app/globals.css +10 -0
- package/cpa-out/nextjs-app-loader-js/eslint.config.mjs +16 -0
- package/cpa-out/nextjs-app-loader-js/jsconfig.json +7 -0
- package/cpa-out/nextjs-app-loader-js/package.json +3 -3
- package/cpa-out/nextjs-app-loader-ts/app/[[...catchall]]/page.tsx +1 -0
- package/cpa-out/nextjs-app-loader-ts/app/globals.css +10 -0
- package/cpa-out/nextjs-app-loader-ts/eslint.config.mjs +18 -0
- package/cpa-out/nextjs-app-loader-ts/package.json +3 -3
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +62 -27
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/nextjs-pages-codegen-js/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/nextjs-pages-codegen-js/eslint.config.mjs +16 -0
- package/cpa-out/nextjs-pages-codegen-js/jsconfig.json +7 -0
- package/cpa-out/nextjs-pages-codegen-js/package.json +4 -4
- package/cpa-out/nextjs-pages-codegen-js/pages/dynamic/[slug].jsx +24 -2
- package/cpa-out/nextjs-pages-codegen-js/plasmic.json +2 -2
- package/cpa-out/nextjs-pages-codegen-js/styles/Home.module.css +141 -0
- package/cpa-out/nextjs-pages-codegen-js/styles/globals.css +10 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/RandomDynamicPageButton.tsx +1 -2
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +75 -29
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/nextjs-pages-codegen-ts/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/nextjs-pages-codegen-ts/eslint.config.mjs +18 -0
- package/cpa-out/nextjs-pages-codegen-ts/package.json +4 -4
- package/cpa-out/nextjs-pages-codegen-ts/pages/dynamic/[slug].tsx +25 -2
- package/cpa-out/nextjs-pages-codegen-ts/plasmic.json +2 -2
- package/cpa-out/nextjs-pages-codegen-ts/styles/Home.module.css +141 -0
- package/cpa-out/nextjs-pages-codegen-ts/styles/globals.css +10 -0
- package/cpa-out/nextjs-pages-loader-js/eslint.config.mjs +16 -0
- package/cpa-out/nextjs-pages-loader-js/jsconfig.json +7 -0
- package/cpa-out/nextjs-pages-loader-js/package.json +3 -3
- package/cpa-out/nextjs-pages-loader-js/pages/[[...catchall]].jsx +1 -0
- package/cpa-out/nextjs-pages-loader-js/styles/Home.module.css +141 -0
- package/cpa-out/nextjs-pages-loader-js/styles/globals.css +10 -0
- package/cpa-out/nextjs-pages-loader-ts/eslint.config.mjs +18 -0
- package/cpa-out/nextjs-pages-loader-ts/package.json +3 -3
- package/cpa-out/nextjs-pages-loader-ts/pages/[[...catchall]].tsx +1 -0
- package/cpa-out/nextjs-pages-loader-ts/styles/Home.module.css +141 -0
- package/cpa-out/nextjs-pages-loader-ts/styles/globals.css +10 -0
- package/cpa-out/react-codegen-js/package.json +2 -2
- package/cpa-out/react-codegen-js/plasmic.json +2 -2
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.jsx +61 -26
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.jsx +6 -39
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/react-codegen-js/src/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/react-codegen-js/src/index.css +68 -0
- package/cpa-out/react-codegen-ts/package.json +2 -2
- package/cpa-out/react-codegen-ts/plasmic.json +2 -2
- package/cpa-out/react-codegen-ts/src/components/RandomDynamicPageButton.tsx +1 -2
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.module.css +468 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.module.css +44 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +74 -28
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.module.css +43 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.module.css +16 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.module.css +702 -0
- package/cpa-out/react-codegen-ts/src/components/plasmic/plasmic__default_style.module.css +363 -0
- package/cpa-out/react-codegen-ts/src/index.css +68 -0
- package/cpa-out/tanstack-codegen-ts/package.json +3 -3
- package/cpa-out/tanstack-codegen-ts/plasmic.json +2 -2
- package/cpa-out/tanstack-codegen-ts/src/components/RandomDynamicPageButton.tsx +1 -2
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicButton.css +495 -0
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.css +44 -0
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicDynamicPage.tsx +74 -28
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.css +43 -0
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicHomepage.tsx +6 -40
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/PlasmicRandomDynamicPageButton.css +16 -0
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/create_plasmic_app/plasmic.css +354 -0
- package/cpa-out/tanstack-codegen-ts/src/components/plasmic/plasmic__default_style.css +363 -0
- package/cpa-out/tanstack-codegen-ts/src/routes/dynamic/$slug/index.tsx +31 -8
- package/cpa-out/tanstack-codegen-ts/src/styles.css +17 -0
- package/dist/nextjs/nextjs.js +80 -8
- package/dist/nextjs/templates/app-codegen/layout.d.ts +2 -2
- package/dist/nextjs/templates/app-codegen/layout.js +8 -2
- package/dist/nextjs/templates/pages-codegen/app.d.ts +2 -2
- package/dist/nextjs/templates/pages-codegen/app.js +8 -2
- package/dist/utils/types.d.ts +4 -0
- package/package.json +3 -3
- package/src/nextjs/nextjs.ts +110 -18
- package/src/nextjs/templates/app-codegen/layout.ts +16 -3
- package/src/nextjs/templates/pages-codegen/app.ts +16 -3
- package/src/utils/types.ts +5 -0
package/src/nextjs/nextjs.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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(
|
|
5
|
-
|
|
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(
|
|
5
|
-
|
|
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
|
`
|
package/src/utils/types.ts
CHANGED
|
@@ -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"
|