create-plasmic-app 0.0.33 → 0.0.37
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/dist/index.d.ts +1 -1
- package/dist/index.js +4 -7
- package/dist/lib.js +33 -46
- package/dist/strategies/common.d.ts +8 -0
- package/dist/strategies/common.js +34 -0
- package/dist/strategies/gatsby.js +71 -41
- package/dist/strategies/nextjs.js +52 -14
- package/dist/strategies/react.js +26 -9
- package/dist/strategies/types.d.ts +15 -4
- package/dist/templates/gatsby.d.ts +10 -2
- package/dist/templates/gatsby.js +149 -8
- package/dist/templates/nextjs.d.ts +3 -1
- package/dist/templates/nextjs.js +64 -14
- package/dist/utils/file-utils.d.ts +1 -9
- package/dist/utils/file-utils.js +4 -78
- package/n/.cache/redux/redux.node.state_0 +0 -0
- package/n/.cache/redux/redux.page.state_0 +0 -0
- package/n/.cache/redux/redux.rest.state +0 -0
- package/package.json +1 -1
- package/src/index.ts +7 -8
- package/src/lib.ts +37 -62
- package/src/strategies/common.ts +30 -0
- package/src/strategies/gatsby.ts +100 -36
- package/src/strategies/nextjs.ts +85 -23
- package/src/strategies/react.ts +30 -11
- package/src/strategies/types.ts +17 -4
- package/src/templates/gatsby.ts +170 -7
- package/src/templates/nextjs.ts +61 -10
- package/src/utils/file-utils.ts +2 -113
package/src/templates/nextjs.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { CodeScheme } from "..";
|
|
2
|
+
import { ifTs } from "../utils/file-utils";
|
|
3
|
+
|
|
1
4
|
export const makeNextjsInitPage = (
|
|
2
5
|
projectId: string,
|
|
3
6
|
projectApiToken: string
|
|
@@ -30,10 +33,6 @@ export const PLASMIC = initPlasmicLoader({
|
|
|
30
33
|
// PLASMIC.registerComponent(...);
|
|
31
34
|
`.trim();
|
|
32
35
|
|
|
33
|
-
function ifTs(ts: boolean, str: string) {
|
|
34
|
-
return ts ? str : "";
|
|
35
|
-
}
|
|
36
|
-
|
|
37
36
|
export function makeNextjsCatchallPage(format: "ts" | "js"): string {
|
|
38
37
|
const ts = format === "ts";
|
|
39
38
|
return `
|
|
@@ -96,20 +95,28 @@ export const getStaticPaths${ifTs(ts, `: GetStaticPaths`)} = async () => {
|
|
|
96
95
|
catchall: mod.path.substring(1).split("/"),
|
|
97
96
|
},
|
|
98
97
|
})),
|
|
99
|
-
|
|
98
|
+
|
|
99
|
+
// Turn on "fallback: 'blocking'" if you would like new paths created
|
|
100
|
+
// in Plasmic to be automatically available
|
|
101
|
+
fallback: false,
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
`.trim();
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
export function makeNextjsHostPage(): string {
|
|
106
|
-
|
|
107
|
+
export function makeNextjsHostPage(scheme: CodeScheme): string {
|
|
108
|
+
const commonImports = `
|
|
107
109
|
import * as React from 'react';
|
|
108
|
-
import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs';
|
|
109
110
|
import Script from 'next/script';
|
|
111
|
+
`.trim();
|
|
112
|
+
|
|
113
|
+
if (scheme === "loader") {
|
|
114
|
+
return `
|
|
115
|
+
${commonImports}
|
|
116
|
+
import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs';
|
|
110
117
|
import { PLASMIC } from '../plasmic-init';
|
|
111
118
|
|
|
112
|
-
export default function
|
|
119
|
+
export default function PlasmicHost() {
|
|
113
120
|
return PLASMIC && (
|
|
114
121
|
<div>
|
|
115
122
|
<Script
|
|
@@ -120,5 +127,49 @@ export default function Host() {
|
|
|
120
127
|
</div>
|
|
121
128
|
);
|
|
122
129
|
}
|
|
123
|
-
|
|
130
|
+
`;
|
|
131
|
+
} else {
|
|
132
|
+
return `
|
|
133
|
+
${commonImports}
|
|
134
|
+
import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/host';
|
|
135
|
+
|
|
136
|
+
// You can register any code components that you want to use here; see
|
|
137
|
+
// https://docs.plasmic.app/learn/code-components-ref/
|
|
138
|
+
// And configure your Plasmic project to use the host url pointing at
|
|
139
|
+
// the /plasmic-host page of your nextjs app (for example,
|
|
140
|
+
// http://localhost:3000/plasmic-host). See
|
|
141
|
+
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
142
|
+
|
|
143
|
+
// registerComponent(...)
|
|
144
|
+
|
|
145
|
+
export default function PlasmicHost() {
|
|
146
|
+
return (
|
|
147
|
+
<div>
|
|
148
|
+
<Script
|
|
149
|
+
src="https://static1.plasmic.app/preamble.js"
|
|
150
|
+
strategy="beforeInteractive"
|
|
151
|
+
/>
|
|
152
|
+
<PlasmicCanvasHost />
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function wrapAppRootForCodegen() {
|
|
161
|
+
return `
|
|
162
|
+
import '../styles/globals.css'
|
|
163
|
+
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
164
|
+
|
|
165
|
+
function MyApp({ Component, pageProps }) {
|
|
166
|
+
return (
|
|
167
|
+
<PlasmicRootProvider>
|
|
168
|
+
<Component {...pageProps} />
|
|
169
|
+
</PlasmicRootProvider>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export default MyApp
|
|
174
|
+
`;
|
|
124
175
|
}
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -4,11 +4,6 @@ import L from "lodash";
|
|
|
4
4
|
import * as path from "upath";
|
|
5
5
|
import { PlatformType } from "../lib";
|
|
6
6
|
import { GATSBY_404 } from "../templates/gatsby";
|
|
7
|
-
import {
|
|
8
|
-
makeNextjsCatchallPage,
|
|
9
|
-
makeNextjsHostPage,
|
|
10
|
-
makeNextjsInitPage,
|
|
11
|
-
} from "../templates/nextjs";
|
|
12
7
|
import { README } from "../templates/readme";
|
|
13
8
|
import { WELCOME_PAGE } from "../templates/welcomePage";
|
|
14
9
|
import { ensure, ensureString } from "./lang-utils";
|
|
@@ -45,67 +40,6 @@ export function stripExtension(
|
|
|
45
40
|
return filename.substring(0, filename.lastIndexOf(ext));
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
/**
|
|
49
|
-
* create-next-app doesn't create next.config.js,
|
|
50
|
-
* so it's safe to just write the file
|
|
51
|
-
* @param absPath
|
|
52
|
-
* @param projectId
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
export async function writeDefaultNextjsConfig(
|
|
56
|
-
projectDir: string,
|
|
57
|
-
projectId: string,
|
|
58
|
-
loader: boolean,
|
|
59
|
-
projectApiToken?: string,
|
|
60
|
-
useTypescript?: boolean
|
|
61
|
-
): Promise<void> {
|
|
62
|
-
const nextjsConfigFile = path.join(projectDir, "next.config.js");
|
|
63
|
-
|
|
64
|
-
if (!loader) {
|
|
65
|
-
await fs.writeFile(
|
|
66
|
-
nextjsConfigFile,
|
|
67
|
-
`
|
|
68
|
-
module.exports = {
|
|
69
|
-
eslint: {
|
|
70
|
-
ignoreDuringBuilds: true,
|
|
71
|
-
},
|
|
72
|
-
trailingSlash: true,
|
|
73
|
-
// Your NextJS config.
|
|
74
|
-
};
|
|
75
|
-
`
|
|
76
|
-
);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (loader && projectApiToken) {
|
|
81
|
-
const initFile = path.join(
|
|
82
|
-
projectDir,
|
|
83
|
-
`plasmic-init.${useTypescript ? "ts" : "js"}`
|
|
84
|
-
);
|
|
85
|
-
await fs.writeFile(
|
|
86
|
-
initFile,
|
|
87
|
-
makeNextjsInitPage(projectId, projectApiToken)
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const pagesFolder = path.join(projectDir, "pages");
|
|
91
|
-
const loaderPage = path.join(
|
|
92
|
-
pagesFolder,
|
|
93
|
-
`[[...catchall]].${useTypescript ? "tsx" : "jsx"}`
|
|
94
|
-
);
|
|
95
|
-
await fs.writeFile(
|
|
96
|
-
loaderPage,
|
|
97
|
-
makeNextjsCatchallPage(useTypescript ? "ts" : "js")
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const hostPage = path.join(
|
|
101
|
-
pagesFolder,
|
|
102
|
-
`plasmic-host.${useTypescript ? "tsx" : "jsx"}`
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
await fs.writeFile(hostPage, makeNextjsHostPage());
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
43
|
export async function writePlasmicLoaderJson(
|
|
110
44
|
projectDir: string,
|
|
111
45
|
projectId: string,
|
|
@@ -336,51 +270,6 @@ export async function ensureTsconfig(projectPath: string): Promise<void> {
|
|
|
336
270
|
}
|
|
337
271
|
}
|
|
338
272
|
|
|
339
|
-
export
|
|
340
|
-
|
|
341
|
-
platform: string,
|
|
342
|
-
scheme: string
|
|
343
|
-
): Promise<void> {
|
|
344
|
-
// with create-plasmic-app v2, isLoader=false
|
|
345
|
-
const isLoader = scheme === "loader";
|
|
346
|
-
const importPkg = isLoader ? `@plasmicapp/loader` : "@plasmicapp/react-web";
|
|
347
|
-
if (platform === "nextjs") {
|
|
348
|
-
const appFilePath = path.join(projectPath, "pages", `_app.js`);
|
|
349
|
-
await fs.writeFile(
|
|
350
|
-
appFilePath,
|
|
351
|
-
`
|
|
352
|
-
import '../styles/globals.css'
|
|
353
|
-
import { PlasmicRootProvider } from "${importPkg}"
|
|
354
|
-
|
|
355
|
-
function MyApp({ Component, pageProps }) {
|
|
356
|
-
return (
|
|
357
|
-
<PlasmicRootProvider>
|
|
358
|
-
<Component {...pageProps} />
|
|
359
|
-
</PlasmicRootProvider>
|
|
360
|
-
)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export default MyApp
|
|
364
|
-
`.trim()
|
|
365
|
-
);
|
|
366
|
-
} else if (platform === "gatsby") {
|
|
367
|
-
const wrapperContent = `
|
|
368
|
-
import React from "react";
|
|
369
|
-
import { PlasmicRootProvider } from "${importPkg}";
|
|
370
|
-
|
|
371
|
-
export const wrapRootElement = ({ element }) => {
|
|
372
|
-
return (
|
|
373
|
-
<PlasmicRootProvider>
|
|
374
|
-
{element}
|
|
375
|
-
</PlasmicRootProvider>
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
`.trim();
|
|
379
|
-
|
|
380
|
-
const browserFilePath = path.join(projectPath, "gatsby-browser.js");
|
|
381
|
-
await fs.writeFile(browserFilePath, wrapperContent);
|
|
382
|
-
|
|
383
|
-
const ssrFilePath = path.join(projectPath, "gatsby-ssr.js");
|
|
384
|
-
await fs.writeFile(ssrFilePath, wrapperContent);
|
|
385
|
-
}
|
|
273
|
+
export function ifTs(ts: boolean, str: string) {
|
|
274
|
+
return ts ? str : "";
|
|
386
275
|
}
|