@foundrykit/cli 3.1.0 → 3.1.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/README.md +10 -1
- package/dist/cli.js +111 -29
- package/dist/cli.js.map +1 -1
- package/dist/index.js +111 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { readFileSync } from "fs";
|
|
5
|
-
import { dirname, join } from "path";
|
|
6
|
-
import { fileURLToPath } from "url";
|
|
7
4
|
import { Command as Command11 } from "commander";
|
|
8
5
|
|
|
9
6
|
// src/commands/add.ts
|
|
@@ -295,11 +292,11 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
295
292
|
if (!await fs2.pathExists(packageJsonPath)) {
|
|
296
293
|
return false;
|
|
297
294
|
}
|
|
298
|
-
const
|
|
295
|
+
const packageJson = await fs2.readJson(packageJsonPath);
|
|
299
296
|
const allDeps = {
|
|
300
|
-
...
|
|
301
|
-
...
|
|
302
|
-
...
|
|
297
|
+
...packageJson.dependencies,
|
|
298
|
+
...packageJson.devDependencies,
|
|
299
|
+
...packageJson.peerDependencies
|
|
303
300
|
};
|
|
304
301
|
return packageName in allDeps;
|
|
305
302
|
} catch {
|
|
@@ -675,6 +672,81 @@ function interactivePrompt() {
|
|
|
675
672
|
};
|
|
676
673
|
}
|
|
677
674
|
|
|
675
|
+
// src/lib/banner.ts
|
|
676
|
+
import { readFileSync } from "fs";
|
|
677
|
+
import { dirname, join } from "path";
|
|
678
|
+
import { fileURLToPath } from "url";
|
|
679
|
+
var KIT = [
|
|
680
|
+
"\u2584\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588",
|
|
681
|
+
"\u2588\u2588\u2588\u2588 \u2580\u2580\u2580\u2580\u2580",
|
|
682
|
+
"\u2588\u2588\u2588\u2588 \u2584\u2584\u2584 ",
|
|
683
|
+
"\u2588\u2588\u2588\u2588 \u2580\u2580\u2580 ",
|
|
684
|
+
"\u2588\u2588\u2588\u2588 ",
|
|
685
|
+
"\u2588\u2588\u2588\u2588 "
|
|
686
|
+
];
|
|
687
|
+
var PLAIN = [
|
|
688
|
+
".#########",
|
|
689
|
+
"#### ",
|
|
690
|
+
"######## ",
|
|
691
|
+
"#### ",
|
|
692
|
+
"#### ####",
|
|
693
|
+
"#### ####"
|
|
694
|
+
];
|
|
695
|
+
function renderBanner(version, info, { isTTY, columns, env: env2, argv }) {
|
|
696
|
+
if (!isTTY || argv.includes("--json")) return null;
|
|
697
|
+
const color = !("NO_COLOR" in env2);
|
|
698
|
+
const locale = env2.LC_ALL || env2.LC_CTYPE || env2.LANG || "UTF-8";
|
|
699
|
+
const unicode = color && !env2.CI && /UTF-?8/i.test(locale);
|
|
700
|
+
const truecolor = /truecolor|24bit/.test(env2.COLORTERM ?? "");
|
|
701
|
+
const pour = (s) => !color ? s : truecolor ? `\x1B[38;2;240;122;58m${s}\x1B[39m` : `\x1B[38;5;208m${s}\x1B[39m`;
|
|
702
|
+
const dim = (s) => color ? `\x1B[2m${s}\x1B[22m` : s;
|
|
703
|
+
if ((columns ?? 80) < 60) {
|
|
704
|
+
return `${pour(unicode ? "\u2584\u2588" : "[F]")} FoundryKit ${dim(version)}`;
|
|
705
|
+
}
|
|
706
|
+
const mark = unicode ? KIT : PLAIN;
|
|
707
|
+
const text = [
|
|
708
|
+
`FoundryKit CLI ${dim(version)}`,
|
|
709
|
+
dim("parts for Payload + Next.js"),
|
|
710
|
+
"",
|
|
711
|
+
...info.map(([label, value]) => `${dim(label.padEnd(10))}${value}`)
|
|
712
|
+
];
|
|
713
|
+
const rows = mark.map((m, i) => `${pour(m)} ${text[i] ?? ""}`.trimEnd());
|
|
714
|
+
return `
|
|
715
|
+
${rows.join("\n")}
|
|
716
|
+
`;
|
|
717
|
+
}
|
|
718
|
+
function printBanner(info) {
|
|
719
|
+
const text = renderBanner(cliVersion(), info, {
|
|
720
|
+
isTTY: Boolean(process.stdout.isTTY),
|
|
721
|
+
columns: process.stdout.columns,
|
|
722
|
+
env: process.env,
|
|
723
|
+
argv: process.argv
|
|
724
|
+
});
|
|
725
|
+
if (text) console.log(text);
|
|
726
|
+
}
|
|
727
|
+
function cliVersion() {
|
|
728
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
729
|
+
for (const rel of ["..", "../.."]) {
|
|
730
|
+
try {
|
|
731
|
+
const pkg = JSON.parse(
|
|
732
|
+
readFileSync(join(dir, rel, "package.json"), "utf8")
|
|
733
|
+
);
|
|
734
|
+
if (pkg.name === "@foundrykit/cli") return pkg.version;
|
|
735
|
+
} catch {
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return "";
|
|
739
|
+
}
|
|
740
|
+
function projectSummary(pkg) {
|
|
741
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
742
|
+
const ver = (n) => deps[n]?.replace(/^[^\d]*/, "");
|
|
743
|
+
return [
|
|
744
|
+
pkg.name,
|
|
745
|
+
deps.next && `Next ${ver("next")}`,
|
|
746
|
+
deps.payload && `Payload ${ver("payload")}`
|
|
747
|
+
].filter(Boolean).join(" \xB7 ");
|
|
748
|
+
}
|
|
749
|
+
|
|
678
750
|
// src/lib/project/index.ts
|
|
679
751
|
import path4 from "path";
|
|
680
752
|
import fs4 from "fs-extra";
|
|
@@ -964,6 +1036,13 @@ function addCommand() {
|
|
|
964
1036
|
try {
|
|
965
1037
|
const project = await loadProject(process.cwd());
|
|
966
1038
|
process.chdir(project.root);
|
|
1039
|
+
printBanner([
|
|
1040
|
+
[
|
|
1041
|
+
"project",
|
|
1042
|
+
projectSummary(await fs5.readJson("package.json").catch(() => ({})))
|
|
1043
|
+
],
|
|
1044
|
+
["registry", resolveRegistryUrl(project.settings)]
|
|
1045
|
+
]);
|
|
967
1046
|
validateProject(project, options);
|
|
968
1047
|
const ids = id ? [id] : await selectComponentsInteractively(project);
|
|
969
1048
|
if (ids.length === 0) {
|
|
@@ -1212,10 +1291,10 @@ function getPackageInstallSpec(packageName, version) {
|
|
|
1212
1291
|
async function getMissingPackages(packages) {
|
|
1213
1292
|
const packageJsonPath = path5.join(process.cwd(), "package.json");
|
|
1214
1293
|
try {
|
|
1215
|
-
const
|
|
1294
|
+
const packageJson = await fs5.readJson(packageJsonPath);
|
|
1216
1295
|
const installedPackages = {
|
|
1217
|
-
...
|
|
1218
|
-
...
|
|
1296
|
+
...packageJson.dependencies,
|
|
1297
|
+
...packageJson.devDependencies
|
|
1219
1298
|
};
|
|
1220
1299
|
return packages.filter((pkg) => !installedPackages[pkg]);
|
|
1221
1300
|
} catch {
|
|
@@ -2105,8 +2184,8 @@ async function collectBasicChecks(cwd) {
|
|
|
2105
2184
|
ok: hasPackageJson,
|
|
2106
2185
|
detail: hasPackageJson ? "Project manifest found" : "Run this command in a project root"
|
|
2107
2186
|
});
|
|
2108
|
-
const
|
|
2109
|
-
const hasNext = !!(
|
|
2187
|
+
const packageJson = hasPackageJson ? await fs7.readJson(packageJsonPath) : null;
|
|
2188
|
+
const hasNext = !!(packageJson?.dependencies?.next || packageJson?.devDependencies?.next);
|
|
2110
2189
|
results.push({
|
|
2111
2190
|
name: "Framework",
|
|
2112
2191
|
ok: hasNext,
|
|
@@ -2172,6 +2251,14 @@ import inquirer4 from "inquirer";
|
|
|
2172
2251
|
function initCommand() {
|
|
2173
2252
|
return new Command4("init").description("Initialize FoundryKit in your project").option("-f, --force", "overwrite existing files").option("--skip-install", "skip installing dependencies").option("--skip-prompts", "use default paths without prompting").action(async (options) => {
|
|
2174
2253
|
try {
|
|
2254
|
+
const pkgPath = path8.join(process.cwd(), "package.json");
|
|
2255
|
+
printBanner([
|
|
2256
|
+
[
|
|
2257
|
+
"project",
|
|
2258
|
+
fs8.existsSync(pkgPath) ? projectSummary(await fs8.readJson(pkgPath).catch(() => ({}))) : path8.basename(process.cwd())
|
|
2259
|
+
],
|
|
2260
|
+
["registry", resolveRegistryUrl()]
|
|
2261
|
+
]);
|
|
2175
2262
|
console.log(chalk6.blue("\u{1F680} Initializing FoundryKit..."));
|
|
2176
2263
|
await validateProject2();
|
|
2177
2264
|
if (!options.force && await isFoundryKitInitialized()) {
|
|
@@ -2245,10 +2332,10 @@ async function validateProject2() {
|
|
|
2245
2332
|
"No package.json found. Please run this command in a project directory."
|
|
2246
2333
|
);
|
|
2247
2334
|
}
|
|
2248
|
-
const
|
|
2335
|
+
const packageJson = await fs8.readJson(packageJsonPath);
|
|
2249
2336
|
const deps = {
|
|
2250
|
-
...
|
|
2251
|
-
...
|
|
2337
|
+
...packageJson.dependencies,
|
|
2338
|
+
...packageJson.devDependencies
|
|
2252
2339
|
};
|
|
2253
2340
|
if (!deps.next) {
|
|
2254
2341
|
throw new Error(
|
|
@@ -2792,13 +2879,13 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
|
2792
2879
|
async function updatePackageScripts() {
|
|
2793
2880
|
console.log(chalk6.blue("\u{1F4DD} Updating package.json scripts..."));
|
|
2794
2881
|
const packageJsonPath = path8.join(process.cwd(), "package.json");
|
|
2795
|
-
const
|
|
2796
|
-
|
|
2797
|
-
...
|
|
2882
|
+
const packageJson = await fs8.readJson(packageJsonPath);
|
|
2883
|
+
packageJson.scripts = {
|
|
2884
|
+
...packageJson.scripts,
|
|
2798
2885
|
"foundrykit:add": "pnpm dlx @foundrykit/cli add",
|
|
2799
2886
|
"foundrykit:update": "pnpm dlx @foundrykit/cli update"
|
|
2800
2887
|
};
|
|
2801
|
-
await fs8.writeJson(packageJsonPath,
|
|
2888
|
+
await fs8.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
|
2802
2889
|
console.log(chalk6.green("\u2705 Package scripts updated"));
|
|
2803
2890
|
}
|
|
2804
2891
|
async function createConfigFile(options, structure, pathConfig) {
|
|
@@ -3734,11 +3821,11 @@ async function getInstalledFoundryKitPackageVersions(root) {
|
|
|
3734
3821
|
if (!fs9.existsSync(packageJsonPath)) {
|
|
3735
3822
|
return {};
|
|
3736
3823
|
}
|
|
3737
|
-
const
|
|
3824
|
+
const packageJson = await fs9.readJson(packageJsonPath);
|
|
3738
3825
|
const dependencies = {
|
|
3739
|
-
...
|
|
3740
|
-
...
|
|
3741
|
-
...
|
|
3826
|
+
...packageJson.dependencies,
|
|
3827
|
+
...packageJson.devDependencies,
|
|
3828
|
+
...packageJson.optionalDependencies
|
|
3742
3829
|
};
|
|
3743
3830
|
return Object.fromEntries(
|
|
3744
3831
|
Object.entries(dependencies).filter(([name]) => name.startsWith("@foundrykit/")).map(([name, version]) => [
|
|
@@ -3966,13 +4053,8 @@ function upgradeCommand() {
|
|
|
3966
4053
|
}
|
|
3967
4054
|
|
|
3968
4055
|
// src/index.ts
|
|
3969
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
3970
|
-
var __dirname = dirname(__filename);
|
|
3971
|
-
var packageJson = JSON.parse(
|
|
3972
|
-
readFileSync(join(__dirname, "..", "package.json"), "utf-8")
|
|
3973
|
-
);
|
|
3974
4056
|
var program = new Command11();
|
|
3975
|
-
program.name("foundrykit").description("FoundryKit CLI - Component library management tool").version(
|
|
4057
|
+
program.name("foundrykit").description("FoundryKit CLI - Component library management tool").version(cliVersion());
|
|
3976
4058
|
program.addCommand(initCommand());
|
|
3977
4059
|
program.addCommand(listCommand());
|
|
3978
4060
|
program.addCommand(addCommand());
|