create-plasmic-app 0.0.71 → 0.0.73
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 +27 -22
- package/package.json +2 -2
- package/src/nextjs/nextjs.ts +46 -41
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
|
+
? '--experimental-app'
|
|
40
|
+
: '--no-experimental-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,8 +46,13 @@ 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
|
-
|
|
49
|
+
// Locking to version 13.3.0 until this is fixed and released:
|
|
50
|
+
// https://github.com/vercel/next.js/issues/48593
|
|
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', {
|
|
51
56
|
workingDir: projectPath,
|
|
52
57
|
});
|
|
53
58
|
}
|
|
@@ -58,14 +63,14 @@ exports.nextjsStrategy = {
|
|
|
58
63
|
overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
64
|
var _b;
|
|
60
65
|
const { projectPath, scheme, platformOptions } = args;
|
|
61
|
-
const nextjsConfigFile = path_1.default.join(projectPath,
|
|
66
|
+
const nextjsConfigFile = path_1.default.join(projectPath, 'next.config.js');
|
|
62
67
|
const appDirOption = ((_b = platformOptions.nextjs) === null || _b === void 0 ? void 0 : _b.appDir)
|
|
63
68
|
? `
|
|
64
69
|
experimental: {
|
|
65
70
|
appDir: true,
|
|
66
71
|
}`
|
|
67
|
-
:
|
|
68
|
-
if (scheme ===
|
|
72
|
+
: '';
|
|
73
|
+
if (scheme === 'codegen') {
|
|
69
74
|
yield fs_1.promises.writeFile(nextjsConfigFile, `
|
|
70
75
|
/** @type {import('next').NextConfig} */
|
|
71
76
|
const nextConfig = {
|
|
@@ -108,37 +113,37 @@ function generateFilesAppDir(args) {
|
|
|
108
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
114
|
const { projectPath, jsOrTs, projectId, projectApiToken } = args;
|
|
110
115
|
// Delete existing pages
|
|
111
|
-
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath,
|
|
116
|
+
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, 'app', 'page.*'));
|
|
112
117
|
// ./plasmic-init.ts
|
|
113
118
|
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)));
|
|
114
119
|
// ./plasmic-init-client.ts
|
|
115
120
|
yield fs_1.promises.writeFile(path_1.default.join(projectPath, `plasmic-init-client.${jsOrTs}x`), (0, plasmic_init_client_1.makePlasmicInitClient_app_loader)(jsOrTs));
|
|
116
121
|
// ./app/plasmic-host/page.tsx
|
|
117
|
-
yield fs_1.promises.mkdir(path_1.default.join(projectPath,
|
|
118
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
122
|
+
yield fs_1.promises.mkdir(path_1.default.join(projectPath, 'app', 'plasmic-host'));
|
|
123
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, 'app', 'plasmic-host', `page.${jsOrTs}x`), (0, plasmic_host_1.makePlasmicHostPage_app_loader)());
|
|
119
124
|
// ./app/[[...catchall]]/page.tsx
|
|
120
|
-
yield fs_1.promises.mkdir(path_1.default.join(projectPath,
|
|
121
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
125
|
+
yield fs_1.promises.mkdir(path_1.default.join(projectPath, 'app', '[[...catchall]]'));
|
|
126
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, 'app', '[[...catchall]]', `page.${jsOrTs}x`), (0, catchall_page_1.makeCatchallPage_app_loader)(jsOrTs));
|
|
122
127
|
});
|
|
123
128
|
}
|
|
124
129
|
function generateFilesPagesDir(args) {
|
|
125
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
131
|
const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
|
|
127
132
|
// Delete existing pages
|
|
128
|
-
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath,
|
|
129
|
-
if (scheme ===
|
|
133
|
+
(0, file_utils_1.deleteGlob)(path_1.default.join(projectPath, 'pages', '*.*'));
|
|
134
|
+
if (scheme === 'loader') {
|
|
130
135
|
// ./plasmic-init.ts
|
|
131
136
|
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)));
|
|
132
137
|
// ./pages/plasmic-host.tsx
|
|
133
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
138
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, 'pages', `plasmic-host.${jsOrTs}x`), (0, plasmic_host_3.makePlasmicHostPage_pages_loader)());
|
|
134
139
|
// ./pages/[[...catchall]].tsx
|
|
135
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
140
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, 'pages', `[[...catchall]].${jsOrTs}x`), (0, catchall_page_2.makeCatchallPage_pages_loader)(jsOrTs));
|
|
136
141
|
}
|
|
137
142
|
else {
|
|
138
143
|
// ./pages/_app.tsx
|
|
139
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
144
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, 'pages', `_app.${jsOrTs}x`), (0, app_1.makeCustomApp_pages_codegen)(jsOrTs));
|
|
140
145
|
// ./pages/plasmic-host.tsx
|
|
141
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
146
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, 'pages', `plasmic-host.${jsOrTs}x`), (0, plasmic_host_2.makePlasmicHostPage_pages_codegen)());
|
|
142
147
|
// This should generate
|
|
143
148
|
// ./plasmic.json
|
|
144
149
|
// ./pages/index.tsx
|
|
@@ -149,10 +154,10 @@ function generateFilesPagesDir(args) {
|
|
|
149
154
|
projectPath,
|
|
150
155
|
});
|
|
151
156
|
// Make an index page if the project didn't have one.
|
|
152
|
-
const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath,
|
|
157
|
+
const config = yield (0, file_utils_1.getPlasmicConfig)(projectPath, 'nextjs', scheme);
|
|
153
158
|
const plasmicFiles = lodash_1.default.map(lodash_1.default.flatMap(config.projects, (p) => p.components), (c) => c.importSpec.modulePath);
|
|
154
|
-
if (!plasmicFiles.find((f) => f.includes(
|
|
155
|
-
yield fs_1.promises.writeFile(path_1.default.join(projectPath,
|
|
159
|
+
if (!plasmicFiles.find((f) => f.includes('/index.'))) {
|
|
160
|
+
yield fs_1.promises.writeFile(path_1.default.join(projectPath, 'pages', `index.${jsOrTs}x`), (0, file_utils_1.generateWelcomePage)(config, 'nextjs'));
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-plasmic-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.73",
|
|
4
4
|
"description": "Create Plasmic-powered React apps",
|
|
5
5
|
"main": "./dist/lib.js",
|
|
6
6
|
"types": "./dist/lib.d.ts",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"validate-npm-package-name": "^3.0.0",
|
|
56
56
|
"yargs": "^16.2.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "1d9faacaaac15e87767697dbdc4215504a358d02"
|
|
59
59
|
}
|
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
|
+
? '--experimental-app'
|
|
30
|
+
: '--no-experimental-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,8 +38,13 @@ export const nextjsStrategy: CPAStrategy = {
|
|
|
38
38
|
await spawnOrFail(createCommand);
|
|
39
39
|
},
|
|
40
40
|
installDeps: async ({ scheme, projectPath }) => {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// Locking to version 13.3.0 until this is fixed and released:
|
|
42
|
+
// https://github.com/vercel/next.js/issues/48593
|
|
43
|
+
await installUpgrade('next@13.3.0', {
|
|
44
|
+
workingDir: projectPath,
|
|
45
|
+
});
|
|
46
|
+
if (scheme === 'loader') {
|
|
47
|
+
return await installUpgrade('@plasmicapp/loader-nextjs', {
|
|
43
48
|
workingDir: projectPath,
|
|
44
49
|
});
|
|
45
50
|
} else {
|
|
@@ -48,14 +53,14 @@ export const nextjsStrategy: CPAStrategy = {
|
|
|
48
53
|
},
|
|
49
54
|
overwriteConfig: async (args) => {
|
|
50
55
|
const { projectPath, scheme, platformOptions } = args;
|
|
51
|
-
const nextjsConfigFile = path.join(projectPath,
|
|
56
|
+
const nextjsConfigFile = path.join(projectPath, 'next.config.js');
|
|
52
57
|
const appDirOption = platformOptions.nextjs?.appDir
|
|
53
58
|
? `
|
|
54
59
|
experimental: {
|
|
55
60
|
appDir: true,
|
|
56
61
|
}`
|
|
57
|
-
:
|
|
58
|
-
if (scheme ===
|
|
62
|
+
: '';
|
|
63
|
+
if (scheme === 'codegen') {
|
|
59
64
|
await fs.writeFile(
|
|
60
65
|
nextjsConfigFile,
|
|
61
66
|
`
|
|
@@ -102,7 +107,7 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
|
|
|
102
107
|
const { projectPath, jsOrTs, projectId, projectApiToken } = args;
|
|
103
108
|
|
|
104
109
|
// Delete existing pages
|
|
105
|
-
deleteGlob(path.join(projectPath,
|
|
110
|
+
deleteGlob(path.join(projectPath, 'app', 'page.*'));
|
|
106
111
|
|
|
107
112
|
// ./plasmic-init.ts
|
|
108
113
|
await fs.writeFile(
|
|
@@ -117,16 +122,16 @@ async function generateFilesAppDir(args: GenerateFilesArgs) {
|
|
|
117
122
|
);
|
|
118
123
|
|
|
119
124
|
// ./app/plasmic-host/page.tsx
|
|
120
|
-
await fs.mkdir(path.join(projectPath,
|
|
125
|
+
await fs.mkdir(path.join(projectPath, 'app', 'plasmic-host'));
|
|
121
126
|
await fs.writeFile(
|
|
122
|
-
path.join(projectPath,
|
|
127
|
+
path.join(projectPath, 'app', 'plasmic-host', `page.${jsOrTs}x`),
|
|
123
128
|
makePlasmicHostPage_app_loader()
|
|
124
129
|
);
|
|
125
130
|
|
|
126
131
|
// ./app/[[...catchall]]/page.tsx
|
|
127
|
-
await fs.mkdir(path.join(projectPath,
|
|
132
|
+
await fs.mkdir(path.join(projectPath, 'app', '[[...catchall]]'));
|
|
128
133
|
await fs.writeFile(
|
|
129
|
-
path.join(projectPath,
|
|
134
|
+
path.join(projectPath, 'app', '[[...catchall]]', `page.${jsOrTs}x`),
|
|
130
135
|
makeCatchallPage_app_loader(jsOrTs)
|
|
131
136
|
);
|
|
132
137
|
}
|
|
@@ -135,9 +140,9 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
|
|
|
135
140
|
const { projectPath, scheme, jsOrTs, projectId, projectApiToken } = args;
|
|
136
141
|
|
|
137
142
|
// Delete existing pages
|
|
138
|
-
deleteGlob(path.join(projectPath,
|
|
143
|
+
deleteGlob(path.join(projectPath, 'pages', '*.*'));
|
|
139
144
|
|
|
140
|
-
if (scheme ===
|
|
145
|
+
if (scheme === 'loader') {
|
|
141
146
|
// ./plasmic-init.ts
|
|
142
147
|
await fs.writeFile(
|
|
143
148
|
path.join(projectPath, `plasmic-init.${jsOrTs}`),
|
|
@@ -146,25 +151,25 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
|
|
|
146
151
|
|
|
147
152
|
// ./pages/plasmic-host.tsx
|
|
148
153
|
await fs.writeFile(
|
|
149
|
-
path.join(projectPath,
|
|
154
|
+
path.join(projectPath, 'pages', `plasmic-host.${jsOrTs}x`),
|
|
150
155
|
makePlasmicHostPage_pages_loader()
|
|
151
156
|
);
|
|
152
157
|
|
|
153
158
|
// ./pages/[[...catchall]].tsx
|
|
154
159
|
await fs.writeFile(
|
|
155
|
-
path.join(projectPath,
|
|
160
|
+
path.join(projectPath, 'pages', `[[...catchall]].${jsOrTs}x`),
|
|
156
161
|
makeCatchallPage_pages_loader(jsOrTs)
|
|
157
162
|
);
|
|
158
163
|
} else {
|
|
159
164
|
// ./pages/_app.tsx
|
|
160
165
|
await fs.writeFile(
|
|
161
|
-
path.join(projectPath,
|
|
166
|
+
path.join(projectPath, 'pages', `_app.${jsOrTs}x`),
|
|
162
167
|
makeCustomApp_pages_codegen(jsOrTs)
|
|
163
168
|
);
|
|
164
169
|
|
|
165
170
|
// ./pages/plasmic-host.tsx
|
|
166
171
|
await fs.writeFile(
|
|
167
|
-
path.join(projectPath,
|
|
172
|
+
path.join(projectPath, 'pages', `plasmic-host.${jsOrTs}x`),
|
|
168
173
|
makePlasmicHostPage_pages_codegen()
|
|
169
174
|
);
|
|
170
175
|
|
|
@@ -179,15 +184,15 @@ async function generateFilesPagesDir(args: GenerateFilesArgs) {
|
|
|
179
184
|
});
|
|
180
185
|
|
|
181
186
|
// Make an index page if the project didn't have one.
|
|
182
|
-
const config = await getPlasmicConfig(projectPath,
|
|
187
|
+
const config = await getPlasmicConfig(projectPath, 'nextjs', scheme);
|
|
183
188
|
const plasmicFiles = L.map(
|
|
184
189
|
L.flatMap(config.projects, (p) => p.components),
|
|
185
190
|
(c) => c.importSpec.modulePath
|
|
186
191
|
);
|
|
187
|
-
if (!plasmicFiles.find((f) => f.includes(
|
|
192
|
+
if (!plasmicFiles.find((f) => f.includes('/index.'))) {
|
|
188
193
|
await fs.writeFile(
|
|
189
|
-
path.join(projectPath,
|
|
190
|
-
generateWelcomePage(config,
|
|
194
|
+
path.join(projectPath, 'pages', `index.${jsOrTs}x`),
|
|
195
|
+
generateWelcomePage(config, 'nextjs')
|
|
191
196
|
);
|
|
192
197
|
}
|
|
193
198
|
}
|