arcanajs 2.5.4 → 3.0.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/README.md +7 -22
- package/bin/arcanajs.js +1 -1
- package/dist/arcanajs.js +2 -0
- package/dist/arcanajs.js.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -0
- package/{framework → dist}/lib/client/index.d.ts +6 -26
- package/{framework → dist}/lib/global.d.ts +6 -10
- package/dist/lib/index.d.ts +38 -0
- package/{framework → dist}/lib/server/ArcanaJSServer.d.ts +4 -4
- package/dist/lib/server/DefaultTemplate.d.ts +1 -0
- package/{framework → dist}/lib/shared/components/Body.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/Head.d.ts +2 -1
- package/{framework → dist}/lib/shared/components/Link.d.ts +2 -2
- package/{framework → dist}/lib/shared/components/NavLink.d.ts +2 -2
- package/dist/lib/shared/components/Page.d.ts +7 -0
- package/{framework → dist}/lib/shared/context/RouterContext.d.ts +1 -0
- package/dist/lib/shared/core/ArcanaJSApp.d.ts +20 -0
- package/{framework → dist}/lib/shared/hooks/useLocation.d.ts +2 -1
- package/dist/lib/shared/hooks/usePage.d.ts +2 -0
- package/dist/lib/shared/hooks/useParams.d.ts +2 -0
- package/dist/lib/shared/hooks/useQuery.d.ts +2 -0
- package/dist/lib/shared/hooks/useRouter.d.ts +2 -0
- package/package.json +16 -26
- package/framework/cli/index.js +0 -204
- package/framework/cli/templates.d.ts +0 -6
- package/framework/cli/templates.js +0 -60
- package/framework/cli/webpack.config.js +0 -310
- package/framework/lib/client/index.js +0 -97
- package/framework/lib/config/index.d.ts +0 -46
- package/framework/lib/config/index.js +0 -115
- package/framework/lib/index.d.ts +0 -19
- package/framework/lib/index.js +0 -59
- package/framework/lib/server/ArcanaJSMiddleware.js +0 -114
- package/framework/lib/server/ArcanaJSServer.js +0 -441
- package/framework/lib/server/ControllerBinder.js +0 -32
- package/framework/lib/server/CsrfMiddleware.js +0 -34
- package/framework/lib/server/DynamicRouter.js +0 -50
- package/framework/lib/server/ResponseHandlerMiddleware.js +0 -30
- package/framework/lib/server/Router.js +0 -203
- package/framework/lib/server/default-index.html +0 -12
- package/framework/lib/server.d.ts +0 -33
- package/framework/lib/server.js +0 -69
- package/framework/lib/shared/components/Body.js +0 -8
- package/framework/lib/shared/components/Head.js +0 -125
- package/framework/lib/shared/components/Link.js +0 -27
- package/framework/lib/shared/components/NavLink.js +0 -13
- package/framework/lib/shared/components/Page.d.ts +0 -6
- package/framework/lib/shared/components/Page.js +0 -10
- package/framework/lib/shared/context/HeadContext.js +0 -5
- package/framework/lib/shared/context/PageContext.js +0 -5
- package/framework/lib/shared/context/RouterContext.js +0 -10
- package/framework/lib/shared/core/ArcanaJSApp.d.ts +0 -14
- package/framework/lib/shared/core/ArcanaJSApp.js +0 -153
- package/framework/lib/shared/hooks/useHead.js +0 -7
- 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.js +0 -21
- package/framework/lib/shared/views/ErrorPage.js +0 -12
- package/framework/lib/shared/views/NotFoundPage.js +0 -11
- package/framework/lib/types.d.ts +0 -174
- package/framework/lib/types.js +0 -8
- package/framework/templates/arcanajs.config.ts +0 -44
- package/framework/templates/package.json +0 -15
- package/framework/templates/postcss.config.js +0 -6
- package/framework/templates/public/arcanajs.png +0 -0
- package/framework/templates/public/arcanajs.svg +0 -12
- package/framework/templates/public/favicon.ico +0 -0
- package/framework/templates/src/arcanajs.d.ts +0 -8
- package/framework/templates/src/client/globals.css +0 -199
- package/framework/templates/src/client/index.tsx +0 -7
- package/framework/templates/src/db/mongo.ts +0 -10
- package/framework/templates/src/db/mongoose.ts +0 -12
- package/framework/templates/src/db/mysql.ts +0 -15
- package/framework/templates/src/db/postgres.ts +0 -8
- package/framework/templates/src/server/controllers/HomeController.ts +0 -7
- package/framework/templates/src/server/controllers/UsersController.ts +0 -37
- package/framework/templates/src/server/index.ts +0 -38
- package/framework/templates/src/server/routes/api.ts +0 -6
- package/framework/templates/src/server/routes/web.ts +0 -7
- package/framework/templates/src/views/ErrorPage.tsx +0 -136
- package/framework/templates/src/views/HomePage.tsx +0 -344
- package/framework/templates/src/views/NotFoundPage.tsx +0 -108
- package/framework/templates/tsconfig.json +0 -27
- /package/{framework → dist}/cli/index.d.ts +0 -0
- /package/{framework → dist}/cli/webpack.config.d.ts +0 -0
- /package/{framework → dist}/lib/server/ArcanaJSMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/ControllerBinder.d.ts +0 -0
- /package/{framework → dist}/lib/server/CsrfMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/DynamicRouter.d.ts +0 -0
- /package/{framework → dist}/lib/server/ResponseHandlerMiddleware.d.ts +0 -0
- /package/{framework → dist}/lib/server/Router.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/HeadContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/context/PageContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/hooks/useHead.d.ts +0 -0
- /package/{framework → dist}/lib/shared/utils/createSingletonContext.d.ts +0 -0
- /package/{framework → dist}/lib/shared/views/ErrorPage.d.ts +0 -0
- /package/{framework → dist}/lib/shared/views/NotFoundPage.d.ts +0 -0
|
@@ -1,310 +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 cwd = process.cwd();
|
|
13
|
-
// Helper to resolve loaders from the framework's node_modules
|
|
14
|
-
const resolveLoader = (loader) => require.resolve(loader);
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
// Helper to find entry file with supported extensions
|
|
17
|
-
const findEntry = (searchPaths) => {
|
|
18
|
-
const extensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
19
|
-
for (const basePath of searchPaths) {
|
|
20
|
-
for (const ext of extensions) {
|
|
21
|
-
const fullPath = path_1.default.resolve(cwd, basePath + ext);
|
|
22
|
-
if (fs_1.default.existsSync(fullPath)) {
|
|
23
|
-
return fullPath;
|
|
24
|
-
}
|
|
25
|
-
// Also check for index files in directories
|
|
26
|
-
const indexPath = path_1.default.resolve(cwd, basePath, "index" + ext);
|
|
27
|
-
if (fs_1.default.existsSync(indexPath)) {
|
|
28
|
-
return indexPath;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// Fallback to example if not found (for internal framework dev) or throw error
|
|
33
|
-
// For now, we'll try the example paths as a last resort before failing
|
|
34
|
-
const exampleClient = path_1.default.resolve(cwd, "src/example/client/index.tsx");
|
|
35
|
-
const exampleServer = path_1.default.resolve(cwd, "src/example/server/index.ts");
|
|
36
|
-
if (searchPaths.some((p) => p.includes("client")) &&
|
|
37
|
-
fs_1.default.existsSync(exampleClient))
|
|
38
|
-
return exampleClient;
|
|
39
|
-
if (searchPaths.some((p) => p.includes("server")) &&
|
|
40
|
-
fs_1.default.existsSync(exampleServer))
|
|
41
|
-
return exampleServer;
|
|
42
|
-
throw new Error(`Could not find entry point. Searched in: ${searchPaths.join(", ")}`);
|
|
43
|
-
};
|
|
44
|
-
const getViewsLoaderPath = () => {
|
|
45
|
-
const viewsDir = path_1.default.resolve(cwd, "src/views");
|
|
46
|
-
const hasViews = fs_1.default.existsSync(viewsDir);
|
|
47
|
-
const viewsLoaderPath = path_1.default.resolve(__dirname, "../../node_modules/.cache/arcanajs/views-loader.js");
|
|
48
|
-
// Ensure cache directory exists
|
|
49
|
-
const cacheDir = path_1.default.dirname(viewsLoaderPath);
|
|
50
|
-
if (!fs_1.default.existsSync(cacheDir)) {
|
|
51
|
-
fs_1.default.mkdirSync(cacheDir, { recursive: true });
|
|
52
|
-
}
|
|
53
|
-
// Generate the loader file
|
|
54
|
-
const loaderContent = hasViews
|
|
55
|
-
? `module.exports = require.context('${viewsDir}', true, /\\.(tsx|jsx)$/);`
|
|
56
|
-
: `module.exports = null;`;
|
|
57
|
-
fs_1.default.writeFileSync(viewsLoaderPath, loaderContent);
|
|
58
|
-
return viewsLoaderPath;
|
|
59
|
-
};
|
|
60
|
-
const createClientConfig = () => {
|
|
61
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
62
|
-
const viewsLoaderPath = getViewsLoaderPath();
|
|
63
|
-
const clientEntry = findEntry([
|
|
64
|
-
"src/client",
|
|
65
|
-
"src/client/index",
|
|
66
|
-
"src/index",
|
|
67
|
-
"src/main",
|
|
68
|
-
]);
|
|
69
|
-
return {
|
|
70
|
-
mode: isProduction ? "production" : "development",
|
|
71
|
-
target: "web",
|
|
72
|
-
entry: {
|
|
73
|
-
client: clientEntry,
|
|
74
|
-
},
|
|
75
|
-
output: {
|
|
76
|
-
path: path_1.default.resolve(cwd, "dist/public"),
|
|
77
|
-
filename: isProduction
|
|
78
|
-
? "[name].[contenthash].bundle.js"
|
|
79
|
-
: "[name].bundle.js",
|
|
80
|
-
publicPath: "/",
|
|
81
|
-
assetModuleFilename: "assets/[hash][ext][query]",
|
|
82
|
-
},
|
|
83
|
-
resolve: {
|
|
84
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
85
|
-
alias: {
|
|
86
|
-
"arcana-views": viewsLoaderPath,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
resolveLoader: {
|
|
90
|
-
modules: ["node_modules", path_1.default.resolve(__dirname, "../../node_modules")],
|
|
91
|
-
},
|
|
92
|
-
module: {
|
|
93
|
-
rules: [
|
|
94
|
-
{
|
|
95
|
-
test: /\.(ts|tsx|js|jsx)$/,
|
|
96
|
-
exclude: /node_modules/,
|
|
97
|
-
use: {
|
|
98
|
-
loader: resolveLoader("babel-loader"),
|
|
99
|
-
options: {
|
|
100
|
-
presets: [
|
|
101
|
-
resolveLoader("@babel/preset-env"),
|
|
102
|
-
[
|
|
103
|
-
resolveLoader("@babel/preset-react"),
|
|
104
|
-
{ runtime: "automatic" },
|
|
105
|
-
],
|
|
106
|
-
resolveLoader("@babel/preset-typescript"),
|
|
107
|
-
],
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
// CSS Modules rule for .module.css files
|
|
112
|
-
{
|
|
113
|
-
test: /\.module\.css$/,
|
|
114
|
-
use: [
|
|
115
|
-
isProduction
|
|
116
|
-
? mini_css_extract_plugin_1.default.loader
|
|
117
|
-
: resolveLoader("style-loader"),
|
|
118
|
-
{
|
|
119
|
-
loader: resolveLoader("css-loader"),
|
|
120
|
-
options: {
|
|
121
|
-
importLoaders: 1,
|
|
122
|
-
modules: {
|
|
123
|
-
localIdentName: isProduction
|
|
124
|
-
? "[hash:base64:8]"
|
|
125
|
-
: "[path][name]__[local]--[hash:base64:5]",
|
|
126
|
-
exportLocalsConvention: "camelCaseOnly",
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
loader: resolveLoader("postcss-loader"),
|
|
132
|
-
options: {
|
|
133
|
-
postcssOptions: {
|
|
134
|
-
config: path_1.default.resolve(cwd, "postcss.config.js"),
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
// Global CSS rule for regular .css files
|
|
141
|
-
{
|
|
142
|
-
test: /\.css$/,
|
|
143
|
-
exclude: /\.module\.css$/,
|
|
144
|
-
use: [
|
|
145
|
-
isProduction
|
|
146
|
-
? mini_css_extract_plugin_1.default.loader
|
|
147
|
-
: resolveLoader("style-loader"),
|
|
148
|
-
{
|
|
149
|
-
loader: resolveLoader("css-loader"),
|
|
150
|
-
options: {
|
|
151
|
-
importLoaders: 1,
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
loader: resolveLoader("postcss-loader"),
|
|
156
|
-
options: {
|
|
157
|
-
postcssOptions: {
|
|
158
|
-
config: path_1.default.resolve(cwd, "postcss.config.js"),
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|eot|ttf|otf)$/i,
|
|
166
|
-
type: "asset/resource",
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
},
|
|
170
|
-
plugins: [
|
|
171
|
-
new clean_webpack_plugin_1.CleanWebpackPlugin(),
|
|
172
|
-
new html_webpack_plugin_1.default({
|
|
173
|
-
template: path_1.default.resolve(__dirname, "../lib/server/default-index.html"),
|
|
174
|
-
filename: "index.html",
|
|
175
|
-
inject: "body",
|
|
176
|
-
minify: isProduction
|
|
177
|
-
? {
|
|
178
|
-
removeComments: false,
|
|
179
|
-
collapseWhitespace: true,
|
|
180
|
-
removeRedundantAttributes: true,
|
|
181
|
-
useShortDoctype: true,
|
|
182
|
-
removeEmptyAttributes: true,
|
|
183
|
-
removeStyleLinkTypeAttributes: true,
|
|
184
|
-
keepClosingSlash: true,
|
|
185
|
-
minifyJS: true,
|
|
186
|
-
minifyCSS: true,
|
|
187
|
-
minifyURLs: true,
|
|
188
|
-
}
|
|
189
|
-
: false,
|
|
190
|
-
}),
|
|
191
|
-
new mini_css_extract_plugin_1.default({
|
|
192
|
-
filename: isProduction ? "[name].[contenthash].css" : "[name].css",
|
|
193
|
-
}),
|
|
194
|
-
],
|
|
195
|
-
optimization: {
|
|
196
|
-
splitChunks: {
|
|
197
|
-
chunks: "all",
|
|
198
|
-
cacheGroups: {
|
|
199
|
-
defaultVendors: {
|
|
200
|
-
test: /[\\/]node_modules[\\/]/,
|
|
201
|
-
priority: -10,
|
|
202
|
-
reuseExistingChunk: true,
|
|
203
|
-
},
|
|
204
|
-
default: {
|
|
205
|
-
minChunks: 2,
|
|
206
|
-
priority: -20,
|
|
207
|
-
reuseExistingChunk: true,
|
|
208
|
-
},
|
|
209
|
-
react: {
|
|
210
|
-
test: /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/,
|
|
211
|
-
name: "react-vendor",
|
|
212
|
-
chunks: "all",
|
|
213
|
-
priority: 10,
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
performance: {
|
|
219
|
-
maxEntrypointSize: 512000,
|
|
220
|
-
maxAssetSize: 512000,
|
|
221
|
-
hints: isProduction ? "warning" : false,
|
|
222
|
-
},
|
|
223
|
-
devtool: isProduction ? "source-map" : "eval-source-map",
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
exports.createClientConfig = createClientConfig;
|
|
227
|
-
const createServerConfig = () => {
|
|
228
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
229
|
-
const serverEntry = findEntry([
|
|
230
|
-
"src/server",
|
|
231
|
-
"src/server/index",
|
|
232
|
-
"src/server/main",
|
|
233
|
-
]);
|
|
234
|
-
const viewsLoaderPath = getViewsLoaderPath();
|
|
235
|
-
return {
|
|
236
|
-
mode: isProduction ? "production" : "development",
|
|
237
|
-
target: "node",
|
|
238
|
-
entry: serverEntry,
|
|
239
|
-
output: {
|
|
240
|
-
path: path_1.default.resolve(cwd, "dist"),
|
|
241
|
-
filename: "server.js",
|
|
242
|
-
},
|
|
243
|
-
externals: [
|
|
244
|
-
(0, webpack_node_externals_1.default)({
|
|
245
|
-
allowlist: [/^arcanajs/],
|
|
246
|
-
}),
|
|
247
|
-
],
|
|
248
|
-
resolve: {
|
|
249
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
250
|
-
alias: {
|
|
251
|
-
"arcana-views": viewsLoaderPath,
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
resolveLoader: {
|
|
255
|
-
modules: ["node_modules", path_1.default.resolve(__dirname, "../../node_modules")],
|
|
256
|
-
},
|
|
257
|
-
module: {
|
|
258
|
-
rules: [
|
|
259
|
-
{
|
|
260
|
-
test: /\.(ts|tsx|js|jsx)$/,
|
|
261
|
-
exclude: /node_modules/,
|
|
262
|
-
use: {
|
|
263
|
-
loader: resolveLoader("babel-loader"),
|
|
264
|
-
options: {
|
|
265
|
-
presets: [
|
|
266
|
-
resolveLoader("@babel/preset-env"),
|
|
267
|
-
[
|
|
268
|
-
resolveLoader("@babel/preset-react"),
|
|
269
|
-
{ runtime: "automatic" },
|
|
270
|
-
],
|
|
271
|
-
resolveLoader("@babel/preset-typescript"),
|
|
272
|
-
],
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
// CSS Modules rule for .module.css files on server (for SSR)
|
|
277
|
-
{
|
|
278
|
-
test: /\.module\.css$/,
|
|
279
|
-
use: {
|
|
280
|
-
loader: resolveLoader("css-loader"),
|
|
281
|
-
options: {
|
|
282
|
-
modules: {
|
|
283
|
-
localIdentName: isProduction
|
|
284
|
-
? "[hash:base64:8]"
|
|
285
|
-
: "[path][name]__[local]--[hash:base64:5]",
|
|
286
|
-
exportLocalsConvention: "camelCaseOnly",
|
|
287
|
-
exportOnlyLocals: true, // Only export class names, not CSS
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
// Regular CSS files - ignore on server side
|
|
293
|
-
{
|
|
294
|
-
test: /\.css$/,
|
|
295
|
-
exclude: /\.module\.css$/,
|
|
296
|
-
use: resolveLoader("null-loader"),
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|eot|ttf|otf)$/i,
|
|
300
|
-
type: "asset/resource",
|
|
301
|
-
generator: {
|
|
302
|
-
emit: false,
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
],
|
|
306
|
-
},
|
|
307
|
-
devtool: isProduction ? "source-map" : "eval-source-map",
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
exports.createServerConfig = createServerConfig;
|
|
@@ -1,97 +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 jsx_runtime_1 = require("react/jsx-runtime");
|
|
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 ErrorPage_1 = __importDefault(require("../shared/views/ErrorPage"));
|
|
12
|
-
const NotFoundPage_1 = __importDefault(require("../shared/views/NotFoundPage"));
|
|
13
|
-
// ============================================================================
|
|
14
|
-
// Client Hydration Function
|
|
15
|
-
// ============================================================================
|
|
16
|
-
/**
|
|
17
|
-
* Hydrate the ArcanaJS application on the client side
|
|
18
|
-
*
|
|
19
|
-
* This function initializes the React application on the client,
|
|
20
|
-
* hydrating the server-rendered HTML with client-side interactivity.
|
|
21
|
-
*
|
|
22
|
-
* @param viewsOrContext - Either a views registry object or a webpack require.context
|
|
23
|
-
* @param layout - Optional layout component to wrap all pages
|
|
24
|
-
* @param options - Optional navigation configuration options
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* // Using webpack require.context (recommended)
|
|
29
|
-
* import { hydrateArcanaJS } from 'arcanajs/client';
|
|
30
|
-
*
|
|
31
|
-
* const views = require.context('./views', false, /\.tsx$/);
|
|
32
|
-
* hydrateArcanaJS(views);
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* // Using manual views registry
|
|
38
|
-
* import { hydrateArcanaJS } from 'arcanajs/client';
|
|
39
|
-
* import HomePage from './views/HomePage';
|
|
40
|
-
* import AboutPage from './views/AboutPage';
|
|
41
|
-
*
|
|
42
|
-
* hydrateArcanaJS({
|
|
43
|
-
* HomePage,
|
|
44
|
-
* AboutPage,
|
|
45
|
-
* });
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* // With navigation options
|
|
51
|
-
* import { hydrateArcanaJS } from 'arcanajs/client';
|
|
52
|
-
*
|
|
53
|
-
* const views = require.context('./views', false, /\.tsx$/);
|
|
54
|
-
* hydrateArcanaJS(views, undefined, {
|
|
55
|
-
* onNavigate: (url) => {
|
|
56
|
-
* // Track page views
|
|
57
|
-
* gtag('event', 'page_view', { page_path: url });
|
|
58
|
-
* }
|
|
59
|
-
* });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
const hydrateArcanaJS = (viewsOrContext, layout, options) => {
|
|
63
|
-
let views = {};
|
|
64
|
-
if (viewsOrContext.keys && typeof viewsOrContext.keys === "function") {
|
|
65
|
-
viewsOrContext.keys().forEach((key) => {
|
|
66
|
-
const viewName = key.replace(/^\.\/(.*)\.tsx$/, "$1");
|
|
67
|
-
views[viewName] = viewsOrContext(key).default;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
views = viewsOrContext;
|
|
72
|
-
}
|
|
73
|
-
// Add default error views if not present
|
|
74
|
-
if (!views["NotFoundPage"]) {
|
|
75
|
-
views["NotFoundPage"] = NotFoundPage_1.default;
|
|
76
|
-
}
|
|
77
|
-
if (!views["ErrorPage"]) {
|
|
78
|
-
views["ErrorPage"] = ErrorPage_1.default;
|
|
79
|
-
}
|
|
80
|
-
const container = document.getElementById("root");
|
|
81
|
-
const dataScript = document.getElementById("__ARCANAJS_DATA__");
|
|
82
|
-
// Client-side HeadManager (noop for push, as Head handles client updates via useEffect)
|
|
83
|
-
const headManager = {
|
|
84
|
-
tags: [],
|
|
85
|
-
push: () => { },
|
|
86
|
-
};
|
|
87
|
-
if (container && dataScript) {
|
|
88
|
-
try {
|
|
89
|
-
const { page, data, params, csrfToken } = JSON.parse(dataScript.textContent || "{}");
|
|
90
|
-
(0, client_1.hydrateRoot)(container, (0, jsx_runtime_1.jsx)(HeadContext_1.HeadContext.Provider, { value: headManager, children: (0, jsx_runtime_1.jsx)(ArcanaJSApp_1.ArcanaJSApp, { initialPage: page, initialData: data, initialParams: params, csrfToken: csrfToken, views: views, layout: layout, onNavigate: options?.onNavigate || (() => { }) }) }));
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
console.error("Failed to parse initial data", e);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
exports.hydrateArcanaJS = hydrateArcanaJS;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ArcanaJS Configuration System
|
|
3
|
-
*
|
|
4
|
-
* Provides utilities for loading and validating ArcanaJS configuration files.
|
|
5
|
-
*/
|
|
6
|
-
import type { ArcanaJSUserConfig, ResolvedArcanaJSConfig } from "../types";
|
|
7
|
-
/**
|
|
8
|
-
* Define a configuration object with type safety
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* export default defineConfig({
|
|
13
|
-
* server: {
|
|
14
|
-
* port: 3000,
|
|
15
|
-
* },
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare function defineConfig(config: ArcanaJSUserConfig): ArcanaJSUserConfig;
|
|
20
|
-
/**
|
|
21
|
-
* Load ArcanaJS configuration from project root
|
|
22
|
-
*
|
|
23
|
-
* Searches for:
|
|
24
|
-
* - arcanajs.config.js
|
|
25
|
-
* - arcanajs.config.ts
|
|
26
|
-
* - arcanajs.config.mjs
|
|
27
|
-
*
|
|
28
|
-
* @param root - Project root directory (defaults to process.cwd())
|
|
29
|
-
* @returns User configuration object or empty object if not found
|
|
30
|
-
*/
|
|
31
|
-
export declare function loadConfig(root?: string): Promise<ArcanaJSUserConfig>;
|
|
32
|
-
/**
|
|
33
|
-
* Resolve user configuration with defaults
|
|
34
|
-
*
|
|
35
|
-
* @param userConfig - User-provided configuration
|
|
36
|
-
* @param root - Project root directory
|
|
37
|
-
* @returns Fully resolved configuration with all defaults applied
|
|
38
|
-
*/
|
|
39
|
-
export declare function resolveConfig(userConfig: ArcanaJSUserConfig, root?: string): ResolvedArcanaJSConfig;
|
|
40
|
-
/**
|
|
41
|
-
* Load and resolve configuration in one step
|
|
42
|
-
*
|
|
43
|
-
* @param root - Project root directory
|
|
44
|
-
* @returns Fully resolved configuration
|
|
45
|
-
*/
|
|
46
|
-
export declare function loadAndResolveConfig(root?: string): Promise<ResolvedArcanaJSConfig>;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ArcanaJS Configuration System
|
|
4
|
-
*
|
|
5
|
-
* Provides utilities for loading and validating ArcanaJS configuration files.
|
|
6
|
-
*/
|
|
7
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
-
};
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.defineConfig = defineConfig;
|
|
12
|
-
exports.loadConfig = loadConfig;
|
|
13
|
-
exports.resolveConfig = resolveConfig;
|
|
14
|
-
exports.loadAndResolveConfig = loadAndResolveConfig;
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
/**
|
|
18
|
-
* Define a configuration object with type safety
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* export default defineConfig({
|
|
23
|
-
* server: {
|
|
24
|
-
* port: 3000,
|
|
25
|
-
* },
|
|
26
|
-
* });
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
function defineConfig(config) {
|
|
30
|
-
return config;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Load ArcanaJS configuration from project root
|
|
34
|
-
*
|
|
35
|
-
* Searches for:
|
|
36
|
-
* - arcanajs.config.js
|
|
37
|
-
* - arcanajs.config.ts
|
|
38
|
-
* - arcanajs.config.mjs
|
|
39
|
-
*
|
|
40
|
-
* @param root - Project root directory (defaults to process.cwd())
|
|
41
|
-
* @returns User configuration object or empty object if not found
|
|
42
|
-
*/
|
|
43
|
-
async function loadConfig(root = process.cwd()) {
|
|
44
|
-
const configFiles = [
|
|
45
|
-
"arcanajs.config.js",
|
|
46
|
-
"arcanajs.config.ts",
|
|
47
|
-
"arcanajs.config.mjs",
|
|
48
|
-
];
|
|
49
|
-
for (const configFile of configFiles) {
|
|
50
|
-
const configPath = path_1.default.resolve(root, configFile);
|
|
51
|
-
if (fs_1.default.existsSync(configPath)) {
|
|
52
|
-
try {
|
|
53
|
-
// For TypeScript files, we need ts-node or tsx
|
|
54
|
-
if (configFile.endsWith(".ts")) {
|
|
55
|
-
try {
|
|
56
|
-
require("tsx/cjs");
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
try {
|
|
60
|
-
require("ts-node/register");
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
console.warn(`Found ${configFile} but ts-node/tsx is not available. Skipping.`);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const config = require(configPath);
|
|
69
|
-
return config.default || config;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
console.error(`Error loading config from ${configPath}:`, error);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Resolve user configuration with defaults
|
|
80
|
-
*
|
|
81
|
-
* @param userConfig - User-provided configuration
|
|
82
|
-
* @param root - Project root directory
|
|
83
|
-
* @returns Fully resolved configuration with all defaults applied
|
|
84
|
-
*/
|
|
85
|
-
function resolveConfig(userConfig, root = process.cwd()) {
|
|
86
|
-
const mode = process.env.NODE_ENV || "development";
|
|
87
|
-
return {
|
|
88
|
-
root,
|
|
89
|
-
mode,
|
|
90
|
-
server: {
|
|
91
|
-
port: userConfig.server?.port || process.env.PORT || 3000,
|
|
92
|
-
staticDir: userConfig.server?.staticDir || "public",
|
|
93
|
-
distDir: userConfig.server?.distDir || "dist/public",
|
|
94
|
-
},
|
|
95
|
-
build: {
|
|
96
|
-
outDir: userConfig.build?.outDir || "dist",
|
|
97
|
-
sourcemap: userConfig.build?.sourcemap ?? mode === "development",
|
|
98
|
-
minify: userConfig.build?.minify ?? mode === "production",
|
|
99
|
-
},
|
|
100
|
-
views: {
|
|
101
|
-
dir: userConfig.views?.dir || "src/views",
|
|
102
|
-
layout: userConfig.views?.layout,
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Load and resolve configuration in one step
|
|
108
|
-
*
|
|
109
|
-
* @param root - Project root directory
|
|
110
|
-
* @returns Fully resolved configuration
|
|
111
|
-
*/
|
|
112
|
-
async function loadAndResolveConfig(root = process.cwd()) {
|
|
113
|
-
const userConfig = await loadConfig(root);
|
|
114
|
-
return resolveConfig(userConfig, root);
|
|
115
|
-
}
|
package/framework/lib/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference path="./global.d.ts" />
|
|
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/useHead";
|
|
12
|
-
export * from "./shared/hooks/useLocation";
|
|
13
|
-
export * from "./shared/hooks/usePage";
|
|
14
|
-
export * from "./shared/hooks/useParams";
|
|
15
|
-
export * from "./shared/hooks/useQuery";
|
|
16
|
-
export * from "./shared/hooks/useRouter";
|
|
17
|
-
export { default as ErrorPage } from "./shared/views/ErrorPage";
|
|
18
|
-
export { default as NotFoundPage } from "./shared/views/NotFoundPage";
|
|
19
|
-
export * from "./types";
|
package/framework/lib/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference path="./global.d.ts" />
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.NotFoundPage = exports.ErrorPage = void 0;
|
|
22
|
-
// ============================================================================
|
|
23
|
-
// Component Exports
|
|
24
|
-
// ============================================================================
|
|
25
|
-
__exportStar(require("./shared/components/Body"), exports);
|
|
26
|
-
__exportStar(require("./shared/components/Head"), exports);
|
|
27
|
-
__exportStar(require("./shared/components/Link"), exports);
|
|
28
|
-
__exportStar(require("./shared/components/NavLink"), exports);
|
|
29
|
-
__exportStar(require("./shared/components/Page"), exports);
|
|
30
|
-
// ============================================================================
|
|
31
|
-
// Context Exports
|
|
32
|
-
// ============================================================================
|
|
33
|
-
__exportStar(require("./shared/context/HeadContext"), exports);
|
|
34
|
-
__exportStar(require("./shared/context/PageContext"), exports);
|
|
35
|
-
__exportStar(require("./shared/context/RouterContext"), exports);
|
|
36
|
-
// ============================================================================
|
|
37
|
-
// Core Exports
|
|
38
|
-
// ============================================================================
|
|
39
|
-
__exportStar(require("./shared/core/ArcanaJSApp"), exports);
|
|
40
|
-
// ============================================================================
|
|
41
|
-
// Hook Exports
|
|
42
|
-
// ============================================================================
|
|
43
|
-
__exportStar(require("./shared/hooks/useHead"), exports);
|
|
44
|
-
__exportStar(require("./shared/hooks/useLocation"), exports);
|
|
45
|
-
__exportStar(require("./shared/hooks/usePage"), exports);
|
|
46
|
-
__exportStar(require("./shared/hooks/useParams"), exports);
|
|
47
|
-
__exportStar(require("./shared/hooks/useQuery"), exports);
|
|
48
|
-
__exportStar(require("./shared/hooks/useRouter"), exports);
|
|
49
|
-
// ============================================================================
|
|
50
|
-
// Default Error Views
|
|
51
|
-
// ============================================================================
|
|
52
|
-
var ErrorPage_1 = require("./shared/views/ErrorPage");
|
|
53
|
-
Object.defineProperty(exports, "ErrorPage", { enumerable: true, get: function () { return __importDefault(ErrorPage_1).default; } });
|
|
54
|
-
var NotFoundPage_1 = require("./shared/views/NotFoundPage");
|
|
55
|
-
Object.defineProperty(exports, "NotFoundPage", { enumerable: true, get: function () { return __importDefault(NotFoundPage_1).default; } });
|
|
56
|
-
// ============================================================================
|
|
57
|
-
// Type Exports
|
|
58
|
-
// ============================================================================
|
|
59
|
-
__exportStar(require("./types"), exports);
|