@modern-js/app-tools 2.49.3-alpha.13 → 2.49.3-alpha.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/index copy.js +216 -0
- package/dist/cjs/plugins/deploy/index.js +13 -169
- package/dist/cjs/plugins/deploy/platforms/netlify.js +112 -64
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +41 -18
- package/dist/cjs/plugins/deploy/platforms/vercel.js +103 -16
- package/dist/cjs/plugins/deploy/utils.js +10 -8
- package/dist/esm/plugins/deploy/index copy.js +367 -0
- package/dist/esm/plugins/deploy/index.js +17 -314
- package/dist/esm/plugins/deploy/platforms/netlify.js +203 -36
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +100 -43
- package/dist/esm/plugins/deploy/platforms/vercel.js +203 -40
- package/dist/esm/plugins/deploy/utils.js +9 -3
- package/dist/esm-node/plugins/deploy/index copy.js +186 -0
- package/dist/esm-node/plugins/deploy/index.js +11 -157
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +103 -65
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +42 -19
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +104 -17
- package/dist/esm-node/plugins/deploy/utils.js +9 -7
- package/dist/types/plugins/deploy/index copy.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -5
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -8
- package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -4
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -8
- package/dist/types/plugins/deploy/utils.d.ts +7 -1
- package/package.json +8 -8
@@ -1,11 +1,8 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
-
import path from "path";
|
4
|
-
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
5
3
|
import { provider } from "std-env";
|
6
|
-
import { isMainEntry } from "../../utils/routes";
|
7
4
|
import { getProjectUsage } from "./utils";
|
8
|
-
import {
|
5
|
+
import { createNodePreset } from "./platforms/node";
|
9
6
|
function deploy_default() {
|
10
7
|
return {
|
11
8
|
name: "@modern-js/plugin-deploy",
|
@@ -18,338 +15,44 @@ function deploy_default() {
|
|
18
15
|
return {
|
19
16
|
beforeDeploy: function beforeDeploy() {
|
20
17
|
return _async_to_generator(function() {
|
21
|
-
var appContext,
|
18
|
+
var appContext, appDirectory, distDirectory, modernConfig, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, deployPreset;
|
22
19
|
return _ts_generator(this, function(_state) {
|
23
20
|
switch (_state.label) {
|
24
21
|
case 0:
|
25
22
|
appContext = api.useAppContext();
|
23
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory;
|
26
24
|
modernConfig = api.useResolvedConfigContext();
|
27
|
-
mainEntryName = modernConfig.source.mainEntryName;
|
28
|
-
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
|
29
25
|
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
30
26
|
needModernServer = useSSR || useAPI || useWebServer;
|
31
|
-
outputDirectory = path.join(appDirectory, ".output");
|
32
|
-
funcsDirectory = outputDirectory;
|
33
|
-
staticDirectory = path.join(outputDirectory, "static");
|
34
|
-
if (!(deployTarget === "node"))
|
35
|
-
return [
|
36
|
-
3,
|
37
|
-
3
|
38
|
-
];
|
39
|
-
return [
|
40
|
-
4,
|
41
|
-
fse.remove(outputDirectory)
|
42
|
-
];
|
43
|
-
case 1:
|
44
|
-
_state.sent();
|
45
|
-
return [
|
46
|
-
4,
|
47
|
-
fse.copy(distDirectory, outputDirectory)
|
48
|
-
];
|
49
|
-
case 2:
|
50
|
-
_state.sent();
|
51
|
-
_state.label = 3;
|
52
|
-
case 3:
|
53
|
-
if (!(deployTarget === "netlify"))
|
54
|
-
return [
|
55
|
-
3,
|
56
|
-
8
|
57
|
-
];
|
58
|
-
netlifyOutput = path.join(appDirectory, ".netlify");
|
59
|
-
funcsDirectory = path.join(netlifyOutput, "functions");
|
60
|
-
routes = [];
|
61
|
-
if (!needModernServer) {
|
62
|
-
entrypoints.forEach(function(entry) {
|
63
|
-
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
64
|
-
routes.push({
|
65
|
-
src: "/".concat(isMain ? "" : "".concat(entry.entryName, "/"), "*"),
|
66
|
-
dest: "/html/".concat(entry.entryName, "/index.html"),
|
67
|
-
status: 200
|
68
|
-
});
|
69
|
-
});
|
70
|
-
} else {
|
71
|
-
routes.push({
|
72
|
-
src: "/*",
|
73
|
-
dest: "/.netlify/functions/index",
|
74
|
-
status: 200
|
75
|
-
});
|
76
|
-
throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
|
77
|
-
}
|
78
|
-
console.log("routes", routes, needModernServer);
|
79
|
-
redirectContent = routes.map(function(route) {
|
80
|
-
return "".concat(route.src, " ").concat(route.dest, " ").concat(route.status);
|
81
|
-
}).join("\n");
|
82
|
-
console.log("redirectContent", redirectContent);
|
83
|
-
return [
|
84
|
-
4,
|
85
|
-
fse.remove(outputDirectory)
|
86
|
-
];
|
87
|
-
case 4:
|
88
|
-
_state.sent();
|
89
|
-
return [
|
90
|
-
4,
|
91
|
-
fse.ensureDir(funcsDirectory)
|
92
|
-
];
|
93
|
-
case 5:
|
94
|
-
_state.sent();
|
95
|
-
return [
|
96
|
-
4,
|
97
|
-
fse.copy(distDirectory, funcsDirectory, {
|
98
|
-
filter: function(src) {
|
99
|
-
var distStaticDirectory = path.join(distDirectory, "static");
|
100
|
-
return !src.includes(distStaticDirectory);
|
101
|
-
}
|
102
|
-
})
|
103
|
-
];
|
104
|
-
case 6:
|
105
|
-
_state.sent();
|
106
|
-
redirectFilePath = path.join(distDirectory, "_redirects");
|
107
|
-
return [
|
108
|
-
4,
|
109
|
-
fse.writeFile(redirectFilePath, redirectContent)
|
110
|
-
];
|
111
|
-
case 7:
|
112
|
-
_state.sent();
|
113
|
-
_state.label = 8;
|
114
|
-
case 8:
|
115
|
-
if (!(deployTarget === "vercel"))
|
116
|
-
return [
|
117
|
-
3,
|
118
|
-
18
|
119
|
-
];
|
120
|
-
vercelOutput = path.join(appDirectory, ".vercel");
|
121
|
-
return [
|
122
|
-
4,
|
123
|
-
fse.remove(vercelOutput)
|
124
|
-
];
|
125
|
-
case 9:
|
126
|
-
_state.sent();
|
127
|
-
outputDirectory = path.join(vercelOutput, "output");
|
128
|
-
config = {
|
129
|
-
version: 3,
|
130
|
-
routes: [
|
131
|
-
{
|
132
|
-
src: "/static/(.*)",
|
133
|
-
headers: {
|
134
|
-
"cache-control": "s-maxage=31536000, immutable"
|
135
|
-
},
|
136
|
-
continue: true
|
137
|
-
},
|
138
|
-
{
|
139
|
-
handle: "filesystem"
|
140
|
-
}
|
141
|
-
]
|
142
|
-
};
|
143
|
-
if (!needModernServer) {
|
144
|
-
entrypoints.forEach(function(entry) {
|
145
|
-
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
146
|
-
config.routes.push({
|
147
|
-
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
148
|
-
headers: {
|
149
|
-
"cache-control": "s-maxage=0"
|
150
|
-
},
|
151
|
-
dest: "/html/".concat(entry.entryName, "/index.html")
|
152
|
-
});
|
153
|
-
});
|
154
|
-
} else {
|
155
|
-
config.routes.push({
|
156
|
-
src: "/(.*)",
|
157
|
-
dest: "/index"
|
158
|
-
});
|
159
|
-
}
|
160
|
-
return [
|
161
|
-
4,
|
162
|
-
fse.ensureDir(outputDirectory)
|
163
|
-
];
|
164
|
-
case 10:
|
165
|
-
_state.sent();
|
166
|
-
return [
|
167
|
-
4,
|
168
|
-
fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
169
|
-
spaces: 2
|
170
|
-
})
|
171
|
-
];
|
172
|
-
case 11:
|
173
|
-
_state.sent();
|
174
|
-
staticDirectory = path.join(outputDirectory, "static/static");
|
175
|
-
return [
|
176
|
-
4,
|
177
|
-
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
178
|
-
];
|
179
|
-
case 12:
|
180
|
-
_state.sent();
|
181
|
-
if (!!needModernServer)
|
182
|
-
return [
|
183
|
-
3,
|
184
|
-
14
|
185
|
-
];
|
186
|
-
destHtmlDirectory = path.join(distDirectory, "html");
|
187
|
-
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
188
|
-
return [
|
189
|
-
4,
|
190
|
-
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
191
|
-
];
|
192
|
-
case 13:
|
193
|
-
_state.sent();
|
194
|
-
return [
|
195
|
-
3,
|
196
|
-
18
|
197
|
-
];
|
198
|
-
case 14:
|
199
|
-
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
200
|
-
return [
|
201
|
-
4,
|
202
|
-
fse.ensureDir(funcsDirectory)
|
203
|
-
];
|
204
|
-
case 15:
|
205
|
-
_state.sent();
|
206
|
-
return [
|
207
|
-
4,
|
208
|
-
fse.copy(distDirectory, funcsDirectory, {
|
209
|
-
filter: function(src) {
|
210
|
-
var distStaticDirectory = path.join(distDirectory, "static");
|
211
|
-
return !src.includes(distStaticDirectory);
|
212
|
-
}
|
213
|
-
})
|
214
|
-
];
|
215
|
-
case 16:
|
216
|
-
_state.sent();
|
217
|
-
return [
|
218
|
-
4,
|
219
|
-
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
220
|
-
runtime: "nodejs16.x",
|
221
|
-
handler: "index.js",
|
222
|
-
launcherType: "Nodejs",
|
223
|
-
shouldAddHelpers: false,
|
224
|
-
supportsResponseStreaming: true
|
225
|
-
})
|
226
|
-
];
|
227
|
-
case 17:
|
228
|
-
_state.sent();
|
229
|
-
_state.label = 18;
|
230
|
-
case 18:
|
231
|
-
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
232
|
-
serverAppContext = {
|
233
|
-
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
234
|
-
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
235
|
-
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
236
|
-
metaName
|
237
|
-
};
|
238
|
-
console.log("serverAppContext", serverAppContext);
|
239
|
-
code = "";
|
240
|
-
console.log("deployTarget111111111", deployTarget);
|
241
27
|
switch (deployTarget) {
|
242
28
|
case "node":
|
243
|
-
|
244
|
-
|
245
|
-
19
|
246
|
-
];
|
29
|
+
deployPreset = createNodePreset(appContext, modernConfig, needModernServer);
|
30
|
+
break;
|
247
31
|
case "vercel":
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
return [
|
254
|
-
3,
|
255
|
-
25
|
256
|
-
];
|
32
|
+
deployPreset = createNodePreset(appContext, modernConfig, needModernServer);
|
33
|
+
break;
|
34
|
+
default: {
|
35
|
+
throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");
|
36
|
+
}
|
257
37
|
}
|
258
|
-
return [
|
259
|
-
3,
|
260
|
-
28
|
261
|
-
];
|
262
|
-
case 19:
|
263
38
|
return [
|
264
39
|
4,
|
265
|
-
|
40
|
+
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare()
|
266
41
|
];
|
267
|
-
case
|
268
|
-
|
269
|
-
return [
|
270
|
-
4,
|
271
|
-
genNodeEntry({
|
272
|
-
plugins,
|
273
|
-
config: modernConfig,
|
274
|
-
appContext: serverAppContext
|
275
|
-
})
|
276
|
-
];
|
277
|
-
case 21:
|
278
|
-
code = _state.sent();
|
279
|
-
return [
|
280
|
-
3,
|
281
|
-
29
|
282
|
-
];
|
283
|
-
case 22:
|
284
|
-
return [
|
285
|
-
4,
|
286
|
-
import("./platforms/vercel")
|
287
|
-
];
|
288
|
-
case 23:
|
289
|
-
genVercelEntry = _state.sent().genVercelEntry;
|
290
|
-
return [
|
291
|
-
4,
|
292
|
-
genVercelEntry({
|
293
|
-
plugins,
|
294
|
-
config: modernConfig,
|
295
|
-
appContext: serverAppContext
|
296
|
-
})
|
297
|
-
];
|
298
|
-
case 24:
|
299
|
-
code = _state.sent();
|
300
|
-
return [
|
301
|
-
3,
|
302
|
-
29
|
303
|
-
];
|
304
|
-
case 25:
|
305
|
-
return [
|
306
|
-
4,
|
307
|
-
import("./platforms/netlify")
|
308
|
-
];
|
309
|
-
case 26:
|
310
|
-
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
311
|
-
return [
|
312
|
-
4,
|
313
|
-
genNetlifyEntry({
|
314
|
-
plugins,
|
315
|
-
config: modernConfig,
|
316
|
-
appContext: serverAppContext
|
317
|
-
})
|
318
|
-
];
|
319
|
-
case 27:
|
320
|
-
code = _state.sent();
|
321
|
-
return [
|
322
|
-
3,
|
323
|
-
29
|
324
|
-
];
|
325
|
-
case 28:
|
326
|
-
{
|
327
|
-
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
328
|
-
}
|
329
|
-
_state.label = 29;
|
330
|
-
case 29:
|
331
|
-
entryFilePath = path.join(funcsDirectory, "index.js");
|
332
|
-
if (!needModernServer)
|
333
|
-
return [
|
334
|
-
3,
|
335
|
-
32
|
336
|
-
];
|
42
|
+
case 1:
|
43
|
+
_state.sent();
|
337
44
|
return [
|
338
45
|
4,
|
339
|
-
|
46
|
+
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput()
|
340
47
|
];
|
341
|
-
case
|
48
|
+
case 2:
|
342
49
|
_state.sent();
|
343
50
|
return [
|
344
51
|
4,
|
345
|
-
|
346
|
-
"@modern-js/prod-server"
|
347
|
-
])
|
52
|
+
deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry()
|
348
53
|
];
|
349
|
-
case
|
54
|
+
case 3:
|
350
55
|
_state.sent();
|
351
|
-
_state.label = 32;
|
352
|
-
case 32:
|
353
56
|
return [
|
354
57
|
2
|
355
58
|
];
|
@@ -1,41 +1,208 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import path from "node:path";
|
4
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
|
5
|
+
import { isMainEntry } from "../../../utils/routes";
|
6
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
7
|
+
import { handleDependencies } from "../dependencies";
|
8
|
+
var createNetlifyPreset = function(appContext, config, needModernServer) {
|
9
|
+
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
|
10
|
+
var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
11
|
+
var netlifyOutput = path.join(appDirectory, ".netlify");
|
12
|
+
var outputDirectory = path.join(netlifyOutput, "output");
|
13
|
+
var funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
14
|
+
var entryFilePath = path.join(funcsDirectory, "index.js");
|
15
|
+
return {
|
16
|
+
prepare: function prepare() {
|
17
|
+
return _async_to_generator(function() {
|
18
|
+
return _ts_generator(this, function(_state) {
|
19
|
+
switch (_state.label) {
|
20
|
+
case 0:
|
21
|
+
return [
|
22
|
+
4,
|
23
|
+
fse.remove(netlifyOutput)
|
24
|
+
];
|
25
|
+
case 1:
|
26
|
+
_state.sent();
|
27
|
+
return [
|
28
|
+
2
|
29
|
+
];
|
30
|
+
}
|
31
|
+
});
|
32
|
+
})();
|
8
33
|
},
|
9
|
-
|
10
|
-
|
34
|
+
writeOutput: function writeOutput() {
|
35
|
+
return _async_to_generator(function() {
|
36
|
+
var config2, mainEntryName, staticDirectory, destHtmlDirectory, outputHtmlDirectory;
|
37
|
+
return _ts_generator(this, function(_state) {
|
38
|
+
switch (_state.label) {
|
39
|
+
case 0:
|
40
|
+
config2 = {
|
41
|
+
version: 3,
|
42
|
+
routes: [
|
43
|
+
{
|
44
|
+
src: "/static/(.*)",
|
45
|
+
headers: {
|
46
|
+
"cache-control": "s-maxage=31536000, immutable"
|
47
|
+
},
|
48
|
+
continue: true
|
49
|
+
},
|
50
|
+
{
|
51
|
+
handle: "filesystem"
|
52
|
+
}
|
53
|
+
]
|
54
|
+
};
|
55
|
+
if (!needModernServer) {
|
56
|
+
mainEntryName = config2.source.mainEntryName;
|
57
|
+
entrypoints.forEach(function(entry) {
|
58
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
59
|
+
config2.routes.push({
|
60
|
+
src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
|
61
|
+
headers: {
|
62
|
+
"cache-control": "s-maxage=0"
|
63
|
+
},
|
64
|
+
dest: "/html/".concat(entry.entryName, "/index.html")
|
65
|
+
});
|
66
|
+
});
|
67
|
+
} else {
|
68
|
+
config2.routes.push({
|
69
|
+
src: "/(.*)",
|
70
|
+
dest: "/index"
|
71
|
+
});
|
72
|
+
}
|
73
|
+
return [
|
74
|
+
4,
|
75
|
+
fse.ensureDir(outputDirectory)
|
76
|
+
];
|
77
|
+
case 1:
|
78
|
+
_state.sent();
|
79
|
+
return [
|
80
|
+
4,
|
81
|
+
fse.writeJSON(path.join(outputDirectory, "config.json"), config2, {
|
82
|
+
spaces: 2
|
83
|
+
})
|
84
|
+
];
|
85
|
+
case 2:
|
86
|
+
_state.sent();
|
87
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
88
|
+
return [
|
89
|
+
4,
|
90
|
+
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
91
|
+
];
|
92
|
+
case 3:
|
93
|
+
_state.sent();
|
94
|
+
if (!!needModernServer)
|
95
|
+
return [
|
96
|
+
3,
|
97
|
+
5
|
98
|
+
];
|
99
|
+
destHtmlDirectory = path.join(distDirectory, "html");
|
100
|
+
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
101
|
+
return [
|
102
|
+
4,
|
103
|
+
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
104
|
+
];
|
105
|
+
case 4:
|
106
|
+
_state.sent();
|
107
|
+
return [
|
108
|
+
3,
|
109
|
+
9
|
110
|
+
];
|
111
|
+
case 5:
|
112
|
+
return [
|
113
|
+
4,
|
114
|
+
fse.ensureDir(funcsDirectory)
|
115
|
+
];
|
116
|
+
case 6:
|
117
|
+
_state.sent();
|
118
|
+
return [
|
119
|
+
4,
|
120
|
+
fse.copy(distDirectory, funcsDirectory, {
|
121
|
+
filter: function(src) {
|
122
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
123
|
+
return !src.includes(distStaticDirectory);
|
124
|
+
}
|
125
|
+
})
|
126
|
+
];
|
127
|
+
case 7:
|
128
|
+
_state.sent();
|
129
|
+
return [
|
130
|
+
4,
|
131
|
+
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
132
|
+
runtime: "nodejs16.x",
|
133
|
+
handler: "index.js",
|
134
|
+
launcherType: "Nodejs",
|
135
|
+
shouldAddHelpers: false,
|
136
|
+
supportsResponseStreaming: true
|
137
|
+
})
|
138
|
+
];
|
139
|
+
case 8:
|
140
|
+
_state.sent();
|
141
|
+
_state.label = 9;
|
142
|
+
case 9:
|
143
|
+
return [
|
144
|
+
2
|
145
|
+
];
|
146
|
+
}
|
147
|
+
});
|
148
|
+
})();
|
149
|
+
},
|
150
|
+
genEntry: function genEntry() {
|
151
|
+
return _async_to_generator(function() {
|
152
|
+
var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, entryCode, serverAppContext;
|
153
|
+
return _ts_generator(this, function(_state) {
|
154
|
+
switch (_state.label) {
|
155
|
+
case 0:
|
156
|
+
if (!needModernServer) {
|
157
|
+
return [
|
158
|
+
2
|
159
|
+
];
|
160
|
+
}
|
161
|
+
serverConfig = {
|
162
|
+
bff: {
|
163
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
164
|
+
},
|
165
|
+
output: {
|
166
|
+
path: "."
|
167
|
+
}
|
168
|
+
};
|
169
|
+
pluginImportCode = genPluginImportsCode(plugins || []);
|
170
|
+
dynamicProdOptions = {
|
171
|
+
config: serverConfig,
|
172
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
173
|
+
plugins
|
174
|
+
};
|
175
|
+
return [
|
176
|
+
4,
|
177
|
+
fse.readFile(path.join(__dirname, "./netlifyEntry.js"))
|
178
|
+
];
|
179
|
+
case 1:
|
180
|
+
entryCode = _state.sent().toString();
|
181
|
+
serverAppContext = serverAppContenxtTemplate(appContext);
|
182
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
183
|
+
return [
|
184
|
+
4,
|
185
|
+
fse.writeFile(entryFilePath, entryCode)
|
186
|
+
];
|
187
|
+
case 2:
|
188
|
+
_state.sent();
|
189
|
+
return [
|
190
|
+
4,
|
191
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
192
|
+
"@modern-js/prod-server"
|
193
|
+
])
|
194
|
+
];
|
195
|
+
case 3:
|
196
|
+
_state.sent();
|
197
|
+
return [
|
198
|
+
2
|
199
|
+
];
|
200
|
+
}
|
201
|
+
});
|
202
|
+
})();
|
11
203
|
}
|
12
204
|
};
|
13
|
-
|
14
|
-
|
15
|
-
let requestHandler = null;
|
16
|
-
|
17
|
-
if(!process.env.NODE_ENV){
|
18
|
-
process.env.NODE_ENV = 'production';
|
19
|
-
}
|
20
|
-
|
21
|
-
async function createHandler() {
|
22
|
-
try {
|
23
|
-
let routes = [];
|
24
|
-
const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
|
25
|
-
try {
|
26
|
-
await fs.access(routeFilepath);
|
27
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
28
|
-
const routeSpec = JSON.parse(content);
|
29
|
-
routes = routeSpec.routes;
|
30
|
-
} catch (error) {
|
31
|
-
console.warn('route.json not found, continuing with empty routes.');
|
32
|
-
}
|
33
|
-
|
34
|
-
const prodServerOptions = {
|
35
|
-
pwd: __dirname,
|
36
|
-
routes,
|
37
|
-
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n requestHandler = await createNetlifyFunction(prodServerOptions)\n\n return requestHandler\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n const handleRequest = async(request, context) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(request, context);\n }\n\n export default handleRequest;\n ");
|
38
|
-
}
|
205
|
+
};
|
39
206
|
export {
|
40
|
-
|
207
|
+
createNetlifyPreset
|
41
208
|
};
|