create-plasmic-app 0.0.149 → 0.0.150

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.
@@ -107,6 +107,10 @@ function generateFilesAppDir(args) {
107
107
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "[[...catchall]]", `page.${jsOrTs}x`), (0, catchall_page_1.makeCatchallPage_app_loader)(jsOrTs));
108
108
  }
109
109
  else {
110
+ // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
111
+ (0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "app", "layout.*"));
112
+ // ./app/layout.tsx
113
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`), (0, layout_1.makeLayout_app_codegen)(jsOrTs));
110
114
  // ./plasmic-init-client.tsx
111
115
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init-client.${jsOrTs}x`), (0, plasmic_init_client_1.makePlasmicInitClient_app_codegen)(jsOrTs));
112
116
  // ./app/plasmic-host/page.tsx
@@ -121,20 +125,8 @@ function generateFilesAppDir(args) {
121
125
  projectApiToken,
122
126
  projectPath,
123
127
  });
124
- // Read plasmic.json so we can wire each top-level project's plasmic.css
125
- // import directly into the root layout template.
126
- const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
127
- const layoutAbsPath = path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`);
128
- const cssImports = getPlasmicCssImports({
129
- projectPath,
130
- rootFileAbsPath: layoutAbsPath,
131
- config,
132
- });
133
- // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
134
- (0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "app", "layout.*"));
135
- // ./app/layout.tsx
136
- yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `layout.${jsOrTs}x`), (0, layout_1.makeLayout_app_codegen)(jsOrTs, cssImports));
137
128
  // Make an index (/) page if the project didn't have one.
129
+ const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
138
130
  const plasmicFiles = lodash_1.default.map(lodash_1.default.flatMap(config.projects, (p) => p.components), (c) => c.importSpec.modulePath);
139
131
  if (!plasmicFiles.find((f) => f.includes("app/page."))) {
140
132
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", `page.${jsOrTs}x`), (0, file_utils_1.generateWelcomePage)(config, "nextjs"));
@@ -156,6 +148,8 @@ function generateFilesPagesDir(args) {
156
148
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `[[...catchall]].${jsOrTs}x`), (0, catchall_page_2.makeCatchallPage_pages_loader)(jsOrTs));
157
149
  }
158
150
  else {
151
+ // ./pages/_app.tsx
152
+ yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `_app.${jsOrTs}x`), (0, app_1.makeCustomApp_pages_codegen)(jsOrTs));
159
153
  // ./pages/plasmic-host.tsx
160
154
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`), (0, plasmic_host_3.makePlasmicHostPage_pages_codegen)());
161
155
  // This should generate
@@ -167,18 +161,8 @@ function generateFilesPagesDir(args) {
167
161
  projectApiToken,
168
162
  projectPath,
169
163
  });
170
- // Read plasmic.json so we can wire each top-level project's plasmic.css
171
- // import directly into the _app template.
172
- const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
173
- const appAbsPath = path_1.default.join(projectPath, "pages", `_app.${jsOrTs}x`);
174
- const cssImports = getPlasmicCssImports({
175
- projectPath,
176
- rootFileAbsPath: appAbsPath,
177
- config,
178
- });
179
- // ./pages/_app.tsx
180
- yield fs_1.promises.writeFile(appAbsPath, (0, app_1.makeCustomApp_pages_codegen)(jsOrTs, cssImports));
181
164
  // Make an index page if the project didn't have one.
165
+ const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
182
166
  const plasmicFiles = lodash_1.default.map(lodash_1.default.flatMap(config.projects, (p) => p.components), (c) => c.importSpec.modulePath);
183
167
  if (!plasmicFiles.find((f) => f.includes("/index."))) {
184
168
  yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `index.${jsOrTs}x`), (0, file_utils_1.generateWelcomePage)(config, "nextjs"));
@@ -186,29 +170,3 @@ function generateFilesPagesDir(args) {
186
170
  }
187
171
  });
188
172
  }
