@modern-js/app-tools 2.49.3-alpha.13 → 2.49.3-alpha.15
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/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
@@ -0,0 +1,186 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
3
|
+
import { provider } from "std-env";
|
4
|
+
import { isMainEntry } from "../../utils/routes";
|
5
|
+
import { getProjectUsage } from "./utils";
|
6
|
+
import { handleDependencies } from "./dependencies";
|
7
|
+
var index_copy_default = () => ({
|
8
|
+
name: "@modern-js/plugin-deploy",
|
9
|
+
pre: [
|
10
|
+
"@modern-js/plugin-bff",
|
11
|
+
"@modern-js/plugin-server"
|
12
|
+
],
|
13
|
+
setup: (api) => {
|
14
|
+
const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
15
|
+
return {
|
16
|
+
async beforeDeploy() {
|
17
|
+
const appContext = api.useAppContext();
|
18
|
+
const modernConfig = api.useResolvedConfigContext();
|
19
|
+
const { source: { mainEntryName } } = modernConfig;
|
20
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
21
|
+
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
22
|
+
const needModernServer = useSSR || useAPI || useWebServer;
|
23
|
+
let outputDirectory = path.join(appDirectory, ".output");
|
24
|
+
let funcsDirectory = outputDirectory;
|
25
|
+
let staticDirectory = path.join(outputDirectory, "static");
|
26
|
+
if (deployTarget === "node") {
|
27
|
+
await fse.remove(outputDirectory);
|
28
|
+
await fse.copy(distDirectory, outputDirectory);
|
29
|
+
}
|
30
|
+
if (deployTarget === "netlify") {
|
31
|
+
const netlifyOutput = path.join(appDirectory, ".netlify");
|
32
|
+
funcsDirectory = path.join(netlifyOutput, "functions");
|
33
|
+
const routes = [];
|
34
|
+
if (!needModernServer) {
|
35
|
+
entrypoints.forEach((entry) => {
|
36
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
37
|
+
routes.push({
|
38
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
39
|
+
dest: `/html/${entry.entryName}/index.html`,
|
40
|
+
status: 200
|
41
|
+
});
|
42
|
+
});
|
43
|
+
} else {
|
44
|
+
routes.push({
|
45
|
+
src: `/*`,
|
46
|
+
dest: `/.netlify/functions/index`,
|
47
|
+
status: 200
|
48
|
+
});
|
49
|
+
throw new Error("Currently on the Netlify platform, only CSR projects are supported, Support for SSR and BFF projects will be available later");
|
50
|
+
}
|
51
|
+
console.log("routes", routes, needModernServer);
|
52
|
+
const redirectContent = routes.map((route) => {
|
53
|
+
return `${route.src} ${route.dest} ${route.status}`;
|
54
|
+
}).join("\n");
|
55
|
+
console.log("redirectContent", redirectContent);
|
56
|
+
await fse.remove(outputDirectory);
|
57
|
+
await fse.ensureDir(funcsDirectory);
|
58
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
59
|
+
filter: (src) => {
|
60
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
61
|
+
return !src.includes(distStaticDirectory);
|
62
|
+
}
|
63
|
+
});
|
64
|
+
const redirectFilePath = path.join(distDirectory, "_redirects");
|
65
|
+
await fse.writeFile(redirectFilePath, redirectContent);
|
66
|
+
}
|
67
|
+
if (deployTarget === "vercel") {
|
68
|
+
const vercelOutput = path.join(appDirectory, ".vercel");
|
69
|
+
await fse.remove(vercelOutput);
|
70
|
+
outputDirectory = path.join(vercelOutput, "output");
|
71
|
+
const config = {
|
72
|
+
version: 3,
|
73
|
+
routes: [
|
74
|
+
{
|
75
|
+
src: "/static/(.*)",
|
76
|
+
headers: {
|
77
|
+
"cache-control": "s-maxage=31536000, immutable"
|
78
|
+
},
|
79
|
+
continue: true
|
80
|
+
},
|
81
|
+
{
|
82
|
+
handle: "filesystem"
|
83
|
+
}
|
84
|
+
]
|
85
|
+
};
|
86
|
+
if (!needModernServer) {
|
87
|
+
entrypoints.forEach((entry) => {
|
88
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
89
|
+
config.routes.push({
|
90
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
91
|
+
headers: {
|
92
|
+
"cache-control": "s-maxage=0"
|
93
|
+
},
|
94
|
+
dest: `/html/${entry.entryName}/index.html`
|
95
|
+
});
|
96
|
+
});
|
97
|
+
} else {
|
98
|
+
config.routes.push({
|
99
|
+
src: "/(.*)",
|
100
|
+
dest: `/index`
|
101
|
+
});
|
102
|
+
}
|
103
|
+
await fse.ensureDir(outputDirectory);
|
104
|
+
await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
105
|
+
spaces: 2
|
106
|
+
});
|
107
|
+
staticDirectory = path.join(outputDirectory, "static/static");
|
108
|
+
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
109
|
+
if (!needModernServer) {
|
110
|
+
const destHtmlDirectory = path.join(distDirectory, "html");
|
111
|
+
const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
112
|
+
await fse.copy(destHtmlDirectory, outputHtmlDirectory);
|
113
|
+
} else {
|
114
|
+
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
115
|
+
await fse.ensureDir(funcsDirectory);
|
116
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
117
|
+
filter: (src) => {
|
118
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
119
|
+
return !src.includes(distStaticDirectory);
|
120
|
+
}
|
121
|
+
});
|
122
|
+
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
123
|
+
runtime: "nodejs16.x",
|
124
|
+
handler: "index.js",
|
125
|
+
launcherType: "Nodejs",
|
126
|
+
shouldAddHelpers: false,
|
127
|
+
supportsResponseStreaming: true
|
128
|
+
});
|
129
|
+
}
|
130
|
+
}
|
131
|
+
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
132
|
+
const serverAppContext = {
|
133
|
+
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
134
|
+
apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
|
135
|
+
lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
|
136
|
+
metaName
|
137
|
+
};
|
138
|
+
console.log("serverAppContext", serverAppContext);
|
139
|
+
let code = ``;
|
140
|
+
console.log("deployTarget111111111", deployTarget);
|
141
|
+
switch (deployTarget) {
|
142
|
+
case "node": {
|
143
|
+
const { genNodeEntry } = await import("./platforms/node");
|
144
|
+
code = await genNodeEntry({
|
145
|
+
plugins,
|
146
|
+
config: modernConfig,
|
147
|
+
appContext: serverAppContext
|
148
|
+
});
|
149
|
+
break;
|
150
|
+
}
|
151
|
+
case "vercel": {
|
152
|
+
const { genVercelEntry } = await import("./platforms/vercel");
|
153
|
+
code = await genVercelEntry({
|
154
|
+
plugins,
|
155
|
+
config: modernConfig,
|
156
|
+
appContext: serverAppContext
|
157
|
+
});
|
158
|
+
break;
|
159
|
+
}
|
160
|
+
case "netlify": {
|
161
|
+
const { genNetlifyEntry } = await import("./platforms/netlify");
|
162
|
+
code = await genNetlifyEntry({
|
163
|
+
plugins,
|
164
|
+
config: modernConfig,
|
165
|
+
appContext: serverAppContext
|
166
|
+
});
|
167
|
+
break;
|
168
|
+
}
|
169
|
+
default: {
|
170
|
+
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
const entryFilePath = path.join(funcsDirectory, "index.js");
|
174
|
+
if (needModernServer) {
|
175
|
+
await fse.writeFile(entryFilePath, code);
|
176
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
177
|
+
"@modern-js/prod-server"
|
178
|
+
]);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
};
|
182
|
+
}
|
183
|
+
});
|
184
|
+
export {
|
185
|
+
index_copy_default as default
|
186
|
+
};
|
@@ -1,9 +1,6 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
3
1
|
import { provider } from "std-env";
|
4
|
-
import { isMainEntry } from "../../utils/routes";
|
5
2
|
import { getProjectUsage } from "./utils";
|
6
|
-
import {
|
3
|
+
import { createNodePreset } from "./platforms/node";
|
7
4
|
var deploy_default = () => ({
|
8
5
|
name: "@modern-js/plugin-deploy",
|
9
6
|
pre: [
|
@@ -15,168 +12,25 @@ var deploy_default = () => ({
|
|
15
12
|
return {
|
16
13
|
async beforeDeploy() {
|
17
14
|
const appContext = api.useAppContext();
|
15
|
+
const { appDirectory, distDirectory } = appContext;
|
18
16
|
const modernConfig = api.useResolvedConfigContext();
|
19
|
-
const { source: { mainEntryName } } = modernConfig;
|
20
|
-
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
21
17
|
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
|
22
18
|
const needModernServer = useSSR || useAPI || useWebServer;
|
23
|
-
let
|
24
|
-
let funcsDirectory = outputDirectory;
|
25
|
-
let staticDirectory = path.join(outputDirectory, "static");
|
26
|
-
if (deployTarget === "node") {
|
27
|
-
await fse.remove(outputDirectory);
|
28
|
-
await fse.copy(distDirectory, outputDirectory);
|
29
|
-
}
|
30
|
-
if (deployTarget === "netlify") {
|
31
|
-
const netlifyOutput = path.join(appDirectory, ".netlify");
|
32
|
-
funcsDirectory = path.join(netlifyOutput, "functions");
|
33
|
-
const routes = [];
|
34
|
-
if (!needModernServer) {
|
35
|
-
entrypoints.forEach((entry) => {
|
36
|
-
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
37
|
-
routes.push({
|
38
|
-
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
39
|
-
dest: `/html/${entry.entryName}/index.html`,
|
40
|
-
status: 200
|
41
|
-
});
|
42
|
-
});
|
43
|
-
} else {
|
44
|
-
routes.push({
|
45
|
-
src: `/*`,
|
46
|
-
dest: `/.netlify/functions/index`,
|
47
|
-
status: 200
|
48
|
-
});
|
49
|
-
throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
|
50
|
-
}
|
51
|
-
console.log("routes", routes, needModernServer);
|
52
|
-
const redirectContent = routes.map((route) => {
|
53
|
-
return `${route.src} ${route.dest} ${route.status}`;
|
54
|
-
}).join("\n");
|
55
|
-
console.log("redirectContent", redirectContent);
|
56
|
-
await fse.remove(outputDirectory);
|
57
|
-
await fse.ensureDir(funcsDirectory);
|
58
|
-
await fse.copy(distDirectory, funcsDirectory, {
|
59
|
-
filter: (src) => {
|
60
|
-
const distStaticDirectory = path.join(distDirectory, "static");
|
61
|
-
return !src.includes(distStaticDirectory);
|
62
|
-
}
|
63
|
-
});
|
64
|
-
const redirectFilePath = path.join(distDirectory, "_redirects");
|
65
|
-
await fse.writeFile(redirectFilePath, redirectContent);
|
66
|
-
}
|
67
|
-
if (deployTarget === "vercel") {
|
68
|
-
const vercelOutput = path.join(appDirectory, ".vercel");
|
69
|
-
await fse.remove(vercelOutput);
|
70
|
-
outputDirectory = path.join(vercelOutput, "output");
|
71
|
-
const config = {
|
72
|
-
version: 3,
|
73
|
-
routes: [
|
74
|
-
{
|
75
|
-
src: "/static/(.*)",
|
76
|
-
headers: {
|
77
|
-
"cache-control": "s-maxage=31536000, immutable"
|
78
|
-
},
|
79
|
-
continue: true
|
80
|
-
},
|
81
|
-
{
|
82
|
-
handle: "filesystem"
|
83
|
-
}
|
84
|
-
]
|
85
|
-
};
|
86
|
-
if (!needModernServer) {
|
87
|
-
entrypoints.forEach((entry) => {
|
88
|
-
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
89
|
-
config.routes.push({
|
90
|
-
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
91
|
-
headers: {
|
92
|
-
"cache-control": "s-maxage=0"
|
93
|
-
},
|
94
|
-
dest: `/html/${entry.entryName}/index.html`
|
95
|
-
});
|
96
|
-
});
|
97
|
-
} else {
|
98
|
-
config.routes.push({
|
99
|
-
src: "/(.*)",
|
100
|
-
dest: `/index`
|
101
|
-
});
|
102
|
-
}
|
103
|
-
await fse.ensureDir(outputDirectory);
|
104
|
-
await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
105
|
-
spaces: 2
|
106
|
-
});
|
107
|
-
staticDirectory = path.join(outputDirectory, "static/static");
|
108
|
-
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
109
|
-
if (!needModernServer) {
|
110
|
-
const destHtmlDirectory = path.join(distDirectory, "html");
|
111
|
-
const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
112
|
-
await fse.copy(destHtmlDirectory, outputHtmlDirectory);
|
113
|
-
} else {
|
114
|
-
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
115
|
-
await fse.ensureDir(funcsDirectory);
|
116
|
-
await fse.copy(distDirectory, funcsDirectory, {
|
117
|
-
filter: (src) => {
|
118
|
-
const distStaticDirectory = path.join(distDirectory, "static");
|
119
|
-
return !src.includes(distStaticDirectory);
|
120
|
-
}
|
121
|
-
});
|
122
|
-
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
123
|
-
runtime: "nodejs16.x",
|
124
|
-
handler: "index.js",
|
125
|
-
launcherType: "Nodejs",
|
126
|
-
shouldAddHelpers: false,
|
127
|
-
supportsResponseStreaming: true
|
128
|
-
});
|
129
|
-
}
|
130
|
-
}
|
131
|
-
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
132
|
-
const serverAppContext = {
|
133
|
-
sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
|
134
|
-
apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
|
135
|
-
lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
|
136
|
-
metaName
|
137
|
-
};
|
138
|
-
console.log("serverAppContext", serverAppContext);
|
139
|
-
let code = ``;
|
140
|
-
console.log("deployTarget111111111", deployTarget);
|
19
|
+
let deployPreset;
|
141
20
|
switch (deployTarget) {
|
142
|
-
case "node":
|
143
|
-
|
144
|
-
code = await genNodeEntry({
|
145
|
-
plugins,
|
146
|
-
config: modernConfig,
|
147
|
-
appContext: serverAppContext
|
148
|
-
});
|
21
|
+
case "node":
|
22
|
+
deployPreset = createNodePreset(appContext, modernConfig, needModernServer);
|
149
23
|
break;
|
150
|
-
|
151
|
-
|
152
|
-
const { genVercelEntry } = await import("./platforms/vercel");
|
153
|
-
code = await genVercelEntry({
|
154
|
-
plugins,
|
155
|
-
config: modernConfig,
|
156
|
-
appContext: serverAppContext
|
157
|
-
});
|
158
|
-
break;
|
159
|
-
}
|
160
|
-
case "netlify": {
|
161
|
-
const { genNetlifyEntry } = await import("./platforms/netlify");
|
162
|
-
code = await genNetlifyEntry({
|
163
|
-
plugins,
|
164
|
-
config: modernConfig,
|
165
|
-
appContext: serverAppContext
|
166
|
-
});
|
24
|
+
case "vercel":
|
25
|
+
deployPreset = createNodePreset(appContext, modernConfig, needModernServer);
|
167
26
|
break;
|
168
|
-
}
|
169
27
|
default: {
|
170
|
-
|
28
|
+
throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");
|
171
29
|
}
|
172
30
|
}
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
await handleDependencies(appDirectory, funcsDirectory, [
|
177
|
-
"@modern-js/prod-server"
|
178
|
-
]);
|
179
|
-
}
|
31
|
+
await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
32
|
+
await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
33
|
+
await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
180
34
|
}
|
181
35
|
};
|
182
36
|
}
|
@@ -1,71 +1,109 @@
|
|
1
|
-
import
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
import path from "node:path";
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
|
3
|
+
import { isMainEntry } from "../../../utils/routes";
|
4
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
5
|
+
import { handleDependencies } from "../dependencies";
|
6
|
+
const createNetlifyPreset = (appContext, config, needModernServer) => {
|
7
|
+
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
8
|
+
const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
9
|
+
const netlifyOutput = path.join(appDirectory, ".netlify");
|
10
|
+
const outputDirectory = path.join(netlifyOutput, "output");
|
11
|
+
const funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
12
|
+
const entryFilePath = path.join(funcsDirectory, "index.js");
|
13
|
+
return {
|
14
|
+
async prepare() {
|
15
|
+
await fse.remove(netlifyOutput);
|
7
16
|
},
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
17
|
+
async writeOutput() {
|
18
|
+
const config2 = {
|
19
|
+
version: 3,
|
20
|
+
routes: [
|
21
|
+
{
|
22
|
+
src: "/static/(.*)",
|
23
|
+
headers: {
|
24
|
+
"cache-control": "s-maxage=31536000, immutable"
|
25
|
+
},
|
26
|
+
continue: true
|
27
|
+
},
|
28
|
+
{
|
29
|
+
handle: "filesystem"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
};
|
33
|
+
if (!needModernServer) {
|
34
|
+
const { source: { mainEntryName } } = config2;
|
35
|
+
entrypoints.forEach((entry) => {
|
36
|
+
const isMain = isMainEntry(entry.entryName, mainEntryName);
|
37
|
+
config2.routes.push({
|
38
|
+
src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
|
39
|
+
headers: {
|
40
|
+
"cache-control": "s-maxage=0"
|
41
|
+
},
|
42
|
+
dest: `/html/${entry.entryName}/index.html`
|
43
|
+
});
|
44
|
+
});
|
45
|
+
} else {
|
46
|
+
config2.routes.push({
|
47
|
+
src: "/(.*)",
|
48
|
+
dest: `/index`
|
49
|
+
});
|
36
50
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
51
|
+
await fse.ensureDir(outputDirectory);
|
52
|
+
await fse.writeJSON(path.join(outputDirectory, "config.json"), config2, {
|
53
|
+
spaces: 2
|
54
|
+
});
|
55
|
+
const staticDirectory = path.join(outputDirectory, "static/static");
|
56
|
+
await fse.copy(path.join(distDirectory, "static"), staticDirectory);
|
57
|
+
if (!needModernServer) {
|
58
|
+
const destHtmlDirectory = path.join(distDirectory, "html");
|
59
|
+
const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
60
|
+
await fse.copy(destHtmlDirectory, outputHtmlDirectory);
|
61
|
+
} else {
|
62
|
+
await fse.ensureDir(funcsDirectory);
|
63
|
+
await fse.copy(distDirectory, funcsDirectory, {
|
64
|
+
filter: (src) => {
|
65
|
+
const distStaticDirectory = path.join(distDirectory, "static");
|
66
|
+
return !src.includes(distStaticDirectory);
|
67
|
+
}
|
68
|
+
});
|
69
|
+
await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
70
|
+
runtime: "nodejs16.x",
|
71
|
+
handler: "index.js",
|
72
|
+
launcherType: "Nodejs",
|
73
|
+
shouldAddHelpers: false,
|
74
|
+
supportsResponseStreaming: true
|
75
|
+
});
|
46
76
|
}
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
77
|
+
},
|
78
|
+
async genEntry() {
|
79
|
+
var _config_bff;
|
80
|
+
if (!needModernServer) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
const serverConfig = {
|
84
|
+
bff: {
|
85
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
86
|
+
},
|
87
|
+
output: {
|
88
|
+
path: "."
|
89
|
+
}
|
90
|
+
};
|
91
|
+
const pluginImportCode = genPluginImportsCode(plugins || []);
|
92
|
+
const dynamicProdOptions = {
|
93
|
+
config: serverConfig,
|
94
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
95
|
+
plugins
|
96
|
+
};
|
97
|
+
let entryCode = (await fse.readFile(path.join(__dirname, "./netlifyEntry.js"))).toString();
|
98
|
+
const serverAppContext = serverAppContenxtTemplate(appContext);
|
99
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
100
|
+
await fse.writeFile(entryFilePath, entryCode);
|
101
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
102
|
+
"@modern-js/prod-server"
|
103
|
+
]);
|
62
104
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
export default handleRequest;
|
67
|
-
`;
|
68
|
-
}
|
105
|
+
};
|
106
|
+
};
|
69
107
|
export {
|
70
|
-
|
108
|
+
createNetlifyPreset
|
71
109
|
};
|
@@ -0,0 +1,68 @@
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
4
|
+
};
|
5
|
+
var require_netlifyEntry = __commonJS({
|
6
|
+
"src/plugins/deploy/platforms/netlifyEntry.js"(exports, module) {
|
7
|
+
const fs = require("node:fs/promises");
|
8
|
+
const path = require("node:path");
|
9
|
+
const { createNetlifyFunction } = require("@modern-js/prod-server/netlify");
|
10
|
+
p_genPluginImportsCode;
|
11
|
+
if (!process.env.NODE_ENV) {
|
12
|
+
process.env.NODE_ENV = "production";
|
13
|
+
}
|
14
|
+
let requestHandler = null;
|
15
|
+
let handlerCreationPromise = null;
|
16
|
+
async function loadRoutes(routeFilepath) {
|
17
|
+
try {
|
18
|
+
await fs.access(routeFilepath);
|
19
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
20
|
+
const routeSpec = JSON.parse(content);
|
21
|
+
return routeSpec.routes || [];
|
22
|
+
} catch (error) {
|
23
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
24
|
+
return [];
|
25
|
+
}
|
26
|
+
}
|
27
|
+
async function initServer() {
|
28
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
29
|
+
const routes = await loadRoutes(routeFilepath);
|
30
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
31
|
+
const prodServerOptions = {
|
32
|
+
pwd: __dirname,
|
33
|
+
routes,
|
34
|
+
disableCustomHook: true,
|
35
|
+
appContext: {
|
36
|
+
sharedDirectory: p_sharedDirectory,
|
37
|
+
apiDirectory: p_apiDirectory,
|
38
|
+
lambdaDirectory: p_lambdaDirectory
|
39
|
+
},
|
40
|
+
...dynamicProdOptions
|
41
|
+
};
|
42
|
+
const app = await createNetlifyFunction(prodServerOptions);
|
43
|
+
return app.getRequestListener();
|
44
|
+
}
|
45
|
+
async function createHandler() {
|
46
|
+
if (!handlerCreationPromise) {
|
47
|
+
handlerCreationPromise = (async () => {
|
48
|
+
try {
|
49
|
+
requestHandler = await initServer();
|
50
|
+
} catch (error) {
|
51
|
+
console.error("Error creating server:", error);
|
52
|
+
process.exit(1);
|
53
|
+
}
|
54
|
+
})();
|
55
|
+
}
|
56
|
+
await handlerCreationPromise;
|
57
|
+
return requestHandler;
|
58
|
+
}
|
59
|
+
createHandler();
|
60
|
+
module.exports = async (request, context) => {
|
61
|
+
if (!requestHandler) {
|
62
|
+
await createHandler();
|
63
|
+
}
|
64
|
+
return requestHandler(request, context);
|
65
|
+
};
|
66
|
+
}
|
67
|
+
});
|
68
|
+
export default require_netlifyEntry();
|