@modern-js/app-tools 2.49.3-alpha.2 → 2.49.3-alpha.20
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/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/plugins/deploy/dependencies.js +1 -12
- package/dist/cjs/plugins/deploy/index.js +25 -147
- package/dist/cjs/plugins/deploy/platforms/netlify.js +120 -0
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +90 -0
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +41 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +145 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +22 -8
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/plugins/deploy/dependencies.js +1 -47
- package/dist/esm/plugins/deploy/index.js +66 -245
- package/dist/esm/plugins/deploy/platforms/netlify.js +182 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +122 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +104 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +220 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +55 -3
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/plugins/deploy/dependencies.js +1 -12
- package/dist/esm-node/plugins/deploy/index.js +24 -136
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +86 -0
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +56 -0
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +40 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +111 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +20 -7
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +10 -0
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/utils.d.ts +8 -1
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +21 -21
- package/dist/cjs/plugins/deploy/entrys/netlify.js +0 -95
- package/dist/cjs/plugins/deploy/entrys/node.js +0 -88
- package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -97
- package/dist/esm/plugins/deploy/entrys/netlify.js +0 -41
- package/dist/esm/plugins/deploy/entrys/node.js +0 -39
- package/dist/esm/plugins/deploy/entrys/vercel.js +0 -43
- package/dist/esm-node/plugins/deploy/entrys/netlify.js +0 -71
- package/dist/esm-node/plugins/deploy/entrys/node.js +0 -64
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -73
- package/dist/types/plugins/deploy/entrys/netlify.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/node.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/vercel.d.ts +0 -6
@@ -0,0 +1,202 @@
|
|
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
|
+
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
|
8
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
9
|
+
var _ts_generator = require("@swc/helpers/_/_ts_generator");
|
10
|
+
var fs = require("node:fs/promises");
|
11
|
+
var path = require("node:path");
|
12
|
+
var createNetlifyFunction = require("@modern-js/prod-server/netlify").createNetlifyFunction;
|
13
|
+
p_genPluginImportsCode;
|
14
|
+
if (!process.env.NODE_ENV) {
|
15
|
+
process.env.NODE_ENV = "production";
|
16
|
+
}
|
17
|
+
var requestHandler = null;
|
18
|
+
var handlerCreationPromise = null;
|
19
|
+
function loadRoutes(routeFilepath) {
|
20
|
+
return _loadRoutes.apply(this, arguments);
|
21
|
+
}
|
22
|
+
function _loadRoutes() {
|
23
|
+
_loadRoutes = _async_to_generator._(function(routeFilepath) {
|
24
|
+
var content, routeSpec, error;
|
25
|
+
return _ts_generator._(this, function(_state) {
|
26
|
+
switch (_state.label) {
|
27
|
+
case 0:
|
28
|
+
_state.trys.push([
|
29
|
+
0,
|
30
|
+
3,
|
31
|
+
,
|
32
|
+
4
|
33
|
+
]);
|
34
|
+
return [
|
35
|
+
4,
|
36
|
+
fs.access(routeFilepath)
|
37
|
+
];
|
38
|
+
case 1:
|
39
|
+
_state.sent();
|
40
|
+
return [
|
41
|
+
4,
|
42
|
+
fs.readFile(routeFilepath, "utf-8")
|
43
|
+
];
|
44
|
+
case 2:
|
45
|
+
content = _state.sent();
|
46
|
+
routeSpec = JSON.parse(content);
|
47
|
+
return [
|
48
|
+
2,
|
49
|
+
routeSpec.routes || []
|
50
|
+
];
|
51
|
+
case 3:
|
52
|
+
error = _state.sent();
|
53
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
54
|
+
return [
|
55
|
+
2,
|
56
|
+
[]
|
57
|
+
];
|
58
|
+
case 4:
|
59
|
+
return [
|
60
|
+
2
|
61
|
+
];
|
62
|
+
}
|
63
|
+
});
|
64
|
+
});
|
65
|
+
return _loadRoutes.apply(this, arguments);
|
66
|
+
}
|
67
|
+
function initServer() {
|
68
|
+
return _initServer.apply(this, arguments);
|
69
|
+
}
|
70
|
+
function _initServer() {
|
71
|
+
_initServer = _async_to_generator._(function() {
|
72
|
+
var routeFilepath, routes, dynamicProdOptions, prodServerOptions, requestHandler2;
|
73
|
+
return _ts_generator._(this, function(_state) {
|
74
|
+
switch (_state.label) {
|
75
|
+
case 0:
|
76
|
+
routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
77
|
+
return [
|
78
|
+
4,
|
79
|
+
loadRoutes(routeFilepath)
|
80
|
+
];
|
81
|
+
case 1:
|
82
|
+
routes = _state.sent();
|
83
|
+
dynamicProdOptions = p_dynamicProdOptions;
|
84
|
+
prodServerOptions = _object_spread._({
|
85
|
+
pwd: __dirname,
|
86
|
+
routes,
|
87
|
+
disableCustomHook: true,
|
88
|
+
appContext: {
|
89
|
+
sharedDirectory: p_sharedDirectory,
|
90
|
+
apiDirectory: p_apiDirectory,
|
91
|
+
lambdaDirectory: p_lambdaDirectory
|
92
|
+
}
|
93
|
+
}, dynamicProdOptions);
|
94
|
+
return [
|
95
|
+
4,
|
96
|
+
createNetlifyFunction(prodServerOptions)
|
97
|
+
];
|
98
|
+
case 2:
|
99
|
+
requestHandler2 = _state.sent();
|
100
|
+
return [
|
101
|
+
2,
|
102
|
+
requestHandler2
|
103
|
+
];
|
104
|
+
}
|
105
|
+
});
|
106
|
+
});
|
107
|
+
return _initServer.apply(this, arguments);
|
108
|
+
}
|
109
|
+
function createHandler() {
|
110
|
+
return _createHandler.apply(this, arguments);
|
111
|
+
}
|
112
|
+
function _createHandler() {
|
113
|
+
_createHandler = _async_to_generator._(function() {
|
114
|
+
return _ts_generator._(this, function(_state) {
|
115
|
+
switch (_state.label) {
|
116
|
+
case 0:
|
117
|
+
if (!handlerCreationPromise) {
|
118
|
+
handlerCreationPromise = _async_to_generator._(function() {
|
119
|
+
var error;
|
120
|
+
return _ts_generator._(this, function(_state2) {
|
121
|
+
switch (_state2.label) {
|
122
|
+
case 0:
|
123
|
+
_state2.trys.push([
|
124
|
+
0,
|
125
|
+
2,
|
126
|
+
,
|
127
|
+
3
|
128
|
+
]);
|
129
|
+
return [
|
130
|
+
4,
|
131
|
+
initServer()
|
132
|
+
];
|
133
|
+
case 1:
|
134
|
+
requestHandler = _state2.sent();
|
135
|
+
return [
|
136
|
+
3,
|
137
|
+
3
|
138
|
+
];
|
139
|
+
case 2:
|
140
|
+
error = _state2.sent();
|
141
|
+
console.error("Error creating server:", error);
|
142
|
+
process.exit(1);
|
143
|
+
return [
|
144
|
+
3,
|
145
|
+
3
|
146
|
+
];
|
147
|
+
case 3:
|
148
|
+
return [
|
149
|
+
2
|
150
|
+
];
|
151
|
+
}
|
152
|
+
});
|
153
|
+
})();
|
154
|
+
}
|
155
|
+
return [
|
156
|
+
4,
|
157
|
+
handlerCreationPromise
|
158
|
+
];
|
159
|
+
case 1:
|
160
|
+
_state.sent();
|
161
|
+
return [
|
162
|
+
2,
|
163
|
+
requestHandler
|
164
|
+
];
|
165
|
+
}
|
166
|
+
});
|
167
|
+
});
|
168
|
+
return _createHandler.apply(this, arguments);
|
169
|
+
}
|
170
|
+
createHandler();
|
171
|
+
module.exports.default = function() {
|
172
|
+
var _ref = _async_to_generator._(function(request, context) {
|
173
|
+
return _ts_generator._(this, function(_state) {
|
174
|
+
switch (_state.label) {
|
175
|
+
case 0:
|
176
|
+
if (!!requestHandler)
|
177
|
+
return [
|
178
|
+
3,
|
179
|
+
2
|
180
|
+
];
|
181
|
+
return [
|
182
|
+
4,
|
183
|
+
createHandler()
|
184
|
+
];
|
185
|
+
case 1:
|
186
|
+
_state.sent();
|
187
|
+
_state.label = 2;
|
188
|
+
case 2:
|
189
|
+
return [
|
190
|
+
2,
|
191
|
+
requestHandler(request, context)
|
192
|
+
];
|
193
|
+
}
|
194
|
+
});
|
195
|
+
});
|
196
|
+
return function(request, context) {
|
197
|
+
return _ref.apply(this, arguments);
|
198
|
+
};
|
199
|
+
}();
|
200
|
+
}
|
201
|
+
});
|
202
|
+
export default require_netlifyEntry();
|
@@ -0,0 +1,122 @@
|
|
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, chalk } from "@modern-js/utils";
|
5
|
+
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
6
|
+
import { handleDependencies } from "../dependencies";
|
7
|
+
var createNodePreset = function(appContext, config, needModernServer) {
|
8
|
+
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins;
|
9
|
+
var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
10
|
+
var outputDirectory = path.join(appDirectory, ".output");
|
11
|
+
var staticDirectory = path.join(outputDirectory, "static");
|
12
|
+
var entryFilePath = path.join(outputDirectory, "index.js");
|
13
|
+
return {
|
14
|
+
prepare: function prepare() {
|
15
|
+
return _async_to_generator(function() {
|
16
|
+
return _ts_generator(this, function(_state) {
|
17
|
+
switch (_state.label) {
|
18
|
+
case 0:
|
19
|
+
return [
|
20
|
+
4,
|
21
|
+
fse.remove(outputDirectory)
|
22
|
+
];
|
23
|
+
case 1:
|
24
|
+
_state.sent();
|
25
|
+
return [
|
26
|
+
2
|
27
|
+
];
|
28
|
+
}
|
29
|
+
});
|
30
|
+
})();
|
31
|
+
},
|
32
|
+
writeOutput: function writeOutput() {
|
33
|
+
return _async_to_generator(function() {
|
34
|
+
return _ts_generator(this, function(_state) {
|
35
|
+
switch (_state.label) {
|
36
|
+
case 0:
|
37
|
+
return [
|
38
|
+
4,
|
39
|
+
fse.copy(distDirectory, outputDirectory)
|
40
|
+
];
|
41
|
+
case 1:
|
42
|
+
_state.sent();
|
43
|
+
return [
|
44
|
+
2
|
45
|
+
];
|
46
|
+
}
|
47
|
+
});
|
48
|
+
})();
|
49
|
+
},
|
50
|
+
genEntry: function genEntry() {
|
51
|
+
return _async_to_generator(function() {
|
52
|
+
var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, entryCode, serverAppContext;
|
53
|
+
return _ts_generator(this, function(_state) {
|
54
|
+
switch (_state.label) {
|
55
|
+
case 0:
|
56
|
+
if (!needModernServer) {
|
57
|
+
return [
|
58
|
+
2
|
59
|
+
];
|
60
|
+
}
|
61
|
+
serverConfig = {
|
62
|
+
server: {
|
63
|
+
port: 8080
|
64
|
+
},
|
65
|
+
bff: {
|
66
|
+
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
67
|
+
},
|
68
|
+
output: {
|
69
|
+
path: "."
|
70
|
+
}
|
71
|
+
};
|
72
|
+
pluginImportCode = genPluginImportsCode(plugins || []);
|
73
|
+
dynamicProdOptions = {
|
74
|
+
config: serverConfig,
|
75
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG,
|
76
|
+
plugins
|
77
|
+
};
|
78
|
+
return [
|
79
|
+
4,
|
80
|
+
fse.readFile(path.join(__dirname, "./nodeEntry.js"))
|
81
|
+
];
|
82
|
+
case 1:
|
83
|
+
entryCode = _state.sent().toString();
|
84
|
+
serverAppContext = serverAppContenxtTemplate(appContext);
|
85
|
+
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);
|
86
|
+
return [
|
87
|
+
4,
|
88
|
+
fse.writeFile(entryFilePath, entryCode)
|
89
|
+
];
|
90
|
+
case 2:
|
91
|
+
_state.sent();
|
92
|
+
return [
|
93
|
+
4,
|
94
|
+
handleDependencies(appDirectory, outputDirectory, [
|
95
|
+
"@modern-js/prod-server"
|
96
|
+
])
|
97
|
+
];
|
98
|
+
case 3:
|
99
|
+
_state.sent();
|
100
|
+
return [
|
101
|
+
2
|
102
|
+
];
|
103
|
+
}
|
104
|
+
});
|
105
|
+
})();
|
106
|
+
},
|
107
|
+
end: function end() {
|
108
|
+
return _async_to_generator(function() {
|
109
|
+
return _ts_generator(this, function(_state) {
|
110
|
+
console.log("Static directory:", chalk.blue(path.relative(appDirectory, staticDirectory)));
|
111
|
+
console.log("You can preview this build by", chalk.blue("node .output/index"));
|
112
|
+
return [
|
113
|
+
2
|
114
|
+
];
|
115
|
+
});
|
116
|
+
})();
|
117
|
+
}
|
118
|
+
};
|
119
|
+
};
|
120
|
+
export {
|
121
|
+
createNodePreset
|
122
|
+
};
|
@@ -0,0 +1,104 @@
|
|
1
|
+
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
|
2
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
3
|
+
var _ts_generator = require("@swc/helpers/_/_ts_generator");
|
4
|
+
var fs = require("node:fs/promises");
|
5
|
+
var path = require("node:path");
|
6
|
+
var createProdServer = require("@modern-js/prod-server").createProdServer;
|
7
|
+
p_genPluginImportsCode;
|
8
|
+
if (!process.env.NODE_ENV) {
|
9
|
+
process.env.NODE_ENV = "production";
|
10
|
+
}
|
11
|
+
function loadRoutes(routeFilepath) {
|
12
|
+
return _loadRoutes.apply(this, arguments);
|
13
|
+
}
|
14
|
+
function _loadRoutes() {
|
15
|
+
_loadRoutes = _async_to_generator._(function(routeFilepath) {
|
16
|
+
var content, routeSpec, error;
|
17
|
+
return _ts_generator._(this, function(_state) {
|
18
|
+
switch (_state.label) {
|
19
|
+
case 0:
|
20
|
+
_state.trys.push([
|
21
|
+
0,
|
22
|
+
3,
|
23
|
+
,
|
24
|
+
4
|
25
|
+
]);
|
26
|
+
return [
|
27
|
+
4,
|
28
|
+
fs.access(routeFilepath)
|
29
|
+
];
|
30
|
+
case 1:
|
31
|
+
_state.sent();
|
32
|
+
return [
|
33
|
+
4,
|
34
|
+
fs.readFile(routeFilepath, "utf-8")
|
35
|
+
];
|
36
|
+
case 2:
|
37
|
+
content = _state.sent();
|
38
|
+
routeSpec = JSON.parse(content);
|
39
|
+
return [
|
40
|
+
2,
|
41
|
+
routeSpec.routes || []
|
42
|
+
];
|
43
|
+
case 3:
|
44
|
+
error = _state.sent();
|
45
|
+
console.warn("route.json not found or invalid, continuing with empty routes.");
|
46
|
+
return [
|
47
|
+
2,
|
48
|
+
[]
|
49
|
+
];
|
50
|
+
case 4:
|
51
|
+
return [
|
52
|
+
2
|
53
|
+
];
|
54
|
+
}
|
55
|
+
});
|
56
|
+
});
|
57
|
+
return _loadRoutes.apply(this, arguments);
|
58
|
+
}
|
59
|
+
function main() {
|
60
|
+
return _main.apply(this, arguments);
|
61
|
+
}
|
62
|
+
function _main() {
|
63
|
+
_main = _async_to_generator._(function() {
|
64
|
+
var routeFilepath, routes, dynamicProdOptions, prodServerOptions, app, port;
|
65
|
+
return _ts_generator._(this, function(_state) {
|
66
|
+
switch (_state.label) {
|
67
|
+
case 0:
|
68
|
+
routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
69
|
+
return [
|
70
|
+
4,
|
71
|
+
loadRoutes(routeFilepath)
|
72
|
+
];
|
73
|
+
case 1:
|
74
|
+
routes = _state.sent();
|
75
|
+
dynamicProdOptions = p_dynamicProdOptions;
|
76
|
+
prodServerOptions = _object_spread._({
|
77
|
+
pwd: __dirname,
|
78
|
+
routes,
|
79
|
+
disableCustomHook: true,
|
80
|
+
appContext: {
|
81
|
+
sharedDirectory: p_sharedDirectory,
|
82
|
+
apiDirectory: p_apiDirectory,
|
83
|
+
lambdaDirectory: p_lambdaDirectory
|
84
|
+
}
|
85
|
+
}, dynamicProdOptions);
|
86
|
+
return [
|
87
|
+
4,
|
88
|
+
createProdServer(prodServerOptions)
|
89
|
+
];
|
90
|
+
case 2:
|
91
|
+
app = _state.sent();
|
92
|
+
port = process.env.PORT || 8080;
|
93
|
+
app.listen(port, function() {
|
94
|
+
console.log("\x1B[32mServer is listening on port", port, "\x1B[0m");
|
95
|
+
});
|
96
|
+
return [
|
97
|
+
2
|
98
|
+
];
|
99
|
+
}
|
100
|
+
});
|
101
|
+
});
|
102
|
+
return _main.apply(this, arguments);
|
103
|
+
}
|
104
|
+
main();
|
File without changes
|
@@ -0,0 +1,220 @@
|
|
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 createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
9
|
+
var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, entrypoints = appContext.entrypoints;
|
10
|
+
var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
11
|
+
var vercelOutput = path.join(appDirectory, ".vercel");
|
12
|
+
var outputDirectory = path.join(vercelOutput, "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(vercelOutput)
|
24
|
+
];
|
25
|
+
case 1:
|
26
|
+
_state.sent();
|
27
|
+
return [
|
28
|
+
2
|
29
|
+
];
|
30
|
+
}
|
31
|
+
});
|
32
|
+
})();
|
33
|
+
},
|
34
|
+
writeOutput: function writeOutput() {
|
35
|
+
return _async_to_generator(function() {
|
36
|
+
var config, mainEntryName, staticDirectory, destHtmlDirectory, outputHtmlDirectory;
|
37
|
+
return _ts_generator(this, function(_state) {
|
38
|
+
switch (_state.label) {
|
39
|
+
case 0:
|
40
|
+
config = {
|
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 = modernConfig.source.mainEntryName;
|
57
|
+
entrypoints.forEach(function(entry) {
|
58
|
+
var isMain = isMainEntry(entry.entryName, mainEntryName);
|
59
|
+
config.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
|
+
config.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"), config, {
|
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 _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, serverAppContext, entryCode;
|
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: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_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
|
+
serverAppContext = serverAppContenxtTemplate(appContext);
|
176
|
+
return [
|
177
|
+
4,
|
178
|
+
fse.readFile(path.join(__dirname, "./vercelEntry.js"))
|
179
|
+
];
|
180
|
+
case 1:
|
181
|
+
entryCode = _state.sent().toString();
|
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
|
+
2
|
191
|
+
];
|
192
|
+
}
|
193
|
+
});
|
194
|
+
})();
|
195
|
+
},
|
196
|
+
end: function end() {
|
197
|
+
return _async_to_generator(function() {
|
198
|
+
return _ts_generator(this, function(_state) {
|
199
|
+
switch (_state.label) {
|
200
|
+
case 0:
|
201
|
+
return [
|
202
|
+
4,
|
203
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
204
|
+
"@modern-js/prod-server"
|
205
|
+
])
|
206
|
+
];
|
207
|
+
case 1:
|
208
|
+
_state.sent();
|
209
|
+
return [
|
210
|
+
2
|
211
|
+
];
|
212
|
+
}
|
213
|
+
});
|
214
|
+
})();
|
215
|
+
}
|
216
|
+
};
|
217
|
+
};
|
218
|
+
export {
|
219
|
+
createVercelPreset
|
220
|
+
};
|