@foundrykit/cli 1.0.16 → 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/.turbo/turbo-build.log +20 -0
- package/.turbo/turbo-test.log +42 -0
- package/.turbo/turbo-type-check.log +4 -0
- package/CHANGELOG.md +17 -0
- package/README.md +29 -311
- package/dist/cli.js +217 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.js +217 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/add.ts +39 -13
- package/src/commands/doctor.ts +117 -1
- package/src/commands/update.ts +145 -5
- package/src/lib/constants.ts +1 -1
- package/src/lib/registry.ts +19 -6
- package/tests/dependency-resolution.test.ts +9 -9
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { exec } from "child_process";
|
|
|
16
16
|
import { promisify } from "util";
|
|
17
17
|
|
|
18
18
|
// src/lib/constants.ts
|
|
19
|
-
var CLI_VERSION = "1.0.
|
|
19
|
+
var CLI_VERSION = "1.0.16";
|
|
20
20
|
var DEFAULT_REGISTRY_URL = "https://foundry.umiflow.com";
|
|
21
21
|
var CACHE_TTL = 24 * 60 * 60 * 1e3;
|
|
22
22
|
var CACHE_DIR = ".foundrykit";
|
|
@@ -760,6 +760,13 @@ Try again later or check your internet connection.`
|
|
|
760
760
|
if (this.isSpecialDependency(id)) {
|
|
761
761
|
return this.createSpecialDependency(id);
|
|
762
762
|
}
|
|
763
|
+
const cache = await this.loadCache();
|
|
764
|
+
const cachedComponent = cache?.componentData?.[id];
|
|
765
|
+
const hasValidCache = cache ? this.isCacheValid(cache) : false;
|
|
766
|
+
if (cachedComponent && hasValidCache) {
|
|
767
|
+
console.log(chalk2.gray(`Using cached data for component: ${id}`));
|
|
768
|
+
return cachedComponent;
|
|
769
|
+
}
|
|
763
770
|
try {
|
|
764
771
|
const url = `${this.config.registryUrl}/registry/${id}`;
|
|
765
772
|
console.log(chalk2.gray(`Fetching component: ${url}`));
|
|
@@ -776,10 +783,9 @@ Try again later or check your internet connection.`
|
|
|
776
783
|
await this.cacheComponent(component);
|
|
777
784
|
return component;
|
|
778
785
|
} catch (error) {
|
|
779
|
-
|
|
780
|
-
if (cache?.componentData?.[id]) {
|
|
786
|
+
if (cachedComponent) {
|
|
781
787
|
console.log(chalk2.yellow(`Using cached data for component: ${id}`));
|
|
782
|
-
return
|
|
788
|
+
return cachedComponent;
|
|
783
789
|
}
|
|
784
790
|
throw new Error(
|
|
785
791
|
`Failed to fetch component "${id}": ${error instanceof Error ? error.message : "Unknown error"}
|
|
@@ -913,10 +919,15 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
913
919
|
*/
|
|
914
920
|
async cacheComponent(component) {
|
|
915
921
|
try {
|
|
916
|
-
const cache = await this.loadCache()
|
|
917
|
-
|
|
922
|
+
const cache = await this.loadCache() ?? {
|
|
923
|
+
version: "1.0.0",
|
|
924
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
925
|
+
components: [],
|
|
926
|
+
componentData: {}
|
|
927
|
+
};
|
|
918
928
|
cache.componentData[component.id] = component;
|
|
919
929
|
cache.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
930
|
+
await fs2.ensureDir(this.config.cacheDir);
|
|
920
931
|
await fs2.writeJson(this.cacheFile, cache, { spaces: 2 });
|
|
921
932
|
} catch (error) {
|
|
922
933
|
console.log(chalk2.gray("Failed to cache component"));
|
|
@@ -1264,6 +1275,7 @@ async function addSingleComponent(id, options) {
|
|
|
1264
1275
|
}
|
|
1265
1276
|
}
|
|
1266
1277
|
await installComponentFiles(componentData, options);
|
|
1278
|
+
await trackInstalledComponent(componentData);
|
|
1267
1279
|
console.log(chalk4.green(`\u2705 ${componentData.name} added successfully!`));
|
|
1268
1280
|
showUsageExample(componentData);
|
|
1269
1281
|
await handlePackageDependencies(componentData);
|
|
@@ -1345,6 +1357,18 @@ async function installComponentFiles(componentData, options) {
|
|
|
1345
1357
|
}
|
|
1346
1358
|
await updateConfigVersion();
|
|
1347
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
|
+
}
|
|
1348
1372
|
async function handlePackageDependencies(componentData) {
|
|
1349
1373
|
const allDependencies = /* @__PURE__ */ new Set();
|
|
1350
1374
|
if (componentData.packageDependencies?.length) {
|
|
@@ -1558,20 +1582,203 @@ function getImportPath(componentData, config) {
|
|
|
1558
1582
|
// src/commands/update.ts
|
|
1559
1583
|
import { Command as Command4 } from "commander";
|
|
1560
1584
|
import chalk5 from "chalk";
|
|
1585
|
+
import inquirer3 from "inquirer";
|
|
1586
|
+
import fs4 from "fs-extra";
|
|
1587
|
+
import path4 from "path";
|
|
1561
1588
|
function updateCommand() {
|
|
1562
|
-
return new Command4("update").description("Update
|
|
1563
|
-
|
|
1564
|
-
|
|
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.'));
|
|
1604
|
+
process.exit(1);
|
|
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
|
+
}
|
|
1565
1677
|
});
|
|
1566
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
|
+
}
|
|
1567
1701
|
|
|
1568
1702
|
// src/commands/doctor.ts
|
|
1569
1703
|
import { Command as Command5 } from "commander";
|
|
1570
1704
|
import chalk6 from "chalk";
|
|
1705
|
+
import fs5 from "fs-extra";
|
|
1706
|
+
import path5 from "path";
|
|
1571
1707
|
function doctorCommand() {
|
|
1572
1708
|
return new Command5("doctor").description("Check project health and configuration").action(async () => {
|
|
1573
1709
|
console.log(chalk6.blue("\u{1F50D} Checking project health..."));
|
|
1574
|
-
|
|
1710
|
+
const results = [];
|
|
1711
|
+
const packageJsonPath = path5.join(process.cwd(), "package.json");
|
|
1712
|
+
const hasPackageJson = await fs5.pathExists(packageJsonPath);
|
|
1713
|
+
results.push({
|
|
1714
|
+
label: "package.json",
|
|
1715
|
+
ok: hasPackageJson,
|
|
1716
|
+
detail: hasPackageJson ? "Project manifest found" : "Run this command in a project root"
|
|
1717
|
+
});
|
|
1718
|
+
let packageJson2 = null;
|
|
1719
|
+
if (hasPackageJson) {
|
|
1720
|
+
packageJson2 = await fs5.readJson(packageJsonPath);
|
|
1721
|
+
}
|
|
1722
|
+
const hasNext = !!packageJson2 && !!(packageJson2.dependencies?.next || packageJson2.devDependencies?.next);
|
|
1723
|
+
results.push({
|
|
1724
|
+
label: "Framework",
|
|
1725
|
+
ok: hasNext,
|
|
1726
|
+
detail: hasNext ? "Next.js dependency detected" : "FoundryKit currently expects a Next.js project"
|
|
1727
|
+
});
|
|
1728
|
+
const configPath = path5.join(process.cwd(), "foundrykit.config.json");
|
|
1729
|
+
const hasConfig = await fs5.pathExists(configPath);
|
|
1730
|
+
results.push({
|
|
1731
|
+
label: "FoundryKit config",
|
|
1732
|
+
ok: hasConfig,
|
|
1733
|
+
detail: hasConfig ? "foundrykit.config.json found" : 'Run "foundrykit init" to create the configuration file'
|
|
1734
|
+
});
|
|
1735
|
+
let config = null;
|
|
1736
|
+
if (hasConfig) {
|
|
1737
|
+
try {
|
|
1738
|
+
config = await loadConfig();
|
|
1739
|
+
const hasRequiredPaths = !!config.paths?.utils && !!config.paths?.primitives && !!config.paths?.components && !!config.paths?.blocks && !!config.paths?.animations;
|
|
1740
|
+
results.push({
|
|
1741
|
+
label: "Config shape",
|
|
1742
|
+
ok: hasRequiredPaths,
|
|
1743
|
+
detail: hasRequiredPaths ? "Required install paths are configured" : "Configuration is missing one or more required install paths"
|
|
1744
|
+
});
|
|
1745
|
+
const registryUrl = config.registry || DEFAULT_REGISTRY_URL;
|
|
1746
|
+
try {
|
|
1747
|
+
const response = await fetch(`${registryUrl}/registry`, {
|
|
1748
|
+
headers: { Accept: "application/json" }
|
|
1749
|
+
});
|
|
1750
|
+
results.push({
|
|
1751
|
+
label: "Registry",
|
|
1752
|
+
ok: response.ok,
|
|
1753
|
+
detail: response.ok ? `Registry reachable at ${registryUrl}` : `Registry returned ${response.status} ${response.statusText}`
|
|
1754
|
+
});
|
|
1755
|
+
} catch (error) {
|
|
1756
|
+
results.push({
|
|
1757
|
+
label: "Registry",
|
|
1758
|
+
ok: false,
|
|
1759
|
+
detail: `Unable to reach ${registryUrl}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
} catch (error) {
|
|
1763
|
+
results.push({
|
|
1764
|
+
label: "Config shape",
|
|
1765
|
+
ok: false,
|
|
1766
|
+
detail: `Failed to read foundrykit.config.json: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
for (const result of results) {
|
|
1771
|
+
const icon = result.ok ? chalk6.green("\u2705") : chalk6.red("\u274C");
|
|
1772
|
+
console.log(`${icon} ${result.label}: ${result.detail}`);
|
|
1773
|
+
}
|
|
1774
|
+
const hasFailures = results.some((result) => !result.ok);
|
|
1775
|
+
if (hasFailures) {
|
|
1776
|
+
console.log(
|
|
1777
|
+
chalk6.yellow("\n\u26A0\uFE0F Found issues that should be resolved before continuing.")
|
|
1778
|
+
);
|
|
1779
|
+
process.exit(1);
|
|
1780
|
+
}
|
|
1781
|
+
console.log(chalk6.green("\n\u2705 All checks passed!"));
|
|
1575
1782
|
});
|
|
1576
1783
|
}
|
|
1577
1784
|
|