commet 2.0.0 → 2.1.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/index.js +83 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24,13 +24,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // src/index.ts
27
- var import_chalk14 = __toESM(require("chalk"));
27
+ var import_chalk15 = __toESM(require("chalk"));
28
28
  var import_commander10 = require("commander");
29
29
 
30
30
  // package.json
31
31
  var package_default = {
32
32
  name: "commet",
33
- version: "2.0.0",
33
+ version: "2.1.0",
34
34
  description: "Commet CLI - Manage your billing platform from the command line",
35
35
  bin: {
36
36
  commet: "./bin/commet"
@@ -160,7 +160,7 @@ function clearProjectConfig() {
160
160
  }
161
161
 
162
162
  // src/utils/telemetry.ts
163
- var CLI_VERSION = true ? "2.0.0" : "0.0.0";
163
+ var CLI_VERSION = true ? "2.1.0" : "0.0.0";
164
164
  var TELEMETRY_URL = "https://commet.co/api/cli/telemetry";
165
165
  function detectRuntime() {
166
166
  if ("Bun" in globalThis) {
@@ -1523,7 +1523,7 @@ var orgsCommand = new import_commander7.Command("orgs").description(
1523
1523
  `
1524
1524
  Examples:
1525
1525
  $ commet orgs Show orgs with current selection marked
1526
- $ commet orgs --json JSON array for agent/CI use
1526
+ $ commet orgs --output agent JSON array for agent/CI use
1527
1527
 
1528
1528
  The slug shown here is what you pass to 'commet link --org <slug>'.
1529
1529
  `
@@ -2314,6 +2314,71 @@ Examples:
2314
2314
  }
2315
2315
  });
2316
2316
 
2317
+ // src/utils/update-check.ts
2318
+ var fs6 = __toESM(require("fs"));
2319
+ var os3 = __toESM(require("os"));
2320
+ var path6 = __toESM(require("path"));
2321
+ var import_chalk14 = __toESM(require("chalk"));
2322
+ var CACHE_FILE = path6.join(os3.homedir(), ".commet", ".update-check");
2323
+ var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
2324
+ var REGISTRY_URL = "https://registry.npmjs.org/commet/latest";
2325
+ function isNewerVersion(latest, current) {
2326
+ const l = latest.split(".").map(Number);
2327
+ const c = current.split(".").map(Number);
2328
+ for (let i = 0; i < 3; i++) {
2329
+ if ((l[i] ?? 0) > (c[i] ?? 0)) return true;
2330
+ if ((l[i] ?? 0) < (c[i] ?? 0)) return false;
2331
+ }
2332
+ return false;
2333
+ }
2334
+ function readCache() {
2335
+ try {
2336
+ return JSON.parse(fs6.readFileSync(CACHE_FILE, "utf8"));
2337
+ } catch {
2338
+ return null;
2339
+ }
2340
+ }
2341
+ function writeCache(cache) {
2342
+ try {
2343
+ fs6.writeFileSync(CACHE_FILE, JSON.stringify(cache), "utf8");
2344
+ } catch {
2345
+ }
2346
+ }
2347
+ function shouldSkip() {
2348
+ if (process.env.COMMET_NO_UPDATE_CHECK === "1") return true;
2349
+ if (process.env.CI) return true;
2350
+ const idx = process.argv.indexOf("--output");
2351
+ if (idx !== -1 && process.argv[idx + 1] === "agent") return true;
2352
+ return false;
2353
+ }
2354
+ var updateAvailable = null;
2355
+ function scheduleUpdateCheck(currentVersion) {
2356
+ if (shouldSkip()) return;
2357
+ const cache = readCache();
2358
+ if (cache && isNewerVersion(cache.latestVersion, currentVersion)) {
2359
+ updateAvailable = cache.latestVersion;
2360
+ }
2361
+ const needsFetch = !cache || Date.now() - cache.checkedAt > CHECK_INTERVAL_MS;
2362
+ if (!needsFetch) return;
2363
+ const controller = new AbortController();
2364
+ const timeout = setTimeout(() => controller.abort(), 3e3);
2365
+ fetch(REGISTRY_URL, { signal: controller.signal }).then((r) => r.json()).then((data) => {
2366
+ writeCache({ latestVersion: data.version, checkedAt: Date.now() });
2367
+ if (!updateAvailable && isNewerVersion(data.version, currentVersion)) {
2368
+ updateAvailable = data.version;
2369
+ }
2370
+ }).catch(() => {
2371
+ }).finally(() => clearTimeout(timeout));
2372
+ }
2373
+ function printUpdateNotification(currentVersion) {
2374
+ if (!updateAvailable) return;
2375
+ console.log("");
2376
+ console.log(
2377
+ ` Update available: ${import_chalk14.default.dim(currentVersion)} \u2192 ${import_chalk14.default.green(updateAvailable)}`
2378
+ );
2379
+ console.log(import_chalk14.default.dim(` Run: npm i -g commet@latest`));
2380
+ }
2381
+
2317
2382
  // src/index.ts
2318
2383
  var program = new import_commander10.Command();
2319
2384
  program.name("commet").description(
@@ -2359,9 +2424,11 @@ program.showSuggestionAfterError();
2359
2424
  program.exitOverride();
2360
2425
  installCrashHandler();
2361
2426
  markCommandStart();
2427
+ scheduleUpdateCheck(package_default.version);
2362
2428
  var commandName = process.argv[2] || "(default)";
2363
2429
  program.hook("postAction", () => {
2364
2430
  reportCommand(commandName, "success");
2431
+ printUpdateNotification(package_default.version);
2365
2432
  });
2366
2433
  try {
2367
2434
  program.parse(process.argv);
@@ -2372,7 +2439,7 @@ try {
2372
2439
  process.exit(0);
2373
2440
  }
2374
2441
  reportCommand(commandName, "error", code);
2375
- console.error(import_chalk14.default.red("Error:"), error.message);
2442
+ console.error(import_chalk15.default.red("Error:"), error.message);
2376
2443
  }
2377
2444
  process.exit(1);
2378
2445
  }
@@ -2460,42 +2527,42 @@ function printAgentInfo() {
2460
2527
  console.log(JSON.stringify(output, null, 2));
2461
2528
  }
2462
2529
  function printDefaultScreen() {
2463
- const version = import_chalk14.default.dim(`v${package_default.version}`);
2530
+ const version = import_chalk15.default.dim(`v${package_default.version}`);
2464
2531
  console.log(`
2465
2532
  ${commetColor.bold("Commet")} ${version}`);
2466
- console.log(import_chalk14.default.dim(" Billing infrastructure as code\n"));
2533
+ console.log(import_chalk15.default.dim(" Billing infrastructure as code\n"));
2467
2534
  const authenticated = authExists();
2468
2535
  const projectConfig = projectConfigExists() ? loadProjectConfig() : null;
2469
2536
  const configFile = findConfigFile(process.cwd());
2470
2537
  if (authenticated) {
2471
- console.log(import_chalk14.default.green(" \u2713 Authenticated"));
2538
+ console.log(import_chalk15.default.green(" \u2713 Authenticated"));
2472
2539
  } else {
2473
2540
  console.log(
2474
- ` ${import_chalk14.default.yellow("\u26A0")} Not logged in ${import_chalk14.default.dim("\u2192 commet login")}`
2541
+ ` ${import_chalk15.default.yellow("\u26A0")} Not logged in ${import_chalk15.default.dim("\u2192 commet login")}`
2475
2542
  );
2476
2543
  }
2477
2544
  if (projectConfig) {
2478
2545
  console.log(
2479
- import_chalk14.default.green(
2480
- ` \u2713 ${projectConfig.orgName} ${import_chalk14.default.dim(`(${projectConfig.mode})`)}`
2546
+ import_chalk15.default.green(
2547
+ ` \u2713 ${projectConfig.orgName} ${import_chalk15.default.dim(`(${projectConfig.mode})`)}`
2481
2548
  )
2482
2549
  );
2483
- console.log(import_chalk14.default.dim(` ${projectConfig.orgId}`));
2550
+ console.log(import_chalk15.default.dim(` ${projectConfig.orgId}`));
2484
2551
  } else if (authenticated) {
2485
2552
  console.log(
2486
- ` ${import_chalk14.default.yellow("\u26A0")} No project linked ${import_chalk14.default.dim("\u2192 commet link")}`
2553
+ ` ${import_chalk15.default.yellow("\u26A0")} No project linked ${import_chalk15.default.dim("\u2192 commet link")}`
2487
2554
  );
2488
2555
  }
2489
2556
  if (configFile) {
2490
2557
  const fileName = configFile.split("/").pop();
2491
- console.log(import_chalk14.default.green(` \u2713 ${fileName}`));
2558
+ console.log(import_chalk15.default.green(` \u2713 ${fileName}`));
2492
2559
  } else if (projectConfig) {
2493
2560
  console.log(
2494
- ` ${import_chalk14.default.yellow("\u26A0")} No config file ${import_chalk14.default.dim("\u2192 commet pull")}`
2561
+ ` ${import_chalk15.default.yellow("\u26A0")} No config file ${import_chalk15.default.dim("\u2192 commet pull")}`
2495
2562
  );
2496
2563
  }
2497
2564
  const cmd = (name) => commetColor(name.padEnd(22));
2498
- const dim = import_chalk14.default.dim;
2565
+ const dim = import_chalk15.default.dim;
2499
2566
  console.log(dim("\n Config"));
2500
2567
  console.log(` ${cmd("pull")}${dim("Sync remote \u2192 commet.config.ts")}`);
2501
2568
  console.log(` ${cmd("push")}${dim("Sync commet.config.ts \u2192 remote")}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commet",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Commet CLI - Manage your billing platform from the command line",
5
5
  "bin": {
6
6
  "commet": "./bin/commet"