189
- /**
190
- * Builds the list of `plasmic.css` imports the Next.js root file (Pages Router
191
- * `_app.{ext}`, App Router `app/layout.{ext}`) needs for every top-level
192
- * project in `plasmic.json`. Next.js disallows global non-module CSS imports
193
- * outside of those files.
194
- *
195
- * The marker comment in the emitted import (plasmic-import: <id>/projectcss)
196
- * matches the convention used by @plasmicapp/cli sync, so subsequent syncs
197
- * can update paths in-place without producing duplicates.
198
- *
199
- * @param rootFileAbsPath Absolute path to the Next.js root file (`_app.{ext}`
200
- * for Pages Router, `app/layout.{ext}` for App Router).
201
- */
202
- function getPlasmicCssImports(args) {
203
- const { projectPath, rootFileAbsPath, config } = args;
204
- return (config.projects || [])
205
- .filter((p) => !p.indirect && !!p.cssFilePath)
206
- .map((p) => {
207
- const absoluteCssPath = path_1.default.join(projectPath, config.srcDir, p.cssFilePath);
208
- let relPath = path_1.default.relative(path_1.default.dirname(rootFileAbsPath), absoluteCssPath);
209
- if (!relPath.startsWith(".")) {
210
- relPath = `./${relPath}`;
211
- }
212
- return { projectId: p.projectId, importPath: relPath };
213
- });
214
- }
@@ -1,2 +1,2 @@
1
- import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
2
- export declare function makeLayout_app_codegen(jsOrTs: JsOrTs, cssImports?: PlasmicCssImport[]): string;
1
+ import { JsOrTs } from "../../../utils/types";
2
+ export declare function makeLayout_app_codegen(jsOrTs: JsOrTs): string;
@@ -2,14 +2,8 @@
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, 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'
5
+ function makeLayout_app_codegen(jsOrTs) {
6
+ return `import '@/app/globals.css'
13
7
  import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
14
8
 
15
9
  export default function RootLayout({
@@ -1,2 +1,2 @@
1
- import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
2
- export declare function makeCustomApp_pages_codegen(jsOrTs: JsOrTs, cssImports?: PlasmicCssImport[]): string;
1
+ import { JsOrTs } from "../../../utils/types";
2
+ export declare function makeCustomApp_pages_codegen(jsOrTs: JsOrTs): string;
@@ -2,14 +2,8 @@
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, 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'
5
+ function makeCustomApp_pages_codegen(jsOrTs) {
6
+ return `import '@/styles/globals.css'
13
7
  import { PlasmicRootProvider } from "@plasmicapp/react-web";${(0, file_utils_1.ifTs)(jsOrTs, `
14
8
  import type { AppProps } from "next/app";`)}
15
9
  import Head from "next/head";
@@ -6,8 +6,4 @@ 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
- };
13
9
  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.149",
3
+ "version": "0.0.150",
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.362",
36
+ "@plasmicapp/cli": "0.1.363",
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": "2dd9cf093c62331b86ac29449b8e6e33f55c863c"
50
+ "gitHead": "87c9e3389e9f775db1b87fb66ee2fe1c74647914"
51
51
  }
@@ -1,4 +1,3 @@
1
- import { PlasmicConfig } from "@plasmicapp/cli/dist/utils/config-utils";
2
1
  import { promises as fs } from "fs";
3
2
  import L from "lodash";
4
3
  import path from "path";
@@ -12,7 +11,6 @@ import {
12
11
  import { ensure } from "../utils/lang-utils";
13
12
  import { installUpgrade } from "../utils/npm-utils";
14
13
  import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
15
- import { PlasmicCssImport } from "../utils/types";
16
14
  import { makeLayout_app_codegen } from "./templates/app-codegen/layout";
17
15
  import { makePlasmicHostPage_app_codegen } from "./templates/app-codegen/plasmic-host";
18
16
  import { makePlasmicInitClient_app_codegen } from "./templates/app-codegen/plasmic-init-client";
@@ -121,6 +119,15 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
121
119
  makeCatchallPage_app_loader(jsOrTs)
122
120
  );
123
121
  } 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
+
124
131
  // ./plasmic-init-client.tsx
125
132
  await fs.writeFile(
126
133
  path.join(projectPath, `plasmic-init-client.${jsOrTs}x`),
@@ -144,26 +151,8 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
144
151
  projectPath,
145
152
  });
146
153
 
147
- // Read plasmic.json so we can wire each top-level project's plasmic.css
148
- // import directly into the root layout template.
149
- const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
150
- const layoutAbsPath = path.join(projectPath, "app", `layout.${jsOrTs}x`);
151
- const cssImports = getPlasmicCssImports({
152
- projectPath,
153
- rootFileAbsPath: layoutAbsPath,
154
- config,
155
- });
156
-
157
- // Replace starter layout. Removes app/layout.js in JS projects before writing layout.jsx.
158
- deleteGlob(path.join(projectPath, "app", "layout.*"));
159
-
160
- // ./app/layout.tsx
161
- await fs.writeFile(
162
- path.join(projectPath, "app", `layout.${jsOrTs}x`),
163
- makeLayout_app_codegen(jsOrTs, cssImports)
164
- );
165
-
166
154
  // Make an index (/) page if the project didn't have one.
