@envmanager-cli/cli 0.1.8 → 0.1.9
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/bin/envmanager.js +51 -10
- package/dist/bin/envmanager.js.map +1 -1
- package/package.json +1 -1
package/dist/bin/envmanager.js
CHANGED
|
@@ -1509,6 +1509,12 @@ async function subscribeToVariableChanges(environmentId, onEvent, onStatus) {
|
|
|
1509
1509
|
channel.on("broadcast", { event: "variable_change" }, (payload) => {
|
|
1510
1510
|
onEvent(payload.payload);
|
|
1511
1511
|
});
|
|
1512
|
+
channel.on("broadcast", { event: "*" }, (payload) => {
|
|
1513
|
+
const data = payload.payload;
|
|
1514
|
+
if (data?.action && data?.key && data?.environment_id) {
|
|
1515
|
+
onEvent(data);
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1512
1518
|
channel.on("system", { event: "*" }, (status) => {
|
|
1513
1519
|
if (status.event === "connected") {
|
|
1514
1520
|
reconnectAttempts = 0;
|
|
@@ -1750,6 +1756,38 @@ var devCommand = new Command9("dev").description("Start real-time sync daemon -
|
|
|
1750
1756
|
spinner.text = "Connecting to realtime...";
|
|
1751
1757
|
let fileWatcher = null;
|
|
1752
1758
|
let isPaused = false;
|
|
1759
|
+
let lastRemoteKeys = null;
|
|
1760
|
+
async function syncRemoteToLocal(silent = false) {
|
|
1761
|
+
const updatedVariables = await fetchAllVariables(environmentId, true);
|
|
1762
|
+
const currentLocal = /* @__PURE__ */ new Map();
|
|
1763
|
+
if (existsSync7(outputFile)) {
|
|
1764
|
+
const content = readFileSync6(outputFile, "utf-8");
|
|
1765
|
+
Object.entries(parseDotenv3(content)).forEach(([k, v]) => {
|
|
1766
|
+
currentLocal.set(k, v);
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
const newMerged = mergeWithRemote(currentLocal, updatedVariables, strategy);
|
|
1770
|
+
const remoteKeySig = [...newMerged.entries()].sort().map(([k, v]) => `${k}=${v}`).join("\n");
|
|
1771
|
+
if (remoteKeySig === lastRemoteKeys) return false;
|
|
1772
|
+
lastRemoteKeys = remoteKeySig;
|
|
1773
|
+
if (!silent) {
|
|
1774
|
+
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
1775
|
+
for (const key of currentLocal.keys()) {
|
|
1776
|
+
if (!newMerged.has(key)) {
|
|
1777
|
+
console.log(chalk10.red(`[${timestamp}] - ${key}`));
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
for (const [key] of newMerged) {
|
|
1781
|
+
if (!currentLocal.has(key)) {
|
|
1782
|
+
console.log(chalk10.green(`[${timestamp}] + ${key}`));
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
writeFileSync3(outputFile, formatEnvFile(newMerged));
|
|
1787
|
+
return true;
|
|
1788
|
+
}
|
|
1789
|
+
const initialKeys = [...merged.entries()].sort().map(([k, v]) => `${k}=${v}`).join("\n");
|
|
1790
|
+
lastRemoteKeys = initialKeys;
|
|
1753
1791
|
const subscription = await subscribeToVariableChanges(
|
|
1754
1792
|
environmentId,
|
|
1755
1793
|
async (event) => {
|
|
@@ -1772,16 +1810,7 @@ var devCommand = new Command9("dev").description("Start real-time sync daemon -
|
|
|
1772
1810
|
}
|
|
1773
1811
|
isPaused = true;
|
|
1774
1812
|
try {
|
|
1775
|
-
|
|
1776
|
-
const currentLocal = /* @__PURE__ */ new Map();
|
|
1777
|
-
if (existsSync7(outputFile)) {
|
|
1778
|
-
const content = readFileSync6(outputFile, "utf-8");
|
|
1779
|
-
Object.entries(parseDotenv3(content)).forEach(([k, v]) => {
|
|
1780
|
-
currentLocal.set(k, v);
|
|
1781
|
-
});
|
|
1782
|
-
}
|
|
1783
|
-
const newMerged = mergeWithRemote(currentLocal, updatedVariables, strategy);
|
|
1784
|
-
writeFileSync3(outputFile, formatEnvFile(newMerged));
|
|
1813
|
+
await syncRemoteToLocal(true);
|
|
1785
1814
|
} finally {
|
|
1786
1815
|
isPaused = false;
|
|
1787
1816
|
}
|
|
@@ -1828,6 +1857,17 @@ Realtime error: ${message || ""}`));
|
|
|
1828
1857
|
console.log(chalk10.gray("Watching for changes. Press Ctrl+C to stop."));
|
|
1829
1858
|
console.log("");
|
|
1830
1859
|
let isCleaningUp = false;
|
|
1860
|
+
const POLL_INTERVAL_MS = 5e3;
|
|
1861
|
+
const pollInterval = setInterval(async () => {
|
|
1862
|
+
if (isPaused) return;
|
|
1863
|
+
isPaused = true;
|
|
1864
|
+
try {
|
|
1865
|
+
await syncRemoteToLocal();
|
|
1866
|
+
} catch {
|
|
1867
|
+
} finally {
|
|
1868
|
+
isPaused = false;
|
|
1869
|
+
}
|
|
1870
|
+
}, POLL_INTERVAL_MS);
|
|
1831
1871
|
const TOKEN_REFRESH_INTERVAL_MS = 30 * 60 * 1e3;
|
|
1832
1872
|
const refreshInterval = setInterval(async () => {
|
|
1833
1873
|
try {
|
|
@@ -1842,6 +1882,7 @@ Realtime error: ${message || ""}`));
|
|
|
1842
1882
|
}
|
|
1843
1883
|
isCleaningUp = true;
|
|
1844
1884
|
console.log(chalk10.gray("\nStopping dev mode..."));
|
|
1885
|
+
clearInterval(pollInterval);
|
|
1845
1886
|
clearInterval(refreshInterval);
|
|
1846
1887
|
fileWatcher?.stop();
|
|
1847
1888
|
subscription.unsubscribe().catch(() => {
|