@anraktech/sync 0.8.0 → 0.10.0
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 +59 -41
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -980,28 +980,49 @@ function startAIAgent(ctx) {
|
|
|
980
980
|
{ role: "system", content: buildSystemPrompt(ctx.config) }
|
|
981
981
|
];
|
|
982
982
|
const rl = createInterface({ input: stdin, output: stdout });
|
|
983
|
-
const
|
|
984
|
-
const line = chalk2.dim("\u2500".repeat(cols));
|
|
983
|
+
const W = Math.min(process.stdout.columns || 60, 60);
|
|
985
984
|
const watchDisplay = ctx.config.watchFolder.startsWith(HOME) ? "~" + ctx.config.watchFolder.slice(HOME.length) : ctx.config.watchFolder;
|
|
986
985
|
const stats = ctx.bootStats;
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
986
|
+
const pad = (s, len) => {
|
|
987
|
+
const visible = s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
988
|
+
const diff = len - visible.length;
|
|
989
|
+
return diff > 0 ? s + " ".repeat(diff) : s;
|
|
990
|
+
};
|
|
991
|
+
const inner = W - 4;
|
|
992
|
+
const title = ` AnrakLegal Sync v${PKG_VERSION} `;
|
|
993
|
+
const topRest = W - 2 - title.length;
|
|
994
|
+
const topLeft = Math.max(1, 1);
|
|
995
|
+
const topRight = Math.max(1, topRest - topLeft);
|
|
996
|
+
const top = chalk2.dim("\u256D" + "\u2500".repeat(topLeft)) + chalk2.bold(title) + chalk2.dim("\u2500".repeat(topRight) + "\u256E");
|
|
997
|
+
const bot = chalk2.dim("\u2570" + "\u2500".repeat(W - 2) + "\u256F");
|
|
998
|
+
const empty = chalk2.dim("\u2502") + " ".repeat(W - 2) + chalk2.dim("\u2502");
|
|
999
|
+
const row = (s) => chalk2.dim("\u2502") + " " + pad(s, inner) + " " + chalk2.dim("\u2502");
|
|
1000
|
+
let statusLine = "";
|
|
994
1001
|
if (stats) {
|
|
995
|
-
|
|
1002
|
+
const parts = [`${stats.cases} case${stats.cases !== 1 ? "s" : ""}`];
|
|
996
1003
|
if (stats.scanned > 0) {
|
|
997
|
-
|
|
1004
|
+
parts.push(`${stats.scanned} files scanned`);
|
|
1005
|
+
}
|
|
1006
|
+
if (stats.queued > 0) {
|
|
1007
|
+
parts.push(chalk2.yellow(`${stats.queued} synced`));
|
|
1008
|
+
} else {
|
|
1009
|
+
parts.push(chalk2.green("up to date"));
|
|
998
1010
|
}
|
|
1011
|
+
statusLine = parts.join(chalk2.dim(" \xB7 "));
|
|
999
1012
|
}
|
|
1000
1013
|
console.log("");
|
|
1001
|
-
console.log(
|
|
1002
|
-
console.log(
|
|
1003
|
-
console.log(chalk2.dim("
|
|
1004
|
-
console.log(chalk2.dim(
|
|
1014
|
+
console.log(top);
|
|
1015
|
+
console.log(empty);
|
|
1016
|
+
console.log(row(`${chalk2.dim("Folder")} ${watchDisplay}`));
|
|
1017
|
+
console.log(row(`${chalk2.dim("Server")} ${ctx.config.apiUrl}`));
|
|
1018
|
+
if (statusLine) {
|
|
1019
|
+
console.log(row(`${chalk2.dim("Status")} ${statusLine}`));
|
|
1020
|
+
}
|
|
1021
|
+
console.log(empty);
|
|
1022
|
+
console.log(row(chalk2.dim("Type naturally to manage your files.")));
|
|
1023
|
+
console.log(row(chalk2.dim('"show my cases" \xB7 "look at downloads" \xB7 "sync"')));
|
|
1024
|
+
console.log(empty);
|
|
1025
|
+
console.log(bot);
|
|
1005
1026
|
console.log("");
|
|
1006
1027
|
const PROMPT = `${chalk2.bold.blue("\u276F")} `;
|
|
1007
1028
|
async function promptLoop() {
|
|
@@ -1234,11 +1255,9 @@ async function startWatching(config) {
|
|
|
1234
1255
|
}
|
|
1235
1256
|
|
|
1236
1257
|
// src/updater.ts
|
|
1237
|
-
import { execFileSync } from "child_process";
|
|
1258
|
+
import { execFileSync, spawn } from "child_process";
|
|
1238
1259
|
import chalk3 from "chalk";
|
|
1239
1260
|
var PACKAGE_NAME = "@anraktech/sync";
|
|
1240
|
-
var CHECK_INTERVAL_MS = 4 * 60 * 60 * 1e3;
|
|
1241
|
-
var updateCache = { lastCheck: 0, latestVersion: null };
|
|
1242
1261
|
function compareVersions(current, latest) {
|
|
1243
1262
|
const a = current.split(".").map(Number);
|
|
1244
1263
|
const b = latest.split(".").map(Number);
|
|
@@ -1260,51 +1279,50 @@ async function fetchLatestVersion() {
|
|
|
1260
1279
|
return null;
|
|
1261
1280
|
}
|
|
1262
1281
|
}
|
|
1263
|
-
function
|
|
1264
|
-
console.log(
|
|
1265
|
-
chalk3.dim(`
|
|
1266
|
-
Update available: ${currentVersion} \u2192 `) + chalk3.green(latestVersion) + chalk3.dim(" \xB7 installing...")
|
|
1267
|
-
);
|
|
1282
|
+
function installUpdate(latestVersion) {
|
|
1268
1283
|
try {
|
|
1269
1284
|
execFileSync("npm", ["install", "-g", `${PACKAGE_NAME}@${latestVersion}`], {
|
|
1270
1285
|
stdio: "pipe",
|
|
1271
1286
|
timeout: 6e4
|
|
1272
1287
|
});
|
|
1273
|
-
console.log(chalk3.green(" \u2713 Updated. Restart to use the new version.\n"));
|
|
1274
1288
|
return true;
|
|
1275
1289
|
} catch {
|
|
1276
1290
|
try {
|
|
1277
|
-
execFileSync("npm", ["install", "-g", `${PACKAGE_NAME}@${latestVersion}`, "--prefix", process.env.HOME + "/.npm-global"], {
|
|
1291
|
+
execFileSync("npm", ["install", "-g", `${PACKAGE_NAME}@${latestVersion}`, "--prefix", (process.env.HOME ?? "") + "/.npm-global"], {
|
|
1278
1292
|
stdio: "pipe",
|
|
1279
1293
|
timeout: 6e4
|
|
1280
1294
|
});
|
|
1281
|
-
console.log(chalk3.green(" Updated successfully. Restart to use the new version."));
|
|
1282
|
-
console.log("");
|
|
1283
1295
|
return true;
|
|
1284
1296
|
} catch {
|
|
1285
|
-
console.log(
|
|
1286
|
-
chalk3.dim(" Update failed. Run: ") + chalk3.cyan(`npm i -g ${PACKAGE_NAME}
|
|
1287
|
-
`)
|
|
1288
|
-
);
|
|
1289
1297
|
return false;
|
|
1290
1298
|
}
|
|
1291
1299
|
}
|
|
1292
1300
|
}
|
|
1293
1301
|
async function checkForUpdates(currentVersion) {
|
|
1302
|
+
if (process.env.ANRAK_SKIP_UPDATE) return;
|
|
1294
1303
|
try {
|
|
1295
|
-
const now = Date.now();
|
|
1296
|
-
if (now - updateCache.lastCheck < CHECK_INTERVAL_MS && updateCache.latestVersion) {
|
|
1297
|
-
if (compareVersions(currentVersion, updateCache.latestVersion) > 0) {
|
|
1298
|
-
performUpdate(currentVersion, updateCache.latestVersion);
|
|
1299
|
-
}
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
1304
|
const latestVersion = await fetchLatestVersion();
|
|
1303
|
-
updateCache = { lastCheck: now, latestVersion };
|
|
1304
1305
|
if (!latestVersion) return;
|
|
1305
|
-
if (compareVersions(currentVersion, latestVersion)
|
|
1306
|
-
|
|
1306
|
+
if (compareVersions(currentVersion, latestVersion) <= 0) return;
|
|
1307
|
+
process.stdout.write(
|
|
1308
|
+
chalk3.dim(` Updating ${currentVersion} \u2192 `) + chalk3.green(latestVersion) + chalk3.dim(" ...")
|
|
1309
|
+
);
|
|
1310
|
+
if (!installUpdate(latestVersion)) {
|
|
1311
|
+
process.stdout.write(
|
|
1312
|
+
chalk3.dim(" failed. Run: ") + chalk3.cyan(`npm i -g ${PACKAGE_NAME}`) + "\n\n"
|
|
1313
|
+
);
|
|
1314
|
+
return;
|
|
1307
1315
|
}
|
|
1316
|
+
process.stdout.write(chalk3.green(" done") + "\n\n");
|
|
1317
|
+
const child = spawn(process.argv[0], process.argv.slice(1), {
|
|
1318
|
+
stdio: "inherit",
|
|
1319
|
+
env: { ...process.env, ANRAK_SKIP_UPDATE: "1" }
|
|
1320
|
+
});
|
|
1321
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
1322
|
+
child.on("error", () => {
|
|
1323
|
+
});
|
|
1324
|
+
await new Promise(() => {
|
|
1325
|
+
});
|
|
1308
1326
|
} catch {
|
|
1309
1327
|
}
|
|
1310
1328
|
}
|