@foundrykit/cli 1.1.0 → 2.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @foundrykit/cli
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - changes to cli update logic for old repos
8
+ - Updated dependencies
9
+ - @foundrykit/types@2.0.0
10
+
11
+ ## 2.0.0
12
+
13
+ ### Major Changes
14
+
15
+ - changes to how the cli works with updates
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+ - @foundrykit/types@1.1.0
21
+
3
22
  ## 1.1.0
4
23
 
5
24
  ### Minor Changes
package/dist/cli.js CHANGED
@@ -1275,6 +1275,7 @@ async function addSingleComponent(id, options) {
1275
1275
  }
1276
1276
  }
1277
1277
  await installComponentFiles(componentData, options);
1278
+ await trackInstalledComponent(componentData);
1278
1279
  console.log(chalk4.green(`\u2705 ${componentData.name} added successfully!`));
1279
1280
  showUsageExample(componentData);
1280
1281
  await handlePackageDependencies(componentData);
@@ -1356,6 +1357,18 @@ async function installComponentFiles(componentData, options) {
1356
1357
  }
1357
1358
  await updateConfigVersion();
1358
1359
  }
1360
+ async function trackInstalledComponent(componentData) {
1361
+ const configPath = path3.join(process.cwd(), "foundrykit.config.json");
1362
+ if (!fs3.existsSync(configPath)) return;
1363
+ const config = await fs3.readJson(configPath);
1364
+ config.installedComponents = config.installedComponents ?? {};
1365
+ config.installedComponents[componentData.id] = {
1366
+ id: componentData.id,
1367
+ version: componentData.version ?? null,
1368
+ installedAt: (/* @__PURE__ */ new Date()).toISOString()
1369
+ };
1370
+ await fs3.writeJson(configPath, config, { spaces: 2 });
1371
+ }
1359
1372
  async function handlePackageDependencies(componentData) {
1360
1373
  const allDependencies = /* @__PURE__ */ new Set();
1361
1374
  if (componentData.packageDependencies?.length) {
@@ -1569,35 +1582,161 @@ function getImportPath(componentData, config) {
1569
1582
  // src/commands/update.ts
1570
1583
  import { Command as Command4 } from "commander";
1571
1584
  import chalk5 from "chalk";
1585
+ import inquirer3 from "inquirer";
1586
+ import fs4 from "fs-extra";
1587
+ import path4 from "path";
1572
1588
  function updateCommand() {
1573
- return new Command4("update").description("Update an existing component or block").argument("<id>", "Component or block ID").option("-p, --path <path>", "Custom installation path").action(async (id, options) => {
1574
- try {
1575
- console.log(chalk5.blue(`\u{1F504} Updating ${id}...`));
1576
- await addSingleComponent(id, {
1577
- ...options,
1578
- overwrite: true
1579
- });
1580
- } catch (error) {
1581
- console.error(chalk5.red(`\u274C Failed to update ${id}:`));
1582
- console.error(
1583
- chalk5.red(error instanceof Error ? error.message : String(error))
1584
- );
1589
+ return new Command4("update").description("Update installed components").argument("[id]", "Component or block ID (omit to update all installed)").option("--opt", "interactively select which components to update, showing available upgrades").option("-p, --path <path>", "Custom installation path").action(async (id, options) => {
1590
+ if (id) {
1591
+ try {
1592
+ console.log(chalk5.blue(`\u{1F504} Updating ${id}...`));
1593
+ await addSingleComponent(id, { ...options, overwrite: true });
1594
+ } catch (error) {
1595
+ console.error(chalk5.red(`\u274C Failed to update ${id}:`));
1596
+ console.error(chalk5.red(error instanceof Error ? error.message : String(error)));
1597
+ process.exit(1);
1598
+ }
1599
+ return;
1600
+ }
1601
+ const configPath = path4.join(process.cwd(), "foundrykit.config.json");
1602
+ if (!fs4.existsSync(configPath)) {
1603
+ console.error(chalk5.red('\u274C FoundryKit not initialized. Run "foundrykit init" first.'));
1585
1604
  process.exit(1);
1586
1605
  }
1606
+ const config = await fs4.readJson(configPath);
1607
+ let installed = config.installedComponents ?? {};
1608
+ let installedIds = Object.keys(installed);
1609
+ if (installedIds.length === 0) {
1610
+ console.log(chalk5.gray("No install tracking found. Scanning filesystem for installed components..."));
1611
+ const registry = getRegistry();
1612
+ let allComponents;
1613
+ try {
1614
+ allComponents = await registry.getComponents();
1615
+ } catch (error) {
1616
+ console.error(chalk5.red("\u274C Failed to fetch registry:"));
1617
+ console.error(chalk5.red(error instanceof Error ? error.message : String(error)));
1618
+ process.exit(1);
1619
+ }
1620
+ for (const component of allComponents) {
1621
+ try {
1622
+ const componentData = await registry.getComponent(component.id);
1623
+ if (await hasConflictingFiles(componentData, options)) {
1624
+ installed[component.id] = {
1625
+ id: component.id,
1626
+ version: null,
1627
+ installedAt: (/* @__PURE__ */ new Date()).toISOString()
1628
+ };
1629
+ }
1630
+ } catch {
1631
+ }
1632
+ }
1633
+ installedIds = Object.keys(installed);
1634
+ if (installedIds.length === 0) {
1635
+ console.log(chalk5.yellow('No installed components found. Use "foundrykit add" to install components.'));
1636
+ return;
1637
+ }
1638
+ console.log(chalk5.gray(`Found ${installedIds.length} installed component(s) via filesystem scan.`));
1639
+ }
1640
+ if (options.opt) {
1641
+ console.log(chalk5.blue(`\u{1F50D} Checking for updates across ${installedIds.length} installed component(s)...`));
1642
+ const registry = getRegistry();
1643
+ const withUpdates = [];
1644
+ const upToDate = [];
1645
+ for (const compId of installedIds) {
1646
+ try {
1647
+ const data = await registry.getComponent(compId);
1648
+ const installedVersion = installed[compId]?.version ?? null;
1649
+ const latestVersion = data.version ?? null;
1650
+ const hasUpdate = latestVersion !== null && installedVersion !== null && latestVersion !== installedVersion;
1651
+ const unknownVersion = installedVersion === null || latestVersion === null;
1652
+ if (hasUpdate || unknownVersion) {
1653
+ withUpdates.push({ id: compId, installed: installedVersion, latest: latestVersion });
1654
+ } else {
1655
+ upToDate.push(compId);
1656
+ }
1657
+ } catch {
1658
+ withUpdates.push({ id: compId, installed: installed[compId]?.version ?? null, latest: null });
1659
+ }
1660
+ }
1661
+ if (upToDate.length > 0) {
1662
+ console.log(chalk5.gray(`
1663
+ \u2713 Already up to date: ${upToDate.join(", ")}`));
1664
+ }
1665
+ if (withUpdates.length === 0) {
1666
+ console.log(chalk5.green("\n\u2705 All components are up to date."));
1667
+ return;
1668
+ }
1669
+ const choices = withUpdates.map(({ id: compId, installed: inst, latest }) => {
1670
+ let versionLabel;
1671
+ if (inst === null && latest === null) {
1672
+ versionLabel = chalk5.gray("(version unknown)");
1673
+ } else if (latest === null) {
1674
+ versionLabel = chalk5.gray(`(installed: ${inst} \u2014 registry version unknown)`);
1675
+ } else if (inst === null) {
1676
+ versionLabel = chalk5.cyan(`(latest: ${latest} \u2014 install version not tracked)`);
1677
+ } else {
1678
+ versionLabel = chalk5.cyan(`(${inst} \u2192 ${latest})`);
1679
+ }
1680
+ return {
1681
+ name: `${compId} ${versionLabel}`,
1682
+ value: compId,
1683
+ checked: true
1684
+ };
1685
+ });
1686
+ const { selectedIds } = await inquirer3.prompt([
1687
+ {
1688
+ type: "checkbox",
1689
+ name: "selectedIds",
1690
+ message: "Select components to update:",
1691
+ choices,
1692
+ pageSize: 20
1693
+ }
1694
+ ]);
1695
+ if (selectedIds.length === 0) {
1696
+ console.log(chalk5.yellow("No components selected."));
1697
+ return;
1698
+ }
1699
+ await runUpdates(selectedIds, options);
1700
+ } else {
1701
+ console.log(chalk5.blue(`\u{1F504} Updating all ${installedIds.length} installed component(s)...`));
1702
+ await runUpdates(installedIds, options);
1703
+ }
1587
1704
  });
1588
1705
  }
1706
+ async function runUpdates(ids, options) {
1707
+ let failed = 0;
1708
+ for (const compId of ids) {
1709
+ try {
1710
+ console.log(chalk5.blue(`
1711
+ \u{1F504} Updating ${compId}...`));
1712
+ await addSingleComponent(compId, { ...options, overwrite: true });
1713
+ } catch (error) {
1714
+ console.error(chalk5.red(`\u274C Failed to update ${compId}:`));
1715
+ console.error(chalk5.red(error instanceof Error ? error.message : String(error)));
1716
+ failed++;
1717
+ }
1718
+ }
1719
+ if (failed > 0) {
1720
+ console.log(chalk5.yellow(`
1721
+ \u26A0 ${failed} component(s) failed to update.`));
1722
+ process.exit(1);
1723
+ } else {
1724
+ console.log(chalk5.green(`
1725
+ \u2705 ${ids.length} component(s) updated successfully!`));
1726
+ }
1727
+ }
1589
1728
 
1590
1729
  // src/commands/doctor.ts
1591
1730
  import { Command as Command5 } from "commander";
1592
1731
  import chalk6 from "chalk";
1593
- import fs4 from "fs-extra";
1594
- import path4 from "path";
1732
+ import fs5 from "fs-extra";
1733
+ import path5 from "path";
1595
1734
  function doctorCommand() {
1596
1735
  return new Command5("doctor").description("Check project health and configuration").action(async () => {
1597
1736
  console.log(chalk6.blue("\u{1F50D} Checking project health..."));
1598
1737
  const results = [];
1599
- const packageJsonPath = path4.join(process.cwd(), "package.json");
1600
- const hasPackageJson = await fs4.pathExists(packageJsonPath);
1738
+ const packageJsonPath = path5.join(process.cwd(), "package.json");
1739
+ const hasPackageJson = await fs5.pathExists(packageJsonPath);
1601
1740
  results.push({
1602
1741
  label: "package.json",
1603
1742
  ok: hasPackageJson,
@@ -1605,7 +1744,7 @@ function doctorCommand() {
1605
1744
  });
1606
1745
  let packageJson2 = null;
1607
1746
  if (hasPackageJson) {
1608
- packageJson2 = await fs4.readJson(packageJsonPath);
1747
+ packageJson2 = await fs5.readJson(packageJsonPath);
1609
1748
  }
1610
1749
  const hasNext = !!packageJson2 && !!(packageJson2.dependencies?.next || packageJson2.devDependencies?.next);
1611
1750
  results.push({
@@ -1613,8 +1752,8 @@ function doctorCommand() {
1613
1752
  ok: hasNext,
1614
1753
  detail: hasNext ? "Next.js dependency detected" : "FoundryKit currently expects a Next.js project"
1615
1754
  });
1616
- const configPath = path4.join(process.cwd(), "foundrykit.config.json");
1617
- const hasConfig = await fs4.pathExists(configPath);
1755
+ const configPath = path5.join(process.cwd(), "foundrykit.config.json");
1756
+ const hasConfig = await fs5.pathExists(configPath);
1618
1757
  results.push({
1619
1758
  label: "FoundryKit config",
1620
1759
  ok: hasConfig,