alepha 0.15.0 → 0.15.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 +43 -98
- package/dist/api/audits/index.d.ts +240 -240
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +2 -2
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.d.ts +185 -185
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +2 -2
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.d.ts +245 -245
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/notifications/index.browser.js +4 -4
- package/dist/api/notifications/index.browser.js.map +1 -1
- package/dist/api/notifications/index.d.ts +74 -74
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js +4 -4
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/parameters/index.d.ts +221 -221
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/users/index.d.ts +1632 -1631
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +26 -34
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.d.ts +132 -132
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/batch/index.d.ts +122 -122
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/bucket/index.d.ts +163 -163
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/cache/core/index.d.ts +46 -46
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cache/redis/index.js +2 -2
- package/dist/cache/redis/index.js.map +1 -1
- package/dist/cli/index.d.ts +5933 -201
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +609 -169
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +296 -296
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +19 -19
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +268 -79
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +768 -694
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +268 -79
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +268 -79
- package/dist/core/index.native.js.map +1 -1
- package/dist/datetime/index.d.ts +44 -44
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/email/index.d.ts +25 -25
- package/dist/email/index.d.ts.map +1 -1
- package/dist/fake/index.d.ts +5409 -5409
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/fake/index.js +22 -22
- package/dist/fake/index.js.map +1 -1
- package/dist/file/index.d.ts +435 -435
- package/dist/file/index.d.ts.map +1 -1
- package/dist/lock/core/index.d.ts +208 -208
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/redis/index.d.ts.map +1 -1
- package/dist/logger/index.d.ts +24 -24
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +1 -5
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +216 -198
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +28 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/index.browser.js +9 -9
- package/dist/orm/index.browser.js.map +1 -1
- package/dist/orm/index.bun.js +83 -76
- package/dist/orm/index.bun.js.map +1 -1
- package/dist/orm/index.d.ts +961 -960
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +88 -81
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +244 -244
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/redis/index.d.ts +105 -105
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/retry/index.d.ts +69 -69
- package/dist/retry/index.d.ts.map +1 -1
- package/dist/router/index.d.ts +6 -6
- package/dist/router/index.d.ts.map +1 -1
- package/dist/scheduler/index.d.ts +108 -26
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js +393 -1
- package/dist/scheduler/index.js.map +1 -1
- package/dist/security/index.d.ts +532 -209
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +1422 -11
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +1296 -271
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +1249 -18
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cache/index.d.ts +56 -56
- package/dist/server/cache/index.d.ts.map +1 -1
- package/dist/server/compress/index.d.ts +3 -3
- package/dist/server/compress/index.d.ts.map +1 -1
- package/dist/server/cookies/index.d.ts +6 -6
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/core/index.d.ts +196 -186
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +43 -27
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +11 -11
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/helmet/index.d.ts +2 -2
- package/dist/server/helmet/index.d.ts.map +1 -1
- package/dist/server/links/index.browser.js +9 -1
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +83 -83
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +13 -5
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts +514 -1
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/metrics/index.js +4462 -4
- package/dist/server/metrics/index.js.map +1 -1
- package/dist/server/multipart/index.d.ts +6 -6
- package/dist/server/multipart/index.d.ts.map +1 -1
- package/dist/server/proxy/index.d.ts +102 -102
- package/dist/server/proxy/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.d.ts +16 -16
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/static/index.d.ts +44 -44
- package/dist/server/static/index.d.ts.map +1 -1
- package/dist/server/swagger/index.d.ts +47 -47
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/sms/index.d.ts +11 -11
- package/dist/sms/index.d.ts.map +1 -1
- package/dist/sms/index.js +3 -3
- package/dist/sms/index.js.map +1 -1
- package/dist/thread/index.d.ts +71 -71
- package/dist/thread/index.d.ts.map +1 -1
- package/dist/thread/index.js +2 -2
- package/dist/thread/index.js.map +1 -1
- package/dist/topic/core/index.d.ts +318 -318
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/redis/index.d.ts +6 -6
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/vite/index.d.ts +2324 -1719
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +123 -475
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.browser.js +3 -3
- package/dist/websocket/index.browser.js.map +1 -1
- package/dist/websocket/index.d.ts +275 -275
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +3 -3
- package/dist/websocket/index.js.map +1 -1
- package/package.json +9 -9
- package/src/api/users/services/SessionService.ts +0 -10
- package/src/cli/apps/AlephaCli.ts +2 -2
- package/src/cli/apps/AlephaPackageBuilderCli.ts +9 -1
- package/src/cli/assets/apiHelloControllerTs.ts +2 -1
- package/src/cli/assets/biomeJson.ts +2 -1
- package/src/cli/assets/claudeMd.ts +9 -4
- package/src/cli/assets/dummySpecTs.ts +2 -1
- package/src/cli/assets/editorconfig.ts +2 -1
- package/src/cli/assets/mainBrowserTs.ts +2 -1
- package/src/cli/assets/mainCss.ts +24 -0
- package/src/cli/assets/tsconfigJson.ts +2 -1
- package/src/cli/assets/webAppRouterTs.ts +2 -1
- package/src/cli/assets/webHelloComponentTsx.ts +6 -2
- package/src/cli/atoms/appEntryOptions.ts +13 -0
- package/src/cli/atoms/buildOptions.ts +1 -1
- package/src/cli/atoms/changelogOptions.ts +1 -1
- package/src/cli/commands/build.ts +63 -47
- package/src/cli/commands/dev.ts +16 -33
- package/src/cli/commands/gen/env.ts +1 -1
- package/src/cli/commands/init.ts +17 -8
- package/src/cli/commands/lint.ts +1 -1
- package/src/cli/defineConfig.ts +9 -0
- package/src/cli/index.ts +2 -1
- package/src/cli/providers/AppEntryProvider.ts +131 -0
- package/src/cli/providers/ViteBuildProvider.ts +82 -0
- package/src/cli/providers/ViteDevServerProvider.ts +350 -0
- package/src/cli/providers/ViteTemplateProvider.ts +27 -0
- package/src/cli/services/AlephaCliUtils.ts +33 -2
- package/src/cli/services/PackageManagerUtils.ts +13 -6
- package/src/cli/services/ProjectScaffolder.ts +72 -49
- package/src/core/Alepha.ts +2 -8
- package/src/core/primitives/$module.ts +12 -0
- package/src/core/providers/KeylessJsonSchemaCodec.spec.ts +257 -0
- package/src/core/providers/KeylessJsonSchemaCodec.ts +396 -14
- package/src/core/providers/SchemaValidator.spec.ts +236 -0
- package/src/logger/providers/PrettyFormatterProvider.ts +0 -9
- package/src/mcp/errors/McpError.ts +30 -0
- package/src/mcp/index.ts +3 -0
- package/src/mcp/transports/SseMcpTransport.ts +16 -6
- package/src/orm/providers/DrizzleKitProvider.ts +3 -5
- package/src/orm/services/Repository.ts +11 -0
- package/src/server/core/index.ts +1 -1
- package/src/server/core/providers/BunHttpServerProvider.ts +1 -1
- package/src/server/core/providers/NodeHttpServerProvider.spec.ts +125 -0
- package/src/server/core/providers/NodeHttpServerProvider.ts +71 -22
- package/src/server/core/providers/ServerLoggerProvider.ts +2 -2
- package/src/server/core/providers/ServerProvider.ts +9 -12
- package/src/server/links/atoms/apiLinksAtom.ts +7 -0
- package/src/server/links/index.browser.ts +2 -0
- package/src/server/links/index.ts +2 -0
- package/src/vite/index.ts +3 -2
- package/src/vite/tasks/buildClient.ts +0 -1
- package/src/vite/tasks/buildServer.ts +68 -21
- package/src/vite/tasks/copyAssets.ts +5 -4
- package/src/vite/tasks/generateSitemap.ts +64 -23
- package/src/vite/tasks/index.ts +0 -2
- package/src/vite/tasks/prerenderPages.ts +49 -24
- package/src/cli/assets/indexHtml.ts +0 -15
- package/src/cli/commands/format.ts +0 -23
- package/src/vite/helpers/boot.ts +0 -117
- package/src/vite/plugins/viteAlephaDev.ts +0 -177
- package/src/vite/tasks/devServer.ts +0 -71
- package/src/vite/tasks/runAlepha.ts +0 -270
- /package/dist/orm/{chunk-DtkW-qnP.js → chunk-DH6iiROE.js} +0 -0
package/dist/vite/index.js
CHANGED
|
@@ -1,90 +1,13 @@
|
|
|
1
1
|
import m, { createRequire } from "node:module";
|
|
2
|
-
import { access, cp, mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import path, { basename, dirname, join, relative, resolve } from "node:path";
|
|
4
|
-
import { AlephaError } from "alepha";
|
|
5
|
-
import { pathToFileURL } from "node:url";
|
|
6
2
|
import { createHash } from "node:crypto";
|
|
7
3
|
import { existsSync, mkdirSync, promises, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
8
5
|
import { promisify } from "node:util";
|
|
9
6
|
import { brotliCompress, gzip } from "node:zlib";
|
|
10
7
|
import { analyzer } from "vite-bundle-analyzer";
|
|
8
|
+
import { access, cp, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
9
|
+
import { AlephaError } from "alepha";
|
|
11
10
|
|
|
12
|
-
//#region ../../src/vite/helpers/boot.ts
|
|
13
|
-
/**
|
|
14
|
-
* Remember:
|
|
15
|
-
* At first, functions was inside alepha/vite package, but it's now used in alepha too.
|
|
16
|
-
* For avoiding cli -> vite, all code moved here.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Server entry files in priority order.
|
|
20
|
-
* main.server.ts is preferred over main.ts for consistency.
|
|
21
|
-
*/
|
|
22
|
-
const SERVER_ENTRIES = [
|
|
23
|
-
"main.server.ts",
|
|
24
|
-
"main.server.tsx",
|
|
25
|
-
"main.ts",
|
|
26
|
-
"main.tsx"
|
|
27
|
-
];
|
|
28
|
-
/**
|
|
29
|
-
* Find browser/client entry file path.
|
|
30
|
-
*/
|
|
31
|
-
const getClientEntry = async (root = process.cwd()) => {
|
|
32
|
-
const indexPath = join(root, "index.html");
|
|
33
|
-
try {
|
|
34
|
-
return extractFirstModuleScriptSrc(await readFile(indexPath, "utf8")).replace(/\\/g, "/");
|
|
35
|
-
} catch {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Find server entry file path.
|
|
41
|
-
*
|
|
42
|
-
* Optimized to use a single readdir() call instead of multiple access() calls.
|
|
43
|
-
*/
|
|
44
|
-
const getServerEntry = async (root = process.cwd(), explicitEntry) => {
|
|
45
|
-
if (explicitEntry) {
|
|
46
|
-
const explicitPath = join(root, explicitEntry);
|
|
47
|
-
try {
|
|
48
|
-
await access(explicitPath);
|
|
49
|
-
return explicitPath;
|
|
50
|
-
} catch {
|
|
51
|
-
throw new AlephaError(`Explicit server entry file "${explicitEntry}" not found.`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const srcDir = join(root, "src");
|
|
55
|
-
try {
|
|
56
|
-
const files = new Set(await readdir(srcDir));
|
|
57
|
-
for (const entry of SERVER_ENTRIES) if (files.has(entry)) return join(srcDir, entry).replace(/\\/g, "/");
|
|
58
|
-
} catch {}
|
|
59
|
-
const clientEntry = await getClientEntry(root);
|
|
60
|
-
if (clientEntry) return clientEntry;
|
|
61
|
-
throw new AlephaError(`Could not find a server entry file. Supported entries: ${SERVER_ENTRIES.map((e) => `src/${e}`).join(", ")}`);
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Extract first module script src from HTML.
|
|
65
|
-
*/
|
|
66
|
-
function extractFirstModuleScriptSrc(html) {
|
|
67
|
-
const scriptRegex = /<script\b[^>]*>[\s\S]*?<\/script>/gi;
|
|
68
|
-
let match = scriptRegex.exec(html);
|
|
69
|
-
while (match) {
|
|
70
|
-
const tag = match[0];
|
|
71
|
-
if (/type=["']module["']/i.test(tag)) {
|
|
72
|
-
const entry = tag.match(/\bsrc=["']([^"']+)["']/i)?.[1];
|
|
73
|
-
if (entry) {
|
|
74
|
-
if (entry.startsWith("/")) return entry.substring(1);
|
|
75
|
-
return entry;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
match = scriptRegex.exec(html);
|
|
79
|
-
}
|
|
80
|
-
throw new AlephaError(`No module script found in the provided HTML.`);
|
|
81
|
-
}
|
|
82
|
-
const boot = {
|
|
83
|
-
getClientEntry,
|
|
84
|
-
getServerEntry
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
88
11
|
//#region ../../src/vite/helpers/createBufferedLogger.ts
|
|
89
12
|
/**
|
|
90
13
|
* Creates a Vite logger that buffers all messages instead of printing them.
|
|
@@ -172,281 +95,20 @@ const importVite = async () => {
|
|
|
172
95
|
} catch (_error) {
|
|
173
96
|
try {
|
|
174
97
|
return createRequire(import.meta.url)("vite");
|
|
175
|
-
} catch (_error
|
|
98
|
+
} catch (_error) {
|
|
176
99
|
throw new Error("Vite is not installed. Please install it with `npm install vite`.");
|
|
177
100
|
}
|
|
178
101
|
}
|
|
179
102
|
};
|
|
180
103
|
|
|
181
104
|
//#endregion
|
|
182
|
-
//#region ../../src/vite/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*/
|
|
189
|
-
function createAlephaRunner(opts) {
|
|
190
|
-
return new AlephaRunner({
|
|
191
|
-
root: process.cwd().replace(/\\/g, "/"),
|
|
192
|
-
started: false,
|
|
193
|
-
log: opts.debug ? (...msg) => console.log(...msg) : () => {},
|
|
194
|
-
entry: opts.entry,
|
|
195
|
-
onReload: () => {}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
var AlephaRunner = class {
|
|
199
|
-
state;
|
|
200
|
-
constructor(state) {
|
|
201
|
-
this.state = state;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Set resolved Vite config.
|
|
205
|
-
*/
|
|
206
|
-
setConfig(config) {
|
|
207
|
-
this.state.config = config;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Check if SSR is enabled for the running app.
|
|
211
|
-
*/
|
|
212
|
-
isSsrEnabled() {
|
|
213
|
-
if (!this.state.app) return false;
|
|
214
|
-
return this.state.app.store.get("alepha.react.server.ssr") ?? false;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Check if app is started.
|
|
218
|
-
*/
|
|
219
|
-
get isStarted() {
|
|
220
|
-
return this.state.started;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Get the running Alepha app instance.
|
|
224
|
-
*/
|
|
225
|
-
get app() {
|
|
226
|
-
return this.state.app;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Start the Alepha application.
|
|
230
|
-
*/
|
|
231
|
-
async start(server) {
|
|
232
|
-
const { loadEnv } = await importVite();
|
|
233
|
-
global.ssrFixStacktrace = (e) => {
|
|
234
|
-
server.ssrFixStacktrace(e);
|
|
235
|
-
let it = e;
|
|
236
|
-
do {
|
|
237
|
-
server.ssrFixStacktrace(it);
|
|
238
|
-
it = it.cause;
|
|
239
|
-
} while (it instanceof Error);
|
|
240
|
-
};
|
|
241
|
-
if (this.state.started) {
|
|
242
|
-
await this.restart(server, true);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (!this.state.config) {
|
|
246
|
-
this.state.log("[DEBUG] No config - skip starting");
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
this.state.onReload?.();
|
|
250
|
-
this.state.log("[DEBUG] Starting Alepha app...");
|
|
251
|
-
this.state.started = false;
|
|
252
|
-
this.state.app = void 0;
|
|
253
|
-
const fileUrl = pathToFileURL(`${path.resolve(this.state.config.root, this.state.entry)}`).href;
|
|
254
|
-
const env = loadEnv("development", this.state.config.root, "");
|
|
255
|
-
const before = { ...process.env };
|
|
256
|
-
for (const key in env) process.env[key] = env[key];
|
|
257
|
-
let port = 5173;
|
|
258
|
-
const address = server.httpServer?.address();
|
|
259
|
-
if (typeof address === "object" && address?.port) port = address.port;
|
|
260
|
-
process.env.NODE_ENV ??= "development";
|
|
261
|
-
process.env.VITE_ALEPHA_DEV = "true";
|
|
262
|
-
process.env.SERVER_HOST ??= typeof server.config.server.host === "string" ? server.config.server.host : "localhost";
|
|
263
|
-
process.env.SERVER_PORT ??= String(port);
|
|
264
|
-
try {
|
|
265
|
-
const now = Date.now();
|
|
266
|
-
await server.ssrLoadModule(fileUrl, { fixStacktrace: true });
|
|
267
|
-
this.state.log(`[DEBUG] Alepha app loaded in ${Date.now() - now}ms`);
|
|
268
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
269
|
-
this.state.app = globalThis.__alepha;
|
|
270
|
-
if (!this.state.app) {
|
|
271
|
-
this.state.log("[DEBUG] No app found - skip starting");
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
this.state.app.store.set("alepha.node.server", server.httpServer);
|
|
275
|
-
console.log("");
|
|
276
|
-
await this.state.app.start();
|
|
277
|
-
this.state.started = true;
|
|
278
|
-
process.env = { ...before };
|
|
279
|
-
this.state.log("[DEBUG] Starting Done!");
|
|
280
|
-
} catch (e) {
|
|
281
|
-
if (e instanceof Error) {
|
|
282
|
-
let it = e;
|
|
283
|
-
do {
|
|
284
|
-
server.ssrFixStacktrace(it);
|
|
285
|
-
it = it.cause;
|
|
286
|
-
} while (it instanceof Error);
|
|
287
|
-
server.ssrFixStacktrace(e);
|
|
288
|
-
if (e.cause instanceof Error) server.ssrFixStacktrace(e.cause);
|
|
289
|
-
this.state.app?.log?.error("App failed to start:", e);
|
|
290
|
-
this.state.app?.log?.info("Waiting for changes to restart...");
|
|
291
|
-
}
|
|
292
|
-
this.state.log("[DEBUG] Alepha app start error");
|
|
293
|
-
this.state.started = false;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Stop the Alepha application.
|
|
298
|
-
*/
|
|
299
|
-
async stop() {
|
|
300
|
-
if (this.state.app?.stop && this.state.started) {
|
|
301
|
-
this.state.log("[DEBUG] Stopping Alepha app...");
|
|
302
|
-
await this.state.app.stop();
|
|
303
|
-
this.state.started = false;
|
|
304
|
-
this.state.log("[DEBUG] Stopping Done!");
|
|
305
|
-
} else this.state.log("[DEBUG] Alepha app not started - skip stop");
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Restart the Alepha application.
|
|
309
|
-
*
|
|
310
|
-
* @returns true if the restart was skipped due to locking
|
|
311
|
-
*/
|
|
312
|
-
async restart(server, invalidate) {
|
|
313
|
-
if (this.state.lock) {
|
|
314
|
-
this.state.log("[DEBUG] STILL LOCKING");
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
this.state.log("[DEBUG] LOCK RESTART");
|
|
318
|
-
this.state.lock = Promise.withResolvers();
|
|
319
|
-
const now = Date.now();
|
|
320
|
-
this.state.log("[DEBUG] RESTART");
|
|
321
|
-
await this.stop();
|
|
322
|
-
this.state.log(`[DEBUG] RESTART (stop) in ${Date.now() - now}ms`);
|
|
323
|
-
if (invalidate) server.moduleGraph.invalidateAll();
|
|
324
|
-
await this.start(server);
|
|
325
|
-
this.state.log(`[DEBUG] RESTART OK in ${Date.now() - now}ms`);
|
|
326
|
-
setTimeout(() => {
|
|
327
|
-
this.state.log("[DEBUG] UNLOCK RESTART");
|
|
328
|
-
this.state.lock?.resolve();
|
|
329
|
-
this.state.lock = void 0;
|
|
330
|
-
}, 500);
|
|
331
|
-
return false;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Send reload event to client.
|
|
335
|
-
*/
|
|
336
|
-
sendReload(server) {
|
|
337
|
-
server.ws.send({
|
|
338
|
-
type: "custom",
|
|
339
|
-
event: "alepha:reload",
|
|
340
|
-
data: {}
|
|
341
|
-
});
|
|
342
|
-
}
|
|
105
|
+
//#region ../../src/vite/helpers/importViteReact.ts
|
|
106
|
+
const importViteReact = async () => {
|
|
107
|
+
try {
|
|
108
|
+
const { default: viteReact } = createRequire(import.meta.url)("@vitejs/plugin-react");
|
|
109
|
+
return viteReact;
|
|
110
|
+
} catch {}
|
|
343
111
|
};
|
|
344
|
-
/**
|
|
345
|
-
* Check if a URL path is a Vite internal file.
|
|
346
|
-
*/
|
|
347
|
-
function isViteInternalPath(pathname) {
|
|
348
|
-
const [path$1] = pathname.split("?");
|
|
349
|
-
if (path$1.startsWith("/@") || path$1.startsWith("/src") || path$1.includes("/node_modules/")) return true;
|
|
350
|
-
return false;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region ../../src/vite/plugins/viteAlephaDev.ts
|
|
355
|
-
/**
|
|
356
|
-
* Plug Alepha into Vite development server.
|
|
357
|
-
*
|
|
358
|
-
* This plugin manages the Alepha application lifecycle during development,
|
|
359
|
-
* handling hot module replacement and request forwarding.
|
|
360
|
-
*/
|
|
361
|
-
async function viteAlephaDev(options = {}) {
|
|
362
|
-
let entry = options.serverEntry;
|
|
363
|
-
if (!entry) {
|
|
364
|
-
entry = await boot.getServerEntry();
|
|
365
|
-
if (!entry) return {
|
|
366
|
-
name: "alepha-dev",
|
|
367
|
-
apply: "serve",
|
|
368
|
-
config() {}
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
const runner = createAlephaRunner({
|
|
372
|
-
entry,
|
|
373
|
-
debug: options.debug
|
|
374
|
-
});
|
|
375
|
-
const { loadEnv } = await importVite();
|
|
376
|
-
const env = loadEnv("development", process.cwd(), "SERVER");
|
|
377
|
-
const config = {};
|
|
378
|
-
if (env.SERVER_PORT) config.server = { port: parseInt(env.SERVER_PORT, 10) };
|
|
379
|
-
return {
|
|
380
|
-
name: "alepha-dev",
|
|
381
|
-
apply: "serve",
|
|
382
|
-
config: () => config,
|
|
383
|
-
configResolved(resolvedConfig) {
|
|
384
|
-
runner.setConfig(resolvedConfig);
|
|
385
|
-
},
|
|
386
|
-
async handleHotUpdate(ctx) {
|
|
387
|
-
if (options.debug) console.log("[DEBUG] HMR", ctx.file);
|
|
388
|
-
if (ctx.file.includes("/.idea/")) return [];
|
|
389
|
-
const isServerOnly = !ctx.modules[0]?._clientModule;
|
|
390
|
-
const isBrowserOnly = !ctx.modules[0]?._ssrModule;
|
|
391
|
-
const isSsrEnabled = runner.isSsrEnabled();
|
|
392
|
-
if (isBrowserOnly) {
|
|
393
|
-
if (options.debug) console.log("[DEBUG] HMR - browser only - no reason to reload server");
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
const root = process.cwd().replace(/\\/g, "/");
|
|
397
|
-
const invalidate = !ctx.file.startsWith(root);
|
|
398
|
-
if (invalidate && options.debug) console.log("[DEBUG] HMR - outside root - invalidate all");
|
|
399
|
-
if (!isSsrEnabled && isServerOnly) {
|
|
400
|
-
await runner.restart(ctx.server, invalidate);
|
|
401
|
-
return [];
|
|
402
|
-
}
|
|
403
|
-
if (isSsrEnabled && ctx.modules[0]) {
|
|
404
|
-
if (await runner.restart(ctx.server, invalidate)) return [];
|
|
405
|
-
if (!runner.isStarted) {
|
|
406
|
-
if (options.debug) console.log("[DEBUG] HMR - abort due to app not started");
|
|
407
|
-
return [];
|
|
408
|
-
}
|
|
409
|
-
if (isServerOnly && runner.isStarted) {
|
|
410
|
-
runner.sendReload(ctx.server);
|
|
411
|
-
return [];
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
},
|
|
415
|
-
async configureServer(server) {
|
|
416
|
-
if (env.SERVER_PORT) server.config.server.port = parseInt(env.SERVER_PORT, 10);
|
|
417
|
-
const middleware = (req, res, next) => {
|
|
418
|
-
if (runner.isStarted && runner.app && req.url && !isViteInternalPath(req.url)) {
|
|
419
|
-
let ended = false;
|
|
420
|
-
const writeHead = res.writeHead.bind(res);
|
|
421
|
-
res.writeHead = (...args) => {
|
|
422
|
-
ended = true;
|
|
423
|
-
return writeHead(args[0], args[1], args[2]);
|
|
424
|
-
};
|
|
425
|
-
return runner.app.events.emit("node:request", {
|
|
426
|
-
req,
|
|
427
|
-
res
|
|
428
|
-
}).then(() => {
|
|
429
|
-
if (!ended) next();
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
next();
|
|
433
|
-
};
|
|
434
|
-
server.middlewares.use((req, res, next) => {
|
|
435
|
-
middleware(req, res, next);
|
|
436
|
-
});
|
|
437
|
-
server.config.logger.info = (msg) => {
|
|
438
|
-
console.log(msg);
|
|
439
|
-
};
|
|
440
|
-
server.config.logger.clearScreen = () => {};
|
|
441
|
-
return () => {
|
|
442
|
-
server.httpServer?.once("listening", () => {
|
|
443
|
-
runner.start(server);
|
|
444
|
-
});
|
|
445
|
-
};
|
|
446
|
-
},
|
|
447
|
-
async closeBundle() {}
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
112
|
|
|
451
113
|
//#endregion
|
|
452
114
|
//#region ../../src/vite/plugins/viteAlephaSsrPreload.ts
|
|
@@ -609,11 +271,11 @@ function viteCompress(options = {}) {
|
|
|
609
271
|
};
|
|
610
272
|
}
|
|
611
273
|
async function compressFile(options = {}, filePath) {
|
|
612
|
-
const { brotli = true, gzip
|
|
274
|
+
const { brotli = true, gzip = true } = options;
|
|
613
275
|
const compressionTasks = [];
|
|
614
276
|
const fileContentPromise = promises.readFile(filePath);
|
|
615
|
-
if (gzip
|
|
616
|
-
const gzipOptions = typeof gzip
|
|
277
|
+
if (gzip) {
|
|
278
|
+
const gzipOptions = typeof gzip === "object" ? gzip : { level: 9 };
|
|
617
279
|
compressionTasks.push(fileContentPromise.then(async (content) => {
|
|
618
280
|
const compressed = await gzipCompress(content, gzipOptions);
|
|
619
281
|
await promises.writeFile(`${filePath}.gz`, compressed);
|
|
@@ -629,15 +291,6 @@ async function compressFile(options = {}, filePath) {
|
|
|
629
291
|
await Promise.all(compressionTasks);
|
|
630
292
|
}
|
|
631
293
|
|
|
632
|
-
//#endregion
|
|
633
|
-
//#region ../../src/vite/helpers/importViteReact.ts
|
|
634
|
-
const importViteReact = async () => {
|
|
635
|
-
try {
|
|
636
|
-
const { default: viteReact } = createRequire(import.meta.url)("@vitejs/plugin-react");
|
|
637
|
-
return viteReact;
|
|
638
|
-
} catch {}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
294
|
//#endregion
|
|
642
295
|
//#region ../../src/vite/tasks/buildClient.ts
|
|
643
296
|
/**
|
|
@@ -665,7 +318,6 @@ async function buildClient(opts) {
|
|
|
665
318
|
chunkSizeWarningLimit: 1e3,
|
|
666
319
|
outDir: opts.dist,
|
|
667
320
|
manifest: true,
|
|
668
|
-
ssrManifest: true,
|
|
669
321
|
rollupOptions: { output: {
|
|
670
322
|
entryFileNames: "entry.[hash].js",
|
|
671
323
|
chunkFileNames: "chunk.[hash].js",
|
|
@@ -721,7 +373,7 @@ async function generateExternals(opts) {
|
|
|
721
373
|
* the dist/index.js entry wrapper.
|
|
722
374
|
*/
|
|
723
375
|
async function buildServer(opts) {
|
|
724
|
-
const { build: viteBuild,
|
|
376
|
+
const { build: viteBuild, resolveConfig } = await importVite();
|
|
725
377
|
const plugins = [];
|
|
726
378
|
const viteReact = await importViteReact();
|
|
727
379
|
if (viteReact && opts.clientDir) plugins.push(viteReact());
|
|
@@ -769,12 +421,14 @@ async function buildServer(opts) {
|
|
|
769
421
|
};
|
|
770
422
|
let result;
|
|
771
423
|
try {
|
|
772
|
-
result = await viteBuild(
|
|
424
|
+
result = await viteBuild(viteBuildServerConfig);
|
|
773
425
|
} catch (error) {
|
|
774
426
|
logger?.flush();
|
|
775
427
|
throw error;
|
|
776
428
|
}
|
|
777
|
-
const
|
|
429
|
+
const resolvedConfig = await resolveConfig(viteBuildServerConfig, "build");
|
|
430
|
+
const externals = [];
|
|
431
|
+
if (Array.isArray(resolvedConfig?.ssr?.external)) externals.push(...resolvedConfig.ssr.external);
|
|
778
432
|
await generateExternals({
|
|
779
433
|
distDir: opts.distDir,
|
|
780
434
|
externals
|
|
@@ -783,14 +437,17 @@ async function buildServer(opts) {
|
|
|
783
437
|
let template = "";
|
|
784
438
|
if (opts.clientDir) template = `__alepha.set("alepha.react.server.template", \`${(await readFile(`${opts.distDir}/${opts.clientDir}/index.html`, "utf-8")).replace(/>\s*</g, "><").trim()}\`);\n`;
|
|
785
439
|
let manifest = "";
|
|
440
|
+
let manifestData;
|
|
786
441
|
if (opts.clientDir) {
|
|
787
442
|
const viteDir = `${opts.distDir}/${opts.clientDir}/.vite`;
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
443
|
+
const clientManifest = await loadJsonFile(`${viteDir}/manifest.json`);
|
|
444
|
+
const preloadManifest = await loadJsonFile(`${viteDir}/preload-manifest.json`);
|
|
445
|
+
manifestData = {
|
|
446
|
+
client: stripClientManifest(clientManifest),
|
|
447
|
+
preload: preloadManifest
|
|
792
448
|
};
|
|
793
|
-
manifest = `__alepha.set("alepha.react.ssr.manifest", ${JSON.stringify(
|
|
449
|
+
manifest = `__alepha.set("alepha.react.ssr.manifest", ${JSON.stringify(manifestData)});\n`;
|
|
450
|
+
opts.alepha.store.set("alepha.react.ssr.manifest", manifestData);
|
|
794
451
|
await rm(viteDir, {
|
|
795
452
|
recursive: true,
|
|
796
453
|
force: true
|
|
@@ -799,20 +456,38 @@ async function buildServer(opts) {
|
|
|
799
456
|
await writeFile(`${opts.distDir}/index.js`, `// This file was automatically generated. DO NOT MODIFY.
|
|
800
457
|
// Changes to this file will be lost when the code is regenerated.
|
|
801
458
|
\n${template}${manifest}import './server/${entryFile}';\n`.trim());
|
|
802
|
-
return {
|
|
459
|
+
return {
|
|
460
|
+
entryFile,
|
|
461
|
+
manifest: manifestData
|
|
462
|
+
};
|
|
803
463
|
}
|
|
804
464
|
/**
|
|
805
465
|
* Load a JSON file, returning undefined if it doesn't exist.
|
|
806
466
|
*/
|
|
807
|
-
async function loadJsonFile(path
|
|
467
|
+
async function loadJsonFile(path) {
|
|
808
468
|
try {
|
|
809
|
-
const content = await readFile(path
|
|
469
|
+
const content = await readFile(path, "utf-8");
|
|
810
470
|
return JSON.parse(content);
|
|
811
471
|
} catch {
|
|
812
472
|
return;
|
|
813
473
|
}
|
|
814
474
|
}
|
|
815
475
|
/**
|
|
476
|
+
* Strip unused fields from client manifest to reduce bundle size.
|
|
477
|
+
* Only keeps: file, isEntry, imports, css
|
|
478
|
+
*/
|
|
479
|
+
function stripClientManifest(manifest) {
|
|
480
|
+
if (!manifest) return void 0;
|
|
481
|
+
const stripped = {};
|
|
482
|
+
for (const [key, entry] of Object.entries(manifest)) stripped[key] = {
|
|
483
|
+
file: entry.file,
|
|
484
|
+
...entry.isEntry && { isEntry: entry.isEntry },
|
|
485
|
+
...entry.imports?.length && { imports: entry.imports },
|
|
486
|
+
...entry.css?.length && { css: entry.css }
|
|
487
|
+
};
|
|
488
|
+
return stripped;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
816
491
|
* Extract entry filename from Vite build result.
|
|
817
492
|
*/
|
|
818
493
|
function extractEntryFromBundle(entry, result) {
|
|
@@ -822,28 +497,6 @@ function extractEntryFromBundle(entry, result) {
|
|
|
822
497
|
return entryFile;
|
|
823
498
|
}
|
|
824
499
|
|
|
825
|
-
//#endregion
|
|
826
|
-
//#region ../../src/vite/helpers/importAlepha.ts
|
|
827
|
-
/**
|
|
828
|
-
* Import Alepha instance from a transpiled server entry file.
|
|
829
|
-
*/
|
|
830
|
-
const importAlepha = async (entry, options) => {
|
|
831
|
-
if (global.__cli_alepha) return global.__cli_alepha;
|
|
832
|
-
const { loadEnv } = await importVite();
|
|
833
|
-
const env = loadEnv("development", process.cwd(), "");
|
|
834
|
-
for (const key in env) process.env[key] = env[key];
|
|
835
|
-
if (options?.env) for (const key in options.env) process.env[key] = options.env[key];
|
|
836
|
-
process.env.ALEPHA_CLI_IMPORT = "true";
|
|
837
|
-
process.env.LOG_LEVEL = "error";
|
|
838
|
-
process.env.LOG_FORMAT = "pretty";
|
|
839
|
-
process.env.NODE_ENV = "production";
|
|
840
|
-
const mod = await import(pathToFileURL(join(process.cwd(), entry)).href);
|
|
841
|
-
if (mod.default) return mod.default;
|
|
842
|
-
const alepha = global.__cli_alepha;
|
|
843
|
-
if (!alepha) throw new AlephaError("Alepha instance not found. Ensure Alepha is initialized.");
|
|
844
|
-
return alepha;
|
|
845
|
-
};
|
|
846
|
-
|
|
847
500
|
//#endregion
|
|
848
501
|
//#region ../../src/vite/tasks/copyAssets.ts
|
|
849
502
|
/**
|
|
@@ -856,8 +509,8 @@ const importAlepha = async (entry, options) => {
|
|
|
856
509
|
* Used by modules like AlephaServerSwagger to distribute UI files.
|
|
857
510
|
*/
|
|
858
511
|
async function copyAssets(opts) {
|
|
859
|
-
const root = opts.root
|
|
860
|
-
const assets =
|
|
512
|
+
const root = opts.root;
|
|
513
|
+
const assets = opts.alepha.store.get("alepha.build.assets");
|
|
861
514
|
if (!assets || assets.length === 0) return;
|
|
862
515
|
const fn = async () => {
|
|
863
516
|
const require = createRequire(join(root, opts.entry));
|
|
@@ -872,39 +525,6 @@ async function copyAssets(opts) {
|
|
|
872
525
|
else await fn();
|
|
873
526
|
}
|
|
874
527
|
|
|
875
|
-
//#endregion
|
|
876
|
-
//#region ../../src/vite/tasks/devServer.ts
|
|
877
|
-
/**
|
|
878
|
-
* Start Vite development server with Alepha plugins.
|
|
879
|
-
*
|
|
880
|
-
* This task starts the Vite dev server with all required plugins:
|
|
881
|
-
* - @vitejs/plugin-react (JSX/TSX compilation)
|
|
882
|
-
* - viteAlephaDev (Alepha server integration)
|
|
883
|
-
* - viteAlephaSsrPreload (SSR module preloading)
|
|
884
|
-
*/
|
|
885
|
-
async function devServer(opts = {}) {
|
|
886
|
-
const { createServer, mergeConfig } = await importVite();
|
|
887
|
-
const plugins = [];
|
|
888
|
-
const viteReact = await importViteReact();
|
|
889
|
-
if (viteReact) plugins.push(viteReact());
|
|
890
|
-
plugins.push(viteAlephaSsrPreload());
|
|
891
|
-
plugins.push(await viteAlephaDev({
|
|
892
|
-
serverEntry: opts.entry,
|
|
893
|
-
debug: opts.debug
|
|
894
|
-
}));
|
|
895
|
-
const server = await createServer(mergeConfig({
|
|
896
|
-
plugins,
|
|
897
|
-
server: {
|
|
898
|
-
port: opts.port,
|
|
899
|
-
host: opts.host
|
|
900
|
-
}
|
|
901
|
-
}, {}));
|
|
902
|
-
await server.listen();
|
|
903
|
-
console.log("");
|
|
904
|
-
server.printUrls();
|
|
905
|
-
server.bindCLIShortcuts({ print: true });
|
|
906
|
-
}
|
|
907
|
-
|
|
908
528
|
//#endregion
|
|
909
529
|
//#region ../../src/vite/tasks/generateCloudflare.ts
|
|
910
530
|
const WARNING_COMMENT$1 = "// This file was automatically generated. DO NOT MODIFY.\n// Changes to this file will be lost when the code is regenerated.\n";
|
|
@@ -938,15 +558,15 @@ async function generateCloudflare(opts = {}) {
|
|
|
938
558
|
};
|
|
939
559
|
const url = process.env.DATABASE_URL;
|
|
940
560
|
if (url?.startsWith("cloudflare-d1:")) {
|
|
941
|
-
const [name
|
|
561
|
+
const [name, id] = url.replace("cloudflare-d1://", "").replace("cloudflare-d1:", "").split(":");
|
|
942
562
|
wrangler.d1_databases = wrangler.d1_databases || [];
|
|
943
563
|
wrangler.d1_databases.push({
|
|
944
|
-
binding: name
|
|
945
|
-
database_name: name
|
|
564
|
+
binding: name,
|
|
565
|
+
database_name: name,
|
|
946
566
|
database_id: id
|
|
947
567
|
});
|
|
948
568
|
wrangler.vars ??= {};
|
|
949
|
-
wrangler.vars.DATABASE_URL = `cloudflare-d1://${name
|
|
569
|
+
wrangler.vars.DATABASE_URL = `cloudflare-d1://${name}:${id}`;
|
|
950
570
|
}
|
|
951
571
|
await writeFile(join(root, distDir, "wrangler.jsonc"), JSON.stringify(wrangler, null, 2));
|
|
952
572
|
await writeWorkerEntryPoint(root, distDir);
|
|
@@ -976,8 +596,8 @@ export default {
|
|
|
976
596
|
|
|
977
597
|
//#endregion
|
|
978
598
|
//#region ../../src/vite/helpers/fileExists.ts
|
|
979
|
-
const fileExists = async (path
|
|
980
|
-
return await access(join(process.cwd(), path
|
|
599
|
+
const fileExists = async (path) => {
|
|
600
|
+
return await access(join(process.cwd(), path)).then(() => true).catch(() => false);
|
|
981
601
|
};
|
|
982
602
|
|
|
983
603
|
//#endregion
|
|
@@ -1023,41 +643,56 @@ CMD ["${command}", "index.js"]
|
|
|
1023
643
|
/**
|
|
1024
644
|
* Generate sitemap.xml from Alepha page primitives.
|
|
1025
645
|
*
|
|
1026
|
-
*
|
|
1027
|
-
* queries all page primitives, and generates a sitemap.xml
|
|
646
|
+
* Queries all page primitives and generates a sitemap.xml
|
|
1028
647
|
* containing URLs for all accessible pages.
|
|
1029
648
|
*/
|
|
1030
649
|
async function generateSitemap(opts) {
|
|
1031
|
-
const
|
|
1032
|
-
if (
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
650
|
+
const pages = getSitemapPages(opts.alepha);
|
|
651
|
+
if (pages.length === 0) return "";
|
|
652
|
+
let result = "";
|
|
653
|
+
const fn = async () => {
|
|
654
|
+
result = generateSitemapFromPages(pages, opts.baseUrl);
|
|
655
|
+
if (opts.output) await writeFile(opts.output, result);
|
|
656
|
+
};
|
|
657
|
+
if (opts.run) await opts.run({
|
|
658
|
+
name: "generate sitemap",
|
|
659
|
+
handler: fn
|
|
660
|
+
});
|
|
661
|
+
else await fn();
|
|
662
|
+
return result;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Get all pages that should be included in the sitemap.
|
|
666
|
+
*/
|
|
667
|
+
function getSitemapPages(alepha) {
|
|
668
|
+
return alepha.primitives("page").filter((page) => {
|
|
669
|
+
const options = page.options;
|
|
670
|
+
if (options.children) return false;
|
|
671
|
+
if (!options.schema?.params) return true;
|
|
672
|
+
if (options.static && typeof options.static === "object" && options.static.entries) return true;
|
|
673
|
+
return false;
|
|
674
|
+
});
|
|
1038
675
|
}
|
|
1039
|
-
function
|
|
1040
|
-
const pages = alepha.primitives("page");
|
|
676
|
+
function generateSitemapFromPages(pages, baseUrl) {
|
|
1041
677
|
const urls = [];
|
|
678
|
+
const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
|
|
1042
679
|
for (const page of pages) {
|
|
1043
680
|
const options = page.options;
|
|
1044
|
-
if (options.children) continue;
|
|
1045
681
|
if (!options.schema?.params) {
|
|
1046
|
-
const path
|
|
1047
|
-
const url = `${
|
|
682
|
+
const path = options.path || "";
|
|
683
|
+
const url = `${normalizedBaseUrl}${path === "" ? "/" : path}`;
|
|
1048
684
|
urls.push(url);
|
|
1049
685
|
} else if (options.static && typeof options.static === "object" && options.static.entries) for (const entry of options.static.entries) {
|
|
1050
|
-
const
|
|
1051
|
-
const url = `${baseUrl.replace(/\/$/, "")}${path$1}`;
|
|
686
|
+
const url = `${normalizedBaseUrl}${buildPathFromParams(options.path || "", entry.params || {})}`;
|
|
1052
687
|
urls.push(url);
|
|
1053
688
|
}
|
|
1054
689
|
}
|
|
1055
690
|
return buildSitemapXml(urls);
|
|
1056
691
|
}
|
|
1057
692
|
function buildPathFromParams(pathPattern, params) {
|
|
1058
|
-
let path
|
|
1059
|
-
for (const [key, value] of Object.entries(params)) path
|
|
1060
|
-
return path
|
|
693
|
+
let path = pathPattern;
|
|
694
|
+
for (const [key, value] of Object.entries(params)) path = path.replace(`:${key}`, String(value));
|
|
695
|
+
return path || "/";
|
|
1061
696
|
}
|
|
1062
697
|
function buildSitemapXml(urls) {
|
|
1063
698
|
const lastMod = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
@@ -1097,8 +732,8 @@ async function generateVercel(opts = {}) {
|
|
|
1097
732
|
/**
|
|
1098
733
|
* Check if a file or directory exists at the given path
|
|
1099
734
|
*/
|
|
1100
|
-
async function exists(path
|
|
1101
|
-
return stat(path
|
|
735
|
+
async function exists(path) {
|
|
736
|
+
return stat(path).then(() => true).catch(() => false);
|
|
1102
737
|
}
|
|
1103
738
|
/**
|
|
1104
739
|
* Create the serverless function entry point that bootstraps Alepha and handles requests
|
|
@@ -1144,10 +779,10 @@ async function writeProjectConfig(distDir, projectId, projectName, orgId) {
|
|
|
1144
779
|
* Create the client directory with a .keep file if it doesn't exist to avoid Vercel errors
|
|
1145
780
|
*/
|
|
1146
781
|
async function ensureClientDir(distDir, clientDir) {
|
|
1147
|
-
const path
|
|
1148
|
-
if (!await exists(path
|
|
1149
|
-
await mkdir(path
|
|
1150
|
-
await writeFile(`${path
|
|
782
|
+
const path = `${distDir}/${clientDir}`;
|
|
783
|
+
if (!await exists(path)) {
|
|
784
|
+
await mkdir(path, { recursive: true });
|
|
785
|
+
await writeFile(`${path}/.keep`, "");
|
|
1151
786
|
}
|
|
1152
787
|
}
|
|
1153
788
|
|
|
@@ -1156,26 +791,39 @@ async function ensureClientDir(distDir, clientDir) {
|
|
|
1156
791
|
/**
|
|
1157
792
|
* Pre-render static pages defined in the Alepha application.
|
|
1158
793
|
*
|
|
1159
|
-
*
|
|
1160
|
-
*
|
|
1161
|
-
*
|
|
1162
|
-
* `static.entries` configuration.
|
|
794
|
+
* Queries all page primitives with `static: true` and generates
|
|
795
|
+
* static HTML files for each page. Supports pages with parameterized
|
|
796
|
+
* routes via `static.entries` configuration.
|
|
1163
797
|
*/
|
|
1164
798
|
async function prerenderPages(opts) {
|
|
1165
|
-
const alepha =
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
799
|
+
const alepha = opts.alepha;
|
|
800
|
+
const pages = getStaticPages(alepha);
|
|
801
|
+
if (pages.length === 0) return { count: 0 };
|
|
802
|
+
let result = { count: 0 };
|
|
803
|
+
const fn = async () => {
|
|
804
|
+
if (!alepha.isConfigured()) await alepha.events.emit("configure", alepha);
|
|
805
|
+
result = await prerenderFromAlepha(pages, opts.dist, opts.compress);
|
|
806
|
+
};
|
|
807
|
+
if (opts.run) await opts.run({
|
|
808
|
+
name: "pre-render pages",
|
|
809
|
+
handler: fn
|
|
810
|
+
});
|
|
811
|
+
else await fn();
|
|
812
|
+
return result;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Get all static pages from the Alepha instance.
|
|
816
|
+
*/
|
|
817
|
+
function getStaticPages(alepha) {
|
|
818
|
+
return alepha.primitives("page").filter((page) => {
|
|
819
|
+
const options = page.options;
|
|
820
|
+
return options.static && !options.children;
|
|
821
|
+
});
|
|
1171
822
|
}
|
|
1172
|
-
async function prerenderFromAlepha(
|
|
823
|
+
async function prerenderFromAlepha(pages, dist, compress) {
|
|
1173
824
|
let count = 0;
|
|
1174
|
-
const pages = alepha.primitives("page");
|
|
1175
825
|
for (const page of pages) {
|
|
1176
826
|
const options = page.options;
|
|
1177
|
-
if (options.children) continue;
|
|
1178
|
-
if (!options.static) continue;
|
|
1179
827
|
const config = typeof options.static === "object" ? options.static : {};
|
|
1180
828
|
if (!options.schema?.params) {
|
|
1181
829
|
count += 1;
|
|
@@ -1202,5 +850,5 @@ async function renderFile(page, options, dist, compress) {
|
|
|
1202
850
|
}
|
|
1203
851
|
|
|
1204
852
|
//#endregion
|
|
1205
|
-
export {
|
|
853
|
+
export { buildClient, buildServer, compressFile, copyAssets, createBufferedLogger, generateCloudflare, generateDocker, generateExternals, generateSitemap, generateVercel, importVite, importViteReact, prerenderPages, viteAlephaSsrPreload, viteCompress };
|
|
1206
854
|
//# sourceMappingURL=index.js.map
|