@jamiefutch/pi-backup 1.1.7 → 1.1.8
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.
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { execSync } from "node:child_process";
|
|
2
|
+
import { execSync, execFileSync } from "node:child_process";
|
|
3
3
|
import { join, dirname } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { existsSync, mkdirSync, readdirSync, statSync, readFileSync, writeFileSync, rmSync, cpSync } from "node:fs";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const HOME_DIR = process.env.HOME || process.env.USERPROFILE || "";
|
|
8
|
+
const IS_WINDOWS = process.platform === "win32";
|
|
9
|
+
const PI_ROOT = join(HOME_DIR, ".pi");
|
|
8
10
|
const INTERNAL_BACKUP_DIR = join(PI_ROOT, "backups");
|
|
9
11
|
const SETTINGS_FILE = join(PI_ROOT, "agent", "settings.json");
|
|
10
|
-
const DEFAULT_EXTERNAL_DIR = join(
|
|
12
|
+
const DEFAULT_EXTERNAL_DIR = join(HOME_DIR, "projects", "personal", "pi-utils", "backups");
|
|
11
13
|
const PACKAGE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
12
14
|
|
|
13
15
|
interface BackupInfo {
|
|
@@ -81,11 +83,11 @@ function resolveExternalBackupDir(ctx?: any): string {
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
function getBackupScriptPath(): string {
|
|
84
|
-
|
|
86
|
+
return join(PACKAGE_ROOT, IS_WINDOWS ? "backup-pi.ps1" : "backup-pi.sh");
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
function getRestoreScriptPath(): string {
|
|
88
|
-
|
|
90
|
+
return join(PACKAGE_ROOT, IS_WINDOWS ? "restore-pi.ps1" : "restore-pi.sh");
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
function ensureDirs(externalDir: string) {
|
|
@@ -206,7 +208,9 @@ function runBackup(internal: boolean, ctx?: any): { success: boolean; output: st
|
|
|
206
208
|
env.BACKUP_ROOT = externalDir;
|
|
207
209
|
env.KEEP_UNCOMPRESSED = "0"; // external: compressed archive only
|
|
208
210
|
}
|
|
209
|
-
|
|
211
|
+
const command = IS_WINDOWS ? "pwsh" : getBackupScriptPath();
|
|
212
|
+
const args = IS_WINDOWS ? ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", getBackupScriptPath()] : [];
|
|
213
|
+
const output = execFileSync(command, args, { env, encoding: "utf-8", maxBuffer: 10 * 1024 * 1024 });
|
|
210
214
|
const match = output.match(/Staging:\s+(.+)$/m) || output.match(/Archive:\s+(.+)$/m);
|
|
211
215
|
const backupPath = match ? match[1].trim() : undefined;
|
|
212
216
|
return { success: true, output, backupPath };
|
|
@@ -217,7 +221,9 @@ function runBackup(internal: boolean, ctx?: any): { success: boolean; output: st
|
|
|
217
221
|
|
|
218
222
|
function runRestore(backupPath: string): { success: boolean; output: string } {
|
|
219
223
|
try {
|
|
220
|
-
|
|
224
|
+
const command = IS_WINDOWS ? "pwsh" : getRestoreScriptPath();
|
|
225
|
+
const args = IS_WINDOWS ? ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", getRestoreScriptPath(), backupPath] : [backupPath];
|
|
226
|
+
const output = execFileSync(command, args, { encoding: "utf-8", maxBuffer: 10 * 1024 * 1024 });
|
|
221
227
|
return { success: true, output };
|
|
222
228
|
} catch (e: any) {
|
|
223
229
|
return { success: false, output: e.stdout || e.stderr || e.message };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamiefutch/pi-backup",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Pi package: Pi backup/restore scripts and TUI extension. Back up and restore all Pi config, skills, extensions, and memory; /pi-backup interactive manager.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|