@anraktech/sync 0.8.0 → 0.9.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.
Files changed (2) hide show
  1. package/dist/cli.js +23 -26
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1234,11 +1234,9 @@ async function startWatching(config) {
1234
1234
  }
1235
1235
 
1236
1236
  // src/updater.ts
1237
- import { execFileSync } from "child_process";
1237
+ import { execFileSync, spawn } from "child_process";
1238
1238
  import chalk3 from "chalk";
1239
1239
  var PACKAGE_NAME = "@anraktech/sync";
1240
- var CHECK_INTERVAL_MS = 4 * 60 * 60 * 1e3;
1241
- var updateCache = { lastCheck: 0, latestVersion: null };
1242
1240
  function compareVersions(current, latest) {
1243
1241
  const a = current.split(".").map(Number);
1244
1242
  const b = latest.split(".").map(Number);
@@ -1260,51 +1258,50 @@ async function fetchLatestVersion() {
1260
1258
  return null;
1261
1259
  }
1262
1260
  }
1263
- function performUpdate(currentVersion, latestVersion) {
1264
- console.log(
1265
- chalk3.dim(`
1266
- Update available: ${currentVersion} \u2192 `) + chalk3.green(latestVersion) + chalk3.dim(" \xB7 installing...")
1267
- );
1261
+ function installUpdate(latestVersion) {
1268
1262
  try {
1269
1263
  execFileSync("npm", ["install", "-g", `${PACKAGE_NAME}@${latestVersion}`], {
1270
1264
  stdio: "pipe",
1271
1265
  timeout: 6e4
1272
1266
  });
1273
- console.log(chalk3.green(" \u2713 Updated. Restart to use the new version.\n"));
1274
1267
  return true;
1275
1268
  } catch {
1276
1269
  try {
1277
- execFileSync("npm", ["install", "-g", `${PACKAGE_NAME}@${latestVersion}`, "--prefix", process.env.HOME + "/.npm-global"], {
1270
+ execFileSync("npm", ["install", "-g", `${PACKAGE_NAME}@${latestVersion}`, "--prefix", (process.env.HOME ?? "") + "/.npm-global"], {
1278
1271
  stdio: "pipe",
1279
1272
  timeout: 6e4
1280
1273
  });
1281
- console.log(chalk3.green(" Updated successfully. Restart to use the new version."));
1282
- console.log("");
1283
1274
  return true;
1284
1275
  } catch {
1285
- console.log(
1286
- chalk3.dim(" Update failed. Run: ") + chalk3.cyan(`npm i -g ${PACKAGE_NAME}
1287
- `)
1288
- );
1289
1276
  return false;
1290
1277
  }
1291
1278
  }
1292
1279
  }
1293
1280
  async function checkForUpdates(currentVersion) {
1281
+ if (process.env.ANRAK_SKIP_UPDATE) return;
1294
1282
  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
1283
  const latestVersion = await fetchLatestVersion();
1303
- updateCache = { lastCheck: now, latestVersion };
1304
1284
  if (!latestVersion) return;
1305
- if (compareVersions(currentVersion, latestVersion) > 0) {
1306
- performUpdate(currentVersion, latestVersion);
1285
+ if (compareVersions(currentVersion, latestVersion) <= 0) return;
1286
+ process.stdout.write(
1287
+ chalk3.dim(` Updating ${currentVersion} \u2192 `) + chalk3.green(latestVersion) + chalk3.dim(" ...")
1288
+ );
1289
+ if (!installUpdate(latestVersion)) {
1290
+ process.stdout.write(
1291
+ chalk3.dim(" failed. Run: ") + chalk3.cyan(`npm i -g ${PACKAGE_NAME}`) + "\n\n"
1292
+ );
1293
+ return;
1307
1294
  }
1295
+ process.stdout.write(chalk3.green(" done") + "\n\n");
1296
+ const child = spawn(process.argv[0], process.argv.slice(1), {
1297
+ stdio: "inherit",
1298
+ env: { ...process.env, ANRAK_SKIP_UPDATE: "1" }
1299
+ });
1300
+ child.on("exit", (code) => process.exit(code ?? 0));
1301
+ child.on("error", () => {
1302
+ });
1303
+ await new Promise(() => {
1304
+ });
1308
1305
  } catch {
1309
1306
  }
1310
1307
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anraktech/sync",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "AnrakLegal desktop file sync agent — watches local folders and syncs to case management",
5
5
  "type": "module",
6
6
  "bin": {