155
+ const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
167
156
  const plasmicFiles = L.map(
168
157
  L.flatMap(config.projects, (p) => p.components),
169
158
  (c) => c.importSpec.modulePath
@@ -205,6 +194,12 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
205
194
  makeCatchallPage_pages_loader(jsOrTs)
206
195
  );
207
196
  } else {
197
+ // ./pages/_app.tsx
198
+ await fs.writeFile(
199
+ path.join(projectPath, "pages", `_app.${jsOrTs}x`),
200
+ makeCustomApp_pages_codegen(jsOrTs)
201
+ );
202
+
208
203
  // ./pages/plasmic-host.tsx
209
204
  await fs.writeFile(
210
205
  path.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`),
@@ -221,23 +216,8 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
221
216
  projectPath,
222
217
  });
223
218
 
224
- // Read plasmic.json so we can wire each top-level project's plasmic.css
225
- // import directly into the _app template.
226
- const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
227
- const appAbsPath = path.join(projectPath, "pages", `_app.${jsOrTs}x`);
228
- const cssImports = getPlasmicCssImports({
229
- projectPath,
230
- rootFileAbsPath: appAbsPath,
231
- config,
232
- });
233
-
234
- // ./pages/_app.tsx
235
- await fs.writeFile(
236
- appAbsPath,
237
- makeCustomApp_pages_codegen(jsOrTs, cssImports)
238
- );
239
-
240
219
  // Make an index page if the project didn't have one.
220
+ const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
241
221
  const plasmicFiles = L.map(
242
222
  L.flatMap(config.projects, (p) => p.components),
243
223
  (c) => c.importSpec.modulePath
@@ -250,42 +230,3 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
250
230
  }
251
231
  }
252
232
  }
253
-
254
- /**
255
- * Builds the list of `plasmic.css` imports the Next.js root file (Pages Router
256
- * `_app.{ext}`, App Router `app/layout.{ext}`) needs for every top-level
257
- * project in `plasmic.json`. Next.js disallows global non-module CSS imports
258
- * outside of those files.
259
- *
260
- * The marker comment in the emitted import (plasmic-import: <id>/projectcss)
261
- * matches the convention used by @plasmicapp/cli sync, so subsequent syncs
262
- * can update paths in-place without producing duplicates.
263
- *
264
- * @param rootFileAbsPath Absolute path to the Next.js root file (`_app.{ext}`
265
- * for Pages Router, `app/layout.{ext}` for App Router).
266
- */
267
- function getPlasmicCssImports(args: {
268
- projectPath: string;
269
- rootFileAbsPath: string;
270
- config: PlasmicConfig;
271
- }): PlasmicCssImport[] {
272
- const { projectPath, rootFileAbsPath, config } = args;
273
- return (config.projects || [])
274
- .filter((p) => !p.indirect && !!p.cssFilePath)
275
- .map((p) => {
276
- const absoluteCssPath = path.join(
277
- projectPath,
278
- config.srcDir,
279
- p.cssFilePath
280
- );
281
- let relPath = path.relative(
282
- path.dirname(rootFileAbsPath),
283
- absoluteCssPath
284
- );
285
- if (!relPath.startsWith(".")) {
286
- relPath = `./${relPath}`;
287
- }
288
-
289
- return { projectId: p.projectId, importPath: relPath };
290
- });
291
- }
@@ -1,21 +1,8 @@
1
1
  import { ifTs } from "../../../utils/file-utils";
2
- import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
2
+ import { JsOrTs } from "../../../utils/types";
3
3
 
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'
4
+ export function makeLayout_app_codegen(jsOrTs: JsOrTs): string {
5
+ return `import '@/app/globals.css'
19
6
  import { ClientPlasmicRootProvider } from "@/plasmic-init-client";
20
7
 
21
8
  export default function RootLayout({
@@ -1,21 +1,8 @@
1
1
  import { ifTs } from "../../../utils/file-utils";
2
- import { JsOrTs, PlasmicCssImport } from "../../../utils/types";
2
+ import { JsOrTs } from "../../../utils/types";
3
3
 
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'
4
+ export function makeCustomApp_pages_codegen(jsOrTs: JsOrTs): string {
5
+ return `import '@/styles/globals.css'
19
6
  import { PlasmicRootProvider } from "@plasmicapp/react-web";${ifTs(
20
7
  jsOrTs,
21
8
  `
@@ -7,11 +7,6 @@ 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
-
15
10
  export function platformTypeToString(s: PlatformType): string {
16
11
  return s === "nextjs"
17
12
  ? "Next.js"