@foundrykit/cli 1.1.0 → 2.0.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/CHANGELOG.md +11 -0
- package/dist/cli.js +131 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.js +131 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/add.ts +22 -0
- package/src/commands/update.ts +138 -15
package/CHANGELOG.md
CHANGED
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,134 @@ 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
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
...options,
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
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
|
+
const installed = config.installedComponents ?? {};
|
|
1608
|
+
const installedIds = Object.keys(installed);
|
|
1609
|
+
if (installedIds.length === 0) {
|
|
1610
|
+
console.log(chalk5.yellow('No installed components found. Use "foundrykit add" to install components.'));
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
if (options.opt) {
|
|
1614
|
+
console.log(chalk5.blue(`\u{1F50D} Checking for updates across ${installedIds.length} installed component(s)...`));
|
|
1615
|
+
const registry = getRegistry();
|
|
1616
|
+
const withUpdates = [];
|
|
1617
|
+
const upToDate = [];
|
|
1618
|
+
for (const compId of installedIds) {
|
|
1619
|
+
try {
|
|
1620
|
+
const data = await registry.getComponent(compId);
|
|
1621
|
+
const installedVersion = installed[compId]?.version ?? null;
|
|
1622
|
+
const latestVersion = data.version ?? null;
|
|
1623
|
+
const hasUpdate = latestVersion !== null && installedVersion !== null && latestVersion !== installedVersion;
|
|
1624
|
+
const unknownVersion = installedVersion === null || latestVersion === null;
|
|
1625
|
+
if (hasUpdate || unknownVersion) {
|
|
1626
|
+
withUpdates.push({ id: compId, installed: installedVersion, latest: latestVersion });
|
|
1627
|
+
} else {
|
|
1628
|
+
upToDate.push(compId);
|
|
1629
|
+
}
|
|
1630
|
+
} catch {
|
|
1631
|
+
withUpdates.push({ id: compId, installed: installed[compId]?.version ?? null, latest: null });
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (upToDate.length > 0) {
|
|
1635
|
+
console.log(chalk5.gray(`
|
|
1636
|
+
\u2713 Already up to date: ${upToDate.join(", ")}`));
|
|
1637
|
+
}
|
|
1638
|
+
if (withUpdates.length === 0) {
|
|
1639
|
+
console.log(chalk5.green("\n\u2705 All components are up to date."));
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
const choices = withUpdates.map(({ id: compId, installed: inst, latest }) => {
|
|
1643
|
+
let versionLabel;
|
|
1644
|
+
if (inst === null && latest === null) {
|
|
1645
|
+
versionLabel = chalk5.gray("(version unknown)");
|
|
1646
|
+
} else if (latest === null) {
|
|
1647
|
+
versionLabel = chalk5.gray(`(installed: ${inst} \u2014 registry version unknown)`);
|
|
1648
|
+
} else if (inst === null) {
|
|
1649
|
+
versionLabel = chalk5.cyan(`(latest: ${latest} \u2014 install version not tracked)`);
|
|
1650
|
+
} else {
|
|
1651
|
+
versionLabel = chalk5.cyan(`(${inst} \u2192 ${latest})`);
|
|
1652
|
+
}
|
|
1653
|
+
return {
|
|
1654
|
+
name: `${compId} ${versionLabel}`,
|
|
1655
|
+
value: compId,
|
|
1656
|
+
checked: true
|
|
1657
|
+
};
|
|
1658
|
+
});
|
|
1659
|
+
const { selectedIds } = await inquirer3.prompt([
|
|
1660
|
+
{
|
|
1661
|
+
type: "checkbox",
|
|
1662
|
+
name: "selectedIds",
|
|
1663
|
+
message: "Select components to update:",
|
|
1664
|
+
choices,
|
|
1665
|
+
pageSize: 20
|
|
1666
|
+
}
|
|
1667
|
+
]);
|
|
1668
|
+
if (selectedIds.length === 0) {
|
|
1669
|
+
console.log(chalk5.yellow("No components selected."));
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
await runUpdates(selectedIds, options);
|
|
1673
|
+
} else {
|
|
1674
|
+
console.log(chalk5.blue(`\u{1F504} Updating all ${installedIds.length} installed component(s)...`));
|
|
1675
|
+
await runUpdates(installedIds, options);
|
|
1676
|
+
}
|
|
1587
1677
|
});
|
|
1588
1678
|
}
|
|
1679
|
+
async function runUpdates(ids, options) {
|
|
1680
|
+
let failed = 0;
|
|
1681
|
+
for (const compId of ids) {
|
|
1682
|
+
try {
|
|
1683
|
+
console.log(chalk5.blue(`
|
|
1684
|
+
\u{1F504} Updating ${compId}...`));
|
|
1685
|
+
await addSingleComponent(compId, { ...options, overwrite: true });
|
|
1686
|
+
} catch (error) {
|
|
1687
|
+
console.error(chalk5.red(`\u274C Failed to update ${compId}:`));
|
|
1688
|
+
console.error(chalk5.red(error instanceof Error ? error.message : String(error)));
|
|
1689
|
+
failed++;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
if (failed > 0) {
|
|
1693
|
+
console.log(chalk5.yellow(`
|
|
1694
|
+
\u26A0 ${failed} component(s) failed to update.`));
|
|
1695
|
+
process.exit(1);
|
|
1696
|
+
} else {
|
|
1697
|
+
console.log(chalk5.green(`
|
|
1698
|
+
\u2705 ${ids.length} component(s) updated successfully!`));
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1589
1701
|
|
|
1590
1702
|
// src/commands/doctor.ts
|
|
1591
1703
|
import { Command as Command5 } from "commander";
|
|
1592
1704
|
import chalk6 from "chalk";
|
|
1593
|
-
import
|
|
1594
|
-
import
|
|
1705
|
+
import fs5 from "fs-extra";
|
|
1706
|
+
import path5 from "path";
|
|
1595
1707
|
function doctorCommand() {
|
|
1596
1708
|
return new Command5("doctor").description("Check project health and configuration").action(async () => {
|
|
1597
1709
|
console.log(chalk6.blue("\u{1F50D} Checking project health..."));
|
|
1598
1710
|
const results = [];
|
|
1599
|
-
const packageJsonPath =
|
|
1600
|
-
const hasPackageJson = await
|
|
1711
|
+
const packageJsonPath = path5.join(process.cwd(), "package.json");
|
|
1712
|
+
const hasPackageJson = await fs5.pathExists(packageJsonPath);
|
|
1601
1713
|
results.push({
|
|
1602
1714
|
label: "package.json",
|
|
1603
1715
|
ok: hasPackageJson,
|
|
@@ -1605,7 +1717,7 @@ function doctorCommand() {
|
|
|
1605
1717
|
});
|
|
1606
1718
|
let packageJson2 = null;
|
|
1607
1719
|
if (hasPackageJson) {
|
|
1608
|
-
packageJson2 = await
|
|
1720
|
+
packageJson2 = await fs5.readJson(packageJsonPath);
|
|
1609
1721
|
}
|
|
1610
1722
|
const hasNext = !!packageJson2 && !!(packageJson2.dependencies?.next || packageJson2.devDependencies?.next);
|
|
1611
1723
|
results.push({
|
|
@@ -1613,8 +1725,8 @@ function doctorCommand() {
|
|
|
1613
1725
|
ok: hasNext,
|
|
1614
1726
|
detail: hasNext ? "Next.js dependency detected" : "FoundryKit currently expects a Next.js project"
|
|
1615
1727
|
});
|
|
1616
|
-
const configPath =
|
|
1617
|
-
const hasConfig = await
|
|
1728
|
+
const configPath = path5.join(process.cwd(), "foundrykit.config.json");
|
|
1729
|
+
const hasConfig = await fs5.pathExists(configPath);
|
|
1618
1730
|
results.push({
|
|
1619
1731
|
label: "FoundryKit config",
|
|
1620
1732
|
ok: hasConfig,
|