@chandresh726/switchy 1.3.10 → 1.3.12

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.js CHANGED
@@ -20,7 +20,7 @@ var init_package = __esm({
20
20
  "package.json"() {
21
21
  package_default = {
22
22
  name: "@chandresh726/switchy",
23
- version: "1.3.10",
23
+ version: "1.3.12",
24
24
  description: "Install, run, update, and stop the local-first Switchy application.",
25
25
  license: "MIT",
26
26
  type: "module",
@@ -688,7 +688,148 @@ var init_process_manager = __esm({
688
688
  }
689
689
  });
690
690
 
691
+ // src/paths.ts
692
+ import { mkdir as mkdir5 } from "node:fs/promises";
693
+ import os3 from "node:os";
694
+ import path13 from "node:path";
695
+ function getSwitchyPaths(configuredRoot = process.env.SWITCHY_HOME) {
696
+ const override = configuredRoot?.trim();
697
+ if (override && !path13.isAbsolute(override)) {
698
+ throw new Error("SWITCHY_HOME must be an absolute path");
699
+ }
700
+ const root = override ? path13.normalize(override) : path13.join(os3.homedir(), ".switchy");
701
+ const data = path13.join(root, "data");
702
+ const app = path13.join(root, "app");
703
+ const runtime = path13.join(root, "runtime");
704
+ const logs = path13.join(root, "logs");
705
+ const cache = path13.join(root, "cache");
706
+ return {
707
+ root,
708
+ data,
709
+ productionData: path13.join(data, "production"),
710
+ app,
711
+ versions: path13.join(app, "versions"),
712
+ currentVersion: path13.join(app, "current.json"),
713
+ runtime,
714
+ processRecord: path13.join(runtime, "process.json"),
715
+ installLock: path13.join(runtime, "install.lock"),
716
+ startLock: path13.join(runtime, "start.lock"),
717
+ logs,
718
+ logFile: path13.join(logs, "switchy.log"),
719
+ cache,
720
+ downloads: path13.join(cache, "downloads"),
721
+ playwright: path13.join(cache, "playwright"),
722
+ updateSnapshots: path13.join(root, "update-snapshots")
723
+ };
724
+ }
725
+ async function ensureSwitchyDirectories(paths) {
726
+ for (const directory of [
727
+ paths.root,
728
+ paths.data,
729
+ paths.app,
730
+ paths.versions,
731
+ paths.runtime,
732
+ paths.logs,
733
+ paths.cache,
734
+ paths.downloads,
735
+ paths.playwright,
736
+ paths.updateSnapshots
737
+ ]) {
738
+ await mkdir5(directory, { recursive: true, mode: 448 });
739
+ }
740
+ }
741
+ var init_paths = __esm({
742
+ "src/paths.ts"() {
743
+ "use strict";
744
+ }
745
+ });
746
+
747
+ // src/open.ts
748
+ var open_exports = {};
749
+ __export(open_exports, {
750
+ openCommand: () => openCommand
751
+ });
752
+ import { spawn as spawn4 } from "node:child_process";
753
+ async function openCommand() {
754
+ const running = await getRunningProcess(getSwitchyPaths());
755
+ if (!running?.live) throw new Error("Switchy is not running or is unresponsive");
756
+ const url = `http://${running.record.hostname}:${running.record.port}`;
757
+ const [executable, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
758
+ const child = spawn4(executable, args, { detached: true, stdio: "ignore" });
759
+ await new Promise((resolve, reject) => {
760
+ child.once("spawn", resolve);
761
+ child.once("error", reject);
762
+ });
763
+ child.unref();
764
+ console.log(url);
765
+ }
766
+ var init_open = __esm({
767
+ "src/open.ts"() {
768
+ "use strict";
769
+ init_paths();
770
+ init_process_manager();
771
+ }
772
+ });
773
+
774
+ // src/arguments.ts
775
+ var OPTIONS = {
776
+ start: { "--port": "value", "--app-version": "value", "--foreground": "flag" },
777
+ stop: { "--force": "flag" },
778
+ restart: {},
779
+ status: { "--json": "flag" },
780
+ doctor: {},
781
+ update: { "--check": "flag", "--download": "flag", "--apply": "flag" },
782
+ startup: {},
783
+ logs: {},
784
+ open: {},
785
+ version: {},
786
+ help: {}
787
+ };
788
+ function parseArguments(args) {
789
+ const command = args[0] ?? "help";
790
+ if (args.includes("--help") || args.includes("-h")) return { command: "help", values: /* @__PURE__ */ new Map(), startup: "status" };
791
+ const selected = command === "--version" || command === "-v" ? "version" : command;
792
+ const options = Object.hasOwn(OPTIONS, selected) ? OPTIONS[selected] : void 0;
793
+ if (!options) throw new Error(`Unknown command: ${command}`);
794
+ const values = /* @__PURE__ */ new Map();
795
+ let startup = "status";
796
+ for (let index = 1; index < args.length; index++) {
797
+ const name = args[index];
798
+ if (selected === "startup" && index === 1 && ["enable", "disable", "status"].includes(name)) {
799
+ startup = name;
800
+ continue;
801
+ }
802
+ const kind = Object.hasOwn(options, name) ? options[name] : void 0;
803
+ if (!kind) throw new Error(`Unknown option for ${selected}: ${name}`);
804
+ if (values.has(name)) throw new Error(`Duplicate option: ${name}`);
805
+ if (kind === "value") {
806
+ const value = args[++index];
807
+ if (!value || value.startsWith("-")) throw new Error(`${name} requires a value`);
808
+ values.set(name, value);
809
+ } else values.set(name, true);
810
+ }
811
+ if (selected === "update" && values.size > 1) throw new Error("Choose one update action: --check, --download, or --apply");
812
+ const port = values.get("--port");
813
+ if (typeof port === "string" && (!/^\d+$/u.test(port) || Number(port) < 1 || Number(port) > 65535)) {
814
+ throw new Error("--port must be an integer between 1 and 65535");
815
+ }
816
+ return { command: selected, values, startup };
817
+ }
818
+
819
+ // src/commands.ts
820
+ init_config();
821
+ import path16 from "node:path";
822
+
823
+ // src/controller.ts
824
+ init_config();
825
+ init_files();
826
+ init_lifecycle_state2();
827
+ init_process_manager();
828
+ import path12 from "node:path";
829
+
691
830
  // src/preferences.ts
831
+ init_files();
832
+ init_lifecycle_state2();
692
833
  import { randomUUID as randomUUID4 } from "node:crypto";
693
834
  async function saveRuntimePreference(paths, changes) {
694
835
  await withDirectoryLock(lifecycleFiles(paths).preferencesLock, async () => {
@@ -701,40 +842,10 @@ async function setRunningPreference(paths, running, port) {
701
842
  async function requestRuntimeStop(paths) {
702
843
  await saveRuntimePreference(paths, { running: false, stopToken: randomUUID4() });
703
844
  }
704
- var init_preferences = __esm({
705
- "src/preferences.ts"() {
706
- "use strict";
707
- init_files();
708
- init_lifecycle_state2();
709
- }
710
- });
711
-
712
- // src/platform.ts
713
- function isSupportedTarget(target) {
714
- return supportedTargets.has(target);
715
- }
716
- function currentTarget(platform = process.platform, architecture = process.arch) {
717
- const target = `${platform}-${architecture}`;
718
- if (!isSupportedTarget(target)) {
719
- throw new Error(`Switchy does not provide a runtime for ${target}`);
720
- }
721
- return target;
722
- }
723
- var SUPPORTED_TARGETS, supportedTargets;
724
- var init_platform = __esm({
725
- "src/platform.ts"() {
726
- "use strict";
727
- SUPPORTED_TARGETS = [
728
- "darwin-arm64",
729
- "linux-arm64",
730
- "linux-x64",
731
- "win32-x64"
732
- ];
733
- supportedTargets = new Set(SUPPORTED_TARGETS);
734
- }
735
- });
736
845
 
737
846
  // src/release.ts
847
+ init_config();
848
+ init_files();
738
849
  import { createHash, randomUUID as randomUUID5 } from "node:crypto";
739
850
  import { createReadStream, createWriteStream } from "node:fs";
740
851
  import {
@@ -749,6 +860,29 @@ import { Readable, Transform } from "node:stream";
749
860
  import { pipeline } from "node:stream/promises";
750
861
  import path8 from "node:path";
751
862
  import { extract } from "tar";
863
+
864
+ // src/platform.ts
865
+ var SUPPORTED_TARGETS = [
866
+ "darwin-arm64",
867
+ "linux-arm64",
868
+ "linux-x64",
869
+ "win32-x64"
870
+ ];
871
+ var supportedTargets = new Set(SUPPORTED_TARGETS);
872
+ function isSupportedTarget(target) {
873
+ return supportedTargets.has(target);
874
+ }
875
+ function currentTarget(platform = process.platform, architecture = process.arch) {
876
+ const target = `${platform}-${architecture}`;
877
+ if (!isSupportedTarget(target)) {
878
+ throw new Error(`Switchy does not provide a runtime for ${target}`);
879
+ }
880
+ return target;
881
+ }
882
+
883
+ // src/release.ts
884
+ var STABLE_VERSION_PATTERN = /^\d+\.\d+\.\d+$/u;
885
+ var MACOS_NOTIFIER_EXECUTABLE = "bin/Switchy Notifications.app/Contents/MacOS/SwitchyNotifier";
752
886
  function notificationRuntimeFiles(target) {
753
887
  if (!target.startsWith("darwin-")) return [];
754
888
  return [
@@ -980,21 +1114,19 @@ async function setCurrentVersion(paths, version, previousVersion) {
980
1114
  };
981
1115
  await writeJsonFileAtomic(paths.currentVersion, value);
982
1116
  }
983
- var STABLE_VERSION_PATTERN, MACOS_NOTIFIER_EXECUTABLE;
984
- var init_release = __esm({
985
- "src/release.ts"() {
986
- "use strict";
987
- init_config();
988
- init_files();
989
- init_platform();
990
- STABLE_VERSION_PATTERN = /^\d+\.\d+\.\d+$/u;
991
- MACOS_NOTIFIER_EXECUTABLE = "bin/Switchy Notifications.app/Contents/MacOS/SwitchyNotifier";
992
- }
993
- });
1117
+
1118
+ // src/updater.ts
1119
+ import { cp as cp3, readdir as readdir5, rename as rename4, rm as rm5, stat as stat6 } from "node:fs/promises";
1120
+ import path11 from "node:path";
994
1121
 
995
1122
  // src/cleanup.ts
996
1123
  import { readdir as readdir3, rm as rm4, stat as stat4 } from "node:fs/promises";
997
1124
  import path9 from "node:path";
1125
+ var STABLE_VERSION_PATTERN2 = /^\d+\.\d+\.\d+$/u;
1126
+ var DOWNLOAD_ARCHIVE_PATTERN = /^switchy-(\d+\.\d+\.\d+)-(?:darwin|linux|win32)-(?:arm64|x64)\.tar\.gz$/u;
1127
+ var INSTALL_DIRECTORY_PREFIX = ".install-";
1128
+ var UPDATE_SNAPSHOT_PREFIX = "update-";
1129
+ var RETAINED_UPDATE_SNAPSHOTS = 3;
998
1130
  async function listEntries(directory) {
999
1131
  try {
1000
1132
  return await readdir3(directory, { withFileTypes: true });
@@ -1047,19 +1179,15 @@ async function pruneInstallArtifacts(paths, retainedVersions) {
1047
1179
  }
1048
1180
  return result;
1049
1181
  }
1050
- var STABLE_VERSION_PATTERN2, DOWNLOAD_ARCHIVE_PATTERN, INSTALL_DIRECTORY_PREFIX, UPDATE_SNAPSHOT_PREFIX, RETAINED_UPDATE_SNAPSHOTS;
1051
- var init_cleanup = __esm({
1052
- "src/cleanup.ts"() {
1053
- "use strict";
1054
- STABLE_VERSION_PATTERN2 = /^\d+\.\d+\.\d+$/u;
1055
- DOWNLOAD_ARCHIVE_PATTERN = /^switchy-(\d+\.\d+\.\d+)-(?:darwin|linux|win32)-(?:arm64|x64)\.tar\.gz$/u;
1056
- INSTALL_DIRECTORY_PREFIX = ".install-";
1057
- UPDATE_SNAPSHOT_PREFIX = "update-";
1058
- RETAINED_UPDATE_SNAPSHOTS = 3;
1059
- }
1060
- });
1182
+
1183
+ // src/updater.ts
1184
+ init_files();
1185
+ init_lifecycle_state2();
1186
+ init_process_manager();
1061
1187
 
1062
1188
  // src/runtime.ts
1189
+ init_lifecycle_state2();
1190
+ init_files();
1063
1191
  import { spawn as spawn2 } from "node:child_process";
1064
1192
  import { cp as cp2, mkdir as mkdir4, open as open4, readdir as readdir4, stat as stat5 } from "node:fs/promises";
1065
1193
  import path10 from "node:path";
@@ -1170,17 +1298,8 @@ async function syncTree(directory) {
1170
1298
  }
1171
1299
  await syncDirectory(directory);
1172
1300
  }
1173
- var init_runtime = __esm({
1174
- "src/runtime.ts"() {
1175
- "use strict";
1176
- init_lifecycle_state2();
1177
- init_files();
1178
- }
1179
- });
1180
1301
 
1181
1302
  // src/updater.ts
1182
- import { cp as cp3, readdir as readdir5, rename as rename4, rm as rm5, stat as stat6 } from "node:fs/promises";
1183
- import path11 from "node:path";
1184
1303
  async function appRequest(paths, route, method = "GET") {
1185
1304
  const running = await getRunningProcess(paths);
1186
1305
  if (!running?.live || running.live.instanceId !== running.record.instanceId) {
@@ -1411,21 +1530,8 @@ async function withUpdateLock(paths, operation) {
1411
1530
  }
1412
1531
  });
1413
1532
  }
1414
- var init_updater = __esm({
1415
- "src/updater.ts"() {
1416
- "use strict";
1417
- init_cleanup();
1418
- init_files();
1419
- init_lifecycle_state2();
1420
- init_process_manager();
1421
- init_preferences();
1422
- init_release();
1423
- init_runtime();
1424
- }
1425
- });
1426
1533
 
1427
1534
  // src/controller.ts
1428
- import path12 from "node:path";
1429
1535
  async function startRuntime(paths, options = {}) {
1430
1536
  const stopToken = (await readPreferences(paths)).stopToken;
1431
1537
  await withDirectoryLock(paths.startLock, () => recoverInterruptedUpdate(paths));
@@ -1498,82 +1604,37 @@ async function restartRuntime(paths) {
1498
1604
  return record;
1499
1605
  });
1500
1606
  }
1501
- var init_controller = __esm({
1502
- "src/controller.ts"() {
1503
- "use strict";
1504
- init_config();
1505
- init_files();
1506
- init_lifecycle_state2();
1507
- init_process_manager();
1508
- init_preferences();
1509
- init_release();
1510
- init_updater();
1511
- }
1512
- });
1513
1607
 
1514
- // src/paths.ts
1515
- import { mkdir as mkdir5 } from "node:fs/promises";
1516
- import os3 from "node:os";
1517
- import path13 from "node:path";
1518
- function getSwitchyPaths(configuredRoot = process.env.SWITCHY_HOME) {
1519
- const override = configuredRoot?.trim();
1520
- if (override && !path13.isAbsolute(override)) {
1521
- throw new Error("SWITCHY_HOME must be an absolute path");
1522
- }
1523
- const root = override ? path13.normalize(override) : path13.join(os3.homedir(), ".switchy");
1524
- const data = path13.join(root, "data");
1525
- const app = path13.join(root, "app");
1526
- const runtime = path13.join(root, "runtime");
1527
- const logs = path13.join(root, "logs");
1528
- const cache = path13.join(root, "cache");
1529
- return {
1530
- root,
1531
- data,
1532
- productionData: path13.join(data, "production"),
1533
- app,
1534
- versions: path13.join(app, "versions"),
1535
- currentVersion: path13.join(app, "current.json"),
1536
- runtime,
1537
- processRecord: path13.join(runtime, "process.json"),
1538
- installLock: path13.join(runtime, "install.lock"),
1539
- startLock: path13.join(runtime, "start.lock"),
1540
- logs,
1541
- logFile: path13.join(logs, "switchy.log"),
1542
- cache,
1543
- downloads: path13.join(cache, "downloads"),
1544
- playwright: path13.join(cache, "playwright"),
1545
- updateSnapshots: path13.join(root, "update-snapshots")
1546
- };
1547
- }
1548
- async function ensureSwitchyDirectories(paths) {
1549
- for (const directory of [
1550
- paths.root,
1551
- paths.data,
1552
- paths.app,
1553
- paths.versions,
1554
- paths.runtime,
1555
- paths.logs,
1556
- paths.cache,
1557
- paths.downloads,
1558
- paths.playwright,
1559
- paths.updateSnapshots
1560
- ]) {
1561
- await mkdir5(directory, { recursive: true, mode: 448 });
1562
- }
1563
- }
1564
- var init_paths = __esm({
1565
- "src/paths.ts"() {
1566
- "use strict";
1567
- }
1568
- });
1608
+ // src/commands.ts
1609
+ init_files();
1610
+ init_lifecycle_state2();
1611
+
1612
+ // src/lifecycle-daemon.ts
1613
+ init_files();
1614
+ import { watch } from "node:fs";
1615
+ import { mkdir as mkdir7 } from "node:fs/promises";
1616
+
1617
+ // src/lifecycle-manager.ts
1618
+ import { randomUUID as randomUUID7 } from "node:crypto";
1619
+ import { readdir as readdir6, rename as rename6 } from "node:fs/promises";
1620
+ import path15 from "node:path";
1621
+ init_files();
1622
+ init_lifecycle_state2();
1623
+ init_paths();
1624
+ init_process_manager();
1569
1625
 
1570
1626
  // src/startup.ts
1627
+ init_files();
1628
+ init_startup_environment();
1629
+ init_lifecycle_state2();
1571
1630
  import { execFile, spawn as spawn3 } from "node:child_process";
1572
1631
  import { randomUUID as randomUUID6 } from "node:crypto";
1573
1632
  import { chmod, copyFile, link, mkdir as mkdir6, open as open5, readFile as readFile4, rename as rename5, rm as rm6, stat as stat7 } from "node:fs/promises";
1574
1633
  import os4 from "node:os";
1575
1634
  import path14 from "node:path";
1576
1635
  import { promisify } from "node:util";
1636
+ var execute = promisify(execFile);
1637
+ var LABEL = "com.switchy.lifecycle";
1577
1638
  function escapeXml(value) {
1578
1639
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
1579
1640
  }
@@ -1593,6 +1654,39 @@ function startupPlist(paths, executable = path14.join(lifecycleFiles(paths).host
1593
1654
  </dict></plist>
1594
1655
  `;
1595
1656
  }
1657
+ var SUPERVISOR = `const fs = require('node:fs');
1658
+ const path = require('node:path');
1659
+ const { spawn } = require('node:child_process');
1660
+ const root = process.env.SWITCHY_HOME;
1661
+ let login = process.argv.includes('--login');
1662
+ let child;
1663
+ let stopping = false;
1664
+ for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => {
1665
+ stopping = true;
1666
+ if (child) child.kill('SIGTERM'); else process.exit(0);
1667
+ });
1668
+ function start() {
1669
+ let current;
1670
+ try { current = JSON.parse(fs.readFileSync(path.join(root, 'app/current.json'), 'utf8')); }
1671
+ catch (error) { if (error.code === 'ENOENT') return; throw error; }
1672
+ if (!/^\\d+\\.\\d+\\.\\d+$/.test(current.version)) throw Error('Invalid installed version');
1673
+ const worker = path.join(root, 'app/versions', current.version, 'bin/lifecycle.cjs');
1674
+ if (!fs.existsSync(worker)) return;
1675
+ const metadata = JSON.parse(fs.readFileSync(path.join(root, 'app/host/node.json'), 'utf8'));
1676
+ child = spawn(path.join(root, 'app/host', metadata.file), [worker, login ? 'serve-login' : 'serve'], {
1677
+ env: { ...process.env, SWITCHY_HOME: root }, stdio: 'inherit', windowsHide: true
1678
+ });
1679
+ child.once('error', error => { console.error('Switchy lifecycle:', error.message); process.exitCode = 1; });
1680
+ child.once('exit', code => {
1681
+ child = undefined;
1682
+ if (stopping || code === 20) return;
1683
+ login = false;
1684
+ if (code === 21) start();
1685
+ else setTimeout(start, 30000);
1686
+ });
1687
+ }
1688
+ start();
1689
+ `;
1596
1690
  async function hostNode(paths) {
1597
1691
  const metadata = await readJsonFile(path14.join(lifecycleFiles(paths).host, "node.json"));
1598
1692
  if (!metadata || !/^node-24\.\d+\.\d+(?:\.exe)?$/u.test(metadata.file)) throw new Error("Switchy manager Node metadata is invalid");
@@ -1688,55 +1782,8 @@ async function setStartupRegistration(paths, enabled) {
1688
1782
  if (uid !== void 0) await execute("/bin/launchctl", ["enable", `gui/${uid}/${LABEL}`]);
1689
1783
  }
1690
1784
  }
1691
- var execute, LABEL, SUPERVISOR;
1692
- var init_startup = __esm({
1693
- "src/startup.ts"() {
1694
- "use strict";
1695
- init_files();
1696
- init_startup_environment();
1697
- init_lifecycle_state2();
1698
- execute = promisify(execFile);
1699
- LABEL = "com.switchy.lifecycle";
1700
- SUPERVISOR = `const fs = require('node:fs');
1701
- const path = require('node:path');
1702
- const { spawn } = require('node:child_process');
1703
- const root = process.env.SWITCHY_HOME;
1704
- let login = process.argv.includes('--login');
1705
- let child;
1706
- let stopping = false;
1707
- for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => {
1708
- stopping = true;
1709
- if (child) child.kill('SIGTERM'); else process.exit(0);
1710
- });
1711
- function start() {
1712
- let current;
1713
- try { current = JSON.parse(fs.readFileSync(path.join(root, 'app/current.json'), 'utf8')); }
1714
- catch (error) { if (error.code === 'ENOENT') return; throw error; }
1715
- if (!/^\\d+\\.\\d+\\.\\d+$/.test(current.version)) throw Error('Invalid installed version');
1716
- const worker = path.join(root, 'app/versions', current.version, 'bin/lifecycle.cjs');
1717
- if (!fs.existsSync(worker)) return;
1718
- const metadata = JSON.parse(fs.readFileSync(path.join(root, 'app/host/node.json'), 'utf8'));
1719
- child = spawn(path.join(root, 'app/host', metadata.file), [worker, login ? 'serve-login' : 'serve'], {
1720
- env: { ...process.env, SWITCHY_HOME: root }, stdio: 'inherit', windowsHide: true
1721
- });
1722
- child.once('error', error => { console.error('Switchy lifecycle:', error.message); process.exitCode = 1; });
1723
- child.once('exit', code => {
1724
- child = undefined;
1725
- if (stopping || code === 20) return;
1726
- login = false;
1727
- if (code === 21) start();
1728
- else setTimeout(start, 30000);
1729
- });
1730
- }
1731
- start();
1732
- `;
1733
- }
1734
- });
1735
1785
 
1736
1786
  // src/lifecycle-manager.ts
1737
- import { readdir as readdir6, rename as rename6 } from "node:fs/promises";
1738
- import { randomUUID as randomUUID7 } from "node:crypto";
1739
- import path15 from "node:path";
1740
1787
  async function configureLifecycle(paths, changes) {
1741
1788
  await withDirectoryLock(lifecycleFiles(paths).preferencesLock, async () => {
1742
1789
  const running = await getRunningProcess(paths);
@@ -1767,7 +1814,7 @@ async function lifecycleTick(login = false) {
1767
1814
  const preferences = await readPreferences(paths);
1768
1815
  const current = { version: record.version };
1769
1816
  if (login && preferences.openAtLogin) {
1770
- const { openCommand: openCommand2 } = await Promise.resolve().then(() => (init_commands(), commands_exports));
1817
+ const { openCommand: openCommand2 } = await Promise.resolve().then(() => (init_open(), open_exports));
1771
1818
  await openCommand2();
1772
1819
  }
1773
1820
  const queued = await nextUpdateRequest(paths);
@@ -1826,24 +1873,11 @@ async function takeLegacyRequest(file) {
1826
1873
  }
1827
1874
  return { file: claimed, request: await readJsonFile(claimed) };
1828
1875
  }
1829
- var init_lifecycle_manager = __esm({
1830
- "src/lifecycle-manager.ts"() {
1831
- "use strict";
1832
- init_files();
1833
- init_lifecycle_state2();
1834
- init_paths();
1835
- init_process_manager();
1836
- init_release();
1837
- init_startup();
1838
- init_controller();
1839
- init_preferences();
1840
- init_updater();
1841
- }
1842
- });
1843
1876
 
1844
1877
  // src/lifecycle-daemon.ts
1845
- import { watch } from "node:fs";
1846
- import { mkdir as mkdir7 } from "node:fs/promises";
1878
+ init_lifecycle_state2();
1879
+ init_paths();
1880
+ init_logs();
1847
1881
  async function serveLifecycle(login) {
1848
1882
  const paths = getSwitchyPaths();
1849
1883
  await ensureSwitchyDirectories(paths);
@@ -1910,18 +1944,10 @@ async function serveLifecycle(login) {
1910
1944
  throw error;
1911
1945
  }
1912
1946
  }
1913
- var init_lifecycle_daemon = __esm({
1914
- "src/lifecycle-daemon.ts"() {
1915
- "use strict";
1916
- init_files();
1917
- init_lifecycle_manager();
1918
- init_lifecycle_state2();
1919
- init_paths();
1920
- init_logs();
1921
- }
1922
- });
1923
1947
 
1924
1948
  // src/lifecycle.ts
1949
+ init_lifecycle_state2();
1950
+ init_paths();
1925
1951
  async function prepareLifecycleHost(paths, runtimeDirectory) {
1926
1952
  if (process.env.SWITCHY_DISABLE_LIFECYCLE === "1") return;
1927
1953
  if (!await installHost(paths, runtimeDirectory)) return;
@@ -1952,32 +1978,11 @@ async function lifecycleCommand(action) {
1952
1978
  throw new Error("Use startup enable, disable, or status");
1953
1979
  }
1954
1980
  }
1955
- var init_lifecycle = __esm({
1956
- "src/lifecycle.ts"() {
1957
- "use strict";
1958
- init_lifecycle_daemon();
1959
- init_lifecycle_manager();
1960
- init_lifecycle_state2();
1961
- init_paths();
1962
- init_startup();
1963
- }
1964
- });
1965
1981
 
1966
1982
  // src/commands.ts
1967
- var commands_exports = {};
1968
- __export(commands_exports, {
1969
- doctorCommand: () => doctorCommand,
1970
- logsCommand: () => logsCommand,
1971
- openCommand: () => openCommand,
1972
- restartCommand: () => restartCommand,
1973
- startCommand: () => startCommand,
1974
- statusCommand: () => statusCommand,
1975
- stopCommand: () => stopCommand,
1976
- updateCommand: () => updateCommand,
1977
- versionCommand: () => versionCommand
1978
- });
1979
- import { spawn as spawn4 } from "node:child_process";
1980
- import path16 from "node:path";
1983
+ init_logs();
1984
+ init_paths();
1985
+ init_process_manager();
1981
1986
  async function startCommand(options = {}) {
1982
1987
  const paths = getSwitchyPaths();
1983
1988
  await ensureSwitchyDirectories(paths);
@@ -2083,87 +2088,13 @@ async function updateCommand(action = "install") {
2083
2088
  async function logsCommand() {
2084
2089
  console.log(await readLogTail(getSwitchyPaths().logFile));
2085
2090
  }
2086
- async function openCommand() {
2087
- const running = await getRunningProcess(getSwitchyPaths());
2088
- if (!running?.live) throw new Error("Switchy is not running or is unresponsive");
2089
- const url = `http://${running.record.hostname}:${running.record.port}`;
2090
- const [executable, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
2091
- const child = spawn4(executable, args, { detached: true, stdio: "ignore" });
2092
- await new Promise((resolve, reject) => {
2093
- child.once("spawn", resolve);
2094
- child.once("error", reject);
2095
- });
2096
- child.unref();
2097
- console.log(url);
2098
- }
2099
2091
  function versionCommand() {
2100
2092
  console.log(CLI_VERSION);
2101
2093
  }
2102
- var init_commands = __esm({
2103
- "src/commands.ts"() {
2104
- "use strict";
2105
- init_config();
2106
- init_controller();
2107
- init_files();
2108
- init_lifecycle();
2109
- init_lifecycle_state2();
2110
- init_logs();
2111
- init_paths();
2112
- init_process_manager();
2113
- init_release();
2114
- init_updater();
2115
- }
2116
- });
2117
-
2118
- // src/arguments.ts
2119
- var OPTIONS = {
2120
- start: { "--port": "value", "--app-version": "value", "--foreground": "flag" },
2121
- stop: { "--force": "flag" },
2122
- restart: {},
2123
- status: { "--json": "flag" },
2124
- doctor: {},
2125
- update: { "--check": "flag", "--download": "flag", "--apply": "flag" },
2126
- startup: {},
2127
- logs: {},
2128
- open: {},
2129
- version: {},
2130
- help: {}
2131
- };
2132
- function parseArguments(args) {
2133
- const command = args[0] ?? "help";
2134
- if (args.includes("--help") || args.includes("-h")) return { command: "help", values: /* @__PURE__ */ new Map(), startup: "status" };
2135
- const selected = command === "--version" || command === "-v" ? "version" : command;
2136
- const options = Object.hasOwn(OPTIONS, selected) ? OPTIONS[selected] : void 0;
2137
- if (!options) throw new Error(`Unknown command: ${command}`);
2138
- const values = /* @__PURE__ */ new Map();
2139
- let startup = "status";
2140
- for (let index = 1; index < args.length; index++) {
2141
- const name = args[index];
2142
- if (selected === "startup" && index === 1 && ["enable", "disable", "status"].includes(name)) {
2143
- startup = name;
2144
- continue;
2145
- }
2146
- const kind = Object.hasOwn(options, name) ? options[name] : void 0;
2147
- if (!kind) throw new Error(`Unknown option for ${selected}: ${name}`);
2148
- if (values.has(name)) throw new Error(`Duplicate option: ${name}`);
2149
- if (kind === "value") {
2150
- const value = args[++index];
2151
- if (!value || value.startsWith("-")) throw new Error(`${name} requires a value`);
2152
- values.set(name, value);
2153
- } else values.set(name, true);
2154
- }
2155
- if (selected === "update" && values.size > 1) throw new Error("Choose one update action: --check, --download, or --apply");
2156
- const port = values.get("--port");
2157
- if (typeof port === "string" && (!/^\d+$/u.test(port) || Number(port) < 1 || Number(port) > 65535)) {
2158
- throw new Error("--port must be an integer between 1 and 65535");
2159
- }
2160
- return { command: selected, values, startup };
2161
- }
2162
2094
 
2163
2095
  // src/cli.ts
2164
- init_commands();
2165
2096
  init_config();
2166
- init_lifecycle();
2097
+ init_open();
2167
2098
  async function main() {
2168
2099
  assertSupportedNodeVersion();
2169
2100
  const { command, values, startup } = parseArguments(process.argv.slice(2));