@marcingadomski94/switchboard 2.4.42 → 2.4.43
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/lib/installer.mjs +41 -0
- package/package.json +1 -1
package/lib/installer.mjs
CHANGED
|
@@ -261,6 +261,9 @@ Usage: npx @marcingadomski94/switchboard [options]
|
|
|
261
261
|
--purge with --uninstall: also remove the data folder
|
|
262
262
|
--help this text
|
|
263
263
|
|
|
264
|
+
backup [--out <file or folder>] an encrypted backup of everything (asks for a passphrase)
|
|
265
|
+
restore <file> [--map <old>=<new>]... restore a backup into this computer's Switchboard (stopped)
|
|
266
|
+
|
|
264
267
|
Running it again upgrades to the latest release or repairs the installed one.
|
|
265
268
|
No sudo, no shell profile changes, no telemetry.`;
|
|
266
269
|
|
|
@@ -632,6 +635,30 @@ class Installer {
|
|
|
632
635
|
return names.every((name) => /^(switchboard-|\.staging-)/.test(name) || name === 'switchboard.log' || name === 'switchboard.pid');
|
|
633
636
|
}
|
|
634
637
|
|
|
638
|
+
/**
|
|
639
|
+
* D168: `switchboard backup|restore …` runs the installed app's own tool (`tools/backup/cli.ts`,
|
|
640
|
+
* the newest installed version that has it), with this terminal (the passphrase is asked there).
|
|
641
|
+
* @param {readonly string[]} argv the command and its arguments
|
|
642
|
+
* @returns {Promise<number>} its exit code
|
|
643
|
+
*/
|
|
644
|
+
async runTool(argv) {
|
|
645
|
+
await this.canonical();
|
|
646
|
+
const candidates = [
|
|
647
|
+
...(await readdir(this.dir).catch(() => [])).filter((name) => name.startsWith('switchboard-')).map((name) => this.lib.join(this.dir, name)),
|
|
648
|
+
...(await readdir(this.lib.join(this.dataDir, 'versions')).catch(() => [])).map((name) => this.lib.join(this.dataDir, 'versions', name)),
|
|
649
|
+
];
|
|
650
|
+
const withTool = [];
|
|
651
|
+
for (const candidate of candidates) if (await exists(this.lib.join(candidate, 'tools', 'backup', 'cli.ts'))) withTool.push(candidate);
|
|
652
|
+
const versionOf = (/** @type {string} */ dir) => releaseVersion(this.lib.basename(dir).replace(/^switchboard-/, '')) ?? '0.0.0';
|
|
653
|
+
const newest = withTool.sort((a, b) => compareVersions(versionOf(b), versionOf(a)))[0];
|
|
654
|
+
if (!newest) fail(`no installed Switchboard with backup and restore was found in ${this.dir} (update it first)`);
|
|
655
|
+
return new Promise((resolve, reject) => {
|
|
656
|
+
const child = spawn(process.execPath, [this.lib.join('tools', 'backup', 'cli.ts'), ...argv], { cwd: newest, env: this.env, shell: false, stdio: 'inherit' });
|
|
657
|
+
child.once('error', reject);
|
|
658
|
+
child.once('close', (code) => resolve(code ?? 1));
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
|
|
635
662
|
async uninstall() {
|
|
636
663
|
await this.canonical();
|
|
637
664
|
this.log(`Uninstalling Switchboard from ${this.dir}`);
|
|
@@ -694,6 +721,20 @@ class Installer {
|
|
|
694
721
|
*/
|
|
695
722
|
export async function main(argv, io = {}) {
|
|
696
723
|
const log = io.log ?? ((line) => console.log(line));
|
|
724
|
+
// D168: backup and restore run the installed app's own tool.
|
|
725
|
+
if (argv[0] === 'backup' || argv[0] === 'restore') {
|
|
726
|
+
const env = io.env ?? process.env;
|
|
727
|
+
try {
|
|
728
|
+
const installer = new Installer(/** @type {Options} */ (parseArgs([])), { env, platform: process.platform, home: env['HOME'] && process.platform !== 'win32' ? env['HOME'] : os.homedir(), log, interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY) });
|
|
729
|
+
return await installer.runTool(argv);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
if (error instanceof InstallError) {
|
|
732
|
+
console.error(`switchboard ${argv[0]}: ${error.message}`);
|
|
733
|
+
return 1;
|
|
734
|
+
}
|
|
735
|
+
throw error;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
697
738
|
const options = parseArgs(argv);
|
|
698
739
|
if (typeof options === 'string') {
|
|
699
740
|
console.error(`switchboard install: ${options}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcingadomski94/switchboard",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.43",
|
|
4
4
|
"description": "Installs Switchboard, the local web app to run, supervise and switch many Claude Code, Codex CLI and OpenCode sessions at once: npx @marcingadomski94/switchboard",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"mcpName": "io.github.MarcinGadomski94/switchboard",
|