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/dist/templates/gatsby.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GATSBY_PLUGIN_CONFIG = exports.GATSBY_404 = exports.
|
|
4
|
-
|
|
3
|
+
exports.wrapAppRootForCodegen = exports.makeGatsbyPlasmicInit = exports.GATSBY_SSR_CONFIG = exports.makeGatsbyHostPage = exports.GATSBY_PLUGIN_CONFIG = exports.GATSBY_404 = exports.makeGatsbyDefaultPage = void 0;
|
|
4
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
5
|
+
const makeGatsbyDefaultPage = (format) => {
|
|
6
|
+
const ts = format === "ts";
|
|
7
|
+
return `
|
|
5
8
|
import React from "react";
|
|
6
9
|
import Helmet from "react-helmet";
|
|
7
10
|
import {
|
|
8
|
-
initPlasmicLoader,
|
|
9
11
|
PlasmicComponent,
|
|
10
|
-
PlasmicRootProvider,
|
|
12
|
+
PlasmicRootProvider,${file_utils_1.ifTs(ts, `
|
|
13
|
+
InitOptions,
|
|
14
|
+
ComponentRenderData,`)}
|
|
11
15
|
} from "@plasmicapp/loader-gatsby";
|
|
12
16
|
import { graphql } from "gatsby";
|
|
17
|
+
import { initPlasmicLoaderWithRegistrations } from "../plasmic-init";
|
|
13
18
|
|
|
14
19
|
export const query = graphql\`
|
|
15
20
|
query ($path: String) {
|
|
@@ -18,7 +23,14 @@ export const query = graphql\`
|
|
|
18
23
|
}
|
|
19
24
|
\`;
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
${file_utils_1.ifTs(ts, `interface PlasmicGatsbyPageProps {
|
|
27
|
+
data: {
|
|
28
|
+
plasmicOptions: InitOptions
|
|
29
|
+
plasmicComponents: ComponentRenderData
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`)}
|
|
33
|
+
const PlasmicGatsbyPage = ({ data }${file_utils_1.ifTs(ts, ": PlasmicGatsbyPageProps")}) => {
|
|
22
34
|
const {
|
|
23
35
|
plasmicComponents,
|
|
24
36
|
plasmicOptions,
|
|
@@ -27,7 +39,7 @@ const PlasmicGatsbyPage = ({ data, location }) => {
|
|
|
27
39
|
const pageMetadata = pageMeta.pageMetadata;
|
|
28
40
|
return (
|
|
29
41
|
<PlasmicRootProvider
|
|
30
|
-
loader={
|
|
42
|
+
loader={initPlasmicLoaderWithRegistrations(plasmicOptions)}
|
|
31
43
|
prefetchedData={plasmicComponents}
|
|
32
44
|
>
|
|
33
45
|
<Helmet>
|
|
@@ -43,13 +55,15 @@ const PlasmicGatsbyPage = ({ data, location }) => {
|
|
|
43
55
|
|
|
44
56
|
export default PlasmicGatsbyPage;
|
|
45
57
|
`.trim();
|
|
58
|
+
};
|
|
59
|
+
exports.makeGatsbyDefaultPage = makeGatsbyDefaultPage;
|
|
46
60
|
exports.GATSBY_404 = `
|
|
47
61
|
const NotFound = () => {
|
|
48
62
|
return "Not Found";
|
|
49
63
|
};
|
|
50
64
|
export default NotFound;
|
|
51
65
|
`.trim();
|
|
52
|
-
const GATSBY_PLUGIN_CONFIG = (projectId, projectApiToken) => `
|
|
66
|
+
const GATSBY_PLUGIN_CONFIG = (projectId, projectApiToken, useTypescript) => `
|
|
53
67
|
{
|
|
54
68
|
resolve: "@plasmicapp/loader-gatsby",
|
|
55
69
|
options: {
|
|
@@ -59,8 +73,135 @@ const GATSBY_PLUGIN_CONFIG = (projectId, projectApiToken) => `
|
|
|
59
73
|
token: "${projectApiToken}",
|
|
60
74
|
},
|
|
61
75
|
], // An array of project ids.
|
|
62
|
-
defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage
|
|
76
|
+
defaultPlasmicPage: require.resolve("./src/templates/defaultPlasmicPage.${useTypescript ? "tsx" : "jsx"}"),
|
|
63
77
|
},
|
|
64
78
|
},
|
|
65
79
|
`;
|
|
66
80
|
exports.GATSBY_PLUGIN_CONFIG = GATSBY_PLUGIN_CONFIG;
|
|
81
|
+
const makeGatsbyHostPage = (opts) => {
|
|
82
|
+
const { useTypescript, scheme } = opts;
|
|
83
|
+
if (scheme === "loader") {
|
|
84
|
+
return `
|
|
85
|
+
import * as React from "react"
|
|
86
|
+
import {
|
|
87
|
+
PlasmicCanvasHost${file_utils_1.ifTs(useTypescript, `, InitOptions`)}
|
|
88
|
+
} from "@plasmicapp/loader-gatsby"
|
|
89
|
+
import { graphql } from "gatsby"
|
|
90
|
+
import { initPlasmicLoaderWithRegistrations } from "../plasmic-init"
|
|
91
|
+
|
|
92
|
+
export const query = graphql\`
|
|
93
|
+
query {
|
|
94
|
+
plasmicOptions
|
|
95
|
+
}
|
|
96
|
+
\`
|
|
97
|
+
|
|
98
|
+
${file_utils_1.ifTs(useTypescript, `interface HostProps {
|
|
99
|
+
data: {
|
|
100
|
+
plasmicOptions: InitOptions;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`)}
|
|
104
|
+
export default function Host({ data }${file_utils_1.ifTs(useTypescript, ": HostProps")}) {
|
|
105
|
+
const { plasmicOptions } = data
|
|
106
|
+
initPlasmicLoaderWithRegistrations(plasmicOptions)
|
|
107
|
+
return <PlasmicCanvasHost />
|
|
108
|
+
}
|
|
109
|
+
`.trim();
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return `
|
|
113
|
+
import * as React from "react"
|
|
114
|
+
import { PlasmicCanvasHost, registerComponent } from "@plasmicapp/host";
|
|
115
|
+
|
|
116
|
+
// You can register any code components that you want to use here; see
|
|
117
|
+
// https://docs.plasmic.app/learn/code-components-ref/
|
|
118
|
+
// And configure your Plasmic project to use the host url pointing at
|
|
119
|
+
// the /plasmic-host page of your nextjs app (for example,
|
|
120
|
+
// http://localhost:3000/plasmic-host). See
|
|
121
|
+
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
122
|
+
|
|
123
|
+
// registerComponent(...)
|
|
124
|
+
|
|
125
|
+
export default function PlasmicHost() {
|
|
126
|
+
return (
|
|
127
|
+
<PlasmicCanvasHost />
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.makeGatsbyHostPage = makeGatsbyHostPage;
|
|
134
|
+
exports.GATSBY_SSR_CONFIG = `
|
|
135
|
+
/**
|
|
136
|
+
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
|
|
137
|
+
*
|
|
138
|
+
* See: https://www.gatsbyjs.com/docs/ssr-apis/
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
const React = require("react")
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Add preamble to allow functional code components in studio.
|
|
145
|
+
*
|
|
146
|
+
* See: https://docs.plasmic.app/learn/functional-code-components/
|
|
147
|
+
*/
|
|
148
|
+
const HeadComponents = [
|
|
149
|
+
<script
|
|
150
|
+
key="plasmic-preamble"
|
|
151
|
+
src="https://static1.plasmic.app/preamble.js"
|
|
152
|
+
/>,
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
const isProduction = process.env.NODE_ENV === "production"
|
|
156
|
+
|
|
157
|
+
exports.onRenderBody = ({ pathname, setHeadComponents }) => {
|
|
158
|
+
/**
|
|
159
|
+
* We add the preamble tag script to all pages during development mode
|
|
160
|
+
* because during development all pages are dynamically rendered based
|
|
161
|
+
* on \`/\` route, during production we add it only in \`/plasmic-host/\`
|
|
162
|
+
*/
|
|
163
|
+
if (!isProduction || pathname === "/plasmic-host/") {
|
|
164
|
+
setHeadComponents(HeadComponents)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
`.trim();
|
|
168
|
+
const makeGatsbyPlasmicInit = (format) => {
|
|
169
|
+
const ts = format === "ts";
|
|
170
|
+
return `
|
|
171
|
+
import {
|
|
172
|
+
initPlasmicLoader,${file_utils_1.ifTs(ts, `
|
|
173
|
+
InitOptions,`)}
|
|
174
|
+
} from "@plasmicapp/loader-gatsby";
|
|
175
|
+
|
|
176
|
+
export function initPlasmicLoaderWithRegistrations(plasmicOptions${file_utils_1.ifTs(ts, ": InitOptions")}) {
|
|
177
|
+
const PLASMIC = initPlasmicLoader(plasmicOptions);
|
|
178
|
+
|
|
179
|
+
// You can register any code components that you want to use here; see
|
|
180
|
+
// https://docs.plasmic.app/learn/code-components-ref/
|
|
181
|
+
// And configure your Plasmic project to use the host url pointing at
|
|
182
|
+
// the /plasmic-host page of your nextjs app (for example,
|
|
183
|
+
// http://localhost:8000/plasmic-host). See
|
|
184
|
+
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
185
|
+
|
|
186
|
+
// PLASMIC.registerComponent(...);
|
|
187
|
+
|
|
188
|
+
return PLASMIC;
|
|
189
|
+
}
|
|
190
|
+
`.trim();
|
|
191
|
+
};
|
|
192
|
+
exports.makeGatsbyPlasmicInit = makeGatsbyPlasmicInit;
|
|
193
|
+
function wrapAppRootForCodegen() {
|
|
194
|
+
return `
|
|
195
|
+
import React from "react";
|
|
196
|
+
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
197
|
+
|
|
198
|
+
export const wrapRootElement = ({ element }) => {
|
|
199
|
+
return (
|
|
200
|
+
<PlasmicRootProvider>
|
|
201
|
+
{element}
|
|
202
|
+
</PlasmicRootProvider>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
exports.wrapAppRootForCodegen = wrapAppRootForCodegen;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodeScheme } from "..";
|
|
1
2
|
export declare const makeNextjsInitPage: (projectId: string, projectApiToken: string) => string;
|
|
2
3
|
export declare function makeNextjsCatchallPage(format: "ts" | "js"): string;
|
|
3
|
-
export declare function makeNextjsHostPage(): string;
|
|
4
|
+
export declare function makeNextjsHostPage(scheme: CodeScheme): string;
|
|
5
|
+
export declare function wrapAppRootForCodegen(): string;
|
package/dist/templates/nextjs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeNextjsHostPage = exports.makeNextjsCatchallPage = exports.makeNextjsInitPage = void 0;
|
|
3
|
+
exports.wrapAppRootForCodegen = exports.makeNextjsHostPage = exports.makeNextjsCatchallPage = exports.makeNextjsInitPage = void 0;
|
|
4
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
4
5
|
const makeNextjsInitPage = (projectId, projectApiToken) => `
|
|
5
6
|
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs";
|
|
6
7
|
|
|
@@ -29,15 +30,12 @@ export const PLASMIC = initPlasmicLoader({
|
|
|
29
30
|
// PLASMIC.registerComponent(...);
|
|
30
31
|
`.trim();
|
|
31
32
|
exports.makeNextjsInitPage = makeNextjsInitPage;
|
|
32
|
-
function ifTs(ts, str) {
|
|
33
|
-
return ts ? str : "";
|
|
34
|
-
}
|
|
35
33
|
function makeNextjsCatchallPage(format) {
|
|
36
34
|
const ts = format === "ts";
|
|
37
35
|
return `
|
|
38
36
|
import * as React from "react";
|
|
39
37
|
import { PlasmicComponent } from "@plasmicapp/loader-nextjs";
|
|
40
|
-
${ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
38
|
+
${file_utils_1.ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
41
39
|
import {
|
|
42
40
|
ComponentRenderData,
|
|
43
41
|
PlasmicRootProvider,
|
|
@@ -45,7 +43,7 @@ import {
|
|
|
45
43
|
import Error from "next/error";
|
|
46
44
|
import { PLASMIC } from "../plasmic-init";
|
|
47
45
|
|
|
48
|
-
export default function PlasmicLoaderPage(props${ifTs(ts, `: {
|
|
46
|
+
export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
|
|
49
47
|
plasmicData?: ComponentRenderData;
|
|
50
48
|
}`)}) {
|
|
51
49
|
const { plasmicData } = props;
|
|
@@ -62,7 +60,7 @@ export default function PlasmicLoaderPage(props${ifTs(ts, `: {
|
|
|
62
60
|
);
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
export const getStaticProps${ifTs(ts, `: GetStaticProps`)} = async (context) => {
|
|
63
|
+
export const getStaticProps${file_utils_1.ifTs(ts, `: GetStaticProps`)} = async (context) => {
|
|
66
64
|
const { catchall } = context.params ?? {};
|
|
67
65
|
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
|
|
68
66
|
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
@@ -80,7 +78,7 @@ export const getStaticProps${ifTs(ts, `: GetStaticProps`)} = async (context) =>
|
|
|
80
78
|
};
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
export const getStaticPaths${ifTs(ts, `: GetStaticPaths`)} = async () => {
|
|
81
|
+
export const getStaticPaths${file_utils_1.ifTs(ts, `: GetStaticPaths`)} = async () => {
|
|
84
82
|
const pageModules = await PLASMIC.fetchPages();
|
|
85
83
|
return {
|
|
86
84
|
paths: pageModules.map((mod) => ({
|
|
@@ -88,20 +86,27 @@ export const getStaticPaths${ifTs(ts, `: GetStaticPaths`)} = async () => {
|
|
|
88
86
|
catchall: mod.path.substring(1).split("/"),
|
|
89
87
|
},
|
|
90
88
|
})),
|
|
91
|
-
|
|
89
|
+
|
|
90
|
+
// Turn on "fallback: 'blocking'" if you would like new paths created
|
|
91
|
+
// in Plasmic to be automatically available
|
|
92
|
+
fallback: false,
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
95
|
`.trim();
|
|
95
96
|
}
|
|
96
97
|
exports.makeNextjsCatchallPage = makeNextjsCatchallPage;
|
|
97
|
-
function makeNextjsHostPage() {
|
|
98
|
-
|
|
98
|
+
function makeNextjsHostPage(scheme) {
|
|
99
|
+
const commonImports = `
|
|
99
100
|
import * as React from 'react';
|
|
100
|
-
import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs';
|
|
101
101
|
import Script from 'next/script';
|
|
102
|
+
`.trim();
|
|
103
|
+
if (scheme === "loader") {
|
|
104
|
+
return `
|
|
105
|
+
${commonImports}
|
|
106
|
+
import { PlasmicCanvasHost } from '@plasmicapp/loader-nextjs';
|
|
102
107
|
import { PLASMIC } from '../plasmic-init';
|
|
103
108
|
|
|
104
|
-
export default function
|
|
109
|
+
export default function PlasmicHost() {
|
|
105
110
|
return PLASMIC && (
|
|
106
111
|
<div>
|
|
107
112
|
<Script
|
|
@@ -112,6 +117,51 @@ export default function Host() {
|
|
|
112
117
|
</div>
|
|
113
118
|
);
|
|
114
119
|
}
|
|
115
|
-
|
|
120
|
+
`;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return `
|
|
124
|
+
${commonImports}
|
|
125
|
+
import { PlasmicCanvasHost, registerComponent } from '@plasmicapp/host';
|
|
126
|
+
|
|
127
|
+
// You can register any code components that you want to use here; see
|
|
128
|
+
// https://docs.plasmic.app/learn/code-components-ref/
|
|
129
|
+
// And configure your Plasmic project to use the host url pointing at
|
|
130
|
+
// the /plasmic-host page of your nextjs app (for example,
|
|
131
|
+
// http://localhost:3000/plasmic-host). See
|
|
132
|
+
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
|
|
133
|
+
|
|
134
|
+
// registerComponent(...)
|
|
135
|
+
|
|
136
|
+
export default function PlasmicHost() {
|
|
137
|
+
return (
|
|
138
|
+
<div>
|
|
139
|
+
<Script
|
|
140
|
+
src="https://static1.plasmic.app/preamble.js"
|
|
141
|
+
strategy="beforeInteractive"
|
|
142
|
+
/>
|
|
143
|
+
<PlasmicCanvasHost />
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
}
|
|
116
149
|
}
|
|
117
150
|
exports.makeNextjsHostPage = makeNextjsHostPage;
|
|
151
|
+
function wrapAppRootForCodegen() {
|
|
152
|
+
return `
|
|
153
|
+
import '../styles/globals.css'
|
|
154
|
+
import { PlasmicRootProvider } from "@plasmicapp/react-web";
|
|
155
|
+
|
|
156
|
+
function MyApp({ Component, pageProps }) {
|
|
157
|
+
return (
|
|
158
|
+
<PlasmicRootProvider>
|
|
159
|
+
<Component {...pageProps} />
|
|
160
|
+
</PlasmicRootProvider>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export default MyApp
|
|
165
|
+
`;
|
|
166
|
+
}
|
|
167
|
+
exports.wrapAppRootForCodegen = wrapAppRootForCodegen;
|
|
@@ -6,14 +6,6 @@ import { PlatformType } from "../lib";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function deleteGlob(searchPattern: string, skipPatterns?: string[]): void;
|
|
8
8
|
export declare function stripExtension(filename: string, removeComposedPath?: boolean): string;
|
|
9
|
-
/**
|
|
10
|
-
* create-next-app doesn't create next.config.js,
|
|
11
|
-
* so it's safe to just write the file
|
|
12
|
-
* @param absPath
|
|
13
|
-
* @param projectId
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export declare function writeDefaultNextjsConfig(projectDir: string, projectId: string, loader: boolean, projectApiToken?: string, useTypescript?: boolean): Promise<void>;
|
|
17
9
|
export declare function writePlasmicLoaderJson(projectDir: string, projectId: string, projectApiToken: string): Promise<void>;
|
|
18
10
|
/**
|
|
19
11
|
* - [nextjs|gatsby, loader, '/' page exists] - remove index file
|
|
@@ -32,4 +24,4 @@ export declare function overwriteIndex(projectPath: string, platform: string, sc
|
|
|
32
24
|
*/
|
|
33
25
|
export declare function overwriteReadme(projectPath: string, platform: PlatformType, buildCommand: string): Promise<void>;
|
|
34
26
|
export declare function ensureTsconfig(projectPath: string): Promise<void>;
|
|
35
|
-
export declare function
|
|
27
|
+
export declare function ifTs(ts: boolean, str: string): string;
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -31,13 +31,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.
|
|
34
|
+
exports.ifTs = exports.ensureTsconfig = exports.overwriteReadme = exports.overwriteIndex = exports.writePlasmicLoaderJson = exports.stripExtension = exports.deleteGlob = void 0;
|
|
35
35
|
const fs_1 = require("fs");
|
|
36
36
|
const glob_1 = __importDefault(require("glob"));
|
|
37
37
|
const lodash_1 = __importDefault(require("lodash"));
|
|
38
38
|
const path = __importStar(require("upath"));
|
|
39
39
|
const gatsby_1 = require("../templates/gatsby");
|
|
40
|
-
const nextjs_1 = require("../templates/nextjs");
|
|
41
40
|
const readme_1 = require("../templates/readme");
|
|
42
41
|
const welcomePage_1 = require("../templates/welcomePage");
|
|
43
42
|
const lang_utils_1 = require("./lang-utils");
|
|
@@ -64,40 +63,6 @@ function stripExtension(filename, removeComposedPath = false) {
|
|
|
64
63
|
return filename.substring(0, filename.lastIndexOf(ext));
|
|
65
64
|
}
|
|
66
65
|
exports.stripExtension = stripExtension;
|
|
67
|
-
/**
|
|
68
|
-
* create-next-app doesn't create next.config.js,
|
|
69
|
-
* so it's safe to just write the file
|
|
70
|
-
* @param absPath
|
|
71
|
-
* @param projectId
|
|
72
|
-
* @returns
|
|
73
|
-
*/
|
|
74
|
-
function writeDefaultNextjsConfig(projectDir, projectId, loader, projectApiToken, useTypescript) {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
const nextjsConfigFile = path.join(projectDir, "next.config.js");
|
|
77
|
-
if (!loader) {
|
|
78
|
-
yield fs_1.promises.writeFile(nextjsConfigFile, `
|
|
79
|
-
module.exports = {
|
|
80
|
-
eslint: {
|
|
81
|
-
ignoreDuringBuilds: true,
|
|
82
|
-
},
|
|
83
|
-
trailingSlash: true,
|
|
84
|
-
// Your NextJS config.
|
|
85
|
-
};
|
|
86
|
-
`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (loader && projectApiToken) {
|
|
90
|
-
const initFile = path.join(projectDir, `plasmic-init.${useTypescript ? "ts" : "js"}`);
|
|
91
|
-
yield fs_1.promises.writeFile(initFile, nextjs_1.makeNextjsInitPage(projectId, projectApiToken));
|
|
92
|
-
const pagesFolder = path.join(projectDir, "pages");
|
|
93
|
-
const loaderPage = path.join(pagesFolder, `[[...catchall]].${useTypescript ? "tsx" : "jsx"}`);
|
|
94
|
-
yield fs_1.promises.writeFile(loaderPage, nextjs_1.makeNextjsCatchallPage(useTypescript ? "ts" : "js"));
|
|
95
|
-
const hostPage = path.join(pagesFolder, `plasmic-host.${useTypescript ? "tsx" : "jsx"}`);
|
|
96
|
-
yield fs_1.promises.writeFile(hostPage, nextjs_1.makeNextjsHostPage());
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
exports.writeDefaultNextjsConfig = writeDefaultNextjsConfig;
|
|
101
66
|
function writePlasmicLoaderJson(projectDir, projectId, projectApiToken) {
|
|
102
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
68
|
const plasmicLoaderJson = path.join(projectDir, "plasmic-loader.json");
|
|
@@ -283,46 +248,7 @@ function ensureTsconfig(projectPath) {
|
|
|
283
248
|
});
|
|
284
249
|
}
|
|
285
250
|
exports.ensureTsconfig = ensureTsconfig;
|
|
286
|
-
function
|
|
287
|
-
return
|
|
288
|
-
// with create-plasmic-app v2, isLoader=false
|
|
289
|
-
const isLoader = scheme === "loader";
|
|
290
|
-
const importPkg = isLoader ? `@plasmicapp/loader` : "@plasmicapp/react-web";
|
|
291
|
-
if (platform === "nextjs") {
|
|
292
|
-
const appFilePath = path.join(projectPath, "pages", `_app.js`);
|
|
293
|
-
yield fs_1.promises.writeFile(appFilePath, `
|
|
294
|
-
import '../styles/globals.css'
|
|
295
|
-
import { PlasmicRootProvider } from "${importPkg}"
|
|
296
|
-
|
|
297
|
-
function MyApp({ Component, pageProps }) {
|
|
298
|
-
return (
|
|
299
|
-
<PlasmicRootProvider>
|
|
300
|
-
<Component {...pageProps} />
|
|
301
|
-
</PlasmicRootProvider>
|
|
302
|
-
)
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export default MyApp
|
|
306
|
-
`.trim());
|
|
307
|
-
}
|
|
308
|
-
else if (platform === "gatsby") {
|
|
309
|
-
const wrapperContent = `
|
|
310
|
-
import React from "react";
|
|
311
|
-
import { PlasmicRootProvider } from "${importPkg}";
|
|
312
|
-
|
|
313
|
-
export const wrapRootElement = ({ element }) => {
|
|
314
|
-
return (
|
|
315
|
-
<PlasmicRootProvider>
|
|
316
|
-
{element}
|
|
317
|
-
</PlasmicRootProvider>
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
`.trim();
|
|
321
|
-
const browserFilePath = path.join(projectPath, "gatsby-browser.js");
|
|
322
|
-
yield fs_1.promises.writeFile(browserFilePath, wrapperContent);
|
|
323
|
-
const ssrFilePath = path.join(projectPath, "gatsby-ssr.js");
|
|
324
|
-
yield fs_1.promises.writeFile(ssrFilePath, wrapperContent);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
251
|
+
function ifTs(ts, str) {
|
|
252
|
+
return ts ? str : "";
|
|
327
253
|
}
|
|
328
|
-
exports.
|
|
254
|
+
exports.ifTs = ifTs;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { setMetadataEnv } from "@plasmicapp/cli";
|
|
3
3
|
import * as Sentry from "@sentry/node";
|
|
4
|
-
import chalk from "chalk";
|
|
5
4
|
import * as fs from "fs";
|
|
6
5
|
import inquirer, { DistinctQuestion } from "inquirer";
|
|
7
6
|
import * as path from "upath";
|
|
@@ -14,6 +13,8 @@ if (process.env.CPA_DEBUG_CHDIR) {
|
|
|
14
13
|
process.chdir(process.env.CPA_DEBUG_CHDIR);
|
|
15
14
|
}
|
|
16
15
|
|
|
16
|
+
export type CodeScheme = "codegen" | "loader";
|
|
17
|
+
|
|
17
18
|
// Check for updates
|
|
18
19
|
const createPlasmicAppVersion = updateNotify();
|
|
19
20
|
|
|
@@ -155,7 +156,7 @@ async function run(): Promise<void> {
|
|
|
155
156
|
|
|
156
157
|
// Scheme to use for Plasmic integration
|
|
157
158
|
// - loader only available for gatsby/next.js
|
|
158
|
-
const scheme:
|
|
159
|
+
const scheme: CodeScheme =
|
|
159
160
|
platform === "nextjs" || platform === "gatsby"
|
|
160
161
|
? await maybePrompt({
|
|
161
162
|
name: "scheme",
|
|
@@ -179,16 +180,14 @@ async function run(): Promise<void> {
|
|
|
179
180
|
|
|
180
181
|
// Get the projectId
|
|
181
182
|
console.log();
|
|
182
|
-
console.log(chalk.green.bold("Go to this URL and **clone** the project:"));
|
|
183
|
-
console.log("https://studio.plasmic.app/starters/simple-light");
|
|
184
|
-
console.log();
|
|
185
|
-
console.log(" Note the project ID in the URL redirect");
|
|
186
|
-
console.log(" (e.g. https://studio.plasmic.app/projects/PROJECT_ID)");
|
|
187
183
|
let projectId: string | undefined;
|
|
188
184
|
while (!projectId) {
|
|
189
185
|
const rawProjectId = await maybePrompt({
|
|
190
186
|
name: "projectId",
|
|
191
|
-
message:
|
|
187
|
+
message: `What is the URL of your project?
|
|
188
|
+
(If you don't have a project yet, create one by going to
|
|
189
|
+
https://studio.plasmic.app/starters/simple-light):
|
|
190
|
+
`,
|
|
192
191
|
});
|
|
193
192
|
projectId = rawProjectId
|
|
194
193
|
.replace("https://studio.plasmic.app/projects/", "")
|
package/src/lib.ts
CHANGED
|
@@ -3,15 +3,8 @@ import chalk from "chalk";
|
|
|
3
3
|
import * as path from "upath";
|
|
4
4
|
import validateProjectName from "validate-npm-package-name";
|
|
5
5
|
import { getCPAStrategy } from "./strategies";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
ensureTsconfig,
|
|
9
|
-
overwriteIndex,
|
|
10
|
-
overwriteReadme,
|
|
11
|
-
wrapAppRoot,
|
|
12
|
-
writeDefaultNextjsConfig,
|
|
13
|
-
} from "./utils/file-utils";
|
|
14
|
-
import { detectPackageManager, installUpgrade } from "./utils/npm-utils";
|
|
6
|
+
import { ensureTsconfig, overwriteReadme } from "./utils/file-utils";
|
|
7
|
+
import { detectPackageManager } from "./utils/npm-utils";
|
|
15
8
|
|
|
16
9
|
export type PlatformType = "nextjs" | "gatsby" | "react";
|
|
17
10
|
export type SchemeType = "codegen" | "loader";
|
|
@@ -84,73 +77,55 @@ export async function create(args: CreatePlasmicAppArgs): Promise<void> {
|
|
|
84
77
|
template,
|
|
85
78
|
});
|
|
86
79
|
|
|
87
|
-
// Ensure that
|
|
88
|
-
|
|
80
|
+
// Ensure that we have a empty tsconfig and @types packages
|
|
81
|
+
// Gatsby by default supports typescript handling internally
|
|
82
|
+
// tsconfig so we don't have to ensure it
|
|
83
|
+
if (useTypescript && platform !== "gatsby") {
|
|
89
84
|
await ensureTsconfig(resolvedProjectPath);
|
|
90
85
|
}
|
|
91
86
|
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const installResult = await installUpgrade("@plasmicapp/cli", {
|
|
96
|
-
workingDir: resolvedProjectPath,
|
|
97
|
-
});
|
|
98
|
-
if (!installResult) {
|
|
99
|
-
throw new Error("Failed to install the Plasmic dependency");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Trigger a sync
|
|
104
|
-
const pkgMgr = detectPackageManager(resolvedProjectPath);
|
|
105
|
-
const npmRunCmd = pkgMgr === "yarn" ? "yarn" : "npm run";
|
|
106
|
-
|
|
107
|
-
if (scheme === "codegen") {
|
|
108
|
-
banner("SYNCING PLASMIC COMPONENTS");
|
|
109
|
-
|
|
110
|
-
const project = projectApiToken
|
|
111
|
-
? `${projectId}:${projectApiToken}`
|
|
112
|
-
: projectId;
|
|
113
|
-
|
|
114
|
-
if (platform === "nextjs") {
|
|
115
|
-
await writeDefaultNextjsConfig(resolvedProjectPath, projectId, false);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await spawnOrFail(
|
|
119
|
-
`npx -p @plasmicapp/cli plasmic sync --yes -p ${project}`,
|
|
120
|
-
resolvedProjectPath
|
|
121
|
-
);
|
|
122
|
-
} else if (scheme === "loader") {
|
|
123
|
-
if (!projectApiToken) {
|
|
124
|
-
projectApiToken = await getProjectApiToken(projectId);
|
|
125
|
-
}
|
|
87
|
+
// Make sure we have an api token for loader
|
|
88
|
+
if (scheme === "loader" && !projectApiToken) {
|
|
89
|
+
projectApiToken = await getProjectApiToken(projectId);
|
|
126
90
|
if (!projectApiToken) {
|
|
127
91
|
throw new Error(`Failed to get projectApiToken for ${projectId}`);
|
|
128
92
|
}
|
|
129
|
-
|
|
130
|
-
await cpaStrategy.configLoader({
|
|
131
|
-
projectPath: resolvedProjectPath,
|
|
132
|
-
projectId,
|
|
133
|
-
projectApiToken,
|
|
134
|
-
useTypescript,
|
|
135
|
-
});
|
|
136
93
|
}
|
|
137
94
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// Overwrite the index file
|
|
145
|
-
await overwriteIndex(resolvedProjectPath, platform, scheme);
|
|
95
|
+
// Install dependency
|
|
96
|
+
banner("INSTALLING THE PLASMIC DEPENDENCY");
|
|
97
|
+
const installResult = await cpaStrategy.installDeps({
|
|
98
|
+
scheme,
|
|
99
|
+
projectPath: resolvedProjectPath,
|
|
100
|
+
});
|
|
146
101
|
|
|
147
|
-
|
|
148
|
-
|
|
102
|
+
if (!installResult) {
|
|
103
|
+
throw new Error("Failed to install the Plasmic dependency");
|
|
149
104
|
}
|
|
150
105
|
|
|
106
|
+
// Configure
|
|
107
|
+
await cpaStrategy.overwriteConfig({
|
|
108
|
+
projectId,
|
|
109
|
+
projectPath: resolvedProjectPath,
|
|
110
|
+
projectApiToken,
|
|
111
|
+
useTypescript,
|
|
112
|
+
scheme,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Generate files
|
|
116
|
+
await cpaStrategy.generateFiles({
|
|
117
|
+
projectPath: resolvedProjectPath,
|
|
118
|
+
useTypescript,
|
|
119
|
+
scheme,
|
|
120
|
+
projectId,
|
|
121
|
+
projectApiToken,
|
|
122
|
+
});
|
|
123
|
+
|
|
151
124
|
/**
|
|
152
125
|
* INSTRUCT USER ON NEXT STEPS
|
|
153
126
|
*/
|
|
127
|
+
const pkgMgr = detectPackageManager(resolvedProjectPath);
|
|
128
|
+
const npmRunCmd = pkgMgr === "yarn" ? "yarn" : "npm run";
|
|
154
129
|
const command =
|
|
155
130
|
platform === "nextjs"
|
|
156
131
|
? `${npmRunCmd} dev`
|