@modern-js/app-tools 3.0.5 → 3.1.0
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/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/cjs/config/default.js +1 -1
- package/dist/cjs/plugins/analyze/utils.js +6 -6
- package/dist/cjs/plugins/deploy/index.js +10 -5
- package/dist/cjs/plugins/deploy/platforms/gh-pages.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/netlify.js +17 -33
- package/dist/cjs/plugins/deploy/platforms/node.js +17 -38
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
- package/dist/cjs/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
- package/dist/{esm/plugins/deploy/platforms → cjs/plugins/deploy/platforms/templates}/node-entry.mjs +5 -27
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +15 -32
- package/dist/cjs/plugins/deploy/types.js +18 -0
- package/dist/cjs/plugins/deploy/utils/generator.js +103 -0
- package/dist/cjs/plugins/deploy/{utils.js → utils/index.js} +28 -24
- package/dist/cjs/utils/register.js +1 -9
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
- package/dist/esm/commands/build.mjs +3 -3
- package/dist/esm/commands/dev.mjs +5 -5
- package/dist/esm/commands/serve.mjs +2 -2
- package/dist/esm/config/default.mjs +1 -1
- package/dist/esm/esm/register-esm.mjs +3 -3
- package/dist/esm/plugins/analyze/utils.mjs +2 -2
- package/dist/esm/plugins/deploy/index.mjs +9 -4
- package/dist/esm/plugins/deploy/platforms/gh-pages.mjs +1 -1
- package/dist/esm/plugins/deploy/platforms/netlify.mjs +25 -41
- package/dist/esm/plugins/deploy/platforms/node.mjs +22 -43
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
- package/dist/esm/plugins/deploy/platforms/vercel.mjs +28 -45
- package/dist/esm/plugins/deploy/types.mjs +0 -0
- package/dist/esm/plugins/deploy/utils/generator.mjs +47 -0
- package/dist/esm/plugins/deploy/utils/index.mjs +40 -0
- package/dist/esm/utils/loadPlugins.mjs +4 -4
- package/dist/esm/utils/register.mjs +6 -14
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
- package/dist/esm-node/commands/build.mjs +3 -3
- package/dist/esm-node/commands/dev.mjs +5 -5
- package/dist/esm-node/commands/serve.mjs +2 -2
- package/dist/esm-node/config/default.mjs +1 -1
- package/dist/esm-node/esm/register-esm.mjs +3 -3
- package/dist/esm-node/plugins/analyze/utils.mjs +2 -2
- package/dist/esm-node/plugins/deploy/index.mjs +9 -4
- package/dist/esm-node/plugins/deploy/platforms/gh-pages.mjs +1 -1
- package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +25 -44
- package/dist/esm-node/plugins/deploy/platforms/node.mjs +22 -46
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +28 -48
- package/dist/esm-node/plugins/deploy/types.mjs +1 -0
- package/dist/esm-node/plugins/deploy/utils/generator.mjs +48 -0
- package/dist/esm-node/plugins/deploy/utils/index.mjs +44 -0
- package/dist/esm-node/utils/loadPlugins.mjs +4 -4
- package/dist/esm-node/utils/register.mjs +6 -14
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -1
- package/dist/types/plugins/deploy/platforms/templates/netlify-entry.d.mts +2 -0
- package/dist/types/plugins/deploy/platforms/templates/node-entry.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.cts +2 -0
- package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.mts +2 -0
- package/dist/types/plugins/deploy/types.d.ts +3 -0
- package/dist/types/plugins/deploy/utils/generator.d.ts +24 -0
- package/dist/types/plugins/deploy/utils/index.d.ts +16 -0
- package/package.json +12 -11
- package/rslib.config.mts +19 -0
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -36
- package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +0 -89
- package/dist/cjs/plugins/deploy/platforms/node-entry.js +0 -75
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -37
- package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +0 -89
- package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +0 -2
- package/dist/esm/plugins/deploy/platforms/netlify-handler.mjs +0 -85
- package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +0 -3
- package/dist/esm/plugins/deploy/platforms/vercel-handler.mjs +0 -85
- package/dist/esm/plugins/deploy/utils.mjs +0 -39
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +0 -3
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.mjs +0 -89
- package/dist/esm-node/plugins/deploy/platforms/node-entry.mjs +0 -72
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +0 -4
- package/dist/esm-node/plugins/deploy/platforms/vercel-handler.mjs +0 -89
- package/dist/esm-node/plugins/deploy/utils.mjs +0 -40
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -2
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
- package/dist/types/plugins/deploy/utils.d.ts +0 -23
- /package/dist/types/plugins/deploy/platforms/{netlify-handler.d.cts → templates/netlify-entry.d.cts} +0 -0
- /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → templates/node-entry.d.cts} +0 -0
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const checkDepExist = (dep, appDir)=>{
|
|
4
|
-
try {
|
|
5
|
-
tryResolve(dep, appDir, process.cwd());
|
|
6
|
-
return true;
|
|
7
|
-
} catch {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { fs, getAliasConfig, isDepExists, loadFromProject, readTsConfigByFile } from "@modern-js/utils";
|
|
11
3
|
const setupTsRuntime = async (appDir, distDir, alias)=>{
|
|
12
4
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
13
|
-
const tsconfigPath =
|
|
5
|
+
const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
|
|
14
6
|
const isTsProject = await fs.pathExists(tsconfigPath);
|
|
15
|
-
const hasTsNode =
|
|
7
|
+
const hasTsNode = isDepExists(appDir, 'ts-node');
|
|
16
8
|
if (!isTsProject || !hasTsNode) return;
|
|
17
9
|
const aliasConfig = getAliasConfig(alias, {
|
|
18
10
|
appDirectory: appDir,
|
|
@@ -29,7 +21,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
|
|
|
29
21
|
]
|
|
30
22
|
});
|
|
31
23
|
} catch {}
|
|
32
|
-
if ('string' == typeof tsPath &&
|
|
24
|
+
if ('string' == typeof tsPath && node_path.isAbsolute(tsPath)) tsPath = node_path.relative(absoluteBaseUrl, tsPath);
|
|
33
25
|
if ('string' == typeof tsPath) tsPath = [
|
|
34
26
|
tsPath
|
|
35
27
|
];
|
|
@@ -48,7 +40,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
|
|
|
48
40
|
transpileOnly: true,
|
|
49
41
|
ignore: [
|
|
50
42
|
'(?:^|/)node_modules/',
|
|
51
|
-
`(?:^|/)${
|
|
43
|
+
`(?:^|/)${node_path.relative(appDir, distDir)}/`
|
|
52
44
|
],
|
|
53
45
|
...tsNodeOptions
|
|
54
46
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
3
3
|
import { dirname as __rspack_dirname } from "node:path";
|
|
4
|
+
import node_path from "node:path";
|
|
4
5
|
import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/builder";
|
|
5
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
6
6
|
var adapterBasic_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
7
7
|
const builderPluginAdapterBasic = (options)=>({
|
|
8
8
|
name: 'builder-plugin-adapter-modern-basic',
|
|
@@ -14,7 +14,7 @@ const builderPluginAdapterBasic = (options)=>({
|
|
|
14
14
|
const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
15
15
|
const depExt = 'mjs';
|
|
16
16
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
17
|
-
chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(
|
|
17
|
+
chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(node_path.join(adapterBasic_dirname, `../loaders/serverModuleLoader.${depExt}`));
|
|
18
18
|
}
|
|
19
19
|
const { appContext } = options;
|
|
20
20
|
const { metaName } = appContext;
|
|
@@ -4,7 +4,7 @@ import { resolve, sep } from "path";
|
|
|
4
4
|
import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
|
|
5
5
|
import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
|
|
6
6
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
7
|
-
import {
|
|
7
|
+
import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
|
|
8
8
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
|
|
9
9
|
const builderPluginAdapterSSR = (options)=>({
|
|
10
10
|
name: 'builder-plugin-adapter-modern-ssr',
|
|
@@ -101,7 +101,7 @@ async function applySSRLoaderEntry(chain, optinos, isServer) {
|
|
|
101
101
|
const { entrypoints } = appContext;
|
|
102
102
|
await Promise.all(entrypoints.map(async (entrypoint)=>{
|
|
103
103
|
const { entryName } = entrypoint;
|
|
104
|
-
const serverLoadersFile =
|
|
104
|
+
const serverLoadersFile = getServerCombinedModuleFile(internalDirectory, entryName);
|
|
105
105
|
if (isServer) try {
|
|
106
106
|
await fs.access(serverLoadersFile, fs.constants.F_OK);
|
|
107
107
|
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
2
3
|
import { fs, logger } from "@modern-js/utils";
|
|
3
4
|
import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
4
5
|
import { setupTsRuntime } from "../utils/register.mjs";
|
|
5
6
|
import { generateRoutes } from "../utils/routes.mjs";
|
|
6
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
7
7
|
async function copyEnvFiles(appDirectory, distDirectory) {
|
|
8
8
|
try {
|
|
9
9
|
const files = await fs.readdir(appDirectory);
|
|
@@ -11,8 +11,8 @@ async function copyEnvFiles(appDirectory, distDirectory) {
|
|
|
11
11
|
const envFiles = files.filter((file)=>envFileRegex.test(file));
|
|
12
12
|
if (0 === envFiles.length) return void logger.debug('No .env files found to copy');
|
|
13
13
|
const copyPromises = envFiles.map(async (envFile)=>{
|
|
14
|
-
const sourcePath =
|
|
15
|
-
const targetPath =
|
|
14
|
+
const sourcePath = node_path.resolve(appDirectory, envFile);
|
|
15
|
+
const targetPath = node_path.resolve(distDirectory, envFile);
|
|
16
16
|
try {
|
|
17
17
|
const stat = await fs.stat(sourcePath);
|
|
18
18
|
if (stat.isDirectory()) return;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { applyPlugins } from "@modern-js/prod-server";
|
|
2
4
|
import { createDevServer } from "@modern-js/server";
|
|
3
5
|
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
|
4
6
|
import { setServer } from "../utils/createServer.mjs";
|
|
@@ -6,8 +8,6 @@ import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
|
6
8
|
import { printInstructions } from "../utils/printInstructions.mjs";
|
|
7
9
|
import { setupTsRuntime } from "../utils/register.mjs";
|
|
8
10
|
import { generateRoutes } from "../utils/routes.mjs";
|
|
9
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
10
|
-
import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
|
|
11
11
|
const dev = async (api, options, devServerOptions)=>{
|
|
12
12
|
if (options.analyze) process.env.BUNDLE_ANALYZE = 'true';
|
|
13
13
|
const normalizedConfig = api.getNormalizedConfig();
|
|
@@ -25,7 +25,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
25
25
|
await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias);
|
|
26
26
|
const { appDirectory, port, apiOnly, metaName, serverRoutes } = appContext;
|
|
27
27
|
const meta = getMeta(metaName);
|
|
28
|
-
const serverConfigPath =
|
|
28
|
+
const serverConfigPath = node_path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
|
29
29
|
await hooks.onBeforeDev.call();
|
|
30
30
|
if (!appContext.builder && !apiOnly) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
31
31
|
await generateRoutes(appContext);
|
|
@@ -56,7 +56,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
56
56
|
const { server } = await createDevServer({
|
|
57
57
|
...serverOptions,
|
|
58
58
|
runCompile: false
|
|
59
|
-
}, devServerOptions?.applyPlugins ||
|
|
59
|
+
}, devServerOptions?.applyPlugins || applyPlugins);
|
|
60
60
|
server.listen({
|
|
61
61
|
port,
|
|
62
62
|
host
|
|
@@ -68,7 +68,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
68
68
|
const { server, afterListen } = await createDevServer({
|
|
69
69
|
...serverOptions,
|
|
70
70
|
builder: appContext.builder
|
|
71
|
-
}, devServerOptions?.applyPlugins ||
|
|
71
|
+
}, devServerOptions?.applyPlugins || applyPlugins);
|
|
72
72
|
server.listen({
|
|
73
73
|
port,
|
|
74
74
|
host
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { createProdServer } from "@modern-js/prod-server";
|
|
3
4
|
import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
|
|
4
5
|
import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
5
6
|
import { printInstructions } from "../utils/printInstructions.mjs";
|
|
6
|
-
import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
|
|
7
7
|
const serve = async (api, serverOptions)=>{
|
|
8
8
|
const appContext = api.getAppContext();
|
|
9
9
|
const userConfig = api.getNormalizedConfig();
|
|
@@ -17,7 +17,7 @@ const serve = async (api, serverOptions)=>{
|
|
|
17
17
|
const meta = getMeta(metaName);
|
|
18
18
|
const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
|
|
19
19
|
const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
|
|
20
|
-
const app = await (serverOptions?.launcher ||
|
|
20
|
+
const app = await (serverOptions?.launcher || createProdServer)({
|
|
21
21
|
metaName,
|
|
22
22
|
pwd: distDirectory,
|
|
23
23
|
config: {
|
|
@@ -5,7 +5,7 @@ function createDefaultConfig(appContext) {
|
|
|
5
5
|
const dev = {
|
|
6
6
|
cliShortcuts: {
|
|
7
7
|
help: false,
|
|
8
|
-
custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key)
|
|
8
|
+
custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key && 'o' !== key)
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
const output = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
2
3
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
4
4
|
const checkDepExist = async (dep)=>{
|
|
5
5
|
try {
|
|
6
6
|
await import(dep);
|
|
@@ -11,7 +11,7 @@ const checkDepExist = async (dep)=>{
|
|
|
11
11
|
};
|
|
12
12
|
const registerModuleHooks = async ({ appDir, distDir, alias })=>{
|
|
13
13
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
14
|
-
const tsconfigPath =
|
|
14
|
+
const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
|
|
15
15
|
const hasTsconfig = await fs.pathExists(tsconfigPath);
|
|
16
16
|
const hasTsNode = await checkDepExist('ts-node');
|
|
17
17
|
if (!hasTsconfig || !hasTsNode) return;
|
|
@@ -20,7 +20,7 @@ const registerModuleHooks = async ({ appDir, distDir, alias })=>{
|
|
|
20
20
|
process.env.TS_NODE_PROJECT = tsconfigPath;
|
|
21
21
|
process.env.TS_NODE_SCOPE = true;
|
|
22
22
|
process.env.TS_NODE_FILES = true;
|
|
23
|
-
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${
|
|
23
|
+
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${node_path.relative(appDir, distDir)}/`;
|
|
24
24
|
register('./ts-node-loader.mjs', import.meta.url, {
|
|
25
25
|
data: {
|
|
26
26
|
appDir,
|
|
@@ -30,7 +30,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
30
30
|
}
|
|
31
31
|
return await parse(content);
|
|
32
32
|
};
|
|
33
|
-
const
|
|
33
|
+
const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
|
|
34
34
|
const checkIsBuildCommands = ()=>{
|
|
35
35
|
const buildCommands = [
|
|
36
36
|
'dev',
|
|
@@ -53,4 +53,4 @@ const isSubDirOrEqual = (parent, child)=>{
|
|
|
53
53
|
const isSubdir = relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
54
54
|
return Boolean(isSubdir);
|
|
55
55
|
};
|
|
56
|
-
export { checkIsBuildCommands, checkIsServeCommand,
|
|
56
|
+
export { checkIsBuildCommands, checkIsServeCommand, getServerCombinedModuleFile, isSubDirOrEqual, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -4,20 +4,25 @@ import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
|
|
|
4
4
|
import { createNetlifyPreset } from "./platforms/netlify.mjs";
|
|
5
5
|
import { createNodePreset } from "./platforms/node.mjs";
|
|
6
6
|
import { createVercelPreset } from "./platforms/vercel.mjs";
|
|
7
|
-
import { getProjectUsage } from "./utils.mjs";
|
|
7
|
+
import { getProjectUsage } from "./utils/index.mjs";
|
|
8
8
|
const deployPresets = {
|
|
9
9
|
node: createNodePreset,
|
|
10
10
|
vercel: createVercelPreset,
|
|
11
11
|
netlify: createNetlifyPreset,
|
|
12
12
|
ghPages: createGhPagesPreset
|
|
13
13
|
};
|
|
14
|
-
async function getDeployPreset(appContext, modernConfig, deployTarget) {
|
|
14
|
+
async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
|
|
15
15
|
const { appDirectory, distDirectory, metaName } = appContext;
|
|
16
16
|
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
|
|
17
17
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
18
18
|
const createPreset = deployPresets[deployTarget];
|
|
19
19
|
if (!createPreset) throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
|
|
20
|
-
return createPreset(
|
|
20
|
+
return createPreset({
|
|
21
|
+
appContext,
|
|
22
|
+
modernConfig,
|
|
23
|
+
needModernServer,
|
|
24
|
+
api
|
|
25
|
+
});
|
|
21
26
|
}
|
|
22
27
|
const deploy = ()=>({
|
|
23
28
|
name: '@modern-js/plugin-deploy',
|
|
@@ -28,7 +33,7 @@ const deploy = ()=>({
|
|
|
28
33
|
const { metaName } = appContext;
|
|
29
34
|
if ('modern-js' !== metaName && !process.env.MODERNJS_DEPLOY) return;
|
|
30
35
|
const modernConfig = api.getNormalizedConfig();
|
|
31
|
-
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
|
36
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget, api);
|
|
32
37
|
deployPreset?.prepare && await deployPreset?.prepare();
|
|
33
38
|
deployPreset?.writeOutput && await deployPreset?.writeOutput();
|
|
34
39
|
deployPreset?.genEntry && await deployPreset?.genEntry();
|
|
@@ -24,7 +24,7 @@ async function reorganizeHtmlFiles(routes, baseDir, baseUrl = '/') {
|
|
|
24
24
|
});
|
|
25
25
|
await Promise.all(copyPromises);
|
|
26
26
|
}
|
|
27
|
-
const createGhPagesPreset = (appContext, modernConfig)=>{
|
|
27
|
+
const createGhPagesPreset = ({ appContext, modernConfig })=>{
|
|
28
28
|
const { serverRoutes, appDirectory, distDirectory } = appContext;
|
|
29
29
|
const { server: { baseUrl } } = modernConfig;
|
|
30
30
|
const outputDirectory = path.join(appDirectory, '.output');
|
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
6
5
|
import { nodeDepEmit } from "ndepe";
|
|
7
6
|
import { isMainEntry } from "../../../utils/routes.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
var netlify_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
7
|
+
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
8
|
+
import { generateHandler } from "../utils/generator.mjs";
|
|
11
9
|
async function cleanDistDirectory(dir) {
|
|
12
10
|
try {
|
|
13
11
|
const items = await fs.readdir(dir);
|
|
14
12
|
for (const item of items){
|
|
15
|
-
const fullPath =
|
|
13
|
+
const fullPath = node_path.join(dir, item);
|
|
16
14
|
if ('static' !== item && '_redirects' !== item && 'html' !== item) await fs.remove(fullPath);
|
|
17
15
|
}
|
|
18
16
|
} catch (error) {
|
|
19
17
|
console.error('Error cleaning directory:', error);
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
|
-
const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
|
|
23
|
-
const { appDirectory, distDirectory, entrypoints,
|
|
20
|
+
const createNetlifyPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
21
|
+
const { appDirectory, distDirectory, entrypoints, moduleType } = appContext;
|
|
24
22
|
const isEsmProject = 'module' === moduleType;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]);
|
|
29
|
-
const netlifyOutput = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.netlify');
|
|
30
|
-
const funcsDirectory = __rspack_external_node_path_c5b9b54f["default"].join(netlifyOutput, 'functions');
|
|
31
|
-
const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'index.js');
|
|
32
|
-
const handlerFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'netlify-handler.cjs');
|
|
23
|
+
const netlifyOutput = node_path.join(appDirectory, '.netlify');
|
|
24
|
+
const funcsDirectory = node_path.join(netlifyOutput, 'functions');
|
|
25
|
+
const entryFilePath = node_path.join(funcsDirectory, 'index.js');
|
|
33
26
|
return {
|
|
34
27
|
async prepare () {
|
|
35
28
|
await fs.remove(netlifyOutput);
|
|
@@ -56,49 +49,37 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
|
|
|
56
49
|
await fs.ensureDir(funcsDirectory);
|
|
57
50
|
await fs.copy(distDirectory, funcsDirectory, {
|
|
58
51
|
filter: (src)=>{
|
|
59
|
-
const distStaticDirectory =
|
|
52
|
+
const distStaticDirectory = node_path.join(distDirectory, "static");
|
|
60
53
|
return !src.includes(distStaticDirectory);
|
|
61
54
|
}
|
|
62
55
|
});
|
|
63
56
|
}
|
|
64
|
-
const redirectFilePath =
|
|
57
|
+
const redirectFilePath = node_path.join(distDirectory, '_redirects');
|
|
65
58
|
await fs.writeFile(redirectFilePath, redirectContent);
|
|
66
59
|
},
|
|
67
60
|
async genEntry () {
|
|
68
61
|
if (!needModernServer) return;
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const meta = getMeta(metaName);
|
|
80
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
81
|
-
const dynamicProdOptions = {
|
|
82
|
-
config: serverConfig
|
|
83
|
-
};
|
|
84
|
-
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
85
|
-
const pluginsCode = getPluginsCode(plugins);
|
|
86
|
-
let handlerCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(netlify_dirname, './netlify-handler.js'))).toString();
|
|
87
|
-
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
88
|
-
handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
|
|
89
|
-
await fs.writeFile(handlerFilePath, handlerCode);
|
|
90
|
-
if (isEsmProject) await fs.writeFile(entryFilePath, "export { handler as default } from './netlify-handler.cjs';\n");
|
|
91
|
-
else await fs.writeFile(entryFilePath, "const { handler } = require('./netlify-handler.cjs');\nexports.handler = handler;\n");
|
|
62
|
+
const template = await readTemplate(`netlify-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
63
|
+
const code = await generateHandler({
|
|
64
|
+
template,
|
|
65
|
+
appContext,
|
|
66
|
+
config: modernConfig,
|
|
67
|
+
isESM: isEsmProject
|
|
68
|
+
});
|
|
69
|
+
await fs.writeFile(entryFilePath, code);
|
|
92
70
|
},
|
|
93
71
|
async end () {
|
|
94
72
|
if ('development' !== process.env.NODE_ENV) await cleanDistDirectory(distDirectory);
|
|
95
73
|
if (!needModernServer) return;
|
|
74
|
+
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
75
|
+
const netlifyEntry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server/netlify') : require.resolve('@modern-js/prod-server/netlify');
|
|
76
|
+
if (!entry || !netlifyEntry) throw new Error('Cannot find @modern-js/prod-server');
|
|
96
77
|
await nodeDepEmit({
|
|
97
78
|
appDir: appDirectory,
|
|
98
79
|
sourceDir: funcsDirectory,
|
|
99
80
|
includeEntries: [
|
|
100
|
-
|
|
101
|
-
|
|
81
|
+
entry,
|
|
82
|
+
netlifyEntry
|
|
102
83
|
],
|
|
103
84
|
copyWholePackage (pkgName) {
|
|
104
85
|
return '@modern-js/utils' === pkgName;
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { ROUTE_SPEC_FILE, SERVER_DIR, chalk, fs, getMeta, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { chalk, fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
6
5
|
import { nodeDepEmit } from "ndepe";
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const { appDirectory, distDirectory, serverPlugins, moduleType, metaName } = appContext;
|
|
6
|
+
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
7
|
+
import { generateHandler } from "../utils/generator.mjs";
|
|
8
|
+
const createNodePreset = ({ appContext, modernConfig, api })=>{
|
|
9
|
+
const { appDirectory, distDirectory, moduleType } = appContext;
|
|
12
10
|
const isEsmProject = 'module' === moduleType;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]);
|
|
17
|
-
const outputDirectory = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.output');
|
|
18
|
-
const staticDirectory = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'static');
|
|
19
|
-
const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'index.js');
|
|
11
|
+
const outputDirectory = node_path.join(appDirectory, '.output');
|
|
12
|
+
const staticDirectory = node_path.join(outputDirectory, 'static');
|
|
13
|
+
const entryFilePath = node_path.join(outputDirectory, 'index.js');
|
|
20
14
|
return {
|
|
21
15
|
async prepare () {
|
|
22
16
|
await fs.remove(outputDirectory);
|
|
@@ -25,44 +19,24 @@ const createNodePreset = (appContext, config)=>{
|
|
|
25
19
|
await fs.copy(distDirectory, outputDirectory);
|
|
26
20
|
},
|
|
27
21
|
async genEntry () {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
distPath: {
|
|
37
|
-
root: '.'
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
42
|
-
const dynamicProdOptions = {
|
|
43
|
-
config: serverConfig
|
|
44
|
-
};
|
|
45
|
-
const meta = getMeta(metaName);
|
|
46
|
-
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
47
|
-
const pluginsCode = getPluginsCode(plugins);
|
|
48
|
-
let entryCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(node_dirname, './node-entry.js'))).toString();
|
|
49
|
-
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
50
|
-
entryCode = entryCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
|
|
51
|
-
if (isEsmProject) {
|
|
52
|
-
const cjsEntryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'index.cjs');
|
|
53
|
-
await fs.writeFile(cjsEntryFilePath, entryCode);
|
|
54
|
-
await fs.writeFile(entryFilePath, "import('./index.cjs');");
|
|
55
|
-
} else await fs.writeFile(entryFilePath, entryCode);
|
|
22
|
+
const template = await readTemplate(`node-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
23
|
+
const code = await generateHandler({
|
|
24
|
+
template,
|
|
25
|
+
appContext,
|
|
26
|
+
config: modernConfig,
|
|
27
|
+
isESM: isEsmProject
|
|
28
|
+
});
|
|
29
|
+
await fs.writeFile(entryFilePath, code);
|
|
56
30
|
},
|
|
57
31
|
async end () {
|
|
58
|
-
console.log('Static directory:', chalk.blue(__rspack_external_node_path_c5b9b54f["default"].relative(appDirectory, staticDirectory)));
|
|
59
|
-
console.log("You can preview this build by", chalk.blue("node .output/index"));
|
|
60
32
|
const filter = (filePath)=>!filePath.startsWith(staticDirectory) && !filePath.endsWith('.map');
|
|
33
|
+
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
34
|
+
if (!entry) throw new Error('Cannot find @modern-js/prod-server');
|
|
61
35
|
await nodeDepEmit({
|
|
62
36
|
appDir: appDirectory,
|
|
63
37
|
sourceDir: outputDirectory,
|
|
64
38
|
includeEntries: [
|
|
65
|
-
|
|
39
|
+
entry
|
|
66
40
|
],
|
|
67
41
|
copyWholePackage (pkgName) {
|
|
68
42
|
return '@modern-js/utils' === pkgName;
|
|
@@ -76,6 +50,8 @@ const createNodePreset = (appContext, config)=>{
|
|
|
76
50
|
};
|
|
77
51
|
}
|
|
78
52
|
});
|
|
53
|
+
console.log('Static directory:', chalk.blue(node_path.relative(appDirectory, staticDirectory).replace(/\\/g, '/')));
|
|
54
|
+
console.log("You can preview this build by", chalk.blue('node .output/index'));
|
|
79
55
|
}
|
|
80
56
|
};
|
|
81
57
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const fs = require('node:fs/promises');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');
|
|
4
|
+
p_genPluginImportsCode;
|
|
5
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
|
|
6
|
+
let requestHandler = null;
|
|
7
|
+
let handlerCreationPromise = null;
|
|
8
|
+
async function loadRoutes(routeFilepath) {
|
|
9
|
+
try {
|
|
10
|
+
await fs.access(routeFilepath);
|
|
11
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
12
|
+
const routeSpec = JSON.parse(content);
|
|
13
|
+
return routeSpec.routes || [];
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function initServer() {
|
|
20
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
21
|
+
const routes = await loadRoutes(routeFilepath);
|
|
22
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
23
|
+
const prodServerOptions = {
|
|
24
|
+
pwd: __dirname,
|
|
25
|
+
routes,
|
|
26
|
+
disableCustomHook: true,
|
|
27
|
+
appContext: {
|
|
28
|
+
sharedDirectory: p_sharedDirectory,
|
|
29
|
+
apiDirectory: p_apiDirectory,
|
|
30
|
+
lambdaDirectory: p_lambdaDirectory,
|
|
31
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
|
32
|
+
},
|
|
33
|
+
plugins: p_plugins,
|
|
34
|
+
serverConfigPath: p_serverDirectory,
|
|
35
|
+
...dynamicProdOptions
|
|
36
|
+
};
|
|
37
|
+
const requestHandler = await createNetlifyFunction(prodServerOptions);
|
|
38
|
+
return requestHandler;
|
|
39
|
+
}
|
|
40
|
+
async function createHandler() {
|
|
41
|
+
if (!handlerCreationPromise) handlerCreationPromise = (async ()=>{
|
|
42
|
+
try {
|
|
43
|
+
requestHandler = await initServer();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Error creating server:', error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
await handlerCreationPromise;
|
|
50
|
+
return requestHandler;
|
|
51
|
+
}
|
|
52
|
+
createHandler();
|
|
53
|
+
const handler = async (request, context)=>{
|
|
54
|
+
if (!requestHandler) await createHandler();
|
|
55
|
+
return requestHandler(request, context);
|
|
56
|
+
};
|
|
57
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { createNetlifyFunction } from '@modern-js/prod-server/netlify';
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
p_genPluginImportsCode;
|
|
7
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
|
|
8
|
+
let requestHandler = null;
|
|
9
|
+
let handlerCreationPromise = null;
|
|
10
|
+
async function loadRoutes(routeFilepath) {
|
|
11
|
+
try {
|
|
12
|
+
await fs.access(routeFilepath);
|
|
13
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
14
|
+
const routeSpec = JSON.parse(content);
|
|
15
|
+
return routeSpec.routes || [];
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function initServer() {
|
|
22
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
23
|
+
const routes = await loadRoutes(routeFilepath);
|
|
24
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
25
|
+
const prodServerOptions = {
|
|
26
|
+
pwd: __dirname,
|
|
27
|
+
routes,
|
|
28
|
+
disableCustomHook: true,
|
|
29
|
+
appContext: {
|
|
30
|
+
sharedDirectory: p_sharedDirectory,
|
|
31
|
+
apiDirectory: p_apiDirectory,
|
|
32
|
+
lambdaDirectory: p_lambdaDirectory,
|
|
33
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
|
34
|
+
},
|
|
35
|
+
plugins: p_plugins,
|
|
36
|
+
serverConfigPath: p_serverDirectory,
|
|
37
|
+
...dynamicProdOptions
|
|
38
|
+
};
|
|
39
|
+
const requestHandler = await createNetlifyFunction(prodServerOptions);
|
|
40
|
+
return requestHandler;
|
|
41
|
+
}
|
|
42
|
+
async function createHandler() {
|
|
43
|
+
if (!handlerCreationPromise) handlerCreationPromise = (async ()=>{
|
|
44
|
+
try {
|
|
45
|
+
requestHandler = await initServer();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('Error creating server:', error);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
await handlerCreationPromise;
|
|
52
|
+
return requestHandler;
|
|
53
|
+
}
|
|
54
|
+
createHandler();
|
|
55
|
+
const handler = async (request, context)=>{
|
|
56
|
+
if (!requestHandler) await createHandler();
|
|
57
|
+
return requestHandler(request, context);
|
|
58
|
+
};
|
|
59
|
+
export default handler;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const fs = require('node:fs/promises');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { createProdServer } = require('@modern-js/prod-server');
|
|
4
|
+
p_genPluginImportsCode;
|
|
5
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
|
|
6
|
+
async function loadRoutes(routeFilepath) {
|
|
7
|
+
try {
|
|
8
|
+
await fs.access(routeFilepath);
|
|
9
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
10
|
+
const routeSpec = JSON.parse(content);
|
|
11
|
+
return routeSpec.routes || [];
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function main() {
|
|
18
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
19
|
+
const routes = await loadRoutes(routeFilepath);
|
|
20
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
21
|
+
const prodServerOptions = {
|
|
22
|
+
pwd: __dirname,
|
|
23
|
+
routes,
|
|
24
|
+
disableCustomHook: true,
|
|
25
|
+
appContext: {
|
|
26
|
+
sharedDirectory: p_sharedDirectory,
|
|
27
|
+
apiDirectory: p_apiDirectory,
|
|
28
|
+
lambdaDirectory: p_lambdaDirectory,
|
|
29
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
|
30
|
+
},
|
|
31
|
+
plugins: p_plugins,
|
|
32
|
+
serverConfigPath: p_serverDirectory,
|
|
33
|
+
...dynamicProdOptions
|
|
34
|
+
};
|
|
35
|
+
const app = await createProdServer(prodServerOptions);
|
|
36
|
+
const port = process.env.PORT || 8080;
|
|
37
|
+
app.listen({
|
|
38
|
+
host: '::',
|
|
39
|
+
port
|
|
40
|
+
}, ()=>{
|
|
41
|
+
console.log(`\x1b[32mServer is listening on http://[::]:${port}`, '\x1b[0m');
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
main();
|