@ggterm/core 0.3.3 → 0.3.4
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/cli-plot.js +38 -18
- package/dist/serve.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cli-plot.js
CHANGED
|
@@ -14599,7 +14599,7 @@ var exports_serve = {};
|
|
|
14599
14599
|
__export(exports_serve, {
|
|
14600
14600
|
handleServe: () => handleServe
|
|
14601
14601
|
});
|
|
14602
|
-
import { watch, writeFileSync as writeFileSync3, unlinkSync } from "fs";
|
|
14602
|
+
import { watch, readFileSync as readFileSync3, writeFileSync as writeFileSync3, unlinkSync, existsSync as existsSync3 } from "fs";
|
|
14603
14603
|
import { join as join3 } from "path";
|
|
14604
14604
|
import { createServer } from "http";
|
|
14605
14605
|
import { spawn } from "child_process";
|
|
@@ -14629,6 +14629,18 @@ function handleServe(port) {
|
|
|
14629
14629
|
ensureHistoryDirs();
|
|
14630
14630
|
const clients = new Set;
|
|
14631
14631
|
let debounceTimer = null;
|
|
14632
|
+
function broadcast(payload) {
|
|
14633
|
+
const sseData = `data: ${payload}
|
|
14634
|
+
|
|
14635
|
+
`;
|
|
14636
|
+
for (const client of clients) {
|
|
14637
|
+
try {
|
|
14638
|
+
client.write(sseData);
|
|
14639
|
+
} catch {
|
|
14640
|
+
clients.delete(client);
|
|
14641
|
+
}
|
|
14642
|
+
}
|
|
14643
|
+
}
|
|
14632
14644
|
const plotsDir = getPlotsDir();
|
|
14633
14645
|
watch(plotsDir, (_event, filename) => {
|
|
14634
14646
|
if (!filename || !filename.endsWith(".json"))
|
|
@@ -14637,20 +14649,28 @@ function handleServe(port) {
|
|
|
14637
14649
|
clearTimeout(debounceTimer);
|
|
14638
14650
|
debounceTimer = setTimeout(() => {
|
|
14639
14651
|
const payload = getLatestPayload();
|
|
14640
|
-
if (
|
|
14641
|
-
|
|
14642
|
-
const sseData = `data: ${payload}
|
|
14643
|
-
|
|
14644
|
-
`;
|
|
14645
|
-
for (const client of clients) {
|
|
14646
|
-
try {
|
|
14647
|
-
client.write(sseData);
|
|
14648
|
-
} catch {
|
|
14649
|
-
clients.delete(client);
|
|
14650
|
-
}
|
|
14651
|
-
}
|
|
14652
|
+
if (payload)
|
|
14653
|
+
broadcast(payload);
|
|
14652
14654
|
}, 150);
|
|
14653
14655
|
});
|
|
14656
|
+
const vegaLitePath = join3(getGGTermDir(), "last-plot-vegalite.json");
|
|
14657
|
+
let styleDebounce = null;
|
|
14658
|
+
watch(getGGTermDir(), (_event, filename) => {
|
|
14659
|
+
if (filename !== "last-plot-vegalite.json")
|
|
14660
|
+
return;
|
|
14661
|
+
if (styleDebounce)
|
|
14662
|
+
clearTimeout(styleDebounce);
|
|
14663
|
+
styleDebounce = setTimeout(() => {
|
|
14664
|
+
if (!existsSync3(vegaLitePath))
|
|
14665
|
+
return;
|
|
14666
|
+
try {
|
|
14667
|
+
const spec = JSON.parse(readFileSync3(vegaLitePath, "utf-8"));
|
|
14668
|
+
const latestId = getLatestPlotId();
|
|
14669
|
+
const provenance = latestId ? { id: latestId, description: "Styled plot", timestamp: new Date().toISOString(), geomTypes: [] } : { id: "styled", description: "Styled plot", timestamp: new Date().toISOString(), geomTypes: [] };
|
|
14670
|
+
broadcast(JSON.stringify({ type: "plot", spec, provenance }));
|
|
14671
|
+
} catch {}
|
|
14672
|
+
}, 200);
|
|
14673
|
+
});
|
|
14654
14674
|
const server = createServer((req, res) => {
|
|
14655
14675
|
const url = new URL(req.url || "/", `http://localhost:${p}`);
|
|
14656
14676
|
if (url.pathname === "/events") {
|
|
@@ -15186,7 +15206,7 @@ var init_serve = __esm(() => {
|
|
|
15186
15206
|
// src/cli-plot.ts
|
|
15187
15207
|
init_src();
|
|
15188
15208
|
init_history();
|
|
15189
|
-
import { readFileSync as
|
|
15209
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync4, existsSync as existsSync4 } from "fs";
|
|
15190
15210
|
import { join as join4 } from "path";
|
|
15191
15211
|
|
|
15192
15212
|
// src/init.ts
|
|
@@ -15803,10 +15823,10 @@ When \`npx ggterm-plot serve\` is running, plots auto-display in the browser/Wav
|
|
|
15803
15823
|
// src/cli-plot.ts
|
|
15804
15824
|
function isServeRunning() {
|
|
15805
15825
|
const markerPath = join4(getGGTermDir(), "serve.json");
|
|
15806
|
-
if (!
|
|
15826
|
+
if (!existsSync4(markerPath))
|
|
15807
15827
|
return false;
|
|
15808
15828
|
try {
|
|
15809
|
-
const info = JSON.parse(
|
|
15829
|
+
const info = JSON.parse(readFileSync4(markerPath, "utf-8"));
|
|
15810
15830
|
process.kill(info.pid, 0);
|
|
15811
15831
|
return true;
|
|
15812
15832
|
} catch {
|
|
@@ -15881,7 +15901,7 @@ var GEOM_TYPES = [
|
|
|
15881
15901
|
var datePattern = /^\d{4}-\d{2}-\d{2}/;
|
|
15882
15902
|
function fileExists(path) {
|
|
15883
15903
|
try {
|
|
15884
|
-
|
|
15904
|
+
readFileSync4(path);
|
|
15885
15905
|
return true;
|
|
15886
15906
|
} catch {
|
|
15887
15907
|
return false;
|
|
@@ -16026,7 +16046,7 @@ Make sure the file path is correct and the file exists.`);
|
|
|
16026
16046
|
}
|
|
16027
16047
|
let text;
|
|
16028
16048
|
try {
|
|
16029
|
-
text =
|
|
16049
|
+
text = readFileSync4(dataFile, "utf-8");
|
|
16030
16050
|
} catch (err) {
|
|
16031
16051
|
console.error(`
|
|
16032
16052
|
Error: Cannot read file: ${dataFile}`);
|
package/dist/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0eH,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0eH,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAkI/C"}
|