@kithinji/pod 1.0.39 → 1.0.40
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/index.js +332 -129
- package/dist/index.js.map +3 -3
- package/dist/types/dev/server.d.ts +1 -0
- package/dist/types/dev/server.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/plugins/generators/utils.d.ts +1 -1
- package/dist/types/plugins/generators/utils.d.ts.map +1 -1
- package/dist/types/plugins/transformers/j2d.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1871,11 +1871,21 @@ var ElementTransformer = class {
|
|
|
1871
1871
|
transformDOMElement(jsxElement, tag, scope, context2) {
|
|
1872
1872
|
const elId = scope.generateUidIdentifier("el");
|
|
1873
1873
|
const statements = [];
|
|
1874
|
+
const isSVGTag = this.isSVGTag(tag);
|
|
1874
1875
|
statements.push(
|
|
1875
1876
|
this.t.variableDeclaration("var", [
|
|
1876
1877
|
this.t.variableDeclarator(
|
|
1877
1878
|
elId,
|
|
1878
|
-
this.t.callExpression(
|
|
1879
|
+
isSVGTag ? this.t.callExpression(
|
|
1880
|
+
this.t.memberExpression(
|
|
1881
|
+
this.t.identifier("document"),
|
|
1882
|
+
this.t.identifier("createElementNS")
|
|
1883
|
+
),
|
|
1884
|
+
[
|
|
1885
|
+
this.t.stringLiteral("http://www.w3.org/2000/svg"),
|
|
1886
|
+
this.t.stringLiteral(tag)
|
|
1887
|
+
]
|
|
1888
|
+
) : this.t.callExpression(
|
|
1879
1889
|
this.t.memberExpression(
|
|
1880
1890
|
this.t.identifier("document"),
|
|
1881
1891
|
this.t.identifier("createElement")
|
|
@@ -1931,6 +1941,36 @@ var ElementTransformer = class {
|
|
|
1931
1941
|
}
|
|
1932
1942
|
return { id: elId, statements };
|
|
1933
1943
|
}
|
|
1944
|
+
isSVGTag(tag) {
|
|
1945
|
+
const svgTags = /* @__PURE__ */ new Set([
|
|
1946
|
+
"svg",
|
|
1947
|
+
"circle",
|
|
1948
|
+
"rect",
|
|
1949
|
+
"line",
|
|
1950
|
+
"path",
|
|
1951
|
+
"polygon",
|
|
1952
|
+
"polyline",
|
|
1953
|
+
"ellipse",
|
|
1954
|
+
"text",
|
|
1955
|
+
"tspan",
|
|
1956
|
+
"g",
|
|
1957
|
+
"defs",
|
|
1958
|
+
"use",
|
|
1959
|
+
"symbol",
|
|
1960
|
+
"marker",
|
|
1961
|
+
"clipPath",
|
|
1962
|
+
"mask",
|
|
1963
|
+
"pattern",
|
|
1964
|
+
"linearGradient",
|
|
1965
|
+
"radialGradient",
|
|
1966
|
+
"stop",
|
|
1967
|
+
"animate",
|
|
1968
|
+
"animateTransform",
|
|
1969
|
+
"foreignObject",
|
|
1970
|
+
"image"
|
|
1971
|
+
]);
|
|
1972
|
+
return svgTags.has(tag);
|
|
1973
|
+
}
|
|
1934
1974
|
transformFragment(path17, scope, context2) {
|
|
1935
1975
|
const fragId = scope.generateUidIdentifier("frag");
|
|
1936
1976
|
const statements = [];
|
|
@@ -2732,8 +2772,8 @@ function stringifyType3(typeNode) {
|
|
|
2732
2772
|
}
|
|
2733
2773
|
function generateStubCode(stub) {
|
|
2734
2774
|
const className = stub.name;
|
|
2735
|
-
const
|
|
2736
|
-
if (
|
|
2775
|
+
const build3 = stub.methods.find((p) => p.name == "build");
|
|
2776
|
+
if (build3 == void 0) {
|
|
2737
2777
|
throw new Error("Component has no build function");
|
|
2738
2778
|
}
|
|
2739
2779
|
const decoratorsStr = stub.decorators.length > 0 ? stub.decorators.join("\n") + "\n" : "";
|
|
@@ -3083,8 +3123,8 @@ function useMyPlugin(options) {
|
|
|
3083
3123
|
const clientTransformer = new ClientBuildTransformer();
|
|
3084
3124
|
return {
|
|
3085
3125
|
name: "Orca",
|
|
3086
|
-
setup(
|
|
3087
|
-
|
|
3126
|
+
setup(build3) {
|
|
3127
|
+
build3.onLoad(
|
|
3088
3128
|
{ filter: /\.tsx?$/ },
|
|
3089
3129
|
async (args) => {
|
|
3090
3130
|
const source = await fs2.readFile(args.path, "utf8");
|
|
@@ -3310,8 +3350,8 @@ import * as fs4 from "fs";
|
|
|
3310
3350
|
function stylePlugin(store) {
|
|
3311
3351
|
return {
|
|
3312
3352
|
name: "style",
|
|
3313
|
-
setup(
|
|
3314
|
-
|
|
3353
|
+
setup(build3) {
|
|
3354
|
+
build3.onEnd(() => {
|
|
3315
3355
|
const styleRules = store.get("style_rules");
|
|
3316
3356
|
if (!styleRules || styleRules.length === 0) {
|
|
3317
3357
|
console.log("No style rules generated");
|
|
@@ -3383,8 +3423,8 @@ function useCompilePlugin(options) {
|
|
|
3383
3423
|
const transformer = new BuildTransformer();
|
|
3384
3424
|
return {
|
|
3385
3425
|
name: "Orca",
|
|
3386
|
-
setup(
|
|
3387
|
-
|
|
3426
|
+
setup(build3) {
|
|
3427
|
+
build3.onLoad(
|
|
3388
3428
|
{ filter: /\.tsx?$/ },
|
|
3389
3429
|
async (args) => {
|
|
3390
3430
|
const source = await fs5.readFile(args.path, "utf8");
|
|
@@ -3518,6 +3558,12 @@ function createHotReloadTransformer(port) {
|
|
|
3518
3558
|
}
|
|
3519
3559
|
|
|
3520
3560
|
// src/dev/server.ts
|
|
3561
|
+
var createLogger = (debugMode = false) => ({
|
|
3562
|
+
info: (...args) => console.log("[INFO]", ...args),
|
|
3563
|
+
error: (...args) => console.error("[ERROR]", ...args),
|
|
3564
|
+
warn: (...args) => console.warn("[WARN]", ...args),
|
|
3565
|
+
debug: (...args) => debugMode && console.log("[DEBUG]", ...args)
|
|
3566
|
+
});
|
|
3521
3567
|
var virtualClientFiles = {
|
|
3522
3568
|
"virtual:navigate": {
|
|
3523
3569
|
output: "navigate",
|
|
@@ -3526,7 +3572,7 @@ export async function navigate(event, url) {
|
|
|
3526
3572
|
event.preventDefault();
|
|
3527
3573
|
|
|
3528
3574
|
try {
|
|
3529
|
-
const { Navigate, getCurrentInjector } = await import("
|
|
3575
|
+
const { Navigate, getCurrentInjector } = await import("/src/client/client.js");
|
|
3530
3576
|
const injector = getCurrentInjector();
|
|
3531
3577
|
|
|
3532
3578
|
if (injector) {
|
|
@@ -3546,8 +3592,8 @@ export async function navigate(event, url) {
|
|
|
3546
3592
|
function createVirtualModulePlugin(virtualFiles) {
|
|
3547
3593
|
return {
|
|
3548
3594
|
name: "virtual-module",
|
|
3549
|
-
setup(
|
|
3550
|
-
|
|
3595
|
+
setup(build3) {
|
|
3596
|
+
build3.onResolve({ filter: /^virtual:/ }, (args) => {
|
|
3551
3597
|
if (virtualFiles[args.path]) {
|
|
3552
3598
|
return {
|
|
3553
3599
|
path: args.path,
|
|
@@ -3555,7 +3601,7 @@ function createVirtualModulePlugin(virtualFiles) {
|
|
|
3555
3601
|
};
|
|
3556
3602
|
}
|
|
3557
3603
|
});
|
|
3558
|
-
|
|
3604
|
+
build3.onLoad({ filter: /.*/, namespace: "virtual" }, (args) => {
|
|
3559
3605
|
const virtualFile = virtualFiles[args.path];
|
|
3560
3606
|
if (virtualFile) {
|
|
3561
3607
|
return {
|
|
@@ -3568,37 +3614,50 @@ function createVirtualModulePlugin(virtualFiles) {
|
|
|
3568
3614
|
};
|
|
3569
3615
|
}
|
|
3570
3616
|
var HotReloadManager = class {
|
|
3571
|
-
constructor(port = 3001) {
|
|
3617
|
+
constructor(port = 3001, logger) {
|
|
3572
3618
|
this.wss = null;
|
|
3573
3619
|
this.clients = /* @__PURE__ */ new Set();
|
|
3574
3620
|
this.port = port;
|
|
3621
|
+
this.logger = logger;
|
|
3575
3622
|
}
|
|
3576
3623
|
start() {
|
|
3577
3624
|
this.wss = new WebSocketServer({ port: this.port });
|
|
3578
3625
|
this.wss.on("connection", (ws) => {
|
|
3579
3626
|
this.clients.add(ws);
|
|
3627
|
+
this.logger.debug(
|
|
3628
|
+
`Client connected. Total clients: ${this.clients.size}`
|
|
3629
|
+
);
|
|
3580
3630
|
ws.on("close", () => {
|
|
3581
3631
|
this.clients.delete(ws);
|
|
3632
|
+
this.logger.debug(
|
|
3633
|
+
`Client disconnected. Total clients: ${this.clients.size}`
|
|
3634
|
+
);
|
|
3582
3635
|
});
|
|
3583
3636
|
ws.on("error", (error) => {
|
|
3584
|
-
|
|
3637
|
+
this.logger.error("WebSocket error:", error);
|
|
3585
3638
|
this.clients.delete(ws);
|
|
3586
3639
|
});
|
|
3587
3640
|
});
|
|
3588
|
-
|
|
3641
|
+
this.logger.info(
|
|
3642
|
+
`Hot reload server listening on ws://localhost:${this.port}`
|
|
3643
|
+
);
|
|
3589
3644
|
}
|
|
3590
3645
|
reload() {
|
|
3591
3646
|
const activeClients = Array.from(this.clients).filter(
|
|
3592
3647
|
(client) => client.readyState === WebSocket.OPEN
|
|
3593
3648
|
);
|
|
3594
3649
|
if (activeClients.length === 0) {
|
|
3650
|
+
this.logger.debug("No active clients to reload");
|
|
3595
3651
|
return;
|
|
3596
3652
|
}
|
|
3653
|
+
this.logger.debug(
|
|
3654
|
+
`Sending reload signal to ${activeClients.length} client(s)`
|
|
3655
|
+
);
|
|
3597
3656
|
activeClients.forEach((client) => {
|
|
3598
3657
|
try {
|
|
3599
3658
|
client.send("reload");
|
|
3600
3659
|
} catch (error) {
|
|
3601
|
-
|
|
3660
|
+
this.logger.error("Failed to send reload signal:", error);
|
|
3602
3661
|
this.clients.delete(client);
|
|
3603
3662
|
}
|
|
3604
3663
|
});
|
|
@@ -3607,14 +3666,16 @@ var HotReloadManager = class {
|
|
|
3607
3666
|
if (this.wss) {
|
|
3608
3667
|
this.clients.forEach((client) => client.close());
|
|
3609
3668
|
this.wss.close();
|
|
3669
|
+
this.logger.debug("Hot reload server closed");
|
|
3610
3670
|
}
|
|
3611
3671
|
}
|
|
3612
3672
|
};
|
|
3613
|
-
async function copyAndProcessHtml(hotReloadPort, preprocessorOptions) {
|
|
3673
|
+
async function copyAndProcessHtml(hotReloadPort, preprocessorOptions, logger) {
|
|
3614
3674
|
try {
|
|
3615
3675
|
await fs7.mkdir("public", { recursive: true });
|
|
3676
|
+
const transformers = hotReloadPort ? [createHotReloadTransformer(hotReloadPort)] : [];
|
|
3616
3677
|
const preprocessor = new HtmlPreprocessor({
|
|
3617
|
-
transformers
|
|
3678
|
+
transformers,
|
|
3618
3679
|
injectScripts: ["./navigate.js"],
|
|
3619
3680
|
...preprocessorOptions
|
|
3620
3681
|
});
|
|
@@ -3622,149 +3683,212 @@ async function copyAndProcessHtml(hotReloadPort, preprocessorOptions) {
|
|
|
3622
3683
|
"./src/client/index.html",
|
|
3623
3684
|
"./public/index.html"
|
|
3624
3685
|
);
|
|
3686
|
+
logger?.debug("HTML processed successfully");
|
|
3625
3687
|
} catch (error) {
|
|
3626
|
-
|
|
3688
|
+
logger?.error("Failed to copy and process index.html:", error);
|
|
3627
3689
|
throw error;
|
|
3628
3690
|
}
|
|
3629
3691
|
}
|
|
3630
|
-
async function cleanDirectories() {
|
|
3692
|
+
async function cleanDirectories(logger) {
|
|
3693
|
+
logger?.debug("Cleaning build directories...");
|
|
3631
3694
|
await Promise.all([
|
|
3632
3695
|
fs7.rm("dist", { recursive: true, force: true }),
|
|
3633
3696
|
fs7.rm("public", { recursive: true, force: true })
|
|
3634
3697
|
]);
|
|
3635
3698
|
}
|
|
3636
|
-
function
|
|
3699
|
+
function waitForProcessExit(process2, timeout = 5e3) {
|
|
3700
|
+
return new Promise((resolve3) => {
|
|
3701
|
+
const timer = setTimeout(() => {
|
|
3702
|
+
process2.kill("SIGKILL");
|
|
3703
|
+
resolve3();
|
|
3704
|
+
}, timeout);
|
|
3705
|
+
process2.once("exit", () => {
|
|
3706
|
+
clearTimeout(timer);
|
|
3707
|
+
resolve3();
|
|
3708
|
+
});
|
|
3709
|
+
process2.kill("SIGTERM");
|
|
3710
|
+
});
|
|
3711
|
+
}
|
|
3712
|
+
function createRestartServerPlugin(serverProcess, onServerReady, hotReloadManager, logger) {
|
|
3637
3713
|
return {
|
|
3638
3714
|
name: "restart-server",
|
|
3639
|
-
setup(
|
|
3640
|
-
|
|
3715
|
+
setup(build3) {
|
|
3716
|
+
build3.onEnd(async (result) => {
|
|
3641
3717
|
if (result.errors.length > 0) {
|
|
3642
|
-
|
|
3718
|
+
logger.error(
|
|
3643
3719
|
`Server build failed with ${result.errors.length} error(s)`
|
|
3644
3720
|
);
|
|
3645
3721
|
return;
|
|
3646
3722
|
}
|
|
3723
|
+
logger.info("Server build completed");
|
|
3647
3724
|
if (serverProcess.current) {
|
|
3648
|
-
|
|
3725
|
+
logger.debug("Stopping existing server process...");
|
|
3726
|
+
await waitForProcessExit(serverProcess.current);
|
|
3649
3727
|
}
|
|
3650
3728
|
serverProcess.current = spawn("node", ["dist/main.js"], {
|
|
3651
3729
|
stdio: "inherit"
|
|
3652
3730
|
});
|
|
3653
3731
|
serverProcess.current.on("error", (err) => {
|
|
3654
|
-
|
|
3732
|
+
logger.error("Server process error:", err);
|
|
3733
|
+
});
|
|
3734
|
+
serverProcess.current.on("exit", (code) => {
|
|
3735
|
+
if (code !== null && code !== 0) {
|
|
3736
|
+
logger.warn(`Server process exited with code ${code}`);
|
|
3737
|
+
}
|
|
3655
3738
|
});
|
|
3656
3739
|
setTimeout(() => {
|
|
3657
|
-
|
|
3740
|
+
onServerReady();
|
|
3741
|
+
if (hotReloadManager) {
|
|
3742
|
+
hotReloadManager.reload();
|
|
3743
|
+
}
|
|
3658
3744
|
}, 500);
|
|
3659
|
-
onServerBuildComplete();
|
|
3660
3745
|
});
|
|
3661
3746
|
}
|
|
3662
3747
|
};
|
|
3663
3748
|
}
|
|
3749
|
+
async function buildVirtualFiles(config, logger) {
|
|
3750
|
+
logger.debug("Building virtual files...");
|
|
3751
|
+
const virtualEntryPoints = {};
|
|
3752
|
+
Object.entries(virtualClientFiles).forEach(([key, value]) => {
|
|
3753
|
+
virtualEntryPoints[value.output] = key;
|
|
3754
|
+
});
|
|
3755
|
+
await esbuild2.build({
|
|
3756
|
+
entryPoints: virtualEntryPoints,
|
|
3757
|
+
bundle: true,
|
|
3758
|
+
outdir: "public",
|
|
3759
|
+
platform: "browser",
|
|
3760
|
+
format: "iife",
|
|
3761
|
+
globalName: "Orca",
|
|
3762
|
+
sourcemap: config.build?.sourcemap ?? true,
|
|
3763
|
+
minify: config.build?.minify ?? false,
|
|
3764
|
+
plugins: [createVirtualModulePlugin(virtualClientFiles)],
|
|
3765
|
+
write: true
|
|
3766
|
+
});
|
|
3767
|
+
logger.debug("Virtual files built successfully");
|
|
3768
|
+
}
|
|
3769
|
+
async function buildClient(clientFiles, config, store, isWatch = false, onBuildComplete, logger) {
|
|
3770
|
+
if (clientFiles.size === 0) {
|
|
3771
|
+
logger?.debug("No client files to build");
|
|
3772
|
+
return null;
|
|
3773
|
+
}
|
|
3774
|
+
logger?.debug(`Building ${clientFiles.size} client file(s)...`);
|
|
3775
|
+
const entryPoints = Array.from(clientFiles);
|
|
3776
|
+
const graph = buildGraph(entryPoints);
|
|
3777
|
+
const buildOptions = {
|
|
3778
|
+
entryPoints,
|
|
3779
|
+
bundle: true,
|
|
3780
|
+
outdir: "public",
|
|
3781
|
+
outbase: ".",
|
|
3782
|
+
platform: "browser",
|
|
3783
|
+
format: "esm",
|
|
3784
|
+
sourcemap: config.build?.sourcemap ?? true,
|
|
3785
|
+
splitting: true,
|
|
3786
|
+
minify: config.build?.minify ?? false,
|
|
3787
|
+
plugins: [
|
|
3788
|
+
...config.plugins?.map((cb) => cb(store)) || [],
|
|
3789
|
+
...config.client_plugins?.map((cb) => cb(store)) || [],
|
|
3790
|
+
useMyPlugin({
|
|
3791
|
+
graph,
|
|
3792
|
+
isServerBuild: false,
|
|
3793
|
+
onClientFound: () => {
|
|
3794
|
+
}
|
|
3795
|
+
}),
|
|
3796
|
+
{
|
|
3797
|
+
name: "client-build-logger",
|
|
3798
|
+
setup(build3) {
|
|
3799
|
+
build3.onEnd((result) => {
|
|
3800
|
+
if (result.errors.length > 0) {
|
|
3801
|
+
logger?.error(
|
|
3802
|
+
`Client build failed with ${result.errors.length} error(s)`
|
|
3803
|
+
);
|
|
3804
|
+
} else {
|
|
3805
|
+
logger?.info("Client build completed");
|
|
3806
|
+
onBuildComplete?.();
|
|
3807
|
+
}
|
|
3808
|
+
});
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
],
|
|
3812
|
+
write: true
|
|
3813
|
+
};
|
|
3814
|
+
if (isWatch) {
|
|
3815
|
+
const ctx = await esbuild2.context(buildOptions);
|
|
3816
|
+
await ctx.watch();
|
|
3817
|
+
return ctx;
|
|
3818
|
+
} else {
|
|
3819
|
+
await esbuild2.build(buildOptions);
|
|
3820
|
+
return null;
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
async function checkClientFilesExist() {
|
|
3824
|
+
try {
|
|
3825
|
+
await Promise.all([
|
|
3826
|
+
fs7.access("src/client/client.tsx"),
|
|
3827
|
+
fs7.access("src/client/index.html")
|
|
3828
|
+
]);
|
|
3829
|
+
return true;
|
|
3830
|
+
} catch {
|
|
3831
|
+
return false;
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3664
3834
|
async function startDevServer() {
|
|
3835
|
+
const logger = createLogger(process.env.DEBUG === "true");
|
|
3665
3836
|
const store = Store.getInstance();
|
|
3666
3837
|
const userConfig = await loadConfig();
|
|
3667
3838
|
const config = mergeConfig(getDefaultConfig(), userConfig);
|
|
3668
3839
|
const HOT_RELOAD_PORT = 3001;
|
|
3669
|
-
const
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3840
|
+
const hasClientFiles = await checkClientFilesExist();
|
|
3841
|
+
if (!hasClientFiles) {
|
|
3842
|
+
logger.warn(
|
|
3843
|
+
"Client files not found (src/client/client.tsx or src/client/index.html missing). Skipping client build."
|
|
3844
|
+
);
|
|
3845
|
+
}
|
|
3846
|
+
const hotReloadManager = hasClientFiles ? new HotReloadManager(HOT_RELOAD_PORT, logger) : null;
|
|
3847
|
+
await cleanDirectories(logger);
|
|
3848
|
+
if (hasClientFiles) {
|
|
3849
|
+
await copyAndProcessHtml(HOT_RELOAD_PORT, config.htmlPreprocessor, logger);
|
|
3850
|
+
hotReloadManager.start();
|
|
3851
|
+
}
|
|
3673
3852
|
const entryPoints = ["src/main.ts"];
|
|
3674
|
-
const clientFiles = /* @__PURE__ */ new Set(["src/client/client.tsx"]);
|
|
3853
|
+
const clientFiles = hasClientFiles ? /* @__PURE__ */ new Set(["src/client/client.tsx"]) : /* @__PURE__ */ new Set();
|
|
3675
3854
|
const serverProcessRef = { current: null };
|
|
3676
3855
|
let clientCtx = null;
|
|
3677
|
-
let virtualCtx = null;
|
|
3678
3856
|
let isShuttingDown = false;
|
|
3679
3857
|
let pendingClientFiles = /* @__PURE__ */ new Set();
|
|
3680
|
-
let
|
|
3681
|
-
async function buildVirtualFiles() {
|
|
3682
|
-
if (isShuttingDown) return;
|
|
3683
|
-
try {
|
|
3684
|
-
if (virtualCtx) {
|
|
3685
|
-
await virtualCtx.dispose();
|
|
3686
|
-
virtualCtx = null;
|
|
3687
|
-
}
|
|
3688
|
-
const virtualEntryPoints = {};
|
|
3689
|
-
Object.entries(virtualClientFiles).forEach(([key, value]) => {
|
|
3690
|
-
virtualEntryPoints[value.output] = key;
|
|
3691
|
-
});
|
|
3692
|
-
virtualCtx = await esbuild2.context({
|
|
3693
|
-
entryPoints: virtualEntryPoints,
|
|
3694
|
-
bundle: true,
|
|
3695
|
-
outdir: "public",
|
|
3696
|
-
platform: "browser",
|
|
3697
|
-
format: "iife",
|
|
3698
|
-
globalName: "Orca",
|
|
3699
|
-
sourcemap: config.build?.sourcemap ?? true,
|
|
3700
|
-
minify: config.build?.minify ?? false,
|
|
3701
|
-
plugins: [createVirtualModulePlugin(virtualClientFiles)],
|
|
3702
|
-
write: true
|
|
3703
|
-
});
|
|
3704
|
-
await virtualCtx.rebuild();
|
|
3705
|
-
} catch (error) {
|
|
3706
|
-
console.error("Failed to build virtual files:", error);
|
|
3707
|
-
throw error;
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3858
|
+
let rebuildTimer = null;
|
|
3710
3859
|
async function rebuildClient() {
|
|
3711
|
-
if (isShuttingDown) return;
|
|
3860
|
+
if (isShuttingDown || !hasClientFiles) return;
|
|
3712
3861
|
try {
|
|
3862
|
+
logger.debug("Scheduling client rebuild...");
|
|
3713
3863
|
if (clientCtx) {
|
|
3714
3864
|
await clientCtx.dispose();
|
|
3715
3865
|
clientCtx = null;
|
|
3716
3866
|
}
|
|
3717
|
-
|
|
3718
|
-
const entryPoints2 = Array.from(clientFiles);
|
|
3719
|
-
const graph = buildGraph(entryPoints2);
|
|
3720
|
-
clientCtx = await esbuild2.context({
|
|
3721
|
-
entryPoints: entryPoints2,
|
|
3722
|
-
bundle: true,
|
|
3723
|
-
outdir: "public",
|
|
3724
|
-
outbase: ".",
|
|
3725
|
-
platform: "browser",
|
|
3726
|
-
format: "esm",
|
|
3727
|
-
sourcemap: config.build?.sourcemap ?? true,
|
|
3728
|
-
splitting: true,
|
|
3729
|
-
minify: config.build?.minify ?? false,
|
|
3730
|
-
plugins: [
|
|
3731
|
-
...config.plugins?.map((cb) => cb(store)) || [],
|
|
3732
|
-
...config.client_plugins?.map((cb) => cb(store)) || [],
|
|
3733
|
-
useMyPlugin({
|
|
3734
|
-
graph,
|
|
3735
|
-
isServerBuild: false,
|
|
3736
|
-
onClientFound: () => {
|
|
3737
|
-
}
|
|
3738
|
-
}),
|
|
3739
|
-
{
|
|
3740
|
-
name: "client-build-logger",
|
|
3741
|
-
setup(build2) {
|
|
3742
|
-
build2.onEnd((result) => {
|
|
3743
|
-
if (result.errors.length > 0) {
|
|
3744
|
-
console.error(
|
|
3745
|
-
`Client build failed with ${result.errors.length} error(s)`
|
|
3746
|
-
);
|
|
3747
|
-
} else {
|
|
3748
|
-
console.log("Client build completed");
|
|
3749
|
-
hotReloadManager.reload();
|
|
3750
|
-
}
|
|
3751
|
-
});
|
|
3752
|
-
}
|
|
3753
|
-
}
|
|
3754
|
-
],
|
|
3755
|
-
write: true
|
|
3756
|
-
});
|
|
3757
|
-
await clientCtx.watch();
|
|
3867
|
+
pendingClientFiles.forEach((file) => clientFiles.add(file));
|
|
3758
3868
|
pendingClientFiles.clear();
|
|
3759
|
-
|
|
3869
|
+
clientCtx = await buildClient(
|
|
3870
|
+
clientFiles,
|
|
3871
|
+
config,
|
|
3872
|
+
store,
|
|
3873
|
+
true,
|
|
3874
|
+
() => hotReloadManager?.reload(),
|
|
3875
|
+
logger
|
|
3876
|
+
);
|
|
3760
3877
|
} catch (error) {
|
|
3761
|
-
|
|
3762
|
-
|
|
3878
|
+
logger.error("Failed to rebuild client:", error);
|
|
3879
|
+
}
|
|
3880
|
+
}
|
|
3881
|
+
function scheduleClientRebuild() {
|
|
3882
|
+
if (rebuildTimer) {
|
|
3883
|
+
clearTimeout(rebuildTimer);
|
|
3763
3884
|
}
|
|
3885
|
+
rebuildTimer = setTimeout(() => {
|
|
3886
|
+
rebuildClient();
|
|
3887
|
+
}, 100);
|
|
3764
3888
|
}
|
|
3765
|
-
async function
|
|
3766
|
-
if (
|
|
3767
|
-
|
|
3889
|
+
async function onServerReady() {
|
|
3890
|
+
if (pendingClientFiles.size > 0) {
|
|
3891
|
+
scheduleClientRebuild();
|
|
3768
3892
|
}
|
|
3769
3893
|
}
|
|
3770
3894
|
const serverCtx = await esbuild2.context({
|
|
@@ -3784,16 +3908,16 @@ async function startDevServer() {
|
|
|
3784
3908
|
onClientFound: async (filePath) => {
|
|
3785
3909
|
const isNewFile = !clientFiles.has(filePath);
|
|
3786
3910
|
if (isNewFile) {
|
|
3787
|
-
|
|
3911
|
+
logger.debug(`New client file discovered: ${filePath}`);
|
|
3788
3912
|
pendingClientFiles.add(filePath);
|
|
3789
|
-
needsClientRebuild = true;
|
|
3790
3913
|
}
|
|
3791
3914
|
}
|
|
3792
3915
|
}),
|
|
3793
3916
|
createRestartServerPlugin(
|
|
3794
3917
|
serverProcessRef,
|
|
3795
|
-
|
|
3796
|
-
hotReloadManager
|
|
3918
|
+
onServerReady,
|
|
3919
|
+
hotReloadManager,
|
|
3920
|
+
logger
|
|
3797
3921
|
)
|
|
3798
3922
|
],
|
|
3799
3923
|
write: true
|
|
@@ -3801,29 +3925,99 @@ async function startDevServer() {
|
|
|
3801
3925
|
async function shutdown() {
|
|
3802
3926
|
if (isShuttingDown) return;
|
|
3803
3927
|
isShuttingDown = true;
|
|
3804
|
-
|
|
3928
|
+
logger.info("Shutting down dev server...");
|
|
3805
3929
|
try {
|
|
3806
3930
|
if (serverProcessRef.current) {
|
|
3807
|
-
|
|
3808
|
-
await
|
|
3931
|
+
logger.debug("Stopping server process...");
|
|
3932
|
+
await waitForProcessExit(serverProcessRef.current);
|
|
3809
3933
|
}
|
|
3810
3934
|
await serverCtx.dispose();
|
|
3811
3935
|
if (clientCtx) await clientCtx.dispose();
|
|
3812
|
-
if (
|
|
3813
|
-
|
|
3814
|
-
console.log("Dev server shut down successfully");
|
|
3936
|
+
if (hotReloadManager) hotReloadManager.close();
|
|
3937
|
+
logger.info("Dev server shut down successfully");
|
|
3815
3938
|
process.exit(0);
|
|
3816
3939
|
} catch (error) {
|
|
3817
|
-
|
|
3940
|
+
logger.error("Error during shutdown:", error);
|
|
3818
3941
|
process.exit(1);
|
|
3819
3942
|
}
|
|
3820
3943
|
}
|
|
3821
3944
|
process.on("SIGINT", shutdown);
|
|
3822
3945
|
process.on("SIGTERM", shutdown);
|
|
3823
|
-
|
|
3824
|
-
|
|
3946
|
+
logger.info("Starting dev server...");
|
|
3947
|
+
if (hasClientFiles) {
|
|
3948
|
+
await buildVirtualFiles(config, logger);
|
|
3949
|
+
}
|
|
3825
3950
|
await serverCtx.watch();
|
|
3826
3951
|
}
|
|
3952
|
+
async function startBuild() {
|
|
3953
|
+
const logger = createLogger(false);
|
|
3954
|
+
const store = Store.getInstance();
|
|
3955
|
+
logger.info("Starting production build...");
|
|
3956
|
+
try {
|
|
3957
|
+
const userConfig = await loadConfig();
|
|
3958
|
+
const config = mergeConfig(getDefaultConfig(), userConfig);
|
|
3959
|
+
const hasClientFiles = await checkClientFilesExist();
|
|
3960
|
+
if (!hasClientFiles) {
|
|
3961
|
+
logger.warn(
|
|
3962
|
+
"Client files not found (src/client/client.tsx or src/client/index.html missing). Skipping client build."
|
|
3963
|
+
);
|
|
3964
|
+
}
|
|
3965
|
+
await cleanDirectories(logger);
|
|
3966
|
+
if (hasClientFiles) {
|
|
3967
|
+
await copyAndProcessHtml(null, config.htmlPreprocessor, logger);
|
|
3968
|
+
await buildVirtualFiles(config, logger);
|
|
3969
|
+
}
|
|
3970
|
+
const clientFiles = hasClientFiles ? /* @__PURE__ */ new Set(["src/client/client.tsx"]) : /* @__PURE__ */ new Set();
|
|
3971
|
+
const entryPoints = ["src/main.ts"];
|
|
3972
|
+
logger.info("Building server...");
|
|
3973
|
+
await esbuild2.build({
|
|
3974
|
+
entryPoints,
|
|
3975
|
+
bundle: true,
|
|
3976
|
+
outdir: config.build?.outDir || "dist",
|
|
3977
|
+
platform: "node",
|
|
3978
|
+
format: "esm",
|
|
3979
|
+
packages: "external",
|
|
3980
|
+
sourcemap: config.build?.sourcemap ?? false,
|
|
3981
|
+
minify: config.build?.minify ?? true,
|
|
3982
|
+
plugins: [
|
|
3983
|
+
...config.plugins?.map((cb) => cb(store)) || [],
|
|
3984
|
+
...config.server_plugins?.map((cb) => cb(store)) || [],
|
|
3985
|
+
useMyPlugin({
|
|
3986
|
+
isServerBuild: true,
|
|
3987
|
+
onClientFound: async (filePath) => {
|
|
3988
|
+
if (hasClientFiles) {
|
|
3989
|
+
clientFiles.add(filePath);
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
}),
|
|
3993
|
+
{
|
|
3994
|
+
name: "build-complete-logger",
|
|
3995
|
+
setup(build3) {
|
|
3996
|
+
build3.onEnd((result) => {
|
|
3997
|
+
if (result.errors.length > 0) {
|
|
3998
|
+
logger.error(
|
|
3999
|
+
`Server build failed with ${result.errors.length} error(s)`
|
|
4000
|
+
);
|
|
4001
|
+
} else {
|
|
4002
|
+
logger.info("Server build completed");
|
|
4003
|
+
}
|
|
4004
|
+
});
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
],
|
|
4008
|
+
write: true
|
|
4009
|
+
});
|
|
4010
|
+
if (hasClientFiles && clientFiles.size > 0) {
|
|
4011
|
+
logger.info(`Building ${clientFiles.size} client file(s)...`);
|
|
4012
|
+
await buildClient(clientFiles, config, store, false, void 0, logger);
|
|
4013
|
+
}
|
|
4014
|
+
logger.info("Production build completed successfully!");
|
|
4015
|
+
logger.info(`Output: dist/${hasClientFiles ? " and public/" : ""}`);
|
|
4016
|
+
} catch (error) {
|
|
4017
|
+
logger.error("Build failed:", error);
|
|
4018
|
+
process.exit(1);
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
3827
4021
|
|
|
3828
4022
|
// src/config/index.ts
|
|
3829
4023
|
var config_exports = {};
|
|
@@ -6544,8 +6738,9 @@ async function compileFiles(entryPoints) {
|
|
|
6544
6738
|
}
|
|
6545
6739
|
|
|
6546
6740
|
// src/index.ts
|
|
6741
|
+
import { fileURLToPath } from "url";
|
|
6547
6742
|
var program = new Command();
|
|
6548
|
-
program.name("pod").description("Pod cli tool").version("1.0.
|
|
6743
|
+
program.name("pod").description("Pod cli tool").version("1.0.40");
|
|
6549
6744
|
program.command("new <name> [type]").description("Start a new Orca Project").action(async (name, type) => {
|
|
6550
6745
|
const orca = async () => {
|
|
6551
6746
|
await addNew(name);
|
|
@@ -6578,6 +6773,9 @@ program.command("new <name> [type]").description("Start a new Orca Project").act
|
|
|
6578
6773
|
program.command("dev").description("Start Pod development server").action(async (opts) => {
|
|
6579
6774
|
await startDevServer();
|
|
6580
6775
|
});
|
|
6776
|
+
program.command("build").description("Start Pod build").action(async (opts) => {
|
|
6777
|
+
await startBuild();
|
|
6778
|
+
});
|
|
6581
6779
|
program.command("compile <files...>").description("Compile ts files with pod").action(async (files) => {
|
|
6582
6780
|
await compileFiles(files);
|
|
6583
6781
|
});
|
|
@@ -6609,7 +6807,10 @@ program.command("deploy").description("Deploy to a target environment").argument
|
|
|
6609
6807
|
process.exit(1);
|
|
6610
6808
|
}
|
|
6611
6809
|
});
|
|
6612
|
-
|
|
6810
|
+
var isMainModule = process.argv[1] === fileURLToPath(import.meta.url);
|
|
6811
|
+
if (isMainModule) {
|
|
6812
|
+
program.parse(process.argv);
|
|
6813
|
+
}
|
|
6613
6814
|
export {
|
|
6614
6815
|
config_exports as config,
|
|
6615
6816
|
expandMacros,
|
|
@@ -6620,8 +6821,10 @@ export {
|
|
|
6620
6821
|
macros_exports as macros,
|
|
6621
6822
|
mergeConfig,
|
|
6622
6823
|
plugins_exports as plugins,
|
|
6824
|
+
program,
|
|
6623
6825
|
resetGlobalMacroGraph,
|
|
6624
6826
|
store_exports as store,
|
|
6625
|
-
stylePlugin
|
|
6827
|
+
stylePlugin,
|
|
6828
|
+
useMyPlugin
|
|
6626
6829
|
};
|
|
6627
6830
|
//# sourceMappingURL=index.js.map
|