arcanajs 2.1.0 → 2.1.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/package.json +2 -2
- package/framework/cli/index.d.ts +0 -1
- package/framework/cli/index.js +0 -107
- package/framework/cli/webpack.config.d.ts +0 -3
- package/framework/cli/webpack.config.js +0 -198
- package/framework/lib/client/index.d.ts +0 -2
- package/framework/lib/client/index.js +0 -40
- package/framework/lib/index.d.ts +0 -17
- package/framework/lib/index.js +0 -33
- package/framework/lib/server/ArcanaJSMiddleware.d.ts +0 -16
- package/framework/lib/server/ArcanaJSMiddleware.js +0 -99
- package/framework/lib/server/ArcanaJSServer.d.ts +0 -21
- package/framework/lib/server/ArcanaJSServer.js +0 -140
- package/framework/lib/server/ControllerBinder.d.ts +0 -4
- package/framework/lib/server/ControllerBinder.js +0 -32
- package/framework/lib/server/CsrfMiddleware.d.ts +0 -2
- package/framework/lib/server/CsrfMiddleware.js +0 -34
- package/framework/lib/server/DynamicRouter.d.ts +0 -2
- package/framework/lib/server/DynamicRouter.js +0 -50
- package/framework/lib/server/ResponseHandlerMiddleware.d.ts +0 -27
- package/framework/lib/server/ResponseHandlerMiddleware.js +0 -30
- package/framework/lib/server/Router.d.ts +0 -94
- package/framework/lib/server/Router.js +0 -203
- package/framework/lib/server.d.ts +0 -6
- package/framework/lib/server.js +0 -28
- package/framework/lib/shared/ArcanaJSApp.d.ts +0 -11
- package/framework/lib/shared/ArcanaJSApp.js +0 -79
- package/framework/lib/shared/components/Body.d.ts +0 -6
- package/framework/lib/shared/components/Body.js +0 -11
- package/framework/lib/shared/components/Head.d.ts +0 -4
- package/framework/lib/shared/components/Head.js +0 -125
- package/framework/lib/shared/components/Link.d.ts +0 -6
- package/framework/lib/shared/components/Link.js +0 -17
- package/framework/lib/shared/components/NavLink.d.ts +0 -8
- package/framework/lib/shared/components/NavLink.js +0 -16
- package/framework/lib/shared/components/Page.d.ts +0 -6
- package/framework/lib/shared/components/Page.js +0 -16
- package/framework/lib/shared/context/HeadContext.d.ts +0 -6
- package/framework/lib/shared/context/HeadContext.js +0 -5
- package/framework/lib/shared/context/PageContext.d.ts +0 -1
- package/framework/lib/shared/context/PageContext.js +0 -5
- package/framework/lib/shared/context/RouterContext.d.ts +0 -13
- package/framework/lib/shared/context/RouterContext.js +0 -13
- package/framework/lib/shared/core/ArcanaJSApp.d.ts +0 -13
- package/framework/lib/shared/core/ArcanaJSApp.js +0 -98
- package/framework/lib/shared/hooks/useDynamicComponents.d.ts +0 -1
- package/framework/lib/shared/hooks/useDynamicComponents.js +0 -20
- package/framework/lib/shared/hooks/useHead.d.ts +0 -1
- package/framework/lib/shared/hooks/useHead.js +0 -7
- package/framework/lib/shared/hooks/useLocation.d.ts +0 -5
- package/framework/lib/shared/hooks/useLocation.js +0 -13
- package/framework/lib/shared/hooks/usePage.d.ts +0 -1
- package/framework/lib/shared/hooks/usePage.js +0 -7
- package/framework/lib/shared/hooks/useParams.d.ts +0 -1
- package/framework/lib/shared/hooks/useParams.js +0 -13
- package/framework/lib/shared/hooks/useQuery.d.ts +0 -1
- package/framework/lib/shared/hooks/useQuery.js +0 -9
- package/framework/lib/shared/hooks/useRouter.d.ts +0 -1
- package/framework/lib/shared/hooks/useRouter.js +0 -13
- package/framework/lib/shared/utils/createSingletonContext.d.ts +0 -11
- package/framework/lib/shared/utils/createSingletonContext.js +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arcanajs",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "ArcanaJS Framework",
|
|
5
5
|
"main": "framework/lib/index.js",
|
|
6
6
|
"types": "framework/lib/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"bin"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build:lib": "tsc -p tsconfig.lib.json",
|
|
19
|
+
"build:lib": "tsc -p tsconfig.lib.json && cp src/lib/server/default-index.html framework/lib/server/",
|
|
20
20
|
"build": "node bin/arcanajs.js build",
|
|
21
21
|
"dev": "node bin/arcanajs.js dev",
|
|
22
22
|
"start": "node bin/arcanajs.js start",
|
package/framework/cli/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/framework/cli/index.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const child_process_1 = require("child_process");
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const webpack_1 = __importDefault(require("webpack"));
|
|
9
|
-
const webpack_config_1 = require("./webpack.config");
|
|
10
|
-
const args = process.argv.slice(2);
|
|
11
|
-
const command = args[0];
|
|
12
|
-
if (!command) {
|
|
13
|
-
console.error("Please specify a command: dev, build, start");
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
const runCompiler = (compiler) => {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
compiler.run((err, stats) => {
|
|
19
|
-
if (err) {
|
|
20
|
-
console.error(err);
|
|
21
|
-
return reject(err);
|
|
22
|
-
}
|
|
23
|
-
if (stats && stats.hasErrors()) {
|
|
24
|
-
console.error(stats.toString({ colors: true }));
|
|
25
|
-
return reject(new Error("Webpack build failed"));
|
|
26
|
-
}
|
|
27
|
-
console.log(stats?.toString({ colors: true }));
|
|
28
|
-
resolve();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
let serverProcess = null;
|
|
33
|
-
const startDevServer = () => {
|
|
34
|
-
if (serverProcess) {
|
|
35
|
-
serverProcess.kill();
|
|
36
|
-
}
|
|
37
|
-
const serverPath = path_1.default.resolve(process.cwd(), "dist/server.js");
|
|
38
|
-
serverProcess = (0, child_process_1.spawn)("node", [serverPath], { stdio: "inherit" });
|
|
39
|
-
serverProcess.on("close", (code) => {
|
|
40
|
-
if (code !== 0 && code !== null) {
|
|
41
|
-
console.error(`Dev server exited with code ${code}`);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const watchCompiler = (compiler, onBuildComplete) => {
|
|
46
|
-
compiler.watch({}, (err, stats) => {
|
|
47
|
-
if (err) {
|
|
48
|
-
console.error(err);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
console.log(stats?.toString({ colors: true }));
|
|
52
|
-
if (stats && !stats.hasErrors() && onBuildComplete) {
|
|
53
|
-
onBuildComplete();
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
const build = async () => {
|
|
58
|
-
process.env.NODE_ENV = "production";
|
|
59
|
-
console.log("Building for production...");
|
|
60
|
-
const clientConfig = (0, webpack_config_1.createClientConfig)();
|
|
61
|
-
const serverConfig = (0, webpack_config_1.createServerConfig)();
|
|
62
|
-
try {
|
|
63
|
-
await runCompiler((0, webpack_1.default)(clientConfig));
|
|
64
|
-
await runCompiler((0, webpack_1.default)(serverConfig));
|
|
65
|
-
console.log("Build complete.");
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.error("Build failed:", error);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const dev = async () => {
|
|
73
|
-
process.env.NODE_ENV = "development";
|
|
74
|
-
console.log("Starting development server...");
|
|
75
|
-
const clientConfig = (0, webpack_config_1.createClientConfig)();
|
|
76
|
-
const serverConfig = (0, webpack_config_1.createServerConfig)();
|
|
77
|
-
// Watch client
|
|
78
|
-
watchCompiler((0, webpack_1.default)(clientConfig));
|
|
79
|
-
// Watch server and restart on build
|
|
80
|
-
watchCompiler((0, webpack_1.default)(serverConfig), () => {
|
|
81
|
-
console.log("Server build complete. Restarting server...");
|
|
82
|
-
startDevServer();
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
const start = () => {
|
|
86
|
-
process.env.NODE_ENV = "production";
|
|
87
|
-
const serverPath = path_1.default.resolve(process.cwd(), "dist/server.js");
|
|
88
|
-
console.log(`Starting server at ${serverPath}...`);
|
|
89
|
-
const child = (0, child_process_1.spawn)("node", [serverPath], { stdio: "inherit" });
|
|
90
|
-
child.on("close", (code) => {
|
|
91
|
-
process.exit(code || 0);
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
switch (command) {
|
|
95
|
-
case "build":
|
|
96
|
-
build();
|
|
97
|
-
break;
|
|
98
|
-
case "dev":
|
|
99
|
-
dev();
|
|
100
|
-
break;
|
|
101
|
-
case "start":
|
|
102
|
-
start();
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
console.error(`Unknown command: ${command}`);
|
|
106
|
-
process.exit(1);
|
|
107
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createServerConfig = exports.createClientConfig = void 0;
|
|
7
|
-
const clean_webpack_plugin_1 = require("clean-webpack-plugin");
|
|
8
|
-
const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
|
|
9
|
-
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const webpack_node_externals_1 = __importDefault(require("webpack-node-externals"));
|
|
12
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
13
|
-
const cwd = process.cwd();
|
|
14
|
-
// Helper to resolve loaders from the framework's node_modules
|
|
15
|
-
const resolveLoader = (loader) => require.resolve(loader);
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
// Helper to find entry file with supported extensions
|
|
18
|
-
const findEntry = (searchPaths) => {
|
|
19
|
-
const extensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
20
|
-
for (const basePath of searchPaths) {
|
|
21
|
-
for (const ext of extensions) {
|
|
22
|
-
const fullPath = path_1.default.resolve(cwd, basePath + ext);
|
|
23
|
-
if (fs_1.default.existsSync(fullPath)) {
|
|
24
|
-
return fullPath;
|
|
25
|
-
}
|
|
26
|
-
// Also check for index files in directories
|
|
27
|
-
const indexPath = path_1.default.resolve(cwd, basePath, "index" + ext);
|
|
28
|
-
if (fs_1.default.existsSync(indexPath)) {
|
|
29
|
-
return indexPath;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Fallback to example if not found (for internal framework dev) or throw error
|
|
34
|
-
// For now, we'll try the example paths as a last resort before failing
|
|
35
|
-
const exampleClient = path_1.default.resolve(cwd, "src/example/client/index.tsx");
|
|
36
|
-
const exampleServer = path_1.default.resolve(cwd, "src/example/server/index.ts");
|
|
37
|
-
if (searchPaths.some((p) => p.includes("client")) &&
|
|
38
|
-
fs_1.default.existsSync(exampleClient))
|
|
39
|
-
return exampleClient;
|
|
40
|
-
if (searchPaths.some((p) => p.includes("server")) &&
|
|
41
|
-
fs_1.default.existsSync(exampleServer))
|
|
42
|
-
return exampleServer;
|
|
43
|
-
throw new Error(`Could not find entry point. Searched in: ${searchPaths.join(", ")}`);
|
|
44
|
-
};
|
|
45
|
-
const createClientConfig = () => {
|
|
46
|
-
const clientEntry = findEntry([
|
|
47
|
-
"src/client",
|
|
48
|
-
"src/client/index",
|
|
49
|
-
"src/index",
|
|
50
|
-
"src/main",
|
|
51
|
-
]);
|
|
52
|
-
return {
|
|
53
|
-
mode: isProduction ? "production" : "development",
|
|
54
|
-
target: "web",
|
|
55
|
-
entry: {
|
|
56
|
-
client: clientEntry,
|
|
57
|
-
},
|
|
58
|
-
output: {
|
|
59
|
-
path: path_1.default.resolve(cwd, "dist/public"),
|
|
60
|
-
filename: isProduction
|
|
61
|
-
? "[name].[contenthash].bundle.js"
|
|
62
|
-
: "[name].bundle.js",
|
|
63
|
-
publicPath: "/",
|
|
64
|
-
assetModuleFilename: "assets/[hash][ext][query]",
|
|
65
|
-
},
|
|
66
|
-
resolve: {
|
|
67
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
68
|
-
},
|
|
69
|
-
resolveLoader: {
|
|
70
|
-
modules: ["node_modules", path_1.default.resolve(__dirname, "../../node_modules")],
|
|
71
|
-
},
|
|
72
|
-
module: {
|
|
73
|
-
rules: [
|
|
74
|
-
{
|
|
75
|
-
test: /\.(ts|tsx|js|jsx)$/,
|
|
76
|
-
exclude: /node_modules/,
|
|
77
|
-
use: {
|
|
78
|
-
loader: resolveLoader("babel-loader"),
|
|
79
|
-
options: {
|
|
80
|
-
presets: [
|
|
81
|
-
resolveLoader("@babel/preset-env"),
|
|
82
|
-
resolveLoader("@babel/preset-react"),
|
|
83
|
-
resolveLoader("@babel/preset-typescript"),
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
test: /\.css$/,
|
|
90
|
-
use: [
|
|
91
|
-
isProduction
|
|
92
|
-
? mini_css_extract_plugin_1.default.loader
|
|
93
|
-
: resolveLoader("style-loader"),
|
|
94
|
-
resolveLoader("css-loader"),
|
|
95
|
-
resolveLoader("postcss-loader"),
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|eot|ttf|otf)$/i,
|
|
100
|
-
type: "asset/resource",
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
plugins: [
|
|
105
|
-
new clean_webpack_plugin_1.CleanWebpackPlugin(),
|
|
106
|
-
new html_webpack_plugin_1.default({
|
|
107
|
-
template: path_1.default.resolve(cwd, "src/lib/server/default-index.html"),
|
|
108
|
-
filename: "index.html",
|
|
109
|
-
inject: "body",
|
|
110
|
-
minify: isProduction
|
|
111
|
-
? {
|
|
112
|
-
removeComments: false,
|
|
113
|
-
collapseWhitespace: true,
|
|
114
|
-
removeRedundantAttributes: true,
|
|
115
|
-
useShortDoctype: true,
|
|
116
|
-
removeEmptyAttributes: true,
|
|
117
|
-
removeStyleLinkTypeAttributes: true,
|
|
118
|
-
keepClosingSlash: true,
|
|
119
|
-
minifyJS: true,
|
|
120
|
-
minifyCSS: true,
|
|
121
|
-
minifyURLs: true,
|
|
122
|
-
}
|
|
123
|
-
: false,
|
|
124
|
-
}),
|
|
125
|
-
new mini_css_extract_plugin_1.default({
|
|
126
|
-
filename: isProduction ? "[name].[contenthash].css" : "[name].css",
|
|
127
|
-
}),
|
|
128
|
-
],
|
|
129
|
-
optimization: {
|
|
130
|
-
splitChunks: {
|
|
131
|
-
chunks: "all",
|
|
132
|
-
cacheGroups: {
|
|
133
|
-
vendor: {
|
|
134
|
-
test: /[\\/]node_modules[\\/]/,
|
|
135
|
-
name: "vendors",
|
|
136
|
-
chunks: "all",
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
devtool: isProduction ? "source-map" : "eval-source-map",
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
exports.createClientConfig = createClientConfig;
|
|
145
|
-
const createServerConfig = () => {
|
|
146
|
-
const serverEntry = findEntry([
|
|
147
|
-
"src/server",
|
|
148
|
-
"src/server/index",
|
|
149
|
-
"src/server/main",
|
|
150
|
-
]);
|
|
151
|
-
return {
|
|
152
|
-
mode: isProduction ? "production" : "development",
|
|
153
|
-
target: "node",
|
|
154
|
-
entry: serverEntry,
|
|
155
|
-
output: {
|
|
156
|
-
path: path_1.default.resolve(cwd, "dist"),
|
|
157
|
-
filename: "server.js",
|
|
158
|
-
},
|
|
159
|
-
externals: [(0, webpack_node_externals_1.default)()],
|
|
160
|
-
resolve: {
|
|
161
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
162
|
-
},
|
|
163
|
-
resolveLoader: {
|
|
164
|
-
modules: ["node_modules", path_1.default.resolve(__dirname, "../../node_modules")],
|
|
165
|
-
},
|
|
166
|
-
module: {
|
|
167
|
-
rules: [
|
|
168
|
-
{
|
|
169
|
-
test: /\.(ts|tsx|js|jsx)$/,
|
|
170
|
-
exclude: /node_modules/,
|
|
171
|
-
use: {
|
|
172
|
-
loader: resolveLoader("babel-loader"),
|
|
173
|
-
options: {
|
|
174
|
-
presets: [
|
|
175
|
-
resolveLoader("@babel/preset-env"),
|
|
176
|
-
resolveLoader("@babel/preset-react"),
|
|
177
|
-
resolveLoader("@babel/preset-typescript"),
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
test: /\.css$/,
|
|
184
|
-
use: resolveLoader("null-loader"), // Ignore CSS on server side
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|eot|ttf|otf)$/i,
|
|
188
|
-
type: "asset/resource",
|
|
189
|
-
generator: {
|
|
190
|
-
emit: false,
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
},
|
|
195
|
-
devtool: isProduction ? "source-map" : "eval-source-map",
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
exports.createServerConfig = createServerConfig;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.hydrateArcanaJS = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const client_1 = require("react-dom/client");
|
|
9
|
-
const HeadContext_1 = require("../shared/context/HeadContext");
|
|
10
|
-
const ArcanaJSApp_1 = require("../shared/core/ArcanaJSApp");
|
|
11
|
-
const hydrateArcanaJS = (viewsOrContext, layout) => {
|
|
12
|
-
let views = {};
|
|
13
|
-
if (viewsOrContext.keys && typeof viewsOrContext.keys === "function") {
|
|
14
|
-
viewsOrContext.keys().forEach((key) => {
|
|
15
|
-
const viewName = key.replace(/^\.\/(.*)\.tsx$/, "$1");
|
|
16
|
-
views[viewName] = viewsOrContext(key).default;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
views = viewsOrContext;
|
|
21
|
-
}
|
|
22
|
-
const container = document.getElementById("root");
|
|
23
|
-
const dataScript = document.getElementById("__ArcanaJS_DATA__");
|
|
24
|
-
// Client-side HeadManager (noop for push, as Head handles client updates via useEffect)
|
|
25
|
-
const headManager = {
|
|
26
|
-
tags: [],
|
|
27
|
-
push: () => { },
|
|
28
|
-
};
|
|
29
|
-
if (container && dataScript) {
|
|
30
|
-
try {
|
|
31
|
-
const { page, data, params, csrfToken } = JSON.parse(dataScript.textContent || "{}");
|
|
32
|
-
(0, client_1.hydrateRoot)(container, react_1.default.createElement(HeadContext_1.HeadContext.Provider, { value: headManager },
|
|
33
|
-
react_1.default.createElement(ArcanaJSApp_1.ArcanaJSApp, { initialPage: page, initialData: data, initialParams: params, csrfToken: csrfToken, views: views, layout: layout })));
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
console.error("Failed to parse initial data", e);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
exports.hydrateArcanaJS = hydrateArcanaJS;
|
package/framework/lib/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from "./client";
|
|
2
|
-
export * from "./shared/components/Body";
|
|
3
|
-
export * from "./shared/components/Head";
|
|
4
|
-
export * from "./shared/components/Link";
|
|
5
|
-
export * from "./shared/components/NavLink";
|
|
6
|
-
export * from "./shared/components/Page";
|
|
7
|
-
export * from "./shared/context/HeadContext";
|
|
8
|
-
export * from "./shared/context/PageContext";
|
|
9
|
-
export * from "./shared/context/RouterContext";
|
|
10
|
-
export * from "./shared/core/ArcanaJSApp";
|
|
11
|
-
export * from "./shared/hooks/useDynamicComponents";
|
|
12
|
-
export * from "./shared/hooks/useHead";
|
|
13
|
-
export * from "./shared/hooks/useLocation";
|
|
14
|
-
export * from "./shared/hooks/usePage";
|
|
15
|
-
export * from "./shared/hooks/useParams";
|
|
16
|
-
export * from "./shared/hooks/useQuery";
|
|
17
|
-
export * from "./shared/hooks/useRouter";
|
package/framework/lib/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./client"), exports);
|
|
18
|
-
__exportStar(require("./shared/components/Body"), exports);
|
|
19
|
-
__exportStar(require("./shared/components/Head"), exports);
|
|
20
|
-
__exportStar(require("./shared/components/Link"), exports);
|
|
21
|
-
__exportStar(require("./shared/components/NavLink"), exports);
|
|
22
|
-
__exportStar(require("./shared/components/Page"), exports);
|
|
23
|
-
__exportStar(require("./shared/context/HeadContext"), exports);
|
|
24
|
-
__exportStar(require("./shared/context/PageContext"), exports);
|
|
25
|
-
__exportStar(require("./shared/context/RouterContext"), exports);
|
|
26
|
-
__exportStar(require("./shared/core/ArcanaJSApp"), exports);
|
|
27
|
-
__exportStar(require("./shared/hooks/useDynamicComponents"), exports);
|
|
28
|
-
__exportStar(require("./shared/hooks/useHead"), exports);
|
|
29
|
-
__exportStar(require("./shared/hooks/useLocation"), exports);
|
|
30
|
-
__exportStar(require("./shared/hooks/usePage"), exports);
|
|
31
|
-
__exportStar(require("./shared/hooks/useParams"), exports);
|
|
32
|
-
__exportStar(require("./shared/hooks/useQuery"), exports);
|
|
33
|
-
__exportStar(require("./shared/hooks/useRouter"), exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
import React from "react";
|
|
3
|
-
declare global {
|
|
4
|
-
namespace Express {
|
|
5
|
-
interface Response {
|
|
6
|
-
renderPage(page: string, data?: any, params?: Record<string, string>): void;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
interface ArcanaJSOptions {
|
|
11
|
-
views: Record<string, React.FC<any>>;
|
|
12
|
-
indexFile?: string;
|
|
13
|
-
layout?: React.FC<any>;
|
|
14
|
-
}
|
|
15
|
-
export declare const createArcanaJSMiddleware: (options: ArcanaJSOptions) => (req: Request, res: Response, next: NextFunction) => void;
|
|
16
|
-
export {};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createArcanaJSMiddleware = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const server_1 = require("react-dom/server");
|
|
10
|
-
const HeadContext_1 = require("../shared/context/HeadContext");
|
|
11
|
-
const ArcanaJSApp_1 = require("../shared/core/ArcanaJSApp");
|
|
12
|
-
const DEFAULT_HTML_TEMPLATE = `<!DOCTYPE html>
|
|
13
|
-
<html lang="en">
|
|
14
|
-
<head>
|
|
15
|
-
<meta charset="UTF-8" />
|
|
16
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
17
|
-
<!--HEAD_CONTENT-->
|
|
18
|
-
</head>
|
|
19
|
-
<body>
|
|
20
|
-
<div id="root"><!--APP_CONTENT--></div>
|
|
21
|
-
<!--ARCANAJS_DATA_SCRIPT-->
|
|
22
|
-
</body>
|
|
23
|
-
</html>`;
|
|
24
|
-
// Helper to prevent XSS in initial data
|
|
25
|
-
const safeStringify = (obj) => {
|
|
26
|
-
return JSON.stringify(obj).replace(/</g, "\\u003c");
|
|
27
|
-
};
|
|
28
|
-
const createArcanaJSMiddleware = (options) => {
|
|
29
|
-
const { views, indexFile, layout } = options;
|
|
30
|
-
let cachedIndexHtml = null;
|
|
31
|
-
const getIndexHtml = (callback) => {
|
|
32
|
-
if (process.env.NODE_ENV === "production" && cachedIndexHtml) {
|
|
33
|
-
return callback(null, cachedIndexHtml);
|
|
34
|
-
}
|
|
35
|
-
if (indexFile && fs_1.default.existsSync(indexFile)) {
|
|
36
|
-
fs_1.default.readFile(indexFile, "utf8", (err, htmlData) => {
|
|
37
|
-
if (!err && process.env.NODE_ENV === "production") {
|
|
38
|
-
cachedIndexHtml = htmlData;
|
|
39
|
-
}
|
|
40
|
-
callback(err, htmlData);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
if (process.env.NODE_ENV === "production") {
|
|
45
|
-
cachedIndexHtml = DEFAULT_HTML_TEMPLATE;
|
|
46
|
-
}
|
|
47
|
-
callback(null, DEFAULT_HTML_TEMPLATE);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return (req, res, next) => {
|
|
51
|
-
res.renderPage = (page, data = {}, params = {}) => {
|
|
52
|
-
const csrfToken = res.locals.csrfToken;
|
|
53
|
-
if (req.headers["x-arcanajs-request"] || req.query.format === "json") {
|
|
54
|
-
return res.json({ page, data, params, csrfToken });
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const headTags = [];
|
|
58
|
-
const headManager = {
|
|
59
|
-
tags: headTags,
|
|
60
|
-
push: (nodes) => headTags.push(nodes),
|
|
61
|
-
};
|
|
62
|
-
const appHtml = (0, server_1.renderToString)(react_1.default.createElement(HeadContext_1.HeadContext.Provider, { value: headManager }, react_1.default.createElement(ArcanaJSApp_1.ArcanaJSApp, {
|
|
63
|
-
initialPage: page,
|
|
64
|
-
initialData: data,
|
|
65
|
-
initialParams: params,
|
|
66
|
-
initialUrl: req.path,
|
|
67
|
-
csrfToken: csrfToken,
|
|
68
|
-
views: views,
|
|
69
|
-
layout: layout,
|
|
70
|
-
})));
|
|
71
|
-
const headHtml = (0, server_1.renderToString)(react_1.default.createElement(react_1.default.Fragment, null, ...headTags));
|
|
72
|
-
getIndexHtml((err, htmlData) => {
|
|
73
|
-
if (err) {
|
|
74
|
-
console.error("Error reading index.html", err);
|
|
75
|
-
return res.status(500).send("Server Error");
|
|
76
|
-
}
|
|
77
|
-
const scriptContent = safeStringify({
|
|
78
|
-
page,
|
|
79
|
-
data,
|
|
80
|
-
params,
|
|
81
|
-
csrfToken,
|
|
82
|
-
});
|
|
83
|
-
const scriptTag = `<script id="__ArcanaJS_DATA__" type="application/json">${scriptContent}</script>`;
|
|
84
|
-
const html = htmlData
|
|
85
|
-
.replace("<!--HEAD_CONTENT-->", headHtml)
|
|
86
|
-
.replace("<!--APP_CONTENT-->", appHtml)
|
|
87
|
-
.replace("<!--ARCANAJS_DATA_SCRIPT-->", scriptTag);
|
|
88
|
-
res.send(html);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
console.error("SSR Error:", error);
|
|
93
|
-
res.status(500).send("Internal Server Error");
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
next();
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
exports.createArcanaJSMiddleware = createArcanaJSMiddleware;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Express, RequestHandler } from "express";
|
|
2
|
-
import React from "react";
|
|
3
|
-
export interface ArcanaJSConfig {
|
|
4
|
-
port?: number | string;
|
|
5
|
-
views?: Record<string, React.FC<any>>;
|
|
6
|
-
viewsDir?: string;
|
|
7
|
-
viewsContext?: any;
|
|
8
|
-
routes?: RequestHandler | RequestHandler[];
|
|
9
|
-
staticDir?: string;
|
|
10
|
-
distDir?: string;
|
|
11
|
-
indexFile?: string;
|
|
12
|
-
layout?: React.FC<any>;
|
|
13
|
-
}
|
|
14
|
-
export declare class ArcanaJSServer {
|
|
15
|
-
app: Express;
|
|
16
|
-
private config;
|
|
17
|
-
constructor(config: ArcanaJSConfig);
|
|
18
|
-
private initialize;
|
|
19
|
-
private discoverViews;
|
|
20
|
-
start(): void;
|
|
21
|
-
}
|