xanix 0.0.0 → 1.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/dist/BaseDocument.d.ts +3 -0
- package/dist/BaseDocument.js +8 -0
- package/dist/Document.d.ts +7 -0
- package/dist/Document.js +7 -0
- package/dist/bin/bundler/buildCache.d.ts +11 -0
- package/dist/bin/bundler/buildCache.js +129 -0
- package/dist/bin/bundler/buildClient.d.ts +3 -0
- package/dist/bin/bundler/buildClient.js +41 -0
- package/dist/bin/bundler/buildServer.d.ts +7 -0
- package/dist/bin/bundler/buildServer.js +55 -0
- package/dist/bin/bundler/cacheNpmModules.d.ts +11 -0
- package/dist/bin/bundler/cacheNpmModules.js +157 -0
- package/dist/bin/bundler/config/output.d.ts +14 -0
- package/dist/bin/bundler/config/output.js +48 -0
- package/dist/bin/bundler/generateClientEntries.d.ts +3 -0
- package/dist/bin/bundler/generateClientEntries.js +59 -0
- package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +4 -0
- package/dist/bin/bundler/plugins/XanixAssets/index.js +22 -0
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +6 -0
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +350 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.d.ts +11 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +156 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.d.ts +6 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.js +36 -0
- package/dist/bin/bundler/plugins/XanixEnv.d.ts +15 -0
- package/dist/bin/bundler/plugins/XanixEnv.js +46 -0
- package/dist/bin/bundler/plugins/XanixHydrate.d.ts +3 -0
- package/dist/bin/bundler/plugins/XanixHydrate.js +34 -0
- package/dist/bin/bundler/plugins/XanixReactRefresh.d.ts +2 -0
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +126 -0
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.d.ts +5 -0
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +22 -0
- package/dist/bin/bundler/plugins/XanixTransform/index.d.ts +5 -0
- package/dist/bin/bundler/plugins/XanixTransform/index.js +19 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer.d.ts +16 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer.js +631 -0
- package/dist/bin/bundler/plugins/XanixWatchChange copy.d.ts +10 -0
- package/dist/bin/bundler/plugins/XanixWatchChange copy.js +30 -0
- package/dist/bin/bundler/plugins/XanixWatchChange.d.ts +9 -0
- package/dist/bin/bundler/plugins/XanixWatchChange.js +27 -0
- package/dist/bin/bundler/plugins/XanixWatchChangeClient.d.ts +7 -0
- package/dist/bin/bundler/plugins/XanixWatchChangeClient.js +15 -0
- package/dist/bin/bundler/plugins/commonjs.d.ts +3 -0
- package/dist/bin/bundler/plugins/commonjs.js +10 -0
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +9 -0
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +27 -0
- package/dist/bin/bundler/plugins/nodeResolve.d.ts +3 -0
- package/dist/bin/bundler/plugins/nodeResolve.js +10 -0
- package/dist/bin/bundler/plugins/pathResolver.d.ts +5 -0
- package/dist/bin/bundler/plugins/pathResolver.js +57 -0
- package/dist/bin/bundler/plugins/plugins.d.ts +8 -0
- package/dist/bin/bundler/plugins/plugins.js +75 -0
- package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +3 -0
- package/dist/bin/bundler/plugins/rollupEsbuild.js +14 -0
- package/dist/bin/bundler/plugins/xanixServerData.d.ts +6 -0
- package/dist/bin/bundler/plugins/xanixServerData.js +224 -0
- package/dist/bin/bundler/plugins/xanixTsconfigAlias.d.ts +6 -0
- package/dist/bin/bundler/plugins/xanixTsconfigAlias.js +51 -0
- package/dist/bin/bundler/plugins/xanixUseDataId.d.ts +4 -0
- package/dist/bin/bundler/plugins/xanixUseDataId.js +93 -0
- package/dist/bin/bundler/watchClient.d.ts +8 -0
- package/dist/bin/bundler/watchClient.js +54 -0
- package/dist/bin/bundler/watchServer.d.ts +10 -0
- package/dist/bin/bundler/watchServer.js +84 -0
- package/dist/bin/cli/build.d.ts +2 -0
- package/dist/bin/cli/build.js +18 -0
- package/dist/bin/cli/dev.d.ts +2 -0
- package/dist/bin/cli/dev.js +103 -0
- package/dist/bin/cli/start.d.ts +2 -0
- package/dist/bin/cli/start.js +19 -0
- package/dist/bin/include/entry.d.ts +3 -0
- package/dist/bin/include/entry.js +28 -0
- package/dist/bin/include/logger.d.ts +10 -0
- package/dist/bin/include/logger.js +11 -0
- package/dist/bin/include/manifest.d.ts +3 -0
- package/dist/bin/include/manifest.js +13 -0
- package/dist/bin/include/utils.d.ts +2 -0
- package/dist/bin/include/utils.js +14 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.js +26 -0
- package/dist/bin/types.d.ts +12 -0
- package/dist/bin/types.js +1 -0
- package/dist/client/components/Body.d.ts +5 -0
- package/dist/client/components/Body.js +10 -0
- package/dist/client/components/Document/context.d.ts +3 -0
- package/dist/client/components/Document/context.js +14 -0
- package/dist/client/components/Document/index.d.ts +8 -0
- package/dist/client/components/Document/index.js +6 -0
- package/dist/client/components/Head copy.d.ts +5 -0
- package/dist/client/components/Head copy.js +8 -0
- package/dist/client/components/Head.d.ts +5 -0
- package/dist/client/components/Head.js +10 -0
- package/dist/client/components/Link.d.ts +6 -0
- package/dist/client/components/Link.js +10 -0
- package/dist/client/context/RouteContext.d.ts +8 -0
- package/dist/client/context/RouteContext.js +16 -0
- package/dist/client/hooks/usePageProps.d.ts +1 -0
- package/dist/client/hooks/usePageProps.js +2 -0
- package/dist/client/hooks/useRoute.d.ts +1 -0
- package/dist/client/hooks/useRoute.js +2 -0
- package/dist/client/hooks/useSearchParams.d.ts +1 -0
- package/dist/client/hooks/useSearchParams.js +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/navigation.d.ts +4 -0
- package/dist/client/navigation.js +14 -0
- package/dist/client/refresh.d.ts +7 -0
- package/dist/client/refresh.js +15 -0
- package/dist/client/runtime.d.ts +10 -0
- package/dist/client/runtime.js +98 -0
- package/dist/client-runtime.d.ts +10 -0
- package/dist/client-runtime.js +113 -0
- package/dist/components/BaseDocument.d.ts +3 -0
- package/dist/components/BaseDocument.js +8 -0
- package/dist/components/Body.d.ts +5 -0
- package/dist/components/Body.js +8 -0
- package/dist/components/Document/Document.d.ts +16 -0
- package/dist/components/Document/Document.js +15 -0
- package/dist/components/Document/context.d.ts +17 -0
- package/dist/components/Document/context.js +13 -0
- package/dist/components/Document/index.d.ts +7 -0
- package/dist/components/Document/index.js +10 -0
- package/dist/components/Document.d.ts +7 -0
- package/dist/components/Document.js +9 -0
- package/dist/components/DocumentContext/DocumentContext.d.ts +15 -0
- package/dist/components/DocumentContext/DocumentContext.js +18 -0
- package/dist/components/DocumentContext/context.d.ts +11 -0
- package/dist/components/DocumentContext/context.js +14 -0
- package/dist/components/DocumentContext/index.d.ts +15 -0
- package/dist/components/DocumentContext/index.js +18 -0
- package/dist/components/DocumentContext.d.ts +19 -0
- package/dist/components/DocumentContext.js +6 -0
- package/dist/components/DocumentProvider.d.ts +13 -0
- package/dist/components/DocumentProvider.js +7 -0
- package/dist/components/Head.d.ts +5 -0
- package/dist/components/Head.js +42 -0
- package/dist/components/Link.d.ts +7 -0
- package/dist/components/Link.js +28 -0
- package/dist/components/Script.d.ts +3 -0
- package/dist/components/Script.js +5 -0
- package/dist/dataLoader.d.ts +11 -0
- package/dist/dataLoader.js +46 -0
- package/dist/document/BaseDocument.d.ts +3 -0
- package/dist/document/BaseDocument.js +8 -0
- package/dist/document/Body.d.ts +5 -0
- package/dist/document/Body.js +9 -0
- package/dist/document/Document/Document.d.ts +7 -0
- package/dist/document/Document/Document.js +10 -0
- package/dist/document/Document/context.d.ts +17 -0
- package/dist/document/Document/context.js +13 -0
- package/dist/document/Document/index.d.ts +7 -0
- package/dist/document/Document/index.js +10 -0
- package/dist/document/Document.d.ts +7 -0
- package/dist/document/Document.js +10 -0
- package/dist/document/DocumentContext.d.ts +17 -0
- package/dist/document/DocumentContext.js +6 -0
- package/dist/document/Head.d.ts +5 -0
- package/dist/document/Head.js +40 -0
- package/dist/document/Link.d.ts +7 -0
- package/dist/document/Link.js +28 -0
- package/dist/document/Script.d.ts +3 -0
- package/dist/document/Script.js +5 -0
- package/dist/document/context.d.ts +17 -0
- package/dist/document/context.js +13 -0
- package/dist/document/index.d.ts +8 -0
- package/dist/document/index.js +7 -0
- package/dist/document/useDocument.d.ts +2 -0
- package/dist/document/useDocument.js +10 -0
- package/dist/hooks/useCookies.d.ts +2 -0
- package/dist/hooks/useCookies.js +11 -0
- package/dist/hooks/useData.d.ts +18 -0
- package/dist/hooks/useData.js +69 -0
- package/dist/hooks/useDocument.d.ts +2 -0
- package/dist/hooks/useDocument.js +10 -0
- package/dist/hooks/useHeaders.d.ts +2 -0
- package/dist/hooks/useHeaders.js +9 -0
- package/dist/hooks/useLocation.d.ts +2 -0
- package/dist/hooks/useLocation.js +25 -0
- package/dist/hooks/usePage.d.ts +5 -0
- package/dist/hooks/usePage.js +9 -0
- package/dist/hooks/useParams.d.ts +2 -0
- package/dist/hooks/useParams.js +6 -0
- package/dist/hooks/usePathname.d.ts +2 -0
- package/dist/hooks/usePathname.js +9 -0
- package/dist/hooks/useRequest.d.ts +2 -0
- package/dist/hooks/useRequest.js +8 -0
- package/dist/hooks/useSearchParams.d.ts +12 -0
- package/dist/hooks/useSearchParams.js +66 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +27 -0
- package/dist/loader.d.ts +11 -0
- package/dist/loader.js +16 -0
- package/dist/navigate.d.ts +7 -0
- package/dist/navigate.js +31 -0
- package/dist/navigation/index.d.ts +2 -0
- package/dist/navigation/index.js +2 -0
- package/dist/navigation/navigate.d.ts +7 -0
- package/dist/navigation/navigate.js +31 -0
- package/dist/navigation/useLocation.d.ts +1 -0
- package/dist/navigation/useLocation.js +22 -0
- package/dist/router/index.d.ts +1 -0
- package/dist/router/index.js +1 -0
- package/dist/router/useParams.d.ts +9 -0
- package/dist/router/useParams.js +50 -0
- package/dist/router/useSearchParams .d.ts +9 -0
- package/dist/router/useSearchParams .js +50 -0
- package/dist/router/useSearchParams.d.ts +11 -0
- package/dist/router/useSearchParams.js +80 -0
- package/dist/server/index.d.ts +0 -0
- package/dist/server/index.js +1 -0
- package/dist/server/page.d.ts +9 -0
- package/dist/server/page.js +60 -0
- package/dist/server/readManifest.d.ts +14 -0
- package/dist/server/readManifest.js +8 -0
- package/dist/server/runtime/createServer.d.ts +12 -0
- package/dist/server/runtime/createServer.js +48 -0
- package/dist/server/runtime/index.d.ts +3 -0
- package/dist/server/runtime/index.js +3 -0
- package/dist/server/runtime/readManifest.d.ts +14 -0
- package/dist/server/runtime/readManifest.js +8 -0
- package/dist/server/runtime/xanixPage.d.ts +9 -0
- package/dist/server/runtime/xanixPage.js +87 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +7 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +27 -0
- package/dist/xanix.d.ts +3 -0
- package/dist/xanix.js +40 -0
- package/package.json +73 -13
- package/src/xanix-env.d.ts +79 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { watch } from "rollup";
|
|
2
|
+
import bundlerOutput, { outDir } from "./config/output.js";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import BuildCache from "./cacheNpmModules.js";
|
|
5
|
+
import XanixResolveCacheDeps from "./plugins/XanixResolveCacheDeps/index.js";
|
|
6
|
+
import { getDocumentFile, getClientRuntimeFile } from "../include/utils.js";
|
|
7
|
+
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
8
|
+
const WatchClient = async (entries, options) => {
|
|
9
|
+
const input = {};
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
input[entry.name] = entry.file;
|
|
12
|
+
}
|
|
13
|
+
input["xanix-runtime"] = getClientRuntimeFile();
|
|
14
|
+
input["xanix-document"] = await getDocumentFile();
|
|
15
|
+
fs.rmSync(outDir.client, {
|
|
16
|
+
recursive: true,
|
|
17
|
+
force: true,
|
|
18
|
+
});
|
|
19
|
+
fs.mkdirSync(outDir.client, {
|
|
20
|
+
recursive: true,
|
|
21
|
+
});
|
|
22
|
+
const buildCache = await BuildCache(entries);
|
|
23
|
+
const watcher = watch({
|
|
24
|
+
input,
|
|
25
|
+
treeshake: true,
|
|
26
|
+
plugins: [
|
|
27
|
+
XanixResolveCacheDeps(buildCache, entries),
|
|
28
|
+
...xanixDefaultPlugins({
|
|
29
|
+
target: "client",
|
|
30
|
+
development: true,
|
|
31
|
+
assetExternal: true,
|
|
32
|
+
onChange: options.onChange,
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
output: bundlerOutput.client(entries, { isDev: true }),
|
|
36
|
+
watch: {
|
|
37
|
+
clearScreen: false,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
watcher.on("event", (event) => {
|
|
41
|
+
switch (event.code) {
|
|
42
|
+
case "BUNDLE_START":
|
|
43
|
+
break;
|
|
44
|
+
case "BUNDLE_END":
|
|
45
|
+
options.onBuildEnd?.();
|
|
46
|
+
break;
|
|
47
|
+
case "ERROR":
|
|
48
|
+
console.error("[client]", event.error);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return watcher;
|
|
53
|
+
};
|
|
54
|
+
export default WatchClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { XanixClientEntry } from "../types.js";
|
|
2
|
+
export type WatcherOptions = {
|
|
3
|
+
rootEntry: string;
|
|
4
|
+
onChange?: (id: string) => Promise<void>;
|
|
5
|
+
onBuildEnd?: (entries: XanixClientEntry[]) => Promise<void>;
|
|
6
|
+
onClientEntryChange: (id: string, entries: XanixClientEntry[]) => Promise<void>;
|
|
7
|
+
onServerChange?: (id: string, entries: XanixClientEntry[]) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
declare const watchServer: ({ rootEntry, onChange, onBuildEnd, onServerChange, onClientEntryChange, }: WatcherOptions) => Promise<import("rollup").RollupWatcher>;
|
|
10
|
+
export default watchServer;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { watch } from "rollup";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { createManifest, readManifest } from "../include/manifest.js";
|
|
5
|
+
import generateClientEntries from "./generateClientEntries.js";
|
|
6
|
+
import bundlerOutput, { outDir } from "./config/output.js";
|
|
7
|
+
import { getDocumentFile } from "../include/utils.js";
|
|
8
|
+
import { entriesEqual } from "../include/entry.js";
|
|
9
|
+
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
const watchServer = async ({ rootEntry, onChange, onBuildEnd, onServerChange, onClientEntryChange, }) => {
|
|
12
|
+
fs.rmSync(outDir.server, {
|
|
13
|
+
recursive: true,
|
|
14
|
+
force: true,
|
|
15
|
+
});
|
|
16
|
+
fs.mkdirSync(outDir.server, {
|
|
17
|
+
recursive: true,
|
|
18
|
+
});
|
|
19
|
+
const entries = await generateClientEntries();
|
|
20
|
+
await createManifest(entries);
|
|
21
|
+
const input = {
|
|
22
|
+
index: path.resolve(root, rootEntry),
|
|
23
|
+
"xanix-document": await getDocumentFile(),
|
|
24
|
+
};
|
|
25
|
+
const changedFiles = new Set();
|
|
26
|
+
const watcher = watch({
|
|
27
|
+
input,
|
|
28
|
+
treeshake: true,
|
|
29
|
+
plugins: [
|
|
30
|
+
...xanixDefaultPlugins({
|
|
31
|
+
target: "server",
|
|
32
|
+
development: true,
|
|
33
|
+
assetExternal: false,
|
|
34
|
+
onChange: onChange,
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
external(id) {
|
|
38
|
+
if (id.startsWith(".") ||
|
|
39
|
+
path.isAbsolute(id) ||
|
|
40
|
+
id === "@" ||
|
|
41
|
+
id.startsWith("@/")) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
output: bundlerOutput.server(),
|
|
47
|
+
watch: {
|
|
48
|
+
clearScreen: false,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
watcher.on("event", async (event) => {
|
|
52
|
+
switch (event.code) {
|
|
53
|
+
case "BUNDLE_START":
|
|
54
|
+
break;
|
|
55
|
+
case "BUNDLE_END":
|
|
56
|
+
if (changedFiles.size) {
|
|
57
|
+
const manifest = await readManifest();
|
|
58
|
+
if (manifest) {
|
|
59
|
+
for (const entry of changedFiles) {
|
|
60
|
+
const isClientEntry = Array.from(manifest.entries.values()).find((e) => e.file === entry);
|
|
61
|
+
if (!isClientEntry) {
|
|
62
|
+
const entries = await generateClientEntries();
|
|
63
|
+
const isEqual = await entriesEqual(entries);
|
|
64
|
+
if (!isEqual) {
|
|
65
|
+
await createManifest(entries);
|
|
66
|
+
await onClientEntryChange?.(entry, entries);
|
|
67
|
+
}
|
|
68
|
+
await onServerChange?.(entry, entries);
|
|
69
|
+
}
|
|
70
|
+
await onChange?.(entry);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
changedFiles.clear();
|
|
74
|
+
}
|
|
75
|
+
await onBuildEnd?.(entries);
|
|
76
|
+
break;
|
|
77
|
+
case "ERROR":
|
|
78
|
+
console.error("[server]", event.error);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return watcher;
|
|
83
|
+
};
|
|
84
|
+
export default watchServer;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import buildServer from "../bundler/buildServer.js";
|
|
2
|
+
import buildClient from "../bundler/buildClient.js";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import logger from "../include/logger.js";
|
|
5
|
+
const build = async (rootEntry) => {
|
|
6
|
+
logger.info(pc.green("Building server..."), "server");
|
|
7
|
+
const st = Date.now();
|
|
8
|
+
await buildServer({
|
|
9
|
+
rootEntry,
|
|
10
|
+
onBuildEnd: async (entries) => {
|
|
11
|
+
logger.info(pc.green("Building client..."), "client");
|
|
12
|
+
const duration = Date.now() - st;
|
|
13
|
+
await buildClient(entries);
|
|
14
|
+
logger.info(pc.green(`Build completed in ${duration}ms`), "complete");
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export default build;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import watchServer from "../bundler/watchServer.js";
|
|
4
|
+
import watchClient from "../bundler/watchClient.js";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import logger from "../include/logger.js";
|
|
7
|
+
import { getEntries } from "../include/entry.js";
|
|
8
|
+
import { outDir } from "../bundler/config/output.js";
|
|
9
|
+
import { WebSocketServer } from "ws";
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
let child;
|
|
12
|
+
function start() {
|
|
13
|
+
child?.kill();
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const filePath = path.join(outDir.server, "index.js");
|
|
16
|
+
child = spawn(process.execPath, [filePath], {
|
|
17
|
+
stdio: !child ? "inherit" : "pipe",
|
|
18
|
+
});
|
|
19
|
+
resolve(child);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const dev = async (rootEntry) => {
|
|
23
|
+
const wss = new WebSocketServer({
|
|
24
|
+
port: 8080,
|
|
25
|
+
});
|
|
26
|
+
let sockets = new Set();
|
|
27
|
+
const broadcast = (message) => {
|
|
28
|
+
sockets.forEach((socket) => {
|
|
29
|
+
if (socket.readyState === 1) {
|
|
30
|
+
socket.send(message);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
wss.on("connection", (ws) => {
|
|
35
|
+
sockets.add(ws);
|
|
36
|
+
ws.on("close", () => {
|
|
37
|
+
sockets.delete(ws);
|
|
38
|
+
});
|
|
39
|
+
ws.on("message", (message) => {
|
|
40
|
+
if (message.toString() === "reload") {
|
|
41
|
+
start();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
let firstBuild = true;
|
|
46
|
+
let _clientWatcher = null;
|
|
47
|
+
const clientWatcher = async (entries) => {
|
|
48
|
+
let changedFiles = new Set();
|
|
49
|
+
_clientWatcher?.close();
|
|
50
|
+
_clientWatcher = await watchClient(entries, {
|
|
51
|
+
onChange: (entry) => {
|
|
52
|
+
const _entry = entries.find((e) => e.file === entry);
|
|
53
|
+
let buildFile = _entry
|
|
54
|
+
? `${_entry.id}.js`
|
|
55
|
+
: entry
|
|
56
|
+
.replace(root.replaceAll("\\", "/"), "")
|
|
57
|
+
.replace(/\.(ts|tsx|jsx)$/, ".js")
|
|
58
|
+
// replace / from first character if exists
|
|
59
|
+
.replace(/^\//, "");
|
|
60
|
+
changedFiles.add(buildFile);
|
|
61
|
+
},
|
|
62
|
+
onBuildEnd: () => {
|
|
63
|
+
if (changedFiles.size) {
|
|
64
|
+
broadcast(JSON.stringify(Array.from(changedFiles)));
|
|
65
|
+
changedFiles.clear();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const watch = await watchServer({
|
|
71
|
+
rootEntry,
|
|
72
|
+
onChange: async (entry) => {
|
|
73
|
+
logger.info(`reload server ${pc.yellow(entry.replace(root.replaceAll("\\", "/"), ""))}`, "update");
|
|
74
|
+
},
|
|
75
|
+
async onClientEntryChange(_entry, entries) {
|
|
76
|
+
await clientWatcher(entries);
|
|
77
|
+
},
|
|
78
|
+
onServerChange: async (entry, entries) => {
|
|
79
|
+
await start();
|
|
80
|
+
},
|
|
81
|
+
onBuildEnd: async () => {
|
|
82
|
+
if (firstBuild) {
|
|
83
|
+
firstBuild = false;
|
|
84
|
+
const entries = await getEntries();
|
|
85
|
+
await clientWatcher(entries);
|
|
86
|
+
await start();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
process.on("SIGINT", () => {
|
|
91
|
+
child?.kill();
|
|
92
|
+
_clientWatcher?.close();
|
|
93
|
+
watch?.close();
|
|
94
|
+
process.exit(0);
|
|
95
|
+
});
|
|
96
|
+
process.on("SIGTERM", () => {
|
|
97
|
+
child?.kill();
|
|
98
|
+
_clientWatcher?.close();
|
|
99
|
+
watch?.close();
|
|
100
|
+
process.exit(0);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
export default dev;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { outDir } from "../bundler/config/output.js";
|
|
4
|
+
let child;
|
|
5
|
+
const start = async () => {
|
|
6
|
+
const filePath = path.join(outDir.server, "index.js");
|
|
7
|
+
child = spawn(process.execPath, [filePath], {
|
|
8
|
+
stdio: "inherit",
|
|
9
|
+
});
|
|
10
|
+
process.on("SIGINT", () => {
|
|
11
|
+
child?.kill();
|
|
12
|
+
process.exit(0);
|
|
13
|
+
});
|
|
14
|
+
process.on("SIGTERM", () => {
|
|
15
|
+
child?.kill();
|
|
16
|
+
process.exit(0);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export default start;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readManifest } from "./manifest.js";
|
|
2
|
+
export const getEntries = async () => {
|
|
3
|
+
const manifest = await readManifest();
|
|
4
|
+
if (!manifest) {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
return manifest.entries;
|
|
8
|
+
};
|
|
9
|
+
export const entriesEqual = async (entries) => {
|
|
10
|
+
const manifest = await readManifest();
|
|
11
|
+
if (!manifest) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (manifest.entries.length !== entries.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
for (const entry of manifest.entries) {
|
|
18
|
+
const existingEntry = entries.find((e) => e.id === entry.id);
|
|
19
|
+
if (!existingEntry) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (existingEntry.name !== entry.name ||
|
|
23
|
+
existingEntry.file !== entry.file) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const logger: {
|
|
2
|
+
info: (msg: string, title?: string) => void;
|
|
3
|
+
warn: (msg: string) => void;
|
|
4
|
+
error: (msg: string) => void;
|
|
5
|
+
warnOnce: (msg: string) => void;
|
|
6
|
+
clearScreen: () => void;
|
|
7
|
+
hasErrorLogged: () => boolean;
|
|
8
|
+
hasWarned: boolean;
|
|
9
|
+
};
|
|
10
|
+
export default logger;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
const logger = {
|
|
3
|
+
info: (msg, title = "xanix") => console.log(`${pc.blue(`[${title}]`)} ${msg}`),
|
|
4
|
+
warn: (msg) => console.log(`${pc.yellow("[xanix:warn]")} ${pc.yellow(msg)}`),
|
|
5
|
+
error: (msg) => console.log(`${pc.red("[xanix:error]")} ${pc.red(msg)}`),
|
|
6
|
+
warnOnce: (msg) => console.log(`${pc.yellow("[xanix:warn]")} ${pc.yellow(msg)}`),
|
|
7
|
+
clearScreen: () => { },
|
|
8
|
+
hasErrorLogged: () => false,
|
|
9
|
+
hasWarned: false,
|
|
10
|
+
};
|
|
11
|
+
export default logger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
let readedManifest = null;
|
|
4
|
+
export const createManifest = async (entries) => {
|
|
5
|
+
const manifest = {
|
|
6
|
+
id: `id_`,
|
|
7
|
+
entries: [...entries.values()],
|
|
8
|
+
};
|
|
9
|
+
readedManifest = manifest;
|
|
10
|
+
const outDir = path.resolve(process.cwd(), ".xanix");
|
|
11
|
+
fs.writeFileSync(path.resolve(outDir, "client-manifest.json"), JSON.stringify(manifest, null, 2));
|
|
12
|
+
};
|
|
13
|
+
export const readManifest = async () => readedManifest;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const __dirname = fileURLToPath(import.meta.url);
|
|
5
|
+
export const getClientRuntimeFile = () => {
|
|
6
|
+
return path.join(__dirname, "../../../client-runtime.js");
|
|
7
|
+
};
|
|
8
|
+
export const getDocumentFile = async () => {
|
|
9
|
+
const documentEntry = path.join(process.cwd(), "Document.tsx");
|
|
10
|
+
if (fs.existsSync(documentEntry)) {
|
|
11
|
+
return documentEntry;
|
|
12
|
+
}
|
|
13
|
+
return path.join(__dirname, "../../../components/BaseDocument.js");
|
|
14
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import dev from "./cli/dev.js";
|
|
4
|
+
import build from "./cli/build.js";
|
|
5
|
+
import start from "./cli/start.js";
|
|
6
|
+
const program = new Command();
|
|
7
|
+
program.name("xanix").description("Xanix application CLI");
|
|
8
|
+
program
|
|
9
|
+
.command("dev")
|
|
10
|
+
.description("Start the Xanix development server")
|
|
11
|
+
.argument("[entry]", "entry file", "index.tsx")
|
|
12
|
+
.action(async (entry) => {
|
|
13
|
+
await dev(entry);
|
|
14
|
+
});
|
|
15
|
+
program
|
|
16
|
+
.command("build")
|
|
17
|
+
.description("Build the Xanix application")
|
|
18
|
+
.argument("[entry]", "entry file", "index.tsx")
|
|
19
|
+
.action(async (entry) => {
|
|
20
|
+
await build(entry);
|
|
21
|
+
});
|
|
22
|
+
program
|
|
23
|
+
.command("start")
|
|
24
|
+
.description("Start the production server")
|
|
25
|
+
.action(start);
|
|
26
|
+
await program.parseAsync();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useDocument } from "./Document/context.js";
|
|
3
|
+
const Body = ({ children }) => {
|
|
4
|
+
const { scripts } = useDocument();
|
|
5
|
+
return (_jsxs("body", { children: [children, Array.isArray(scripts) &&
|
|
6
|
+
scripts
|
|
7
|
+
.filter(({ placement }) => placement === "body")
|
|
8
|
+
.map((s) => (_jsx("script", { src: s.src, type: s.type || "text/javascript" }, s.src)))] }));
|
|
9
|
+
};
|
|
10
|
+
export default Body;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
export const DocumentContext = createContext({
|
|
3
|
+
title: "",
|
|
4
|
+
meta: new Map(),
|
|
5
|
+
styles: new Set(),
|
|
6
|
+
scripts: [],
|
|
7
|
+
});
|
|
8
|
+
export const useDocument = () => {
|
|
9
|
+
const context = useContext(DocumentContext);
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw new Error("useDocument must be used within a DocumentProvider");
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { XanixDocumentData } from "../../../types";
|
|
2
|
+
import { HTMLProps } from "react";
|
|
3
|
+
export type DocumentProps = HTMLProps<HTMLHtmlElement> & {
|
|
4
|
+
document: XanixDocumentData;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
declare const Document: ({ document, children, ...props }: DocumentProps) => import("react").JSX.Element;
|
|
8
|
+
export default Document;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DocumentContext } from "./context";
|
|
3
|
+
const Document = ({ document, children, ...props }) => {
|
|
4
|
+
return (_jsx(DocumentContext.Provider, { value: document, children: _jsx("html", { ...props, children: children }) }));
|
|
5
|
+
};
|
|
6
|
+
export default Document;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getDocumentData } from "../../utils/index.js";
|
|
3
|
+
const doc = getDocumentData();
|
|
4
|
+
const Head = ({ children }) => {
|
|
5
|
+
doc.head = children;
|
|
6
|
+
return _jsx(_Fragment, {});
|
|
7
|
+
};
|
|
8
|
+
export default Head;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useDocument } from "./Document/context.js";
|
|
3
|
+
const Head = ({ children }) => {
|
|
4
|
+
const { title, meta, styles, scripts } = useDocument();
|
|
5
|
+
return (_jsxs("head", { children: [_jsx("title", { children: title }), Array.from(meta.entries()).map(([name, content]) => (_jsx("meta", { name: name, content: content }, name))), children, Array.from(styles).map((href) => (_jsx("link", { rel: "stylesheet", href: href }, href))), Array.isArray(scripts) &&
|
|
6
|
+
scripts
|
|
7
|
+
.filter(({ placement }) => placement === "head")
|
|
8
|
+
.map((s) => (_jsx("script", { src: s.src, type: s.type || "text/javascript" }, s.src)))] }));
|
|
9
|
+
};
|
|
10
|
+
export default Head;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { navigate } from "../navigation";
|
|
3
|
+
const Link = ({ children, ...props }) => {
|
|
4
|
+
return (_jsx("a", { ...props, onClick: (e) => {
|
|
5
|
+
e.preventDefault();
|
|
6
|
+
e.stopPropagation();
|
|
7
|
+
navigate(props.href);
|
|
8
|
+
}, children: children }));
|
|
9
|
+
};
|
|
10
|
+
export default Link;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const RouteContext: React.Context<string>;
|
|
3
|
+
type RouteProviderProps = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
value?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const RouteProvider: ({ children, value }: RouteProviderProps) => React.JSX.Element;
|
|
8
|
+
export default RouteContext;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
export const RouteContext = React.createContext("");
|
|
4
|
+
let dispach = null;
|
|
5
|
+
export const RouteProvider = ({ children, value }) => {
|
|
6
|
+
const [route, setRoute] = React.useState(value || window.location.pathname);
|
|
7
|
+
useMemo(() => {
|
|
8
|
+
if (value) {
|
|
9
|
+
dispach = () => {
|
|
10
|
+
setRoute(value);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}, [value]);
|
|
14
|
+
return (_jsx(RouteContext.Provider, { value: route, children: children }));
|
|
15
|
+
};
|
|
16
|
+
export default RouteContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare const usePageProps: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare const useRoute: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare const useSearchParams: () => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const navigate = (path) => {
|
|
2
|
+
window.dispatchEvent(new CustomEvent("xanix:navigate", {
|
|
3
|
+
detail: { path },
|
|
4
|
+
}));
|
|
5
|
+
};
|
|
6
|
+
export const back = () => {
|
|
7
|
+
window.history.back();
|
|
8
|
+
};
|
|
9
|
+
export const forward = () => {
|
|
10
|
+
window.history.forward();
|
|
11
|
+
};
|
|
12
|
+
export const preload = async (path) => {
|
|
13
|
+
window.dispatchEvent(new CustomEvent("xanix:preload", { detail: { path } }));
|
|
14
|
+
};
|