create-plasmic-app 0.0.73 → 0.0.75
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/nextjs/nextjs.d.ts +1 -1
- package/dist/nextjs/nextjs.js +22 -27
- package/package.json +3 -4
- package/src/nextjs/nextjs.ts +41 -46
package/dist/nextjs/nextjs.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CPAStrategy } from
|
|
1
|
+
import { CPAStrategy } from "../utils/strategy";
|
|
2
2
|
export declare const nextjsStrategy: CPAStrategy;
|
package/dist/nextjs/nextjs.js
CHANGED
|
@@ -36,9 +36,9 @@ exports.nextjsStrategy = {
|
|
|
36
36
|
const { projectPath, template, jsOrTs, platformOptions } = args;
|
|
37
37
|
const typescriptArg = `--${jsOrTs}`;
|
|
38
38
|
const experimentalAppArg = ((_a = platformOptions.nextjs) === null || _a === void 0 ? void 0 : _a.appDir)
|
|
39
|
-
?
|
|
40
|
-
:
|
|
41
|
-
const templateArg = template ? ` --template ${template}` :
|
|
39
|
+
? "--app"
|
|
40
|
+
: "--no-app";
|
|
41
|
+
const templateArg = template ? ` --template ${template}` : "";
|
|
42
42
|
const createCommand = `npx create-next-app@latest ${projectPath} ${typescriptArg} ${experimentalAppArg} ${templateArg}` +
|
|
43
43
|
` --eslint --no-src-dir --import-alias "@/*" --no-tailwind`;
|
|
44
44
|
// Default Next.js starter already supports Typescript
|
|
@@ -46,13 +46,8 @@ exports.nextjsStrategy = {
|
|
|
46
46
|
yield (0, cmd_utils_1.spawnOrFail)(createCommand);
|
|
47
47
|
}),
|
|
48
48
|
installDeps: ({ scheme, projectPath }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
yield (0, npm_utils_1.installUpgrade)('next@13.3.0', {
|
|
52
|
-
workingDir: projectPath,
|
|
53
|
-
});
|
|
54
|
-
if (scheme === 'loader') {
|
|
55
|
-
return yield (0, npm_utils_1.installUpgrade)('@plasmicapp/loader-nextjs', {
|
|
49
|
+
if (scheme === "loader") {
|
|
50
|
+
return yield (0, npm_utils_1.installUpgrade)("@plasmicapp/loader-nextjs", {
|
|
56
51
|
workingDir: projectPath,
|
|
57
52
|
});
|
|
58
53
|
}
|
|
@@ -63,14 +58,14 @@ exports.nextjsStrategy = {
|
|
|
63
58
|
overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
59
|
var _b;
|
|
65
60
|
const { projectPath, scheme, platformOptions } = args;
|
|
66
|
-
const nextjsConfigFile = path_1.default.join(projectPath,
|
|
61
|
+
const nextjsConfigFile = path_1.default.join(projectPath, "next.config.js");
|
|
67
62
|
const appDirOption = ((_b = platformOptions.nextjs) === null || _b === void 0 ? void 0 : _b.appDir)
|
|
68
63
|
? `
|
|
69
64
|
experimental: {
|
|
70
65
|
appDir: true,
|
|
71
66
|
}`
|
|
72
|
-
:
|
|
73
|
-
if (scheme ===
|
|
67
|
+
: "";
|
|
68
|
+
if (scheme === "codegen") {
|
|
74
69
|
yield fs_1.promises.writeFile(nextjsConfigFile, `
|
|
75
70
|
/** @type {import('next').NextConfig} */
|
|
76
71
|
const nextConfig = {
|
|
@@ -113,37 +108,37 @@ function generateFilesAppDir(args) {
|
|
|
113
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
109
|
const { projectPath, jsOrTs, projectId, projectApiToken } = args;
|
|
115
110
|
// Delete existing pages
|
|
116
|
-
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath,
|
|
111
|
+
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "app", "page.*"));
|
|
117
112
|
// ./plasmic-init.ts
|
|
118
113
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init.${jsOrTs}`), (0, plasmic_init_1.makePlasmicInit_app_loader)(projectId, (0, lang_utils_1.ensure)(projectApiToken)));
|
|
119
114
|
// ./plasmic-init-client.ts
|
|
120
115
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init-client.${jsOrTs}x`), (0, plasmic_init_client_1.makePlasmicInitClient_app_loader)(jsOrTs));
|
|
121
116
|
// ./app/plasmic-host/page.tsx
|
|
122
|
-
yield fs_1.promises.mkdir(path_1.default.join(projectPath,
|
|
123
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
117
|
+
yield fs_1.promises.mkdir(path_1.default.join(projectPath, "app", "plasmic-host"));
|
|
118
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "plasmic-host", `page.${jsOrTs}x`), (0, plasmic_host_1.makePlasmicHostPage_app_loader)());
|
|
124
119
|
// ./app/[[...catchall]]/page.tsx
|
|
125
|
-
yield fs_1.promises.mkdir(path_1.default.join(projectPath,
|
|
126
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
120
|
+
yield fs_1.promises.mkdir(path_1.default.join(projectPath, "app", "[[...catchall]]"));
|
|
121
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "app", "[[...catchall]]", `page.${jsOrTs}x`), (0, catchall_page_1.makeCatchallPage_app_loader)(jsOrTs));
|
|
127
122
|
});
|
|
128
123
|
}
|
|
129
124
|
function generateFilesPagesDir(args) {
|
|
130
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
126
|
const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
|
|
132
127
|
// Delete existing pages
|
|
133
|
-
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath,
|
|
134
|
-
if (scheme ===
|
|
128
|
+
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, "pages", "*.*"));
|
|
129
|
+
if (scheme === "loader") {
|
|
135
130
|
// ./plasmic-init.ts
|
|
136
131
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init.${jsOrTs}`), (0, plasmic_init_2.makePlasmicInit_pages_loader)(projectId, (0, lang_utils_1.ensure)(projectApiToken)));
|
|
137
132
|
// ./pages/plasmic-host.tsx
|
|
138
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
133
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`), (0, plasmic_host_3.makePlasmicHostPage_pages_loader)());
|
|
139
134
|
// ./pages/[[...catchall]].tsx
|
|
140
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
135
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `[[...catchall]].${jsOrTs}x`), (0, catchall_page_2.makeCatchallPage_pages_loader)(jsOrTs));
|
|
141
136
|
}
|
|
142
137
|
else {
|
|
143
138
|
// ./pages/_app.tsx
|
|
144
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
139
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `_app.${jsOrTs}x`), (0, app_1.makeCustomApp_pages_codegen)(jsOrTs));
|
|
145
140
|
// ./pages/plasmic-host.tsx
|
|
146
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
141
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`), (0, plasmic_host_2.makePlasmicHostPage_pages_codegen)());
|
|
147
142
|
// This should generate
|
|
148
143
|
// ./plasmic.json
|
|
149
144
|
// ./pages/index.tsx
|
|
@@ -154,10 +149,10 @@ function generateFilesPagesDir(args) {
|
|
|
154
149
|
projectPath,
|
|
155
150
|
});
|
|
156
151
|
// Make an index page if the project didn't have one.
|
|
157
|
-
const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath,
|
|
152
|
+
const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, "nextjs", scheme);
|
|
158
153
|
const plasmicFiles = lodash_1.default.map(lodash_1.default.flatMap(config.projects, (p) => p.components), (c) => c.importSpec.modulePath);
|
|
159
|
-
if (!plasmicFiles.find((f) => f.includes(
|
|
160
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
154
|
+
if (!plasmicFiles.find((f) => f.includes("/index."))) {
|
|
155
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, "pages", `index.${jsOrTs}x`), (0, file_utils_1.generateWelcomePage)(config, "nextjs"));
|
|
161
156
|
}
|
|
162
157
|
}
|
|
163
158
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-plasmic-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.75",
|
|
4
4
|
"description": "Create Plasmic-powered React apps",
|
|
5
5
|
"main": "./dist/lib.js",
|
|
6
6
|
"types": "./dist/lib.d.ts",
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
"jest": "^26.6.3",
|
|
38
38
|
"jest-circus": "^26.6.3",
|
|
39
39
|
"ts-jest": "^26.5.3",
|
|
40
|
-
"ts-node": "^10.9.1"
|
|
41
|
-
"typescript": "^4.2.3"
|
|
40
|
+
"ts-node": "^10.9.1"
|
|
42
41
|
},
|
|
43
42
|
"dependencies": {
|
|
44
43
|
"@plasmicapp/cli": "0.1.187",
|
|
@@ -55,5 +54,5 @@
|
|
|
55
54
|
"validate-npm-package-name": "^3.0.0",
|
|
56
55
|
"yargs": "^16.2.0"
|
|
57
56
|
},
|
|
58
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "9046e96d5d51d83325652cfb6b8d160aabdfb201"
|
|
59
58
|
}
|
package/src/nextjs/nextjs.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { promises as fs } from
|
|
2
|
-
import L from
|
|
3
|
-
import path from
|
|
4
|
-
import { spawnOrFail } from
|
|
5
|
-
import { installCodegenDeps, runCodegenSync } from
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import L from "lodash";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { spawnOrFail } from "../utils/cmd-utils";
|
|
5
|
+
import { installCodegenDeps, runCodegenSync } from "../utils/codegen";
|
|
6
6
|
import {
|
|
7
7
|
deleteGlob,
|
|
8
8
|
generateWelcomePage,
|
|
9
9
|
getPlasmicConfig,
|
|
10
|
-
} from
|
|
11
|
-
import { ensure } from
|
|
12
|
-
import { installUpgrade } from
|
|
13
|
-
import { CPAStrategy, GenerateFilesArgs } from
|
|
14
|
-
import { makeCatchallPage_app_loader } from
|
|
15
|
-
import { makePlasmicHostPage_app_loader } from
|
|
16
|
-
import { makePlasmicInit_app_loader } from
|
|
17
|
-
import { makePlasmicInitClient_app_loader } from
|
|
18
|
-
import { makeCustomApp_pages_codegen } from
|
|
19
|
-
import { makePlasmicHostPage_pages_codegen } from
|
|
20
|
-
import { makeCatchallPage_pages_loader } from
|
|
21
|
-
import { makePlasmicHostPage_pages_loader } from
|
|
22
|
-
import { makePlasmicInit_pages_loader } from
|
|
10
|
+
} from "../utils/file-utils";
|
|
11
|
+
import { ensure } from "../utils/lang-utils";
|
|
12
|
+
import { installUpgrade } from "../utils/npm-utils";
|
|
13
|
+
import { CPAStrategy, GenerateFilesArgs } from "../utils/strategy";
|
|
14
|
+
import { makeCatchallPage_app_loader } from "./templates/app-loader/catchall-page";
|
|
15
|
+
import { makePlasmicHostPage_app_loader } from "./templates/app-loader/plasmic-host";
|
|
16
|
+
import { makePlasmicInit_app_loader } from "./templates/app-loader/plasmic-init";
|
|
17
|
+
import { makePlasmicInitClient_app_loader } from "./templates/app-loader/plasmic-init-client";
|
|
18
|
+
import { makeCustomApp_pages_codegen } from "./templates/pages-codegen/app";
|
|
19
|
+
import { makePlasmicHostPage_pages_codegen } from "./templates/pages-codegen/plasmic-host";
|
|
20
|
+
import { makeCatchallPage_pages_loader } from "./templates/pages-loader/catchall-page";
|
|
21
|
+
import { makePlasmicHostPage_pages_loader } from "./templates/pages-loader/plasmic-host";
|
|
22
|
+
import { makePlasmicInit_pages_loader } from "./templates/pages-loader/plasmic-init";
|
|
23
23
|
|
|
24
24
|
export const nextjsStrategy: CPAStrategy = {
|
|
25
25
|
create: async (args) => {
|
|
26
26
|
const { projectPath, template, jsOrTs, platformOptions } = args;
|
|
27
27
|
const typescriptArg = `--${jsOrTs}`;
|
|
28
28
|
const experimentalAppArg = platformOptions.nextjs?.appDir
|
|
29
|
-
?
|
|
30
|
-
:
|
|
31
|
-
const templateArg = template ? ` --template ${template}` :
|
|
29
|
+
? "--app"
|
|
30
|
+
: "--no-app";
|
|
31
|
+
const templateArg = template ? ` --template ${template}` : "";
|
|
32
32
|
const createCommand =
|
|
33
33
|
`npx create-next-app@latest ${projectPath} ${typescriptArg} ${experimentalAppArg} ${templateArg}` +
|
|
34
34
|
` --eslint --no-src-dir --import-alias "@/*" --no-tailwind`;
|
|
@@ -38,13 +38,8 @@ export const nextjsStrategy: CPAStrategy = {
|
|
|
38
38
|
await spawnOrFail(createCommand);
|
|
39
39
|
},
|
|
40
40
|
installDeps: async ({ scheme, projectPath }) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await installUpgrade('next@13.3.0', {
|
|
44
|
-
workingDir: projectPath,
|
|
45
|
-
});
|
|
46
|
-
if (scheme === 'loader') {
|
|
47
|
-
return await installUpgrade('@plasmicapp/loader-nextjs', {
|
|
41
|
+
if (scheme === "loader") {
|
|
42
|
+
return await installUpgrade("@plasmicapp/loader-nextjs", {
|
|
48
43
|
workingDir: projectPath,
|
|
49
44
|
});
|
|
50
45
|
} else {
|
|
@@ -53,14 +48,14 @@ export const nextjsStrategy: CPAStrategy = {
|
|
|
53
48
|
},
|
|
54
49
|
overwriteConfig: async (args) => {
|
|
55
50
|
const { projectPath, scheme, platformOptions } = args;
|
|
56
|
-
const nextjsConfigFile = path.join(projectPath,
|
|
51
|
+
const nextjsConfigFile = path.join(projectPath, "next.config.js");
|
|
57
52
|
const appDirOption = platformOptions.nextjs?.appDir
|
|
58
53
|
? `
|
|
59
54
|
experimental: {
|
|
60
55
|
appDir: true,
|
|
61
56
|
}`
|
|
62
|
-
:
|
|
63
|
-
if (scheme ===
|
|
57
|
+
: "";
|
|
58
|
+
if (scheme === "codegen") {
|
|
64
59
|
await fs.writeFile(
|
|
65
60
|
nextjsConfigFile,
|
|
66
61
|
`
|
|
@@ -107,7 +102,7 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
|
|
|
107
102
|
const { projectPath, jsOrTs, projectId, projectApiToken } = args;
|
|
108
103
|
|
|
109
104
|
// Delete existing pages
|
|
110
|
-
deleteGlob(path.join(projectPath,
|
|
105
|
+
deleteGlob(path.join(projectPath, "app", "page.*"));
|
|
111
106
|
|
|
112
107
|
// ./plasmic-init.ts
|
|
113
108
|
await fs.writeFile(
|
|
@@ -122,16 +117,16 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
|
|
|
122
117
|
);
|
|
123
118
|
|
|
124
119
|
// ./app/plasmic-host/page.tsx
|
|
125
|
-
await fs.mkdir(path.join(projectPath,
|
|
120
|
+
await fs.mkdir(path.join(projectPath, "app", "plasmic-host"));
|
|
126
121
|
await fs.writeFile(
|
|
127
|
-
path.join(projectPath,
|
|
122
|
+
path.join(projectPath, "app", "plasmic-host", `page.${jsOrTs}x`),
|
|
128
123
|
makePlasmicHostPage_app_loader()
|
|
129
124
|
);
|
|
130
125
|
|
|
131
126
|
// ./app/[[...catchall]]/page.tsx
|
|
132
|
-
await fs.mkdir(path.join(projectPath,
|
|
127
|
+
await fs.mkdir(path.join(projectPath, "app", "[[...catchall]]"));
|
|
133
128
|
await fs.writeFile(
|
|
134
|
-
path.join(projectPath,
|
|
129
|
+
path.join(projectPath, "app", "[[...catchall]]", `page.${jsOrTs}x`),
|
|
135
130
|
makeCatchallPage_app_loader(jsOrTs)
|
|
136
131
|
);
|
|
137
132
|
}
|
|
@@ -140,9 +135,9 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
|
|
|
140
135
|
const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
|
|
141
136
|
|
|
142
137
|
// Delete existing pages
|
|
143
|
-
deleteGlob(path.join(projectPath,
|
|
138
|
+
deleteGlob(path.join(projectPath, "pages", "*.*"));
|
|
144
139
|
|
|
145
|
-
if (scheme ===
|
|
140
|
+
if (scheme === "loader") {
|
|
146
141
|
// ./plasmic-init.ts
|
|
147
142
|
await fs.writeFile(
|
|
148
143
|
path.join(projectPath, `plasmic-init.${jsOrTs}`),
|
|
@@ -151,25 +146,25 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
|
|
|
151
146
|
|
|
152
147
|
// ./pages/plasmic-host.tsx
|
|
153
148
|
await fs.writeFile(
|
|
154
|
-
path.join(projectPath,
|
|
149
|
+
path.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`),
|
|
155
150
|
makePlasmicHostPage_pages_loader()
|
|
156
151
|
);
|
|
157
152
|
|
|
158
153
|
// ./pages/[[...catchall]].tsx
|
|
159
154
|
await fs.writeFile(
|
|
160
|
-
path.join(projectPath,
|
|
155
|
+
path.join(projectPath, "pages", `[[...catchall]].${jsOrTs}x`),
|
|
161
156
|
makeCatchallPage_pages_loader(jsOrTs)
|
|
162
157
|
);
|
|
163
158
|
} else {
|
|
164
159
|
// ./pages/_app.tsx
|
|
165
160
|
await fs.writeFile(
|
|
166
|
-
path.join(projectPath,
|
|
161
|
+
path.join(projectPath, "pages", `_app.${jsOrTs}x`),
|
|
167
162
|
makeCustomApp_pages_codegen(jsOrTs)
|
|
168
163
|
);
|
|
169
164
|
|
|
170
165
|
// ./pages/plasmic-host.tsx
|
|
171
166
|
await fs.writeFile(
|
|
172
|
-
path.join(projectPath,
|
|
167
|
+
path.join(projectPath, "pages", `plasmic-host.${jsOrTs}x`),
|
|
173
168
|
makePlasmicHostPage_pages_codegen()
|
|
174
169
|
);
|
|
175
170
|
|
|
@@ -184,15 +179,15 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
|
|
|
184
179
|
});
|
|
185
180
|
|
|
186
181
|
// Make an index page if the project didn't have one.
|
|
187
|
-
const config = await getPlasmicConfig(projectPath,
|
|
182
|
+
const config = await getPlasmicConfig(projectPath, "nextjs", scheme);
|
|
188
183
|
const plasmicFiles = L.map(
|
|
189
184
|
L.flatMap(config.projects, (p) => p.components),
|
|
190
185
|
(c) => c.importSpec.modulePath
|
|
191
186
|
);
|
|
192
|
-
if (!plasmicFiles.find((f) => f.includes(
|
|
187
|
+
if (!plasmicFiles.find((f) => f.includes("/index."))) {
|
|
193
188
|
await fs.writeFile(
|
|
194
|
-
path.join(projectPath,
|
|
195
|
-
generateWelcomePage(config,
|
|
189
|
+
path.join(projectPath, "pages", `index.${jsOrTs}x`),
|
|
190
|
+
generateWelcomePage(config, "nextjs")
|
|
196
191
|
);
|
|
197
192
|
}
|
|
198
193
|
}
|