commet 1.4.3 → 1.6.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 +142 -17
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ var import_commander11 = require("commander");
30
30
  // package.json
31
31
  var package_default = {
32
32
  name: "commet",
33
- version: "1.4.3",
33
+ version: "1.6.0",
34
34
  description: "Commet CLI - Manage your billing platform from the command line",
35
35
  bin: {
36
36
  commet: "./bin/commet"
@@ -45,7 +45,8 @@ var package_default = {
45
45
  dev: "tsup --watch",
46
46
  lint: "biome lint src/",
47
47
  "lint:fix": "biome lint --write src/",
48
- typecheck: "tsc --noEmit"
48
+ typecheck: "tsc --noEmit",
49
+ clean: "rm -rf .turbo node_modules dist"
49
50
  },
50
51
  keywords: [
51
52
  "billing",
@@ -399,6 +400,61 @@ function updatePackageJson(dest, projectName) {
399
400
  fs2.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
400
401
  `);
401
402
  }
403
+ async function fetchLatestVersion(packageName) {
404
+ const response = await fetch(
405
+ `https://registry.npmjs.org/${packageName}/latest`
406
+ );
407
+ if (!response.ok) {
408
+ throw new Error(
409
+ `Failed to fetch version for ${packageName} (HTTP ${response.status})`
410
+ );
411
+ }
412
+ const data = await response.json();
413
+ return data.version;
414
+ }
415
+ async function resolveWorkspaceDeps(dest) {
416
+ const pkgPath = path2.join(dest, "package.json");
417
+ const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"));
418
+ const depSections = [
419
+ "dependencies",
420
+ "devDependencies",
421
+ "peerDependencies"
422
+ ];
423
+ const workspaceDeps = /* @__PURE__ */ new Map();
424
+ for (const section of depSections) {
425
+ const deps = pkg[section];
426
+ if (!deps) continue;
427
+ for (const [name, version] of Object.entries(deps)) {
428
+ if (typeof version === "string" && version.startsWith("workspace:")) {
429
+ const existing = workspaceDeps.get(name);
430
+ if (existing) {
431
+ existing.push(section);
432
+ } else {
433
+ workspaceDeps.set(name, [section]);
434
+ }
435
+ }
436
+ }
437
+ }
438
+ if (workspaceDeps.size === 0) return 0;
439
+ const resolved = /* @__PURE__ */ new Map();
440
+ await Promise.all(
441
+ Array.from(workspaceDeps.keys()).map(async (name) => {
442
+ resolved.set(name, await fetchLatestVersion(name));
443
+ })
444
+ );
445
+ for (const [name, sections] of workspaceDeps) {
446
+ const version = resolved.get(name);
447
+ if (!version) {
448
+ throw new Error(`Could not resolve version for ${name}`);
449
+ }
450
+ for (const section of sections) {
451
+ pkg[section][name] = version;
452
+ }
453
+ }
454
+ fs2.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
455
+ `);
456
+ return workspaceDeps.size;
457
+ }
402
458
  function copyEnvExample(dest) {
403
459
  const examplePath = path2.join(dest, ".env.example");
404
460
  const envPath = path2.join(dest, ".env");
@@ -426,7 +482,13 @@ function linkProject(dest, orgId, orgName, environment) {
426
482
  "utf8"
427
483
  );
428
484
  }
429
- async function askSkills() {
485
+ function isInteractive() {
486
+ return process.stdin.isTTY === true;
487
+ }
488
+ async function resolveSkills(opts) {
489
+ if (typeof opts.skills === "boolean") return opts.skills;
490
+ if (opts.yes) return true;
491
+ if (!isInteractive()) return false;
430
492
  try {
431
493
  return await (0, import_prompts.confirm)({
432
494
  message: `Add ${commetColor("agent skills")}?`,
@@ -457,7 +519,7 @@ async function installSkills(projectRoot) {
457
519
  var createCommand = new import_commander.Command("create").description("Create a new Commet app from a template").argument("[name]", "Project name").option(
458
520
  "-t, --template <template>",
459
521
  "Template to use (fixed, seats, metered, credits, balance-ai, balance-fixed)"
460
- ).option("--ref <ref>", "Git ref to fetch templates from", "main").option("--list", "List available templates").action(async (argName, opts) => {
522
+ ).option("--org <slug>", "Organization slug or ID (skips selection)").option("--skills", "Install agent skills").option("--no-skills", "Skip agent skills installation").option("-y, --yes", "Accept defaults for optional prompts").option("--ref <ref>", "Git ref to fetch templates from", "main").option("--list", "List available templates").action(async (argName, opts) => {
461
523
  if (opts.list) {
462
524
  console.log(import_chalk3.default.bold("\nAvailable templates:\n"));
463
525
  for (const t of TEMPLATES) {
@@ -469,16 +531,23 @@ var createCommand = new import_commander.Command("create").description("Create a
469
531
  return;
470
532
  }
471
533
  let projectName = argName;
472
- try {
473
- if (!projectName) {
534
+ if (!projectName) {
535
+ if (!isInteractive()) {
536
+ console.log(import_chalk3.default.red("\u2717 Project name is required"));
537
+ console.log(
538
+ import_chalk3.default.dim("Pass as positional argument: commet create <name>")
539
+ );
540
+ return;
541
+ }
542
+ try {
474
543
  projectName = await (0, import_prompts.input)({
475
544
  message: "Project name:",
476
545
  theme: promptTheme
477
546
  });
547
+ } catch {
548
+ console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
549
+ return;
478
550
  }
479
- } catch {
480
- console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
481
- return;
482
551
  }
483
552
  const dest = path2.resolve(projectName);
484
553
  if (fs2.existsSync(dest)) {
@@ -488,6 +557,11 @@ var createCommand = new import_commander.Command("create").description("Create a
488
557
  return;
489
558
  }
490
559
  if (!authExists()) {
560
+ if (!isInteractive()) {
561
+ console.log(import_chalk3.default.red("\u2717 Not authenticated"));
562
+ console.log(import_chalk3.default.dim("Run `commet login` first"));
563
+ return;
564
+ }
491
565
  let environment;
492
566
  try {
493
567
  environment = await (0, import_prompts.select)({
@@ -541,9 +615,32 @@ var createCommand = new import_commander.Command("create").description("Create a
541
615
  return;
542
616
  }
543
617
  let selectedOrg;
544
- if (organizations.length === 1) {
618
+ if (opts.org) {
619
+ const match = organizations.find(
620
+ (org) => org.slug === opts.org || org.id === opts.org
621
+ );
622
+ if (!match) {
623
+ console.log(import_chalk3.default.red(`\u2717 Organization "${opts.org}" not found`));
624
+ console.log(
625
+ import_chalk3.default.dim(
626
+ `Available: ${organizations.map((o) => o.slug).join(", ")}`
627
+ )
628
+ );
629
+ return;
630
+ }
631
+ selectedOrg = match;
632
+ } else if (organizations.length === 1) {
545
633
  selectedOrg = organizations[0];
546
634
  } else {
635
+ if (!isInteractive()) {
636
+ console.log(import_chalk3.default.red("\u2717 Organization is required"));
637
+ console.log(
638
+ import_chalk3.default.dim(
639
+ `Pass --org=<slug>. Available: ${organizations.map((o) => o.slug).join(", ")}`
640
+ )
641
+ );
642
+ return;
643
+ }
547
644
  try {
548
645
  const orgId = await (0, import_prompts.select)({
549
646
  message: "Organization:",
@@ -567,8 +664,17 @@ var createCommand = new import_commander.Command("create").description("Create a
567
664
  );
568
665
  return;
569
666
  }
570
- try {
571
- if (!template) {
667
+ if (!template) {
668
+ if (!isInteractive()) {
669
+ console.log(import_chalk3.default.red("\u2717 Template is required"));
670
+ console.log(
671
+ import_chalk3.default.dim(
672
+ `Pass --template=<name>. Available: ${TEMPLATES.map((t) => t.name).join(", ")}`
673
+ )
674
+ );
675
+ return;
676
+ }
677
+ try {
572
678
  const selected = await (0, import_prompts.select)({
573
679
  message: "Billing model:",
574
680
  choices: TEMPLATES.map((t) => ({
@@ -578,12 +684,12 @@ var createCommand = new import_commander.Command("create").description("Create a
578
684
  theme: promptTheme
579
685
  });
580
686
  template = TEMPLATES.find((t) => t.name === selected);
687
+ } catch {
688
+ console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
689
+ return;
581
690
  }
582
- } catch {
583
- console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
584
- return;
585
691
  }
586
- const shouldInstallSkills = await askSkills();
692
+ const shouldInstallSkills = await resolveSkills(opts);
587
693
  const downloadSpinner = (0, import_ora2.default)("Downloading template...").start();
588
694
  try {
589
695
  await downloadTemplate(template.dir, dest, opts.ref);
@@ -600,6 +706,24 @@ var createCommand = new import_commander.Command("create").description("Create a
600
706
  }
601
707
  updatePackageJson(dest, projectName);
602
708
  copyEnvExample(dest);
709
+ const resolveSpinner = (0, import_ora2.default)("Resolving package versions...").start();
710
+ try {
711
+ const count = await resolveWorkspaceDeps(dest);
712
+ if (count > 0) {
713
+ resolveSpinner.succeed(`Resolved ${count} package versions`);
714
+ } else {
715
+ resolveSpinner.stop();
716
+ }
717
+ } catch (error) {
718
+ resolveSpinner.fail("Failed to resolve package versions");
719
+ if (error instanceof Error) {
720
+ console.error(import_chalk3.default.red(error.message));
721
+ }
722
+ if (fs2.existsSync(dest)) {
723
+ fs2.rmSync(dest, { recursive: true, force: true });
724
+ }
725
+ return;
726
+ }
603
727
  const planSpinner = (0, import_ora2.default)("Creating plans...").start();
604
728
  const templateResult = await apiRequest(`${baseURL}/api/cli/templates`, {
605
729
  method: "POST",
@@ -1305,7 +1429,8 @@ try {
1305
1429
  program.parse(process.argv);
1306
1430
  } catch (error) {
1307
1431
  if (error instanceof Error) {
1308
- if (error.message.includes("outputHelp")) {
1432
+ const code = error.code;
1433
+ if (code === "commander.version" || code === "commander.help" || code === "commander.helpDisplayed") {
1309
1434
  process.exit(0);
1310
1435
  }
1311
1436
  console.error(import_chalk13.default.red("Error:"), error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commet",
3
- "version": "1.4.3",
3
+ "version": "1.6.0",
4
4
  "description": "Commet CLI - Manage your billing platform from the command line",
5
5
  "bin": {
6
6
  "commet": "./bin/commet"
@@ -50,6 +50,7 @@
50
50
  "dev": "tsup --watch",
51
51
  "lint": "biome lint src/",
52
52
  "lint:fix": "biome lint --write src/",
53
- "typecheck": "tsc --noEmit"
53
+ "typecheck": "tsc --noEmit",
54
+ "clean": "rm -rf .turbo node_modules dist"
54
55
  }
55
56
  }