@xfe-repo/web-app 1.6.2 → 2.0.0-beta.1
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/README.md +64 -1
- package/client.d.ts +1 -0
- package/deploy/.drone.yml +12 -5
- package/deploy/Dockerfile +14 -6
- package/deploy/helm/templates/deployment.yaml +5 -18
- package/deploy/helm/templates/svc.yaml +1 -1
- package/dist/cli.js +275 -413
- package/dist/cli.mjs +273 -267
- package/dist/config.d.mts +20 -6
- package/dist/config.d.ts +20 -6
- package/dist/config.js +83 -297
- package/dist/config.mjs +69 -2
- package/dist/framework.d.mts +10 -0
- package/dist/framework.d.ts +10 -0
- package/dist/framework.js +174 -0
- package/dist/framework.mjs +137 -0
- package/dist/react-router-config.d.mts +11 -0
- package/dist/react-router-config.d.ts +11 -0
- package/dist/react-router-config.js +66 -0
- package/dist/react-router-config.mjs +35 -0
- package/dist/root.d.mts +17 -0
- package/dist/root.d.ts +17 -0
- package/dist/root.js +61 -0
- package/dist/root.mjs +34 -0
- package/dist/serve.d.mts +10 -0
- package/dist/serve.d.ts +10 -0
- package/dist/serve.js +71 -0
- package/dist/serve.mjs +36 -0
- package/dist/vite.d.mts +9 -0
- package/dist/vite.d.ts +9 -0
- package/dist/vite.js +135 -0
- package/dist/vite.mjs +100 -0
- package/package.json +22 -71
- package/tsconfig.json +4 -1
- package/config/env.js +0 -104
- package/config/getHttpsConfig.js +0 -66
- package/config/jest/babelTransform.js +0 -29
- package/config/jest/cssTransform.js +0 -14
- package/config/jest/fileTransform.js +0 -40
- package/config/modules.js +0 -133
- package/config/paths.js +0 -65
- package/config/webpack/persistentCache/createEnvironmentHash.js +0 -9
- package/config/webpack/webpack.config.js +0 -724
- package/config/webpack/webpackDevServer.config.js +0 -122
- package/deploy/nginx.conf +0 -62
- package/dist/chunk-75BJNL7E.mjs +0 -239
- package/scripts/build.js +0 -217
- package/scripts/dev.js +0 -162
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/framework.ts
|
|
31
|
+
var framework_exports = {};
|
|
32
|
+
__export(framework_exports, {
|
|
33
|
+
getFrameworkRoot: () => getFrameworkRoot,
|
|
34
|
+
prepareFramework: () => prepareFramework
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(framework_exports);
|
|
37
|
+
var import_node_fs = __toESM(require("fs"));
|
|
38
|
+
var import_node_module = require("module");
|
|
39
|
+
var import_node_path = __toESM(require("path"));
|
|
40
|
+
var import_node_url = require("url");
|
|
41
|
+
|
|
42
|
+
// src/config.ts
|
|
43
|
+
var import_path = __toESM(require("path"));
|
|
44
|
+
var import_fs = __toESM(require("fs"));
|
|
45
|
+
var import_yaml = __toESM(require("yaml"));
|
|
46
|
+
var loadXfeConfig = (root = process.cwd()) => {
|
|
47
|
+
const xfeConfigPath = import_path.default.join(root, "xfe.json");
|
|
48
|
+
if (!import_fs.default.existsSync(xfeConfigPath)) {
|
|
49
|
+
throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
|
|
50
|
+
}
|
|
51
|
+
const xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
|
|
52
|
+
const config = JSON.parse(xfeConfigContent);
|
|
53
|
+
const renderMode = config.webapp?.renderMode;
|
|
54
|
+
if (renderMode !== void 0 && renderMode !== "client" && renderMode !== "server") {
|
|
55
|
+
throw new Error("xfe.json.webapp.renderMode \u53EA\u80FD\u4E3A client \u6216 server");
|
|
56
|
+
}
|
|
57
|
+
return config;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/framework.ts
|
|
61
|
+
var import_meta = {};
|
|
62
|
+
var frameworkDirectory = typeof __dirname === "string" ? __dirname : import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
63
|
+
var requireFromFramework = (0, import_node_module.createRequire)(import_node_path.default.join(frameworkDirectory, "framework.js"));
|
|
64
|
+
var extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
65
|
+
var findSource = (directory, name) => extensions.map((extension) => import_node_path.default.join(directory, `${name}${extension}`)).find(import_node_fs.default.existsSync);
|
|
66
|
+
var findValueExports = (file) => [...import_node_fs.default.readFileSync(file, "utf8").matchAll(/^\s*export\s+(?:async\s+)?(?:const|let|var|function|class)\s+([A-Za-z_$][\w$]*)/gm)].map(
|
|
67
|
+
([, name]) => name
|
|
68
|
+
);
|
|
69
|
+
var importPath = (from, target) => {
|
|
70
|
+
const relative = import_node_path.default.relative(from, target).replace(import_node_path.default.extname(target), "").replaceAll(import_node_path.default.sep, "/");
|
|
71
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
72
|
+
};
|
|
73
|
+
var writeGenerated = (file, content) => {
|
|
74
|
+
if (import_node_fs.default.existsSync(file) && import_node_fs.default.readFileSync(file, "utf8") === content) return;
|
|
75
|
+
import_node_fs.default.writeFileSync(file, content);
|
|
76
|
+
};
|
|
77
|
+
var defaultRootSource = (projectRoot, appDirectory) => {
|
|
78
|
+
const { webapp = {} } = loadXfeConfig(projectRoot);
|
|
79
|
+
const layoutSource = findSource(import_node_path.default.join(projectRoot, "src"), "layout");
|
|
80
|
+
const layoutExports = layoutSource ? findValueExports(layoutSource) : [];
|
|
81
|
+
const hasErrorView = layoutExports.includes("ErrorView");
|
|
82
|
+
const layoutImport = layoutSource ? `import AppLayout${hasErrorView ? ", { ErrorView }" : ""} from ${JSON.stringify(importPath(appDirectory, layoutSource))}
|
|
83
|
+
` : "";
|
|
84
|
+
return `import { createElement, type ReactNode } from 'react'
|
|
85
|
+
import { Outlet } from 'react-router'
|
|
86
|
+
import { Document, PageError, PageLoading } from '@xfe-repo/web-app/dist/root.mjs'
|
|
87
|
+
${layoutImport}
|
|
88
|
+
export const meta = () => [{ title: ${JSON.stringify(webapp.title || "XFE App")} }]
|
|
89
|
+
export const Layout = ({ children }: { children: ReactNode }) => createElement(Document, { children, lang: ${JSON.stringify(webapp.lang || "zh-CN")}, themeColor: ${JSON.stringify(webapp.themeColor)} })
|
|
90
|
+
export default function Root() { return ${layoutSource ? "createElement(AppLayout, { children: createElement(Outlet) })" : "createElement(Outlet)"} }
|
|
91
|
+
export function ErrorBoundary() { return createElement(PageError, { ${hasErrorView ? "view: ErrorView" : ""} }) }
|
|
92
|
+
export function HydrateFallback() { return createElement(PageLoading) }
|
|
93
|
+
`;
|
|
94
|
+
};
|
|
95
|
+
var getFrameworkRoot = (projectRoot) => import_node_path.default.join(projectRoot, "node_modules/.cache/xfe-web/react-router");
|
|
96
|
+
var prepareFramework = (projectRoot = process.cwd()) => {
|
|
97
|
+
const sourceDirectory = import_node_path.default.join(projectRoot, "src");
|
|
98
|
+
const rootSource = findSource(sourceDirectory, "root");
|
|
99
|
+
const appServerSource = findSource(sourceDirectory, "app.server");
|
|
100
|
+
const pagesSource = import_node_path.default.join(sourceDirectory, "pages");
|
|
101
|
+
if (!import_node_fs.default.existsSync(pagesSource)) throw new Error("\u672A\u627E\u5230 src/pages");
|
|
102
|
+
const rootDirectory = getFrameworkRoot(projectRoot);
|
|
103
|
+
const appDirectory = import_node_path.default.join(rootDirectory, "app");
|
|
104
|
+
import_node_fs.default.mkdirSync(appDirectory, { recursive: true });
|
|
105
|
+
const routerDirectory = import_node_path.default.dirname(requireFromFramework.resolve("react-router/package.json"));
|
|
106
|
+
const routerLink = import_node_path.default.join(rootDirectory, "node_modules/react-router");
|
|
107
|
+
import_node_fs.default.mkdirSync(import_node_path.default.dirname(routerLink), { recursive: true });
|
|
108
|
+
if (!import_node_fs.default.lstatSync(routerLink, { throwIfNoEntry: false })?.isSymbolicLink() || import_node_fs.default.readlinkSync(routerLink) !== routerDirectory) {
|
|
109
|
+
import_node_fs.default.rmSync(routerLink, { force: true });
|
|
110
|
+
import_node_fs.default.symlinkSync(routerDirectory, routerLink, "junction");
|
|
111
|
+
}
|
|
112
|
+
const rootTarget = import_node_path.default.join(appDirectory, "root.tsx");
|
|
113
|
+
const rootImport = rootSource ? importPath(appDirectory, rootSource) : "";
|
|
114
|
+
const rootExports = rootSource ? findValueExports(rootSource).filter((name) => name !== "middleware" || !appServerSource) : [];
|
|
115
|
+
const namedExports = rootExports.length ? `export { ${rootExports.join(", ")} } from ${JSON.stringify(rootImport)}
|
|
116
|
+
` : "";
|
|
117
|
+
const errorBoundaryExport = rootExports.includes("ErrorBoundary") ? "" : "export { DefaultErrorBoundary as ErrorBoundary } from '@xfe-repo/web-router/errors'\n";
|
|
118
|
+
const middlewareExport = appServerSource ? `export { middleware } from ${JSON.stringify(importPath(appDirectory, appServerSource))}
|
|
119
|
+
` : "";
|
|
120
|
+
writeGenerated(
|
|
121
|
+
rootTarget,
|
|
122
|
+
rootSource ? `export * from ${JSON.stringify(rootImport)}
|
|
123
|
+
export { default } from ${JSON.stringify(rootImport)}
|
|
124
|
+
${namedExports}${errorBoundaryExport}${middlewareExport}` : `${defaultRootSource(projectRoot, appDirectory)}${middlewareExport}`
|
|
125
|
+
);
|
|
126
|
+
const pagesLink = import_node_path.default.join(appDirectory, "pages");
|
|
127
|
+
if (!import_node_fs.default.existsSync(pagesLink)) import_node_fs.default.symlinkSync(import_node_path.default.relative(appDirectory, pagesSource), pagesLink, "dir");
|
|
128
|
+
writeGenerated(
|
|
129
|
+
import_node_path.default.join(rootDirectory, "react-router.config.js"),
|
|
130
|
+
"export { default } from '@xfe-repo/web-app/dist/react-router-config.mjs'\n"
|
|
131
|
+
);
|
|
132
|
+
writeGenerated(
|
|
133
|
+
import_node_path.default.join(appDirectory, "routes.js"),
|
|
134
|
+
`import { collectPageRoutes } from '@xfe-repo/web-router/routes'
|
|
135
|
+
export default collectPageRoutes(${JSON.stringify(appDirectory)})
|
|
136
|
+
`
|
|
137
|
+
);
|
|
138
|
+
const defaultsDirectory = import_node_path.default.join(import_node_path.default.dirname(requireFromFramework.resolve("@react-router/dev/package.json")), "dist/config/defaults");
|
|
139
|
+
writeGenerated(
|
|
140
|
+
import_node_path.default.join(appDirectory, "entry.server.tsx"),
|
|
141
|
+
`export { default, streamTimeout } from ${JSON.stringify(importPath(appDirectory, import_node_path.default.join(defaultsDirectory, "entry.server.web.tsx")))}
|
|
142
|
+
`
|
|
143
|
+
);
|
|
144
|
+
const typeScriptConfig = import_node_path.default.join(rootDirectory, "tsconfig.json");
|
|
145
|
+
writeGenerated(
|
|
146
|
+
typeScriptConfig,
|
|
147
|
+
JSON.stringify(
|
|
148
|
+
{
|
|
149
|
+
extends: import_node_path.default.join(projectRoot, "tsconfig.json"),
|
|
150
|
+
compilerOptions: { rootDirs: [projectRoot, rootDirectory, import_node_path.default.join(rootDirectory, ".react-router/types")] },
|
|
151
|
+
include: [
|
|
152
|
+
import_node_path.default.join(sourceDirectory, "**/*"),
|
|
153
|
+
import_node_path.default.join(projectRoot, "types/**/*"),
|
|
154
|
+
import_node_path.default.join(appDirectory, "*.tsx"),
|
|
155
|
+
import_node_path.default.join(rootDirectory, ".react-router/types/**/*")
|
|
156
|
+
],
|
|
157
|
+
exclude: []
|
|
158
|
+
},
|
|
159
|
+
null,
|
|
160
|
+
2
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
return {
|
|
164
|
+
appDirectory,
|
|
165
|
+
rootDirectory,
|
|
166
|
+
viteConfig: import_node_path.default.resolve(frameworkDirectory, "vite.mjs"),
|
|
167
|
+
typeScriptConfig
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
getFrameworkRoot,
|
|
173
|
+
prepareFramework
|
|
174
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// src/framework.ts
|
|
2
|
+
import fs2 from "fs";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import path2 from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
// src/config.ts
|
|
8
|
+
import path from "path";
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import yaml from "yaml";
|
|
11
|
+
var loadXfeConfig = (root = process.cwd()) => {
|
|
12
|
+
const xfeConfigPath = path.join(root, "xfe.json");
|
|
13
|
+
if (!fs.existsSync(xfeConfigPath)) {
|
|
14
|
+
throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
|
|
15
|
+
}
|
|
16
|
+
const xfeConfigContent = fs.readFileSync(xfeConfigPath, "utf8");
|
|
17
|
+
const config = JSON.parse(xfeConfigContent);
|
|
18
|
+
const renderMode = config.webapp?.renderMode;
|
|
19
|
+
if (renderMode !== void 0 && renderMode !== "client" && renderMode !== "server") {
|
|
20
|
+
throw new Error("xfe.json.webapp.renderMode \u53EA\u80FD\u4E3A client \u6216 server");
|
|
21
|
+
}
|
|
22
|
+
return config;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/framework.ts
|
|
26
|
+
var frameworkDirectory = typeof __dirname === "string" ? __dirname : path2.dirname(fileURLToPath(import.meta.url));
|
|
27
|
+
var requireFromFramework = createRequire(path2.join(frameworkDirectory, "framework.js"));
|
|
28
|
+
var extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
29
|
+
var findSource = (directory, name) => extensions.map((extension) => path2.join(directory, `${name}${extension}`)).find(fs2.existsSync);
|
|
30
|
+
var findValueExports = (file) => [...fs2.readFileSync(file, "utf8").matchAll(/^\s*export\s+(?:async\s+)?(?:const|let|var|function|class)\s+([A-Za-z_$][\w$]*)/gm)].map(
|
|
31
|
+
([, name]) => name
|
|
32
|
+
);
|
|
33
|
+
var importPath = (from, target) => {
|
|
34
|
+
const relative = path2.relative(from, target).replace(path2.extname(target), "").replaceAll(path2.sep, "/");
|
|
35
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
36
|
+
};
|
|
37
|
+
var writeGenerated = (file, content) => {
|
|
38
|
+
if (fs2.existsSync(file) && fs2.readFileSync(file, "utf8") === content) return;
|
|
39
|
+
fs2.writeFileSync(file, content);
|
|
40
|
+
};
|
|
41
|
+
var defaultRootSource = (projectRoot, appDirectory) => {
|
|
42
|
+
const { webapp = {} } = loadXfeConfig(projectRoot);
|
|
43
|
+
const layoutSource = findSource(path2.join(projectRoot, "src"), "layout");
|
|
44
|
+
const layoutExports = layoutSource ? findValueExports(layoutSource) : [];
|
|
45
|
+
const hasErrorView = layoutExports.includes("ErrorView");
|
|
46
|
+
const layoutImport = layoutSource ? `import AppLayout${hasErrorView ? ", { ErrorView }" : ""} from ${JSON.stringify(importPath(appDirectory, layoutSource))}
|
|
47
|
+
` : "";
|
|
48
|
+
return `import { createElement, type ReactNode } from 'react'
|
|
49
|
+
import { Outlet } from 'react-router'
|
|
50
|
+
import { Document, PageError, PageLoading } from '@xfe-repo/web-app/dist/root.mjs'
|
|
51
|
+
${layoutImport}
|
|
52
|
+
export const meta = () => [{ title: ${JSON.stringify(webapp.title || "XFE App")} }]
|
|
53
|
+
export const Layout = ({ children }: { children: ReactNode }) => createElement(Document, { children, lang: ${JSON.stringify(webapp.lang || "zh-CN")}, themeColor: ${JSON.stringify(webapp.themeColor)} })
|
|
54
|
+
export default function Root() { return ${layoutSource ? "createElement(AppLayout, { children: createElement(Outlet) })" : "createElement(Outlet)"} }
|
|
55
|
+
export function ErrorBoundary() { return createElement(PageError, { ${hasErrorView ? "view: ErrorView" : ""} }) }
|
|
56
|
+
export function HydrateFallback() { return createElement(PageLoading) }
|
|
57
|
+
`;
|
|
58
|
+
};
|
|
59
|
+
var getFrameworkRoot = (projectRoot) => path2.join(projectRoot, "node_modules/.cache/xfe-web/react-router");
|
|
60
|
+
var prepareFramework = (projectRoot = process.cwd()) => {
|
|
61
|
+
const sourceDirectory = path2.join(projectRoot, "src");
|
|
62
|
+
const rootSource = findSource(sourceDirectory, "root");
|
|
63
|
+
const appServerSource = findSource(sourceDirectory, "app.server");
|
|
64
|
+
const pagesSource = path2.join(sourceDirectory, "pages");
|
|
65
|
+
if (!fs2.existsSync(pagesSource)) throw new Error("\u672A\u627E\u5230 src/pages");
|
|
66
|
+
const rootDirectory = getFrameworkRoot(projectRoot);
|
|
67
|
+
const appDirectory = path2.join(rootDirectory, "app");
|
|
68
|
+
fs2.mkdirSync(appDirectory, { recursive: true });
|
|
69
|
+
const routerDirectory = path2.dirname(requireFromFramework.resolve("react-router/package.json"));
|
|
70
|
+
const routerLink = path2.join(rootDirectory, "node_modules/react-router");
|
|
71
|
+
fs2.mkdirSync(path2.dirname(routerLink), { recursive: true });
|
|
72
|
+
if (!fs2.lstatSync(routerLink, { throwIfNoEntry: false })?.isSymbolicLink() || fs2.readlinkSync(routerLink) !== routerDirectory) {
|
|
73
|
+
fs2.rmSync(routerLink, { force: true });
|
|
74
|
+
fs2.symlinkSync(routerDirectory, routerLink, "junction");
|
|
75
|
+
}
|
|
76
|
+
const rootTarget = path2.join(appDirectory, "root.tsx");
|
|
77
|
+
const rootImport = rootSource ? importPath(appDirectory, rootSource) : "";
|
|
78
|
+
const rootExports = rootSource ? findValueExports(rootSource).filter((name) => name !== "middleware" || !appServerSource) : [];
|
|
79
|
+
const namedExports = rootExports.length ? `export { ${rootExports.join(", ")} } from ${JSON.stringify(rootImport)}
|
|
80
|
+
` : "";
|
|
81
|
+
const errorBoundaryExport = rootExports.includes("ErrorBoundary") ? "" : "export { DefaultErrorBoundary as ErrorBoundary } from '@xfe-repo/web-router/errors'\n";
|
|
82
|
+
const middlewareExport = appServerSource ? `export { middleware } from ${JSON.stringify(importPath(appDirectory, appServerSource))}
|
|
83
|
+
` : "";
|
|
84
|
+
writeGenerated(
|
|
85
|
+
rootTarget,
|
|
86
|
+
rootSource ? `export * from ${JSON.stringify(rootImport)}
|
|
87
|
+
export { default } from ${JSON.stringify(rootImport)}
|
|
88
|
+
${namedExports}${errorBoundaryExport}${middlewareExport}` : `${defaultRootSource(projectRoot, appDirectory)}${middlewareExport}`
|
|
89
|
+
);
|
|
90
|
+
const pagesLink = path2.join(appDirectory, "pages");
|
|
91
|
+
if (!fs2.existsSync(pagesLink)) fs2.symlinkSync(path2.relative(appDirectory, pagesSource), pagesLink, "dir");
|
|
92
|
+
writeGenerated(
|
|
93
|
+
path2.join(rootDirectory, "react-router.config.js"),
|
|
94
|
+
"export { default } from '@xfe-repo/web-app/dist/react-router-config.mjs'\n"
|
|
95
|
+
);
|
|
96
|
+
writeGenerated(
|
|
97
|
+
path2.join(appDirectory, "routes.js"),
|
|
98
|
+
`import { collectPageRoutes } from '@xfe-repo/web-router/routes'
|
|
99
|
+
export default collectPageRoutes(${JSON.stringify(appDirectory)})
|
|
100
|
+
`
|
|
101
|
+
);
|
|
102
|
+
const defaultsDirectory = path2.join(path2.dirname(requireFromFramework.resolve("@react-router/dev/package.json")), "dist/config/defaults");
|
|
103
|
+
writeGenerated(
|
|
104
|
+
path2.join(appDirectory, "entry.server.tsx"),
|
|
105
|
+
`export { default, streamTimeout } from ${JSON.stringify(importPath(appDirectory, path2.join(defaultsDirectory, "entry.server.web.tsx")))}
|
|
106
|
+
`
|
|
107
|
+
);
|
|
108
|
+
const typeScriptConfig = path2.join(rootDirectory, "tsconfig.json");
|
|
109
|
+
writeGenerated(
|
|
110
|
+
typeScriptConfig,
|
|
111
|
+
JSON.stringify(
|
|
112
|
+
{
|
|
113
|
+
extends: path2.join(projectRoot, "tsconfig.json"),
|
|
114
|
+
compilerOptions: { rootDirs: [projectRoot, rootDirectory, path2.join(rootDirectory, ".react-router/types")] },
|
|
115
|
+
include: [
|
|
116
|
+
path2.join(sourceDirectory, "**/*"),
|
|
117
|
+
path2.join(projectRoot, "types/**/*"),
|
|
118
|
+
path2.join(appDirectory, "*.tsx"),
|
|
119
|
+
path2.join(rootDirectory, ".react-router/types/**/*")
|
|
120
|
+
],
|
|
121
|
+
exclude: []
|
|
122
|
+
},
|
|
123
|
+
null,
|
|
124
|
+
2
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
return {
|
|
128
|
+
appDirectory,
|
|
129
|
+
rootDirectory,
|
|
130
|
+
viteConfig: path2.resolve(frameworkDirectory, "vite.mjs"),
|
|
131
|
+
typeScriptConfig
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export {
|
|
135
|
+
getFrameworkRoot,
|
|
136
|
+
prepareFramework
|
|
137
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react-router-config.ts
|
|
31
|
+
var react_router_config_exports = {};
|
|
32
|
+
__export(react_router_config_exports, {
|
|
33
|
+
default: () => react_router_config_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(react_router_config_exports);
|
|
36
|
+
var import_node_path = __toESM(require("path"));
|
|
37
|
+
|
|
38
|
+
// src/config.ts
|
|
39
|
+
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_fs = __toESM(require("fs"));
|
|
41
|
+
var import_yaml = __toESM(require("yaml"));
|
|
42
|
+
var loadXfeConfig = (root = process.cwd()) => {
|
|
43
|
+
const xfeConfigPath = import_path.default.join(root, "xfe.json");
|
|
44
|
+
if (!import_fs.default.existsSync(xfeConfigPath)) {
|
|
45
|
+
throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
|
|
46
|
+
}
|
|
47
|
+
const xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
|
|
48
|
+
const config = JSON.parse(xfeConfigContent);
|
|
49
|
+
const renderMode = config.webapp?.renderMode;
|
|
50
|
+
if (renderMode !== void 0 && renderMode !== "client" && renderMode !== "server") {
|
|
51
|
+
throw new Error("xfe.json.webapp.renderMode \u53EA\u80FD\u4E3A client \u6216 server");
|
|
52
|
+
}
|
|
53
|
+
return config;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/react-router-config.ts
|
|
57
|
+
var projectRoot = process.env.XFE_WEB_ROOT;
|
|
58
|
+
if (!projectRoot) throw new Error("\u7F3A\u5C11 XFE_WEB_ROOT\uFF0CReact Router \u5FC5\u987B\u901A\u8FC7 xfe-web \u542F\u52A8");
|
|
59
|
+
var { webapp = {} } = loadXfeConfig(projectRoot);
|
|
60
|
+
var react_router_config_default = {
|
|
61
|
+
appDirectory: "app",
|
|
62
|
+
basename: webapp.basename || "/",
|
|
63
|
+
buildDirectory: import_node_path.default.join(projectRoot, "build"),
|
|
64
|
+
future: { unstable_optimizeDeps: true },
|
|
65
|
+
ssr: webapp.renderMode !== "client"
|
|
66
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/react-router-config.ts
|
|
2
|
+
import path2 from "path";
|
|
3
|
+
|
|
4
|
+
// src/config.ts
|
|
5
|
+
import path from "path";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import yaml from "yaml";
|
|
8
|
+
var loadXfeConfig = (root = process.cwd()) => {
|
|
9
|
+
const xfeConfigPath = path.join(root, "xfe.json");
|
|
10
|
+
if (!fs.existsSync(xfeConfigPath)) {
|
|
11
|
+
throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
|
|
12
|
+
}
|
|
13
|
+
const xfeConfigContent = fs.readFileSync(xfeConfigPath, "utf8");
|
|
14
|
+
const config = JSON.parse(xfeConfigContent);
|
|
15
|
+
const renderMode = config.webapp?.renderMode;
|
|
16
|
+
if (renderMode !== void 0 && renderMode !== "client" && renderMode !== "server") {
|
|
17
|
+
throw new Error("xfe.json.webapp.renderMode \u53EA\u80FD\u4E3A client \u6216 server");
|
|
18
|
+
}
|
|
19
|
+
return config;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/react-router-config.ts
|
|
23
|
+
var projectRoot = process.env.XFE_WEB_ROOT;
|
|
24
|
+
if (!projectRoot) throw new Error("\u7F3A\u5C11 XFE_WEB_ROOT\uFF0CReact Router \u5FC5\u987B\u901A\u8FC7 xfe-web \u542F\u52A8");
|
|
25
|
+
var { webapp = {} } = loadXfeConfig(projectRoot);
|
|
26
|
+
var react_router_config_default = {
|
|
27
|
+
appDirectory: "app",
|
|
28
|
+
basename: webapp.basename || "/",
|
|
29
|
+
buildDirectory: path2.join(projectRoot, "build"),
|
|
30
|
+
future: { unstable_optimizeDeps: true },
|
|
31
|
+
ssr: webapp.renderMode !== "client"
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
react_router_config_default as default
|
|
35
|
+
};
|
package/dist/root.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PropsWithChildren, ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
declare function PageLoading(): react.JSX.Element;
|
|
5
|
+
declare function Document({ children, lang, themeColor }: PropsWithChildren<{
|
|
6
|
+
lang?: string;
|
|
7
|
+
themeColor?: string;
|
|
8
|
+
}>): react.JSX.Element;
|
|
9
|
+
declare function PageError({ view }: {
|
|
10
|
+
view?: ComponentType<{
|
|
11
|
+
error: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
}): react.ReactElement<{
|
|
14
|
+
error: unknown;
|
|
15
|
+
}, string | react.JSXElementConstructor<any>> | react.FunctionComponentElement<{}>;
|
|
16
|
+
|
|
17
|
+
export { Document, PageError, PageLoading };
|
package/dist/root.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PropsWithChildren, ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
declare function PageLoading(): react.JSX.Element;
|
|
5
|
+
declare function Document({ children, lang, themeColor }: PropsWithChildren<{
|
|
6
|
+
lang?: string;
|
|
7
|
+
themeColor?: string;
|
|
8
|
+
}>): react.JSX.Element;
|
|
9
|
+
declare function PageError({ view }: {
|
|
10
|
+
view?: ComponentType<{
|
|
11
|
+
error: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
}): react.ReactElement<{
|
|
14
|
+
error: unknown;
|
|
15
|
+
}, string | react.JSXElementConstructor<any>> | react.FunctionComponentElement<{}>;
|
|
16
|
+
|
|
17
|
+
export { Document, PageError, PageLoading };
|
package/dist/root.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/root.tsx
|
|
21
|
+
var root_exports = {};
|
|
22
|
+
__export(root_exports, {
|
|
23
|
+
Document: () => Document,
|
|
24
|
+
PageError: () => PageError,
|
|
25
|
+
PageLoading: () => PageLoading
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(root_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_react_router = require("react-router");
|
|
30
|
+
var import_errors = require("@xfe-repo/web-router/errors");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
function PageLoading() {
|
|
33
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("main", { role: "status", "aria-live": "polite", children: "\u6B63\u5728\u52A0\u8F7D\u9875\u9762\u2026" });
|
|
34
|
+
}
|
|
35
|
+
function Document({ children, lang = "zh-CN", themeColor }) {
|
|
36
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("html", { lang, children: [
|
|
37
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("head", { children: [
|
|
38
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", { charSet: "utf-8" }),
|
|
39
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
|
|
40
|
+
themeColor && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", { name: "theme-color", content: themeColor }),
|
|
41
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router.Meta, {}),
|
|
42
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router.Links, {})
|
|
43
|
+
] }),
|
|
44
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("body", { children: [
|
|
45
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("noscript", { children: "\u8BF7\u5141\u8BB8 JavaScript \u8FD0\u884C\u3002" }),
|
|
46
|
+
children,
|
|
47
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router.ScrollRestoration, {}),
|
|
48
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router.Scripts, {})
|
|
49
|
+
] })
|
|
50
|
+
] });
|
|
51
|
+
}
|
|
52
|
+
function PageError({ view }) {
|
|
53
|
+
const error = (0, import_react_router.useRouteError)();
|
|
54
|
+
return view ? (0, import_react.createElement)(view, { error }) : (0, import_react.createElement)(import_errors.DefaultErrorBoundary);
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
Document,
|
|
59
|
+
PageError,
|
|
60
|
+
PageLoading
|
|
61
|
+
});
|
package/dist/root.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/root.tsx
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { Links, Meta, Scripts, ScrollRestoration, useRouteError } from "react-router";
|
|
4
|
+
import { DefaultErrorBoundary } from "@xfe-repo/web-router/errors";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function PageLoading() {
|
|
7
|
+
return /* @__PURE__ */ jsx("main", { role: "status", "aria-live": "polite", children: "\u6B63\u5728\u52A0\u8F7D\u9875\u9762\u2026" });
|
|
8
|
+
}
|
|
9
|
+
function Document({ children, lang = "zh-CN", themeColor }) {
|
|
10
|
+
return /* @__PURE__ */ jsxs("html", { lang, children: [
|
|
11
|
+
/* @__PURE__ */ jsxs("head", { children: [
|
|
12
|
+
/* @__PURE__ */ jsx("meta", { charSet: "utf-8" }),
|
|
13
|
+
/* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
|
|
14
|
+
themeColor && /* @__PURE__ */ jsx("meta", { name: "theme-color", content: themeColor }),
|
|
15
|
+
/* @__PURE__ */ jsx(Meta, {}),
|
|
16
|
+
/* @__PURE__ */ jsx(Links, {})
|
|
17
|
+
] }),
|
|
18
|
+
/* @__PURE__ */ jsxs("body", { children: [
|
|
19
|
+
/* @__PURE__ */ jsx("noscript", { children: "\u8BF7\u5141\u8BB8 JavaScript \u8FD0\u884C\u3002" }),
|
|
20
|
+
children,
|
|
21
|
+
/* @__PURE__ */ jsx(ScrollRestoration, {}),
|
|
22
|
+
/* @__PURE__ */ jsx(Scripts, {})
|
|
23
|
+
] })
|
|
24
|
+
] });
|
|
25
|
+
}
|
|
26
|
+
function PageError({ view }) {
|
|
27
|
+
const error = useRouteError();
|
|
28
|
+
return view ? createElement(view, { error }) : createElement(DefaultErrorBoundary);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
Document,
|
|
32
|
+
PageError,
|
|
33
|
+
PageLoading
|
|
34
|
+
};
|
package/dist/serve.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
|
|
3
|
+
declare const serveClient: ({ directory, host, port, basename, }: {
|
|
4
|
+
directory: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
basename?: string;
|
|
8
|
+
}) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
9
|
+
|
|
10
|
+
export { serveClient };
|
package/dist/serve.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
|
|
3
|
+
declare const serveClient: ({ directory, host, port, basename, }: {
|
|
4
|
+
directory: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
basename?: string;
|
|
8
|
+
}) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
9
|
+
|
|
10
|
+
export { serveClient };
|