@foundrykit/cli 2.0.12 → 3.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/README.md +71 -6
- package/dist/cli.js +2130 -677
- package/dist/cli.js.map +1 -1
- package/dist/index.js +2130 -677
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/schema.json +60 -0
- package/.turbo/turbo-type-check.log +0 -4
- package/CHANGELOG.md +0 -254
- package/docs/DEPENDENCY_RESOLUTION.md +0 -201
- package/postcss.config.mjs +0 -6
- package/src/commands/add.ts +0 -1069
- package/src/commands/doctor.ts +0 -130
- package/src/commands/init.ts +0 -928
- package/src/commands/list.ts +0 -167
- package/src/commands/update.ts +0 -323
- package/src/index.ts +0 -34
- package/src/lib/constants.ts +0 -42
- package/src/lib/registry.ts +0 -627
- package/tests/dependency-resolution.test.ts +0 -579
- package/tsconfig.json +0 -11
- package/tsconfig.lint.json +0 -8
- package/tsup.config.ts +0 -16
package/dist/index.js
CHANGED
|
@@ -4,19 +4,23 @@
|
|
|
4
4
|
import { readFileSync } from "fs";
|
|
5
5
|
import { dirname, join } from "path";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
|
-
import { Command as
|
|
7
|
+
import { Command as Command10 } from "commander";
|
|
8
8
|
|
|
9
9
|
// src/commands/add.ts
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { promisify } from "util";
|
|
13
|
-
import chalk2 from "chalk";
|
|
10
|
+
import path5 from "path";
|
|
11
|
+
import chalk3 from "chalk";
|
|
14
12
|
import { Command } from "commander";
|
|
15
|
-
import
|
|
13
|
+
import fs5 from "fs-extra";
|
|
14
|
+
import inquirer2 from "inquirer";
|
|
15
|
+
|
|
16
|
+
// src/lib/apply.ts
|
|
17
|
+
import path3 from "path";
|
|
18
|
+
import chalk2 from "chalk";
|
|
19
|
+
import { createTwoFilesPatch } from "diff";
|
|
20
|
+
import fs3 from "fs-extra";
|
|
16
21
|
import inquirer from "inquirer";
|
|
17
22
|
|
|
18
23
|
// src/lib/constants.ts
|
|
19
|
-
var CLI_VERSION = "1.0.16";
|
|
20
24
|
var DEFAULT_REGISTRY_URL = "https://foundry.umiflow.com";
|
|
21
25
|
var NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
22
26
|
var CACHE_TTL = 24 * 60 * 60 * 1e3;
|
|
@@ -45,15 +49,67 @@ var FOUNDRYKIT_PACKAGE_ALIASES = [
|
|
|
45
49
|
"types",
|
|
46
50
|
"utils"
|
|
47
51
|
];
|
|
52
|
+
var SETTINGS_FILE = "foundrykit.json";
|
|
53
|
+
var LOCK_FILE = "foundrykit.lock.json";
|
|
54
|
+
var LEGACY_CONFIG_FILE = "foundrykit.config.json";
|
|
55
|
+
var SCHEMA_URL = "https://unpkg.com/@foundrykit/cli@3/schema.json";
|
|
56
|
+
var LEGACY_DEFAULT_REGISTRY_URL = "https://foundry.umiflow.com";
|
|
57
|
+
var DEFAULT_HUB_URL = "http://localhost:3003";
|
|
58
|
+
var CREDENTIALS_FILE = "credentials.json";
|
|
59
|
+
|
|
60
|
+
// src/lib/project/files.ts
|
|
61
|
+
import { createHash, randomBytes } from "crypto";
|
|
62
|
+
import path from "path";
|
|
63
|
+
import fs from "fs-extra";
|
|
64
|
+
function fingerprint(content) {
|
|
65
|
+
const hash = createHash("sha256").update(content.replace(/\r\n/g, "\n")).digest("base64");
|
|
66
|
+
return `sha256-${hash}`;
|
|
67
|
+
}
|
|
68
|
+
async function fileStatus(absPath, recorded) {
|
|
69
|
+
if (!await fs.pathExists(absPath)) return "missing";
|
|
70
|
+
if (recorded === void 0) return "unknown";
|
|
71
|
+
const current = fingerprint(await fs.readFile(absPath, "utf8"));
|
|
72
|
+
return current === recorded ? "unchanged" : "edited";
|
|
73
|
+
}
|
|
74
|
+
function sortKeys(value) {
|
|
75
|
+
if (Array.isArray(value)) return value.map(sortKeys);
|
|
76
|
+
if (value && typeof value === "object") {
|
|
77
|
+
return Object.fromEntries(
|
|
78
|
+
Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => [k, sortKeys(v)])
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
function stableStringify(value) {
|
|
84
|
+
return `${JSON.stringify(sortKeys(value), null, 2)}
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
async function writeFileAtomic(absPath, content) {
|
|
88
|
+
if (await fs.pathExists(absPath) && await fs.readFile(absPath, "utf8") === content) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
await fs.ensureDir(path.dirname(absPath));
|
|
92
|
+
const tmp = `${absPath}.${randomBytes(4).toString("hex")}.tmp`;
|
|
93
|
+
try {
|
|
94
|
+
await fs.writeFile(tmp, content);
|
|
95
|
+
await fs.rename(tmp, absPath);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
await fs.remove(tmp);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
48
102
|
|
|
49
103
|
// src/lib/registry.ts
|
|
50
104
|
import os from "os";
|
|
51
|
-
import
|
|
105
|
+
import path2 from "path";
|
|
52
106
|
import chalk from "chalk";
|
|
53
|
-
import
|
|
107
|
+
import fs2 from "fs-extra";
|
|
108
|
+
function resolveRegistryUrl(settings) {
|
|
109
|
+
return process.env.FOUNDRYKIT_REGISTRY_URL || settings?.registry || DEFAULT_REGISTRY_URL;
|
|
110
|
+
}
|
|
54
111
|
var DEFAULT_CONFIG = {
|
|
55
|
-
|
|
56
|
-
cacheDir: path.join(os.homedir(), CACHE_DIR, "cache"),
|
|
112
|
+
cacheDir: path2.join(os.homedir(), CACHE_DIR, "cache"),
|
|
57
113
|
cacheMaxAge: CACHE_TTL
|
|
58
114
|
};
|
|
59
115
|
var RegistryService = class {
|
|
@@ -61,8 +117,12 @@ var RegistryService = class {
|
|
|
61
117
|
cacheFile;
|
|
62
118
|
foundryKitPackagesPromise = null;
|
|
63
119
|
constructor(config) {
|
|
64
|
-
this.config = {
|
|
65
|
-
|
|
120
|
+
this.config = {
|
|
121
|
+
...DEFAULT_CONFIG,
|
|
122
|
+
registryUrl: resolveRegistryUrl(),
|
|
123
|
+
...config
|
|
124
|
+
};
|
|
125
|
+
this.cacheFile = path2.join(this.config.cacheDir, "registry.json");
|
|
66
126
|
}
|
|
67
127
|
/**
|
|
68
128
|
* Fetch all components from the registry
|
|
@@ -230,11 +290,11 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
230
290
|
*/
|
|
231
291
|
async isPackageInstalled(packageName) {
|
|
232
292
|
try {
|
|
233
|
-
const packageJsonPath =
|
|
234
|
-
if (!await
|
|
293
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
294
|
+
if (!await fs2.pathExists(packageJsonPath)) {
|
|
235
295
|
return false;
|
|
236
296
|
}
|
|
237
|
-
const packageJson2 = await
|
|
297
|
+
const packageJson2 = await fs2.readJson(packageJsonPath);
|
|
238
298
|
const allDeps = {
|
|
239
299
|
...packageJson2.dependencies,
|
|
240
300
|
...packageJson2.devDependencies,
|
|
@@ -357,8 +417,8 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
357
417
|
components,
|
|
358
418
|
componentData: cache?.componentData || {}
|
|
359
419
|
};
|
|
360
|
-
await
|
|
361
|
-
await
|
|
420
|
+
await fs2.ensureDir(this.config.cacheDir);
|
|
421
|
+
await fs2.writeJson(this.cacheFile, newCache, { spaces: 2 });
|
|
362
422
|
} catch {
|
|
363
423
|
console.log(chalk.gray("Failed to update cache"));
|
|
364
424
|
}
|
|
@@ -376,8 +436,8 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
376
436
|
};
|
|
377
437
|
cache.componentData[component.id] = component;
|
|
378
438
|
cache.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
379
|
-
await
|
|
380
|
-
await
|
|
439
|
+
await fs2.ensureDir(this.config.cacheDir);
|
|
440
|
+
await fs2.writeJson(this.cacheFile, cache, { spaces: 2 });
|
|
381
441
|
} catch {
|
|
382
442
|
console.log(chalk.gray("Failed to cache component"));
|
|
383
443
|
}
|
|
@@ -387,8 +447,8 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
387
447
|
*/
|
|
388
448
|
async loadCache() {
|
|
389
449
|
try {
|
|
390
|
-
if (await
|
|
391
|
-
return await
|
|
450
|
+
if (await fs2.pathExists(this.cacheFile)) {
|
|
451
|
+
return await fs2.readJson(this.cacheFile);
|
|
392
452
|
}
|
|
393
453
|
} catch {
|
|
394
454
|
console.log(chalk.gray("Failed to load cache"));
|
|
@@ -424,8 +484,8 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
424
484
|
*/
|
|
425
485
|
async clearCache() {
|
|
426
486
|
try {
|
|
427
|
-
if (await
|
|
428
|
-
await
|
|
487
|
+
if (await fs2.pathExists(this.cacheFile)) {
|
|
488
|
+
await fs2.remove(this.cacheFile);
|
|
429
489
|
console.log(chalk.green("Cache cleared successfully"));
|
|
430
490
|
}
|
|
431
491
|
} catch (error) {
|
|
@@ -439,9 +499,9 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
439
499
|
*/
|
|
440
500
|
async getCacheStats() {
|
|
441
501
|
try {
|
|
442
|
-
if (await
|
|
502
|
+
if (await fs2.pathExists(this.cacheFile)) {
|
|
443
503
|
const cache = await this.loadCache();
|
|
444
|
-
const stats = await
|
|
504
|
+
const stats = await fs2.stat(this.cacheFile);
|
|
445
505
|
return {
|
|
446
506
|
exists: true,
|
|
447
507
|
size: stats.size,
|
|
@@ -460,9 +520,12 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
460
520
|
}
|
|
461
521
|
};
|
|
462
522
|
var registryInstance = null;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
523
|
+
var registryInstanceUrl = null;
|
|
524
|
+
function getRegistry(config, settings) {
|
|
525
|
+
const registryUrl = config?.registryUrl ?? resolveRegistryUrl(settings);
|
|
526
|
+
if (!registryInstance || registryInstanceUrl !== registryUrl) {
|
|
527
|
+
registryInstance = new RegistryService({ ...config, registryUrl });
|
|
528
|
+
registryInstanceUrl = registryUrl;
|
|
466
529
|
}
|
|
467
530
|
return registryInstance;
|
|
468
531
|
}
|
|
@@ -480,48 +543,469 @@ function normalizeVersion(version) {
|
|
|
480
543
|
return version.replace(/^[^\d]*/, "").split("-")[0]?.replace(/[^\d.]/g, "") || "0";
|
|
481
544
|
}
|
|
482
545
|
|
|
546
|
+
// src/lib/apply.ts
|
|
547
|
+
async function applyComponent(project, data, opts) {
|
|
548
|
+
const result = {
|
|
549
|
+
id: data.id,
|
|
550
|
+
written: [],
|
|
551
|
+
upToDate: [],
|
|
552
|
+
skippedEdited: [],
|
|
553
|
+
skippedUnknown: [],
|
|
554
|
+
kept: [],
|
|
555
|
+
droppedFromLock: [],
|
|
556
|
+
failed: []
|
|
557
|
+
};
|
|
558
|
+
const { settings } = project;
|
|
559
|
+
const previous = project.lock.components[data.id]?.files ?? {};
|
|
560
|
+
const files = {};
|
|
561
|
+
const seen = /* @__PURE__ */ new Set();
|
|
562
|
+
for (const file of data.files) {
|
|
563
|
+
const isUtils = data.id === "utils" || file.path === "lib/utils.ts";
|
|
564
|
+
const resolved = isUtils ? settings.paths.utils || "lib/utils.ts" : resolveComponentPath(file.path, data.category, settings);
|
|
565
|
+
let rel = resolved;
|
|
566
|
+
try {
|
|
567
|
+
let abs = project.resolveInRoot(path3.join(opts.basePath ?? "", resolved));
|
|
568
|
+
rel = path3.relative(project.root, abs).split(path3.sep).join("/");
|
|
569
|
+
if (!previous[rel]) {
|
|
570
|
+
const suffix = resolved.split(/[\\/]/).slice(isUtils ? -1 : -2).join("/");
|
|
571
|
+
const recordedPath = Object.keys(previous).find(
|
|
572
|
+
(key) => !seen.has(key) && (key === suffix || key.endsWith(`/${suffix}`))
|
|
573
|
+
);
|
|
574
|
+
if (recordedPath) {
|
|
575
|
+
rel = recordedPath;
|
|
576
|
+
abs = project.resolveInRoot(recordedPath);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
seen.add(rel);
|
|
580
|
+
const recorded = previous[rel];
|
|
581
|
+
const keepRecorded = () => {
|
|
582
|
+
if (recorded) files[rel] = recorded;
|
|
583
|
+
};
|
|
584
|
+
if (!file.content || file.content.trim() === "") {
|
|
585
|
+
console.log(chalk2.yellow(` \u26A0 Skipping ${rel} - no content available`));
|
|
586
|
+
keepRecorded();
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
const next = transformImportsForConfig(file.content, settings);
|
|
590
|
+
const disk = await fs3.pathExists(abs) ? await fs3.readFile(abs, "utf8") : void 0;
|
|
591
|
+
if (disk !== void 0 && fingerprint(disk) === fingerprint(next)) {
|
|
592
|
+
files[rel] = fingerprint(next);
|
|
593
|
+
result.upToDate.push(rel);
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
const status = await fileStatus(abs, recorded);
|
|
597
|
+
let write = status === "missing" || status === "unchanged" || opts.overwrite;
|
|
598
|
+
if (!write && status === "edited") {
|
|
599
|
+
result.skippedEdited.push(rel);
|
|
600
|
+
keepRecorded();
|
|
601
|
+
} else if (!write && opts.prompt) {
|
|
602
|
+
const diff = createTwoFilesPatch(
|
|
603
|
+
rel,
|
|
604
|
+
rel,
|
|
605
|
+
disk ?? "",
|
|
606
|
+
next,
|
|
607
|
+
"your file",
|
|
608
|
+
"registry"
|
|
609
|
+
);
|
|
610
|
+
if (await opts.prompt(rel, diff) === "overwrite") {
|
|
611
|
+
write = true;
|
|
612
|
+
} else {
|
|
613
|
+
files[rel] = fingerprint(next);
|
|
614
|
+
result.kept.push(rel);
|
|
615
|
+
}
|
|
616
|
+
} else if (!write) {
|
|
617
|
+
result.skippedUnknown.push(rel);
|
|
618
|
+
keepRecorded();
|
|
619
|
+
}
|
|
620
|
+
if (write) {
|
|
621
|
+
await fs3.outputFile(abs, next);
|
|
622
|
+
files[rel] = fingerprint(next);
|
|
623
|
+
result.written.push(rel);
|
|
624
|
+
}
|
|
625
|
+
} catch (error) {
|
|
626
|
+
result.failed.push(
|
|
627
|
+
`${rel}: ${error instanceof Error ? error.message : String(error)}`
|
|
628
|
+
);
|
|
629
|
+
const recorded = previous[rel];
|
|
630
|
+
if (recorded) files[rel] = recorded;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const existing = project.lock.components[data.id];
|
|
634
|
+
if (existing && result.written.length + result.upToDate.length === 0) {
|
|
635
|
+
if (result.kept.length > 0) {
|
|
636
|
+
existing.files = { ...existing.files };
|
|
637
|
+
for (const rel of result.kept) existing.files[rel] = files[rel];
|
|
638
|
+
}
|
|
639
|
+
return result;
|
|
640
|
+
}
|
|
641
|
+
for (const rel of Object.keys(previous)) {
|
|
642
|
+
if (!seen.has(rel)) result.droppedFromLock.push(rel);
|
|
643
|
+
}
|
|
644
|
+
const entry = { version: data.version ?? null };
|
|
645
|
+
const registry = resolveRegistryUrl(settings);
|
|
646
|
+
if (registry !== DEFAULT_REGISTRY_URL && registry !== LEGACY_DEFAULT_REGISTRY_URL) {
|
|
647
|
+
entry.registry = registry;
|
|
648
|
+
}
|
|
649
|
+
if (Object.keys(files).length > 0) entry.files = files;
|
|
650
|
+
project.lock.components[data.id] = entry;
|
|
651
|
+
return result;
|
|
652
|
+
}
|
|
653
|
+
function interactivePrompt() {
|
|
654
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return void 0;
|
|
655
|
+
return async (file, diff) => {
|
|
656
|
+
console.log(
|
|
657
|
+
diff.split("\n").map(
|
|
658
|
+
(line) => line.startsWith("+") && !line.startsWith("+++") ? chalk2.green(line) : line.startsWith("-") && !line.startsWith("---") ? chalk2.red(line) : line
|
|
659
|
+
).join("\n")
|
|
660
|
+
);
|
|
661
|
+
const { choice } = await inquirer.prompt([
|
|
662
|
+
{
|
|
663
|
+
type: "list",
|
|
664
|
+
name: "choice",
|
|
665
|
+
message: `${file} isn't tracked yet and differs from the registry version.`,
|
|
666
|
+
choices: [
|
|
667
|
+
{ name: "Keep my file", value: "keep" },
|
|
668
|
+
{ name: "Overwrite with the registry version", value: "overwrite" }
|
|
669
|
+
],
|
|
670
|
+
default: "keep"
|
|
671
|
+
}
|
|
672
|
+
]);
|
|
673
|
+
return choice;
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// src/lib/project/index.ts
|
|
678
|
+
import path4 from "path";
|
|
679
|
+
import fs4 from "fs-extra";
|
|
680
|
+
|
|
681
|
+
// src/lib/project/migrate.ts
|
|
682
|
+
var KNOWN_PACKAGE_IDS = [
|
|
683
|
+
...FOUNDRYKIT_PACKAGE_ALIASES.filter((id) => id !== "utils"),
|
|
684
|
+
"form-plugin",
|
|
685
|
+
"seo-plugin",
|
|
686
|
+
"guides-plugin",
|
|
687
|
+
"history-plugin",
|
|
688
|
+
"media-plugin",
|
|
689
|
+
"menu-plugin",
|
|
690
|
+
"permissions-plugin",
|
|
691
|
+
"search-plugin",
|
|
692
|
+
"svg-maps",
|
|
693
|
+
"tile-maps",
|
|
694
|
+
"biome-config",
|
|
695
|
+
"advanced-seo-plugin",
|
|
696
|
+
"advanced-forms-plugin"
|
|
697
|
+
];
|
|
698
|
+
function migrateLegacyConfig(legacy, pkg) {
|
|
699
|
+
const { version: _v, installedComponents, registry, ...rest } = legacy;
|
|
700
|
+
const settings = { $schema: SCHEMA_URL, ...rest };
|
|
701
|
+
if (registry && registry !== DEFAULT_REGISTRY_URL && registry !== LEGACY_DEFAULT_REGISTRY_URL) {
|
|
702
|
+
settings.registry = registry;
|
|
703
|
+
}
|
|
704
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
705
|
+
const components = {};
|
|
706
|
+
for (const [id, entry] of Object.entries(installedComponents ?? {})) {
|
|
707
|
+
const isPackage = id !== "utils" && (`@foundrykit/${id}` in deps || KNOWN_PACKAGE_IDS.includes(id));
|
|
708
|
+
if (!isPackage) components[id] = { version: entry.version };
|
|
709
|
+
}
|
|
710
|
+
return { settings, lock: { lockfileVersion: 1, components } };
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// src/lib/project/settings.ts
|
|
714
|
+
var SettingsError = class extends Error {
|
|
715
|
+
constructor(key, expected) {
|
|
716
|
+
super(`foundrykit.json: "${key}" must be ${expected}`);
|
|
717
|
+
this.key = key;
|
|
718
|
+
this.name = "SettingsError";
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
var RULES = [
|
|
722
|
+
["$schema", "string", false],
|
|
723
|
+
["registry", "string", false],
|
|
724
|
+
["packageManager", "string", true],
|
|
725
|
+
["typescript", "boolean", true],
|
|
726
|
+
["framework", "string", true],
|
|
727
|
+
["tailwind.css", "string", true],
|
|
728
|
+
["aliases.@", "string", true],
|
|
729
|
+
["aliases.@/components", "string", true],
|
|
730
|
+
["aliases.@/lib", "string", true],
|
|
731
|
+
["aliases.@/hooks", "string", true],
|
|
732
|
+
["paths.primitives", "string", true],
|
|
733
|
+
["paths.components", "string", true],
|
|
734
|
+
["paths.blocks", "string", true],
|
|
735
|
+
["paths.animations", "string", true],
|
|
736
|
+
["paths.utils", "string", true],
|
|
737
|
+
["paths.hooks", "string", false],
|
|
738
|
+
["paths.maps", "string", false],
|
|
739
|
+
["hub.project", "string", false, /^[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/],
|
|
740
|
+
["hub.url", "string", false, /^https?:\/\//]
|
|
741
|
+
];
|
|
742
|
+
var KNOWN_TOP_LEVEL = new Set(RULES.map(([p]) => p.split(".")[0]));
|
|
743
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
744
|
+
function validateSettings(raw) {
|
|
745
|
+
if (!isObject(raw)) throw new SettingsError("(root)", "an object");
|
|
746
|
+
for (const [path10, type, required, pattern] of RULES) {
|
|
747
|
+
const [parent, child] = path10.includes(".") ? [path10.slice(0, path10.indexOf(".")), path10.slice(path10.indexOf(".") + 1)] : [void 0, path10];
|
|
748
|
+
let holder = raw;
|
|
749
|
+
if (parent) {
|
|
750
|
+
holder = raw[parent];
|
|
751
|
+
if (holder === void 0 && !required) continue;
|
|
752
|
+
if (!isObject(holder)) {
|
|
753
|
+
if (required)
|
|
754
|
+
throw new SettingsError(
|
|
755
|
+
path10,
|
|
756
|
+
`${type} (parent "${parent}" must be an object)`
|
|
757
|
+
);
|
|
758
|
+
throw new SettingsError(parent, "an object");
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
const value = holder[child];
|
|
762
|
+
if (value === void 0) {
|
|
763
|
+
if (required) throw new SettingsError(path10, `a ${type} (missing)`);
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
if (typeof value !== type) throw new SettingsError(path10, `a ${type}`);
|
|
767
|
+
if (pattern && !pattern.test(value))
|
|
768
|
+
throw new SettingsError(path10, `a string matching ${pattern.source}`);
|
|
769
|
+
}
|
|
770
|
+
const warnings = Object.keys(raw).filter((k) => !KNOWN_TOP_LEVEL.has(k)).map((k) => `foundrykit.json: unknown key "${k}" (ignored)`);
|
|
771
|
+
return { settings: raw, warnings };
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/lib/project/index.ts
|
|
775
|
+
var ProjectError = class extends Error {
|
|
776
|
+
constructor(message) {
|
|
777
|
+
super(message);
|
|
778
|
+
this.name = "ProjectError";
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
function findProjectRoot(cwd) {
|
|
782
|
+
let dir = path4.resolve(cwd);
|
|
783
|
+
for (; ; ) {
|
|
784
|
+
if (fs4.existsSync(path4.join(dir, SETTINGS_FILE)) || fs4.existsSync(path4.join(dir, LEGACY_CONFIG_FILE))) {
|
|
785
|
+
return dir;
|
|
786
|
+
}
|
|
787
|
+
const parent = path4.dirname(dir);
|
|
788
|
+
if (parent === dir) return null;
|
|
789
|
+
dir = parent;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
async function readJson(file) {
|
|
793
|
+
try {
|
|
794
|
+
return JSON.parse(await fs4.readFile(file, "utf8"));
|
|
795
|
+
} catch (error) {
|
|
796
|
+
throw new ProjectError(
|
|
797
|
+
`Could not read ${path4.basename(file)}: ${error.message}`
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function checkLock(raw) {
|
|
802
|
+
const lock = raw;
|
|
803
|
+
if (!lock || typeof lock !== "object" || lock.lockfileVersion !== 1 || !lock.components || typeof lock.components !== "object") {
|
|
804
|
+
throw new ProjectError(
|
|
805
|
+
`${LOCK_FILE} is invalid: expected lockfileVersion 1 and a "components" object`
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
return lock;
|
|
809
|
+
}
|
|
810
|
+
async function loadProject(cwd, opts = {}) {
|
|
811
|
+
const root = findProjectRoot(cwd);
|
|
812
|
+
if (!root) {
|
|
813
|
+
throw new ProjectError(
|
|
814
|
+
`No ${SETTINGS_FILE} found. Run \`foundrykit init\` first.`
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
const settingsPath = path4.join(root, SETTINGS_FILE);
|
|
818
|
+
const lockPath = path4.join(root, LOCK_FILE);
|
|
819
|
+
const legacyPath = path4.join(root, LEGACY_CONFIG_FILE);
|
|
820
|
+
const hasSettings = await fs4.pathExists(settingsPath);
|
|
821
|
+
const hasLegacy = await fs4.pathExists(legacyPath);
|
|
822
|
+
let rawSettings;
|
|
823
|
+
let lock = { lockfileVersion: 1, components: {} };
|
|
824
|
+
let migration = "none";
|
|
825
|
+
const warnings = [];
|
|
826
|
+
if (hasSettings) {
|
|
827
|
+
rawSettings = await readJson(settingsPath);
|
|
828
|
+
if (await fs4.pathExists(lockPath)) {
|
|
829
|
+
lock = checkLock(await readJson(lockPath));
|
|
830
|
+
}
|
|
831
|
+
if (hasLegacy) {
|
|
832
|
+
warnings.push(
|
|
833
|
+
`${LEGACY_CONFIG_FILE} is no longer used and can be deleted.`
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
} else {
|
|
837
|
+
const pkgPath = path4.join(root, "package.json");
|
|
838
|
+
const pkg = await fs4.pathExists(pkgPath) ? await readJson(pkgPath) : {};
|
|
839
|
+
const migrated = migrateLegacyConfig(
|
|
840
|
+
await readJson(legacyPath),
|
|
841
|
+
pkg
|
|
842
|
+
);
|
|
843
|
+
rawSettings = migrated.settings;
|
|
844
|
+
lock = migrated.lock;
|
|
845
|
+
migration = "pending";
|
|
846
|
+
}
|
|
847
|
+
const validated = validateSettings(rawSettings);
|
|
848
|
+
warnings.push(...validated.warnings);
|
|
849
|
+
const project = {
|
|
850
|
+
root,
|
|
851
|
+
settings: validated.settings,
|
|
852
|
+
lock,
|
|
853
|
+
migration,
|
|
854
|
+
warnings,
|
|
855
|
+
resolveInRoot(p) {
|
|
856
|
+
const abs = path4.resolve(root, p);
|
|
857
|
+
const rel = path4.relative(root, abs);
|
|
858
|
+
if (rel === ".." || rel.startsWith(`..${path4.sep}`) || path4.isAbsolute(rel)) {
|
|
859
|
+
throw new ProjectError(`Path escapes the project root: ${p}`);
|
|
860
|
+
}
|
|
861
|
+
return abs;
|
|
862
|
+
},
|
|
863
|
+
async saveLock() {
|
|
864
|
+
await writeFileAtomic(lockPath, stableStringify(project.lock));
|
|
865
|
+
},
|
|
866
|
+
async saveSettings() {
|
|
867
|
+
await writeFileAtomic(settingsPath, stableStringify(project.settings));
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
if (migration === "pending" && !opts.readOnly) {
|
|
871
|
+
await project.saveLock();
|
|
872
|
+
await project.saveSettings();
|
|
873
|
+
await fs4.remove(legacyPath);
|
|
874
|
+
project.migration = "done";
|
|
875
|
+
process.stderr.write(
|
|
876
|
+
`Migrated ${LEGACY_CONFIG_FILE} to ${SETTINGS_FILE} and ${LOCK_FILE}. Commit both new files.
|
|
877
|
+
`
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
return project;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// src/lib/run.ts
|
|
884
|
+
import { spawn } from "child_process";
|
|
885
|
+
var SPEC_RE = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*(?:@[A-Za-z0-9^~<>=*.+-]+)?$/;
|
|
886
|
+
function validatePackageSpecs(specs) {
|
|
887
|
+
for (const spec of specs) {
|
|
888
|
+
if (!SPEC_RE.test(spec)) {
|
|
889
|
+
throw new Error(`Invalid package spec: ${JSON.stringify(spec)}`);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
function buildSpawn(pm, args, platform = process.platform) {
|
|
894
|
+
return platform === "win32" ? {
|
|
895
|
+
// One command string (no args array) also avoids Node's DEP0190 warning.
|
|
896
|
+
command: [pm, ...args.map((a) => `"${a}"`)].join(" "),
|
|
897
|
+
args: [],
|
|
898
|
+
shell: true
|
|
899
|
+
} : { command: pm, args, shell: false };
|
|
900
|
+
}
|
|
901
|
+
function killTree(pid, fallback) {
|
|
902
|
+
if (pid === void 0) {
|
|
903
|
+
fallback();
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (process.platform === "win32") {
|
|
907
|
+
spawn("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore" });
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
try {
|
|
911
|
+
process.kill(-pid, "SIGKILL");
|
|
912
|
+
} catch {
|
|
913
|
+
fallback();
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
function runPackageManager(pm, args, opts) {
|
|
917
|
+
const timeoutMs = opts.timeoutMs ?? 10 * 60 * 1e3;
|
|
918
|
+
const label = `${pm} ${args.join(" ")}`;
|
|
919
|
+
const spec = buildSpawn(pm, args);
|
|
920
|
+
return new Promise((resolve, reject) => {
|
|
921
|
+
const options = {
|
|
922
|
+
cwd: opts.cwd,
|
|
923
|
+
stdio: ["ignore", 2, 2],
|
|
924
|
+
env: { ...process.env, CI: process.env.CI ?? "1" },
|
|
925
|
+
shell: spec.shell,
|
|
926
|
+
detached: process.platform !== "win32"
|
|
927
|
+
};
|
|
928
|
+
const child = spec.shell ? spawn(spec.command, options) : spawn(spec.command, spec.args, options);
|
|
929
|
+
const signals = { SIGINT: 130, SIGTERM: 143 };
|
|
930
|
+
const handlers = Object.entries(signals).map(([sig, exitCode]) => {
|
|
931
|
+
const handler = () => {
|
|
932
|
+
killTree(child.pid, () => child.kill("SIGKILL"));
|
|
933
|
+
process.exit(exitCode);
|
|
934
|
+
};
|
|
935
|
+
if (process.platform !== "win32")
|
|
936
|
+
process.once(sig, handler);
|
|
937
|
+
return [sig, handler];
|
|
938
|
+
});
|
|
939
|
+
const cleanup = () => {
|
|
940
|
+
clearTimeout(timer);
|
|
941
|
+
for (const [sig, handler] of handlers) process.off(sig, handler);
|
|
942
|
+
};
|
|
943
|
+
const timer = setTimeout(() => {
|
|
944
|
+
killTree(child.pid, () => child.kill("SIGKILL"));
|
|
945
|
+
cleanup();
|
|
946
|
+
reject(new Error(`\`${label}\` timed out after ${timeoutMs / 1e3}s`));
|
|
947
|
+
}, timeoutMs);
|
|
948
|
+
child.on("error", (err) => {
|
|
949
|
+
cleanup();
|
|
950
|
+
reject(new Error(`\`${label}\` failed to start: ${err.message}`));
|
|
951
|
+
});
|
|
952
|
+
child.on("close", (code) => {
|
|
953
|
+
cleanup();
|
|
954
|
+
if (code === 0) resolve();
|
|
955
|
+
else reject(new Error(`\`${label}\` exited with code ${code}`));
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
|
|
483
960
|
// src/commands/add.ts
|
|
484
|
-
var execAsync = promisify(exec);
|
|
485
961
|
function addCommand() {
|
|
486
962
|
return new Command("add").description("Add a component or block to your project").argument("[id]", "Component or block ID (optional for interactive mode)").option("--with-animation", "Include animation variants").option("-p, --path <path>", "Custom installation path").option("-o, --overwrite", "Overwrite existing files").action(async (id, options) => {
|
|
487
963
|
try {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
964
|
+
const project = await loadProject(process.cwd());
|
|
965
|
+
process.chdir(project.root);
|
|
966
|
+
validateProject(project, options);
|
|
967
|
+
const ids = id ? [id] : await selectComponentsInteractively(project);
|
|
968
|
+
if (ids.length === 0) {
|
|
969
|
+
console.log(chalk3.yellow("No components selected."));
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
try {
|
|
973
|
+
for (const componentId of ids) {
|
|
974
|
+
await addSingleComponent(project, componentId, options);
|
|
496
975
|
}
|
|
497
|
-
}
|
|
498
|
-
await
|
|
976
|
+
} finally {
|
|
977
|
+
await project.saveLock();
|
|
499
978
|
}
|
|
500
979
|
} catch (error) {
|
|
501
|
-
console.error(
|
|
980
|
+
console.error(chalk3.red("\u274C Failed to add component:"));
|
|
502
981
|
console.error(
|
|
503
|
-
|
|
982
|
+
chalk3.red(error instanceof Error ? error.message : String(error))
|
|
504
983
|
);
|
|
505
984
|
process.exit(1);
|
|
506
985
|
}
|
|
507
986
|
});
|
|
508
987
|
}
|
|
509
|
-
async function selectComponentsInteractively() {
|
|
510
|
-
|
|
988
|
+
async function selectComponentsInteractively(project) {
|
|
989
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
990
|
+
throw new Error(
|
|
991
|
+
"No component id given. Pass component ids when not running interactively."
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
console.log(chalk3.blue("\u{1F4E6} Select components to add:"));
|
|
511
995
|
console.log(
|
|
512
|
-
|
|
996
|
+
chalk3.gray(" Use arrow keys to navigate, space to select, a to toggle all")
|
|
513
997
|
);
|
|
514
|
-
console.log(
|
|
515
|
-
const registry = getRegistry();
|
|
998
|
+
console.log(chalk3.gray(" Press enter when done\n"));
|
|
999
|
+
const registry = getRegistry(void 0, project.settings);
|
|
516
1000
|
try {
|
|
517
|
-
console.log(
|
|
1001
|
+
console.log(chalk3.gray("Fetching components from registry..."));
|
|
518
1002
|
const allComponents = await registry.getComponents();
|
|
519
1003
|
if (allComponents.length === 0) {
|
|
520
|
-
console.log(
|
|
1004
|
+
console.log(chalk3.yellow("No components available in the registry."));
|
|
521
1005
|
return [];
|
|
522
1006
|
}
|
|
523
1007
|
const groupedChoices = createGroupedChoices(allComponents);
|
|
524
|
-
const { selectedComponents } = await
|
|
1008
|
+
const { selectedComponents } = await inquirer2.prompt([
|
|
525
1009
|
{
|
|
526
1010
|
type: "checkbox",
|
|
527
1011
|
name: "selectedComponents",
|
|
@@ -533,9 +1017,9 @@ async function selectComponentsInteractively() {
|
|
|
533
1017
|
]);
|
|
534
1018
|
return selectedComponents;
|
|
535
1019
|
} catch (error) {
|
|
536
|
-
console.error(
|
|
1020
|
+
console.error(chalk3.red("Failed to fetch components from registry:"));
|
|
537
1021
|
console.error(
|
|
538
|
-
|
|
1022
|
+
chalk3.red(error instanceof Error ? error.message : String(error))
|
|
539
1023
|
);
|
|
540
1024
|
throw error;
|
|
541
1025
|
}
|
|
@@ -553,13 +1037,13 @@ function createGroupedChoices(components) {
|
|
|
553
1037
|
const categoryComponents = components.filter((c) => c.category === category);
|
|
554
1038
|
if (categoryComponents.length === 0) continue;
|
|
555
1039
|
choices.push({
|
|
556
|
-
name:
|
|
1040
|
+
name: chalk3.bold.cyan(`\u2500\u2500\u2500 ${category.toUpperCase()} \u2500\u2500\u2500`),
|
|
557
1041
|
disabled: true,
|
|
558
1042
|
value: `separator-${category}`
|
|
559
1043
|
});
|
|
560
1044
|
for (const component of categoryComponents) {
|
|
561
1045
|
choices.push({
|
|
562
|
-
name: `${component.name} - ${
|
|
1046
|
+
name: `${component.name} - ${chalk3.gray(component.description)}`,
|
|
563
1047
|
value: component.id,
|
|
564
1048
|
short: component.name
|
|
565
1049
|
});
|
|
@@ -567,149 +1051,110 @@ function createGroupedChoices(components) {
|
|
|
567
1051
|
}
|
|
568
1052
|
return choices;
|
|
569
1053
|
}
|
|
570
|
-
async function addSingleComponent(id, options) {
|
|
571
|
-
console.log(
|
|
1054
|
+
async function addSingleComponent(project, id, options) {
|
|
1055
|
+
console.log(chalk3.blue(`
|
|
572
1056
|
\u{1F4E6} Adding ${id} to your project...`));
|
|
573
|
-
|
|
574
|
-
const
|
|
1057
|
+
const registry = getRegistry(void 0, project.settings);
|
|
1058
|
+
const applyOptions = {
|
|
1059
|
+
overwrite: Boolean(options.overwrite),
|
|
1060
|
+
prompt: interactivePrompt(),
|
|
1061
|
+
basePath: options.path
|
|
1062
|
+
};
|
|
1063
|
+
const depOptions = {
|
|
1064
|
+
overwrite: false,
|
|
1065
|
+
prompt: applyOptions.prompt
|
|
1066
|
+
};
|
|
575
1067
|
try {
|
|
576
1068
|
const componentData = await registry.getComponent(id, options.force);
|
|
577
|
-
|
|
578
|
-
const { shouldContinue } = await inquirer.prompt([
|
|
579
|
-
{
|
|
580
|
-
type: "confirm",
|
|
581
|
-
name: "shouldContinue",
|
|
582
|
-
message: `Some files for ${componentData.name} already exist. Overwrite?`,
|
|
583
|
-
default: false
|
|
584
|
-
}
|
|
585
|
-
]);
|
|
586
|
-
if (!shouldContinue) {
|
|
587
|
-
console.log(chalk2.yellow(`\u23ED\uFE0F Skipping ${componentData.name}.`));
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
1069
|
+
const results = [];
|
|
591
1070
|
if (componentData.registryDependencies?.length) {
|
|
592
|
-
console.log(
|
|
1071
|
+
console.log(chalk3.blue("\u{1F4E6} Installing required dependencies..."));
|
|
593
1072
|
for (const dep of componentData.registryDependencies) {
|
|
1073
|
+
if (["hooks", "types"].includes(dep)) {
|
|
1074
|
+
console.log(chalk3.green(` \u2713 ${dep} package is available`));
|
|
1075
|
+
continue;
|
|
1076
|
+
}
|
|
594
1077
|
try {
|
|
595
1078
|
const depData = await registry.getComponent(dep);
|
|
596
|
-
if (
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const hasExisting = await hasConflictingFiles(depData, options);
|
|
601
|
-
if (!hasExisting) {
|
|
602
|
-
await installComponentFiles(depData, options);
|
|
603
|
-
console.log(chalk2.green(` \u2713 Installed ${dep}`));
|
|
604
|
-
} else {
|
|
605
|
-
console.log(chalk2.gray(` \u23ED ${dep} already exists`));
|
|
606
|
-
}
|
|
1079
|
+
if (depData.files.length === 0) continue;
|
|
1080
|
+
results.push(
|
|
1081
|
+
reportApply(await applyComponent(project, depData, depOptions))
|
|
1082
|
+
);
|
|
607
1083
|
} catch (error) {
|
|
608
1084
|
console.log(
|
|
609
|
-
|
|
1085
|
+
chalk3.yellow(
|
|
610
1086
|
` \u26A0 Could not install dependency "${dep}": ${error instanceof Error ? error.message : "Unknown error"}`
|
|
611
1087
|
)
|
|
612
1088
|
);
|
|
613
1089
|
}
|
|
614
1090
|
}
|
|
615
1091
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
1092
|
+
if (componentData.files.length > 0) {
|
|
1093
|
+
console.log(chalk3.blue("\u{1F4DD} Installing component files..."));
|
|
1094
|
+
results.push(
|
|
1095
|
+
reportApply(await applyComponent(project, componentData, applyOptions))
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
const failed = results.reduce((n, r) => n + r.failed.length, 0);
|
|
1099
|
+
const skipped = results.reduce(
|
|
1100
|
+
(n, r) => n + r.skippedEdited.length + r.skippedUnknown.length,
|
|
1101
|
+
0
|
|
1102
|
+
);
|
|
1103
|
+
if (failed > 0) {
|
|
1104
|
+
console.error(
|
|
1105
|
+
chalk3.red(
|
|
1106
|
+
`\u274C ${componentData.name}: ${failed} file(s) could not be written.`
|
|
1107
|
+
)
|
|
1108
|
+
);
|
|
1109
|
+
} else if (skipped > 0) {
|
|
1110
|
+
console.log(
|
|
1111
|
+
chalk3.yellow(
|
|
1112
|
+
`\u26A0\uFE0F ${componentData.name} added with ${skipped} file(s) skipped.`
|
|
1113
|
+
)
|
|
1114
|
+
);
|
|
1115
|
+
} else {
|
|
1116
|
+
console.log(chalk3.green(`\u2705 ${componentData.name} added successfully!`));
|
|
1117
|
+
}
|
|
1118
|
+
showUsageExample(componentData, project.settings);
|
|
620
1119
|
await handlePackageDependencies(componentData, options);
|
|
621
1120
|
} catch (error) {
|
|
622
|
-
console.error(
|
|
1121
|
+
console.error(chalk3.red(`Failed to add ${id}:`));
|
|
623
1122
|
throw error;
|
|
624
1123
|
}
|
|
625
1124
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
1125
|
+
function reportApply(result) {
|
|
1126
|
+
console.log(chalk3.bold(` ${result.id}`));
|
|
1127
|
+
for (const f of result.written) console.log(chalk3.gray(` \u2713 Wrote ${f}`));
|
|
1128
|
+
for (const f of result.upToDate)
|
|
1129
|
+
console.log(chalk3.gray(` = ${f} is up to date`));
|
|
1130
|
+
for (const f of result.kept) console.log(chalk3.gray(` \u2022 Kept your ${f}`));
|
|
1131
|
+
for (const f of result.skippedEdited)
|
|
1132
|
+
console.log(
|
|
1133
|
+
chalk3.yellow(` \u26A0 Skipped ${f}: edited locally (use --overwrite)`)
|
|
1134
|
+
);
|
|
1135
|
+
for (const f of result.skippedUnknown)
|
|
1136
|
+
console.log(
|
|
1137
|
+
chalk3.yellow(
|
|
1138
|
+
` \u26A0 Skipped ${f}: exists but isn't tracked (run in a terminal to review, or use --overwrite)`
|
|
1139
|
+
)
|
|
1140
|
+
);
|
|
1141
|
+
for (const f of result.droppedFromLock)
|
|
1142
|
+
console.log(
|
|
1143
|
+
chalk3.gray(` \u2022 ${f} is no longer part of ${result.id}; left on disk`)
|
|
1144
|
+
);
|
|
1145
|
+
for (const f of result.failed) {
|
|
1146
|
+
console.error(chalk3.red(` \u2717 ${f}`));
|
|
1147
|
+
process.exitCode = 1;
|
|
634
1148
|
}
|
|
1149
|
+
return result;
|
|
635
1150
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
if (!fs2.existsSync(packageJsonPath)) {
|
|
1151
|
+
function validateProject(project, options) {
|
|
1152
|
+
if (!fs5.existsSync(path5.join(project.root, "package.json"))) {
|
|
639
1153
|
throw new Error(
|
|
640
1154
|
"No package.json found. Please run this command in a project root."
|
|
641
1155
|
);
|
|
642
1156
|
}
|
|
643
|
-
|
|
644
|
-
if (!fs2.existsSync(configPath)) {
|
|
645
|
-
throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
|
|
646
|
-
}
|
|
647
|
-
await updateConfigVersion();
|
|
648
|
-
}
|
|
649
|
-
async function hasConflictingFiles(componentData, options) {
|
|
650
|
-
const config = await loadConfig();
|
|
651
|
-
const basePath = options.path || process.cwd();
|
|
652
|
-
for (const file of componentData.files) {
|
|
653
|
-
let resolvedPath;
|
|
654
|
-
if (componentData.id === "utils" || file.path === "lib/utils.ts") {
|
|
655
|
-
resolvedPath = config.paths.utils || "lib/utils.ts";
|
|
656
|
-
} else {
|
|
657
|
-
resolvedPath = resolveComponentPath(
|
|
658
|
-
file.path,
|
|
659
|
-
componentData.category,
|
|
660
|
-
config
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
const filePath = path2.join(basePath, resolvedPath);
|
|
664
|
-
if (fs2.existsSync(filePath)) {
|
|
665
|
-
return true;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
return false;
|
|
669
|
-
}
|
|
670
|
-
async function installComponentFiles(componentData, options) {
|
|
671
|
-
const config = await loadConfig();
|
|
672
|
-
const basePath = options.path || process.cwd();
|
|
673
|
-
if (componentData.files.length === 0) {
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
console.log(chalk2.blue("\u{1F4DD} Installing component files..."));
|
|
677
|
-
for (const file of componentData.files) {
|
|
678
|
-
let resolvedPath;
|
|
679
|
-
if (componentData.id === "utils" || file.path === "lib/utils.ts") {
|
|
680
|
-
resolvedPath = config.paths.utils || "lib/utils.ts";
|
|
681
|
-
} else {
|
|
682
|
-
resolvedPath = resolveComponentPath(
|
|
683
|
-
file.path,
|
|
684
|
-
componentData.category,
|
|
685
|
-
config
|
|
686
|
-
);
|
|
687
|
-
}
|
|
688
|
-
const filePath = path2.join(basePath, resolvedPath);
|
|
689
|
-
await fs2.ensureDir(path2.dirname(filePath));
|
|
690
|
-
if (!file.content || file.content.trim() === "") {
|
|
691
|
-
console.log(
|
|
692
|
-
chalk2.yellow(` \u26A0 Skipping ${resolvedPath} - no content available`)
|
|
693
|
-
);
|
|
694
|
-
continue;
|
|
695
|
-
}
|
|
696
|
-
const transformedContent = transformImportsForConfig(file.content, config);
|
|
697
|
-
await fs2.writeFile(filePath, transformedContent);
|
|
698
|
-
console.log(chalk2.gray(` \u2713 Created ${resolvedPath}`));
|
|
699
|
-
}
|
|
700
|
-
await updateConfigVersion();
|
|
701
|
-
}
|
|
702
|
-
async function trackInstalledComponent(componentData) {
|
|
703
|
-
const configPath = path2.join(process.cwd(), "foundrykit.config.json");
|
|
704
|
-
if (!fs2.existsSync(configPath)) return;
|
|
705
|
-
const config = await fs2.readJson(configPath);
|
|
706
|
-
config.installedComponents = config.installedComponents ?? {};
|
|
707
|
-
config.installedComponents[componentData.id] = {
|
|
708
|
-
id: componentData.id,
|
|
709
|
-
version: componentData.version ?? null,
|
|
710
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
711
|
-
};
|
|
712
|
-
await fs2.writeJson(configPath, config, { spaces: 2 });
|
|
1157
|
+
if (options.path) project.resolveInRoot(options.path);
|
|
713
1158
|
}
|
|
714
1159
|
async function handlePackageDependencies(componentData, options = {}) {
|
|
715
1160
|
const allDependencies = /* @__PURE__ */ new Set();
|
|
@@ -724,32 +1169,36 @@ async function handlePackageDependencies(componentData, options = {}) {
|
|
|
724
1169
|
const forcePackageUpdate = componentData.files.length === 0 && (options.force || options.overwrite);
|
|
725
1170
|
const missingPackages = forcePackageUpdate ? dependencies : await getMissingPackages(dependencies);
|
|
726
1171
|
if (missingPackages.length === 0) {
|
|
727
|
-
console.log(
|
|
1172
|
+
console.log(chalk3.green("\u2705 All required packages are already installed"));
|
|
728
1173
|
return;
|
|
729
1174
|
}
|
|
730
1175
|
const packagesToInstall = missingPackages.map(
|
|
731
1176
|
(pkg) => forcePackageUpdate ? getPackageInstallSpec(pkg, componentData.version) : pkg
|
|
732
1177
|
);
|
|
733
1178
|
console.log(
|
|
734
|
-
|
|
1179
|
+
chalk3.yellow(
|
|
735
1180
|
forcePackageUpdate ? "\n\u{1F4E6} Updating required packages..." : "\n\u{1F4E6} Installing required packages..."
|
|
736
1181
|
)
|
|
737
1182
|
);
|
|
738
|
-
console.log(
|
|
1183
|
+
console.log(chalk3.gray(` ${packagesToInstall.join(", ")}`));
|
|
739
1184
|
const packageManager = await detectPackageManager();
|
|
740
1185
|
try {
|
|
741
|
-
|
|
742
|
-
console.log(chalk2.blue(` Running: ${installCommand}`));
|
|
743
|
-
const { stderr } = await execAsync(installCommand);
|
|
744
|
-
if (stderr && !stderr.includes("warning")) {
|
|
745
|
-
console.error(chalk2.yellow(` Warning: ${stderr}`));
|
|
746
|
-
}
|
|
747
|
-
console.log(chalk2.green("\u2705 Packages installed successfully"));
|
|
748
|
-
} catch {
|
|
749
|
-
console.log(chalk2.yellow("\n\u26A0\uFE0F Could not install packages automatically"));
|
|
750
|
-
console.log(chalk2.gray(" Please install them manually:"));
|
|
1186
|
+
validatePackageSpecs(packagesToInstall);
|
|
751
1187
|
console.log(
|
|
752
|
-
|
|
1188
|
+
chalk3.blue(
|
|
1189
|
+
` Running: ${packageManager} add ${packagesToInstall.join(" ")}`
|
|
1190
|
+
)
|
|
1191
|
+
);
|
|
1192
|
+
await runPackageManager(packageManager, ["add", ...packagesToInstall], {
|
|
1193
|
+
cwd: process.cwd()
|
|
1194
|
+
});
|
|
1195
|
+
console.log(chalk3.green("\u2705 Packages installed successfully"));
|
|
1196
|
+
} catch (error) {
|
|
1197
|
+
console.log(chalk3.yellow("\n\u26A0\uFE0F Could not install packages automatically"));
|
|
1198
|
+
console.log(chalk3.gray(` ${error.message}`));
|
|
1199
|
+
console.log(chalk3.gray(" Please install them manually:"));
|
|
1200
|
+
console.log(
|
|
1201
|
+
chalk3.cyan(` ${packageManager} add ${packagesToInstall.join(" ")}`)
|
|
753
1202
|
);
|
|
754
1203
|
}
|
|
755
1204
|
}
|
|
@@ -760,9 +1209,9 @@ function getPackageInstallSpec(packageName, version) {
|
|
|
760
1209
|
return `${packageName}@${version ?? "latest"}`;
|
|
761
1210
|
}
|
|
762
1211
|
async function getMissingPackages(packages) {
|
|
763
|
-
const packageJsonPath =
|
|
1212
|
+
const packageJsonPath = path5.join(process.cwd(), "package.json");
|
|
764
1213
|
try {
|
|
765
|
-
const packageJson2 = await
|
|
1214
|
+
const packageJson2 = await fs5.readJson(packageJsonPath);
|
|
766
1215
|
const installedPackages = {
|
|
767
1216
|
...packageJson2.dependencies,
|
|
768
1217
|
...packageJson2.devDependencies
|
|
@@ -773,49 +1222,39 @@ async function getMissingPackages(packages) {
|
|
|
773
1222
|
}
|
|
774
1223
|
}
|
|
775
1224
|
async function detectPackageManager() {
|
|
776
|
-
if (await
|
|
1225
|
+
if (await fs5.pathExists(path5.join(process.cwd(), "pnpm-lock.yaml"))) {
|
|
777
1226
|
return "pnpm";
|
|
778
1227
|
}
|
|
779
|
-
if (await
|
|
1228
|
+
if (await fs5.pathExists(path5.join(process.cwd(), "yarn.lock"))) {
|
|
780
1229
|
return "yarn";
|
|
781
1230
|
}
|
|
782
|
-
if (await
|
|
1231
|
+
if (await fs5.pathExists(path5.join(process.cwd(), "package-lock.json"))) {
|
|
783
1232
|
return "npm";
|
|
784
1233
|
}
|
|
785
|
-
if (await
|
|
1234
|
+
if (await fs5.pathExists(path5.join(process.cwd(), "bun.lockb"))) {
|
|
786
1235
|
return "bun";
|
|
787
1236
|
}
|
|
788
1237
|
return "pnpm";
|
|
789
1238
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
console.log(chalk2.cyan("\n\u{1F4A1} Usage:"));
|
|
1239
|
+
function showUsageExample(componentData, config) {
|
|
1240
|
+
console.log(chalk3.cyan("\n\u{1F4A1} Usage:"));
|
|
793
1241
|
if (componentData.files.length === 0) {
|
|
794
1242
|
const packageName = componentData.packageDependencies?.find(
|
|
795
1243
|
(dep) => dep.startsWith("@foundrykit/")
|
|
796
1244
|
);
|
|
797
1245
|
if (packageName) {
|
|
798
|
-
console.log(
|
|
1246
|
+
console.log(chalk3.gray(`import { ... } from "${packageName}"`));
|
|
799
1247
|
}
|
|
800
1248
|
return;
|
|
801
1249
|
}
|
|
802
1250
|
const componentName = componentData.name.replace(/\s+/g, "");
|
|
803
1251
|
const importPath = getImportPath(componentData, config);
|
|
804
|
-
console.log(
|
|
1252
|
+
console.log(chalk3.gray(`import { ${componentName} } from "${importPath}"`));
|
|
805
1253
|
if (componentData.usageExample) {
|
|
806
|
-
console.log(
|
|
1254
|
+
console.log(chalk3.gray(`
|
|
807
1255
|
${componentData.usageExample}`));
|
|
808
1256
|
}
|
|
809
1257
|
}
|
|
810
|
-
async function loadConfig() {
|
|
811
|
-
const configPath = path2.join(process.cwd(), "foundrykit.config.json");
|
|
812
|
-
if (!fs2.existsSync(configPath)) {
|
|
813
|
-
throw new Error(
|
|
814
|
-
'Configuration file not found. Run "foundrykit init" first.'
|
|
815
|
-
);
|
|
816
|
-
}
|
|
817
|
-
return fs2.readJson(configPath);
|
|
818
|
-
}
|
|
819
1258
|
function transformImportsForConfig(content, config) {
|
|
820
1259
|
let transformed = content;
|
|
821
1260
|
const importPaths = getConfiguredImportPaths(config);
|
|
@@ -1011,22 +1450,22 @@ function getInstalledComponentExportMap(config, category) {
|
|
|
1011
1450
|
if (!categoryPath) {
|
|
1012
1451
|
return exportMap;
|
|
1013
1452
|
}
|
|
1014
|
-
const absoluteCategoryPath =
|
|
1453
|
+
const absoluteCategoryPath = path5.resolve(
|
|
1015
1454
|
process.cwd(),
|
|
1016
1455
|
normalizeConfigPath(categoryPath)
|
|
1017
1456
|
);
|
|
1018
|
-
if (!
|
|
1457
|
+
if (!fs5.existsSync(absoluteCategoryPath)) {
|
|
1019
1458
|
return exportMap;
|
|
1020
1459
|
}
|
|
1021
|
-
for (const entry of
|
|
1460
|
+
for (const entry of fs5.readdirSync(absoluteCategoryPath, {
|
|
1022
1461
|
withFileTypes: true
|
|
1023
1462
|
})) {
|
|
1024
1463
|
if (!entry.isDirectory()) continue;
|
|
1025
1464
|
const componentPath = entry.name;
|
|
1026
|
-
const componentDir =
|
|
1027
|
-
const entryFiles = ["index.tsx", "index.ts", "index.jsx", "index.js"].map((fileName) =>
|
|
1465
|
+
const componentDir = path5.join(absoluteCategoryPath, componentPath);
|
|
1466
|
+
const entryFiles = ["index.tsx", "index.ts", "index.jsx", "index.js"].map((fileName) => path5.join(componentDir, fileName)).filter((filePath) => fs5.existsSync(filePath));
|
|
1028
1467
|
for (const filePath of entryFiles) {
|
|
1029
|
-
const content =
|
|
1468
|
+
const content = fs5.readFileSync(filePath, "utf-8");
|
|
1030
1469
|
for (const exportName of parseExportNames(content)) {
|
|
1031
1470
|
exportMap.set(exportName, componentPath);
|
|
1032
1471
|
}
|
|
@@ -1071,34 +1510,34 @@ function resolveComponentPath(originalPath, category, config) {
|
|
|
1071
1510
|
return paths.utils || "lib/utils.ts";
|
|
1072
1511
|
}
|
|
1073
1512
|
const categoryPath = getConfiguredCategoryPath(config, category) || paths.components;
|
|
1074
|
-
const fileName =
|
|
1075
|
-
const componentName =
|
|
1513
|
+
const fileName = path5.basename(originalPath);
|
|
1514
|
+
const componentName = path5.dirname(originalPath).split("/").pop() || "";
|
|
1076
1515
|
if (category === "primitives") {
|
|
1077
|
-
return
|
|
1516
|
+
return path5.join(categoryPath, componentName, fileName);
|
|
1078
1517
|
} else if (category === "components") {
|
|
1079
|
-
return
|
|
1518
|
+
return path5.join(paths.components, componentName, fileName);
|
|
1080
1519
|
} else if (category === "blocks") {
|
|
1081
|
-
return
|
|
1082
|
-
paths.blocks ||
|
|
1520
|
+
return path5.join(
|
|
1521
|
+
paths.blocks || path5.join(paths.components, "blocks"),
|
|
1083
1522
|
componentName,
|
|
1084
1523
|
fileName
|
|
1085
1524
|
);
|
|
1086
1525
|
} else if (category === "animations") {
|
|
1087
|
-
return
|
|
1088
|
-
paths.animations ||
|
|
1526
|
+
return path5.join(
|
|
1527
|
+
paths.animations || path5.join(paths.components, "animations"),
|
|
1089
1528
|
componentName,
|
|
1090
1529
|
fileName
|
|
1091
1530
|
);
|
|
1092
1531
|
} else if (category === "maps") {
|
|
1093
|
-
return
|
|
1094
|
-
paths.maps ||
|
|
1532
|
+
return path5.join(
|
|
1533
|
+
paths.maps || path5.join(paths.components, "maps"),
|
|
1095
1534
|
componentName,
|
|
1096
1535
|
fileName
|
|
1097
1536
|
);
|
|
1098
1537
|
} else if (category === "hooks") {
|
|
1099
|
-
return
|
|
1538
|
+
return path5.join(paths.hooks || "hooks", componentName, fileName);
|
|
1100
1539
|
} else if (category === "packages") {
|
|
1101
|
-
return
|
|
1540
|
+
return path5.join(paths.components, componentName, fileName);
|
|
1102
1541
|
}
|
|
1103
1542
|
return originalPath;
|
|
1104
1543
|
}
|
|
@@ -1114,7 +1553,7 @@ function getConfiguredCategoryPath(config, category) {
|
|
|
1114
1553
|
case "animations":
|
|
1115
1554
|
return paths.animations;
|
|
1116
1555
|
case "maps":
|
|
1117
|
-
return paths.maps ??
|
|
1556
|
+
return paths.maps ?? path5.join(paths.components, "maps");
|
|
1118
1557
|
case "hooks":
|
|
1119
1558
|
return paths.hooks ?? "hooks";
|
|
1120
1559
|
case "packages":
|
|
@@ -1133,8 +1572,8 @@ function getImportPath(componentData, config) {
|
|
|
1133
1572
|
maps: "components/maps",
|
|
1134
1573
|
utils: "lib/utils"
|
|
1135
1574
|
};
|
|
1136
|
-
const componentName =
|
|
1137
|
-
|
|
1575
|
+
const componentName = path5.basename(
|
|
1576
|
+
path5.dirname(componentData.files[0]?.path || "")
|
|
1138
1577
|
);
|
|
1139
1578
|
if (componentData.category === "primitives") {
|
|
1140
1579
|
return `${resolveImportBasePath(paths.primitives, config, {
|
|
@@ -1154,7 +1593,7 @@ function getImportPath(componentData, config) {
|
|
|
1154
1593
|
})}/${componentName}`;
|
|
1155
1594
|
} else if (componentData.category === "maps") {
|
|
1156
1595
|
return `${resolveImportBasePath(
|
|
1157
|
-
paths.maps ||
|
|
1596
|
+
paths.maps || path5.join(paths.components, "maps"),
|
|
1158
1597
|
config,
|
|
1159
1598
|
{
|
|
1160
1599
|
preferRootAlias: true
|
|
@@ -1168,106 +1607,574 @@ function getImportPath(componentData, config) {
|
|
|
1168
1607
|
return `@/components/${componentName}`;
|
|
1169
1608
|
}
|
|
1170
1609
|
|
|
1171
|
-
// src/commands/
|
|
1172
|
-
import path3 from "path";
|
|
1173
|
-
import chalk3 from "chalk";
|
|
1610
|
+
// src/commands/connect.ts
|
|
1174
1611
|
import { Command as Command2 } from "commander";
|
|
1175
|
-
import
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1612
|
+
import inquirer3 from "inquirer";
|
|
1613
|
+
|
|
1614
|
+
// src/lib/hub/credentials.ts
|
|
1615
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
1616
|
+
import os2 from "os";
|
|
1617
|
+
import path6 from "path";
|
|
1618
|
+
import fs6 from "fs-extra";
|
|
1619
|
+
|
|
1620
|
+
// src/lib/hub/errors.ts
|
|
1621
|
+
var SESSION_EXPIRED = "Session expired \u2014 run `foundrykit login`";
|
|
1622
|
+
var HubError = class extends Error {
|
|
1623
|
+
constructor(status, code, message) {
|
|
1624
|
+
super(message);
|
|
1625
|
+
this.status = status;
|
|
1626
|
+
this.code = code;
|
|
1627
|
+
this.name = "HubError";
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
var unreachable = (hubUrl) => new HubError(
|
|
1631
|
+
0,
|
|
1632
|
+
"unreachable",
|
|
1633
|
+
`Can't reach the hub at ${hubUrl}. Is it running?`
|
|
1634
|
+
);
|
|
1635
|
+
var unexpectedResponse = (status) => new HubError(status, "internal", "Hub returned an unexpected response");
|
|
1636
|
+
|
|
1637
|
+
// src/lib/hub/credentials.ts
|
|
1638
|
+
var CredentialsError = class extends Error {
|
|
1639
|
+
constructor(file) {
|
|
1640
|
+
super(`${file} is not valid JSON. Delete it and run \`foundrykit login\`.`);
|
|
1641
|
+
this.name = "CredentialsError";
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
function normalizeHubUrl(url) {
|
|
1645
|
+
const invalid2 = () => new HubError(
|
|
1646
|
+
0,
|
|
1647
|
+
"invalid_request",
|
|
1648
|
+
`Invalid hub URL: ${url.replace(/\/\/[^/]*@/, "//")}`
|
|
1649
|
+
);
|
|
1650
|
+
let u;
|
|
1651
|
+
try {
|
|
1652
|
+
u = new URL(url.trim());
|
|
1653
|
+
} catch {
|
|
1654
|
+
throw invalid2();
|
|
1655
|
+
}
|
|
1656
|
+
if (u.protocol !== "http:" && u.protocol !== "https:" || u.username || u.password)
|
|
1657
|
+
throw invalid2();
|
|
1658
|
+
return `${u.protocol}//${u.host}${u.pathname}`.replace(/\/+$/, "");
|
|
1659
|
+
}
|
|
1660
|
+
function resolveHubUrl(opts) {
|
|
1661
|
+
return normalizeHubUrl(
|
|
1662
|
+
opts.flag || process.env.FOUNDRYKIT_HUB_URL || opts.settings?.hub?.url || DEFAULT_HUB_URL
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
function credentialsPath(home) {
|
|
1666
|
+
return path6.join(home ?? os2.homedir(), CACHE_DIR, CREDENTIALS_FILE);
|
|
1667
|
+
}
|
|
1668
|
+
async function readAll(file) {
|
|
1669
|
+
let raw;
|
|
1670
|
+
try {
|
|
1671
|
+
raw = await fs6.readFile(file, "utf8");
|
|
1672
|
+
} catch (error) {
|
|
1673
|
+
if (error.code === "ENOENT") return {};
|
|
1674
|
+
throw error;
|
|
1675
|
+
}
|
|
1676
|
+
try {
|
|
1677
|
+
const parsed = JSON.parse(raw);
|
|
1678
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
1679
|
+
return parsed;
|
|
1680
|
+
} catch {
|
|
1681
|
+
}
|
|
1682
|
+
throw new CredentialsError(file);
|
|
1683
|
+
}
|
|
1684
|
+
async function writeAll(file, all) {
|
|
1685
|
+
const dir = path6.dirname(file);
|
|
1686
|
+
await fs6.ensureDir(dir, { mode: 448 });
|
|
1687
|
+
await fs6.chmod(dir, 448);
|
|
1688
|
+
const tmp = `${file}.${randomBytes2(4).toString("hex")}.tmp`;
|
|
1689
|
+
try {
|
|
1690
|
+
await fs6.writeFile(tmp, `${JSON.stringify(all, null, 2)}
|
|
1691
|
+
`, {
|
|
1692
|
+
mode: 384
|
|
1196
1693
|
});
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1694
|
+
await fs6.rename(tmp, file);
|
|
1695
|
+
} catch (error) {
|
|
1696
|
+
await fs6.remove(tmp);
|
|
1697
|
+
throw error;
|
|
1698
|
+
}
|
|
1699
|
+
await fs6.chmod(file, 384);
|
|
1700
|
+
}
|
|
1701
|
+
async function readCredential(hubUrl, home) {
|
|
1702
|
+
const all = await readAll(credentialsPath(home));
|
|
1703
|
+
const entry = all[normalizeHubUrl(hubUrl)];
|
|
1704
|
+
return typeof entry?.token === "string" ? entry : null;
|
|
1705
|
+
}
|
|
1706
|
+
async function saveCredential(hubUrl, cred, home) {
|
|
1707
|
+
const file = credentialsPath(home);
|
|
1708
|
+
const all = await readAll(file);
|
|
1709
|
+
all[normalizeHubUrl(hubUrl)] = cred;
|
|
1710
|
+
await writeAll(file, all);
|
|
1711
|
+
}
|
|
1712
|
+
async function deleteCredential(hubUrl, home) {
|
|
1713
|
+
const file = credentialsPath(home);
|
|
1714
|
+
const all = await readAll(file);
|
|
1715
|
+
const key = normalizeHubUrl(hubUrl);
|
|
1716
|
+
if (!(key in all)) return false;
|
|
1717
|
+
delete all[key];
|
|
1718
|
+
await writeAll(file, all);
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
// src/lib/hub/client.ts
|
|
1723
|
+
var isTimeout = (e) => e?.name === "TimeoutError";
|
|
1724
|
+
var timedOut = (hubUrl) => new HubError(0, "timeout", `The hub at ${hubUrl} didn't answer in time.`);
|
|
1725
|
+
async function hubFetch(hubUrl, token, method, path10, body, opts = {}) {
|
|
1726
|
+
let res;
|
|
1727
|
+
try {
|
|
1728
|
+
res = await fetch(`${hubUrl}${path10}`, {
|
|
1729
|
+
method,
|
|
1730
|
+
// A 307/308 would resend the body (tokens, secrets) to wherever it points.
|
|
1731
|
+
redirect: "error",
|
|
1732
|
+
...opts.timeoutMs && { signal: AbortSignal.timeout(opts.timeoutMs) },
|
|
1733
|
+
headers: {
|
|
1734
|
+
accept: "application/json",
|
|
1735
|
+
...body !== void 0 && { "content-type": "application/json" },
|
|
1736
|
+
...token && { authorization: `Bearer ${token}` }
|
|
1737
|
+
},
|
|
1738
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
1203
1739
|
});
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1740
|
+
} catch (e) {
|
|
1741
|
+
throw isTimeout(e) ? timedOut(hubUrl) : unreachable(hubUrl);
|
|
1742
|
+
}
|
|
1743
|
+
if (res.status === 401)
|
|
1744
|
+
throw new HubError(401, "unauthorized", SESSION_EXPIRED);
|
|
1745
|
+
let json;
|
|
1746
|
+
try {
|
|
1747
|
+
json = await res.json();
|
|
1748
|
+
} catch (e) {
|
|
1749
|
+
if (isTimeout(e)) throw timedOut(hubUrl);
|
|
1750
|
+
json = void 0;
|
|
1751
|
+
}
|
|
1752
|
+
if (!res.ok) {
|
|
1753
|
+
const e = json?.error;
|
|
1754
|
+
if (e && typeof e.code === "string" && typeof e.message === "string")
|
|
1755
|
+
throw new HubError(res.status, e.code, e.message);
|
|
1756
|
+
throw new HubError(res.status, "internal", `Hub returned ${res.status}`);
|
|
1757
|
+
}
|
|
1758
|
+
if (json === void 0)
|
|
1759
|
+
throw new HubError(res.status, "internal", `Hub returned ${res.status}`);
|
|
1760
|
+
return json;
|
|
1761
|
+
}
|
|
1762
|
+
async function requireSignedIn(hubUrl, home) {
|
|
1763
|
+
const cred = await readCredential(hubUrl, home);
|
|
1764
|
+
if (!cred)
|
|
1765
|
+
throw new HubError(
|
|
1766
|
+
401,
|
|
1767
|
+
"unauthorized",
|
|
1768
|
+
`Not signed in to ${hubUrl}. Run \`foundrykit login\`.`
|
|
1769
|
+
);
|
|
1770
|
+
return cred;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// src/lib/hub/io.ts
|
|
1774
|
+
import chalk4 from "chalk";
|
|
1775
|
+
function defaultIO() {
|
|
1776
|
+
return {
|
|
1777
|
+
out: (s) => console.log(s),
|
|
1778
|
+
err: (s) => process.stderr.write(`${s}
|
|
1779
|
+
`),
|
|
1780
|
+
isTTY: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
1781
|
+
stdin: process.stdin,
|
|
1782
|
+
cwd: process.cwd()
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
function fail(io, json, e) {
|
|
1786
|
+
let code = "internal";
|
|
1787
|
+
let message = e instanceof Error ? e.message : String(e);
|
|
1788
|
+
if (e instanceof HubError) code = e.code;
|
|
1789
|
+
else if (e instanceof ProjectError || e instanceof SettingsError)
|
|
1790
|
+
code = "invalid_request";
|
|
1791
|
+
else if (!(e instanceof CredentialsError))
|
|
1792
|
+
message = message.split("\n")[0] ?? "";
|
|
1793
|
+
io.out(
|
|
1794
|
+
json ? JSON.stringify({ error: { code, message } }) : chalk4.red(message)
|
|
1795
|
+
);
|
|
1796
|
+
return 1;
|
|
1797
|
+
}
|
|
1798
|
+
async function hubUrlFor(flag, io) {
|
|
1799
|
+
return (await resolveHub(flag, io)).url;
|
|
1800
|
+
}
|
|
1801
|
+
async function resolveHub(flag, io) {
|
|
1802
|
+
let hub = { url: resolveHubUrl({ flag }), fromSettings: false };
|
|
1803
|
+
if (!flag && !process.env.FOUNDRYKIT_HUB_URL) {
|
|
1804
|
+
let settings;
|
|
1805
|
+
try {
|
|
1806
|
+
settings = (await loadProject(io.cwd, { readOnly: true })).settings;
|
|
1807
|
+
} catch (e) {
|
|
1808
|
+
if (!(e instanceof ProjectError)) throw e;
|
|
1809
|
+
}
|
|
1810
|
+
hub = {
|
|
1811
|
+
url: resolveHubUrl({ settings }),
|
|
1812
|
+
fromSettings: Boolean(settings?.hub?.url)
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
warnIfPlainHttp(hub.url, io);
|
|
1816
|
+
return hub;
|
|
1817
|
+
}
|
|
1818
|
+
var LOOPBACK = ["localhost", "127.0.0.1", "[::1]"];
|
|
1819
|
+
function warnIfPlainHttp(url, io) {
|
|
1820
|
+
let u;
|
|
1821
|
+
try {
|
|
1822
|
+
u = new URL(url);
|
|
1823
|
+
} catch {
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
if (u.protocol === "http:" && !LOOPBACK.includes(u.hostname))
|
|
1827
|
+
io.err(`Warning: ${url} is not https, so your token is sent unencrypted.`);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
// src/commands/connect.ts
|
|
1831
|
+
var SERVICE_CONFIG = {
|
|
1832
|
+
github: [{ key: "owner", required: false, default: "umi-labs" }],
|
|
1833
|
+
dokploy: [
|
|
1834
|
+
{ key: "baseUrl", required: true },
|
|
1835
|
+
{ key: "serverId", required: true },
|
|
1836
|
+
{ key: "githubProviderId", required: true }
|
|
1837
|
+
],
|
|
1838
|
+
sentry: [
|
|
1839
|
+
{ key: "org", required: true },
|
|
1840
|
+
{ key: "team", required: true },
|
|
1841
|
+
{ key: "baseUrl", required: false, default: "https://sentry.io" }
|
|
1842
|
+
]
|
|
1843
|
+
};
|
|
1844
|
+
var SERVICES = Object.keys(SERVICE_CONFIG);
|
|
1845
|
+
var REVOKE_HINT = "Revoke it in the hub (Admin \u203A Connections or Settings).";
|
|
1846
|
+
var invalid = (message) => new HubError(0, "invalid_request", message);
|
|
1847
|
+
function parseConfigPairs(pairs) {
|
|
1848
|
+
const config = {};
|
|
1849
|
+
for (const pair of pairs) {
|
|
1850
|
+
const i = pair.indexOf("=");
|
|
1851
|
+
if (i < 1) throw invalid("Use --config key=value");
|
|
1852
|
+
config[pair.slice(0, i)] = pair.slice(i + 1);
|
|
1853
|
+
}
|
|
1854
|
+
return config;
|
|
1855
|
+
}
|
|
1856
|
+
async function readToken(stdin) {
|
|
1857
|
+
let raw = "";
|
|
1858
|
+
for await (const chunk of stdin) raw += chunk.toString();
|
|
1859
|
+
const token = raw.trim();
|
|
1860
|
+
if (!token) throw invalid("No token on stdin.");
|
|
1861
|
+
return token;
|
|
1862
|
+
}
|
|
1863
|
+
async function runConnect(service, opts, io, deps) {
|
|
1864
|
+
let secret = "";
|
|
1865
|
+
try {
|
|
1866
|
+
if (!SERVICES.includes(service))
|
|
1867
|
+
throw invalid(
|
|
1868
|
+
`Unknown service ${service}. Use github, dokploy or sentry.`
|
|
1869
|
+
);
|
|
1870
|
+
const svc = service;
|
|
1871
|
+
const config = parseConfigPairs(opts.config);
|
|
1872
|
+
const missing = SERVICE_CONFIG[svc].filter((f) => f.required && !config[f.key]).map((f) => f.key);
|
|
1873
|
+
const interactive = io.isTTY && !opts.tokenStdin && !opts.json;
|
|
1874
|
+
if (opts.tokenStdin && io.stdin.isTTY)
|
|
1875
|
+
throw invalid(
|
|
1876
|
+
"--token-stdin needs the token piped in (your terminal would show it). Pipe it, or leave out --token-stdin to be asked."
|
|
1877
|
+
);
|
|
1878
|
+
if (!interactive) {
|
|
1879
|
+
if (!opts.tokenStdin)
|
|
1880
|
+
throw invalid(
|
|
1881
|
+
io.isTTY ? "Pass --token-stdin with --json." : "Pass --token-stdin when not in a terminal."
|
|
1882
|
+
);
|
|
1883
|
+
if (missing.length) throw invalid(`Missing --config ${missing[0]}=`);
|
|
1884
|
+
}
|
|
1885
|
+
const { url: hubUrl, fromSettings } = await resolveHub(void 0, io);
|
|
1886
|
+
const { token } = await requireSignedIn(hubUrl, io.home);
|
|
1887
|
+
io.err(
|
|
1888
|
+
`Sending the token to ${hubUrl}${fromSettings ? " (from foundrykit.json)" : ""}`
|
|
1889
|
+
);
|
|
1890
|
+
let owner = opts.owner ?? (svc === "github" ? "me" : "umi");
|
|
1891
|
+
if (interactive) {
|
|
1892
|
+
const required = (v) => Boolean(v.trim()) || "Required";
|
|
1893
|
+
const answers = await deps.prompt([
|
|
1894
|
+
...opts.owner ? [] : [
|
|
1895
|
+
{
|
|
1896
|
+
type: "input",
|
|
1897
|
+
name: "owner",
|
|
1898
|
+
message: "Owner (me, umi, <org> or <org>/<project>):",
|
|
1899
|
+
default: owner,
|
|
1900
|
+
validate: required
|
|
1901
|
+
}
|
|
1902
|
+
],
|
|
1903
|
+
...missing.map((key) => ({
|
|
1904
|
+
type: "input",
|
|
1905
|
+
name: key,
|
|
1906
|
+
message: `${key}:`,
|
|
1907
|
+
validate: required
|
|
1908
|
+
})),
|
|
1909
|
+
{
|
|
1910
|
+
type: "password",
|
|
1911
|
+
name: "token",
|
|
1912
|
+
message: `${svc} token:`,
|
|
1913
|
+
mask: "*",
|
|
1914
|
+
validate: required
|
|
1915
|
+
}
|
|
1916
|
+
]);
|
|
1917
|
+
if (!opts.owner) owner = String(answers.owner).trim();
|
|
1918
|
+
for (const key of missing) config[key] = String(answers[key]).trim();
|
|
1919
|
+
secret = String(answers.token).trim();
|
|
1920
|
+
} else {
|
|
1921
|
+
secret = await readToken(io.stdin);
|
|
1922
|
+
}
|
|
1923
|
+
const body = {
|
|
1924
|
+
service: svc,
|
|
1925
|
+
owner,
|
|
1926
|
+
...opts.label && { label: opts.label },
|
|
1927
|
+
...Object.keys(config).length && { config },
|
|
1928
|
+
secret
|
|
1929
|
+
};
|
|
1930
|
+
const res = await hubFetch(
|
|
1931
|
+
hubUrl,
|
|
1932
|
+
token,
|
|
1933
|
+
"POST",
|
|
1934
|
+
"/api/cli/connections",
|
|
1935
|
+
body
|
|
1936
|
+
);
|
|
1937
|
+
const c = res.connection;
|
|
1938
|
+
io.out(
|
|
1939
|
+
opts.json ? JSON.stringify(res) : `Connected ${c.service} for ${c.owner} (${c.label}) on ${hubUrl}.`
|
|
1940
|
+
);
|
|
1941
|
+
return 0;
|
|
1942
|
+
} catch (e) {
|
|
1943
|
+
if (e instanceof HubError) {
|
|
1944
|
+
if (secret) e.message = e.message.split(secret).join("***");
|
|
1945
|
+
if (e.code === "conflict") e.message = `${e.message} ${REVOKE_HINT}`;
|
|
1946
|
+
}
|
|
1947
|
+
return fail(io, opts.json, e);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
async function runConnections(opts, io, cwd) {
|
|
1951
|
+
try {
|
|
1952
|
+
let ref;
|
|
1953
|
+
try {
|
|
1954
|
+
ref = (await loadProject(cwd, { readOnly: true })).settings.hub?.project;
|
|
1955
|
+
} catch (e) {
|
|
1956
|
+
if (!(e instanceof ProjectError)) throw e;
|
|
1957
|
+
}
|
|
1958
|
+
const hubUrl = await hubUrlFor(void 0, { ...io, cwd });
|
|
1959
|
+
const { token } = await requireSignedIn(hubUrl, io.home);
|
|
1960
|
+
const res = await hubFetch(
|
|
1961
|
+
hubUrl,
|
|
1962
|
+
token,
|
|
1963
|
+
"GET",
|
|
1964
|
+
`/api/cli/connections${ref ? `?project=${encodeURIComponent(ref)}` : ""}`
|
|
1965
|
+
);
|
|
1966
|
+
if (opts.json) {
|
|
1967
|
+
io.out(JSON.stringify(res));
|
|
1968
|
+
return 0;
|
|
1969
|
+
}
|
|
1970
|
+
if (!res.connections.length && !res.resolved)
|
|
1971
|
+
io.out("No connections. Run `foundrykit connect <service>`.");
|
|
1972
|
+
for (const c of res.connections) {
|
|
1973
|
+
const used = c.lastUsedAt ? c.lastUsedAt.slice(0, 10) : "never";
|
|
1974
|
+
const mark = res.resolved?.[c.service] === c.id ? ` \u2190 used for ${ref}` : "";
|
|
1975
|
+
io.out(`${c.service} ${c.owner} ${c.label} last used ${used}${mark}`);
|
|
1976
|
+
}
|
|
1977
|
+
for (const svc of SERVICES)
|
|
1978
|
+
if (res.resolved?.[svc] === null)
|
|
1979
|
+
io.out(`${svc}: none \u2014 run foundrykit connect ${svc}`);
|
|
1980
|
+
return 0;
|
|
1981
|
+
} catch (e) {
|
|
1982
|
+
return fail(io, opts.json, e);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
function connectCommand() {
|
|
1986
|
+
return new Command2("connect").description("Connect a service (github, dokploy, sentry) on the hub").argument("<service>", "github, dokploy or sentry").option("--owner <owner>", "me, umi, <org> or <org>/<project>").option("--label <label>", "label shown in the hub").option("--token-stdin", "read the token from stdin").option("--config <k=v...>", "service config, e.g. --config org=umi").option("--json", "print JSON").action(
|
|
1987
|
+
async (service, opts) => {
|
|
1988
|
+
process.exitCode = await runConnect(
|
|
1989
|
+
service,
|
|
1990
|
+
{
|
|
1991
|
+
owner: opts.owner,
|
|
1992
|
+
label: opts.label,
|
|
1993
|
+
tokenStdin: Boolean(opts.tokenStdin),
|
|
1994
|
+
config: opts.config ?? [],
|
|
1995
|
+
json: Boolean(opts.json)
|
|
1996
|
+
},
|
|
1997
|
+
defaultIO(),
|
|
1998
|
+
{ prompt: inquirer3.prompt }
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
);
|
|
2002
|
+
}
|
|
2003
|
+
function connectionsCommand() {
|
|
2004
|
+
return new Command2("connections").description("List your hub connections").option("--json", "print JSON").action(async (opts) => {
|
|
2005
|
+
const io = defaultIO();
|
|
2006
|
+
process.exitCode = await runConnections(
|
|
2007
|
+
{ json: Boolean(opts.json) },
|
|
2008
|
+
io,
|
|
2009
|
+
io.cwd
|
|
2010
|
+
);
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
// src/commands/doctor.ts
|
|
2015
|
+
import path7 from "path";
|
|
2016
|
+
import chalk5 from "chalk";
|
|
2017
|
+
import { Command as Command3 } from "commander";
|
|
2018
|
+
import fs7 from "fs-extra";
|
|
2019
|
+
async function collectDoctorChecks(cwd) {
|
|
2020
|
+
const root = findProjectRoot(cwd);
|
|
2021
|
+
const checks = await collectBasicChecks(root ?? cwd);
|
|
2022
|
+
if (!root) {
|
|
2023
|
+
checks.push({
|
|
2024
|
+
name: "FoundryKit config",
|
|
2025
|
+
ok: false,
|
|
2026
|
+
detail: `No ${SETTINGS_FILE} found. Run "foundrykit init" to create it`
|
|
2027
|
+
});
|
|
2028
|
+
return checks;
|
|
2029
|
+
}
|
|
2030
|
+
const hasSettings = await fs7.pathExists(path7.join(root, SETTINGS_FILE));
|
|
2031
|
+
const hasLock = await fs7.pathExists(path7.join(root, LOCK_FILE));
|
|
2032
|
+
const hasLegacy = await fs7.pathExists(path7.join(root, LEGACY_CONFIG_FILE));
|
|
2033
|
+
checks.push({
|
|
2034
|
+
name: "FoundryKit files",
|
|
2035
|
+
ok: hasSettings && hasLock || !hasSettings && hasLegacy,
|
|
2036
|
+
detail: `${!hasSettings && hasLegacy ? "Migration pending: " : ""}${SETTINGS_FILE} ${hasSettings ? "found" : "missing"}, ${LOCK_FILE} ${hasLock ? "found" : "missing"}${hasLegacy ? `, legacy ${LEGACY_CONFIG_FILE} present` : ""}`
|
|
2037
|
+
});
|
|
2038
|
+
let project;
|
|
2039
|
+
try {
|
|
2040
|
+
project = await loadProject(cwd, { readOnly: true });
|
|
2041
|
+
} catch (error) {
|
|
2042
|
+
checks.push({
|
|
2043
|
+
name: "Settings",
|
|
2044
|
+
ok: false,
|
|
2045
|
+
detail: error instanceof SettingsError ? `Invalid setting "${error.key}": ${error.message}` : error instanceof Error ? error.message : String(error)
|
|
2046
|
+
});
|
|
2047
|
+
return checks;
|
|
2048
|
+
}
|
|
2049
|
+
if (project.migration === "pending") {
|
|
2050
|
+
checks.push({
|
|
2051
|
+
name: "Migration",
|
|
2052
|
+
ok: true,
|
|
2053
|
+
detail: `Migration pending: ${LEGACY_CONFIG_FILE} will be converted to ${SETTINGS_FILE} and ${LOCK_FILE} the next time you run add or update`
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
checks.push({
|
|
2057
|
+
name: "Settings",
|
|
2058
|
+
ok: true,
|
|
2059
|
+
detail: `Valid${project.warnings.length ? ` (${project.warnings.join("; ")})` : ""}`
|
|
2060
|
+
});
|
|
2061
|
+
const missing = [];
|
|
2062
|
+
const edited = [];
|
|
2063
|
+
const unreadable = [];
|
|
2064
|
+
for (const entry of Object.values(project.lock.components)) {
|
|
2065
|
+
for (const [file, recorded] of Object.entries(entry.files ?? {})) {
|
|
2066
|
+
try {
|
|
2067
|
+
const status = await fileStatus(project.resolveInRoot(file), recorded);
|
|
2068
|
+
if (status === "missing") missing.push(file);
|
|
2069
|
+
if (status === "edited") edited.push(file);
|
|
2070
|
+
} catch (error) {
|
|
2071
|
+
unreadable.push(
|
|
2072
|
+
`${file} (${error instanceof Error ? error.message : String(error)})`
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
if (unreadable.length) {
|
|
2078
|
+
checks.push({
|
|
2079
|
+
name: "Lock paths",
|
|
2080
|
+
ok: false,
|
|
2081
|
+
detail: `Lock lists files that can't be checked: ${unreadable.join(", ")}`
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
checks.push({
|
|
2085
|
+
name: "Tracked files",
|
|
2086
|
+
ok: missing.length === 0,
|
|
2087
|
+
detail: missing.length ? `Lock lists files that no longer exist: ${missing.join(", ")}` : "All files in the lock exist"
|
|
2088
|
+
});
|
|
2089
|
+
if (edited.length) {
|
|
2090
|
+
checks.push({
|
|
2091
|
+
name: "Edited files",
|
|
2092
|
+
ok: true,
|
|
2093
|
+
detail: `Edited since install (update will skip them): ${edited.join(", ")}`
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
return checks;
|
|
2097
|
+
}
|
|
2098
|
+
async function collectBasicChecks(cwd) {
|
|
2099
|
+
const results = [];
|
|
2100
|
+
const packageJsonPath = path7.join(cwd, "package.json");
|
|
2101
|
+
const hasPackageJson = await fs7.pathExists(packageJsonPath);
|
|
2102
|
+
results.push({
|
|
2103
|
+
name: "package.json",
|
|
2104
|
+
ok: hasPackageJson,
|
|
2105
|
+
detail: hasPackageJson ? "Project manifest found" : "Run this command in a project root"
|
|
2106
|
+
});
|
|
2107
|
+
const packageJson2 = hasPackageJson ? await fs7.readJson(packageJsonPath) : null;
|
|
2108
|
+
const hasNext = !!(packageJson2?.dependencies?.next || packageJson2?.devDependencies?.next);
|
|
2109
|
+
results.push({
|
|
2110
|
+
name: "Framework",
|
|
2111
|
+
ok: hasNext,
|
|
2112
|
+
detail: hasNext ? "Next.js dependency detected" : "FoundryKit currently expects a Next.js project"
|
|
2113
|
+
});
|
|
2114
|
+
return results;
|
|
2115
|
+
}
|
|
2116
|
+
async function registryCheck(cwd) {
|
|
2117
|
+
let registryUrl;
|
|
2118
|
+
try {
|
|
2119
|
+
registryUrl = resolveRegistryUrl(
|
|
2120
|
+
(await loadProject(cwd, { readOnly: true })).settings
|
|
2121
|
+
);
|
|
2122
|
+
} catch {
|
|
2123
|
+
return null;
|
|
2124
|
+
}
|
|
2125
|
+
try {
|
|
2126
|
+
const response = await fetch(`${registryUrl}/registry`, {
|
|
2127
|
+
headers: { Accept: "application/json" }
|
|
2128
|
+
});
|
|
2129
|
+
return {
|
|
2130
|
+
name: "Registry",
|
|
2131
|
+
ok: response.ok,
|
|
2132
|
+
detail: response.ok ? `Registry reachable at ${registryUrl}` : `Registry returned ${response.status} ${response.statusText}`
|
|
2133
|
+
};
|
|
2134
|
+
} catch (error) {
|
|
2135
|
+
return {
|
|
2136
|
+
name: "Registry",
|
|
2137
|
+
ok: false,
|
|
2138
|
+
detail: `Unable to reach ${registryUrl}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
function doctorCommand() {
|
|
2143
|
+
return new Command3("doctor").description("Check project health and configuration").action(async () => {
|
|
2144
|
+
console.log(chalk5.blue("\u{1F50D} Checking project health..."));
|
|
2145
|
+
const results = await collectDoctorChecks(process.cwd());
|
|
2146
|
+
const registry = await registryCheck(process.cwd());
|
|
2147
|
+
if (registry) results.push(registry);
|
|
2148
|
+
for (const result of results) {
|
|
2149
|
+
const icon = result.ok ? chalk5.green("\u2705") : chalk5.red("\u274C");
|
|
2150
|
+
console.log(`${icon} ${result.name}: ${result.detail}`);
|
|
2151
|
+
}
|
|
2152
|
+
const hasFailures = results.some((result) => !result.ok);
|
|
1244
2153
|
if (hasFailures) {
|
|
1245
2154
|
console.log(
|
|
1246
|
-
|
|
2155
|
+
chalk5.yellow(
|
|
1247
2156
|
"\n\u26A0\uFE0F Found issues that should be resolved before continuing."
|
|
1248
2157
|
)
|
|
1249
2158
|
);
|
|
1250
2159
|
process.exit(1);
|
|
1251
2160
|
}
|
|
1252
|
-
console.log(
|
|
2161
|
+
console.log(chalk5.green("\n\u2705 All checks passed!"));
|
|
1253
2162
|
});
|
|
1254
2163
|
}
|
|
1255
2164
|
|
|
1256
2165
|
// src/commands/init.ts
|
|
1257
|
-
import
|
|
1258
|
-
import
|
|
1259
|
-
import {
|
|
1260
|
-
import
|
|
1261
|
-
import
|
|
1262
|
-
import fs4 from "fs-extra";
|
|
1263
|
-
import inquirer2 from "inquirer";
|
|
2166
|
+
import path8 from "path";
|
|
2167
|
+
import chalk6 from "chalk";
|
|
2168
|
+
import { Command as Command4 } from "commander";
|
|
2169
|
+
import fs8 from "fs-extra";
|
|
2170
|
+
import inquirer4 from "inquirer";
|
|
1264
2171
|
function initCommand() {
|
|
1265
|
-
return new
|
|
2172
|
+
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) => {
|
|
1266
2173
|
try {
|
|
1267
|
-
console.log(
|
|
2174
|
+
console.log(chalk6.blue("\u{1F680} Initializing FoundryKit..."));
|
|
1268
2175
|
await validateProject2();
|
|
1269
2176
|
if (!options.force && await isFoundryKitInitialized()) {
|
|
1270
|
-
const { shouldContinue } = await
|
|
2177
|
+
const { shouldContinue } = await inquirer4.prompt([
|
|
1271
2178
|
{
|
|
1272
2179
|
type: "confirm",
|
|
1273
2180
|
name: "shouldContinue",
|
|
@@ -1276,13 +2183,13 @@ function initCommand() {
|
|
|
1276
2183
|
}
|
|
1277
2184
|
]);
|
|
1278
2185
|
if (!shouldContinue) {
|
|
1279
|
-
console.log(
|
|
2186
|
+
console.log(chalk6.yellow("\u274C Initialization cancelled."));
|
|
1280
2187
|
return;
|
|
1281
2188
|
}
|
|
1282
2189
|
}
|
|
1283
2190
|
const projectStructure = await detectProjectStructure();
|
|
1284
2191
|
console.log(
|
|
1285
|
-
|
|
2192
|
+
chalk6.gray(
|
|
1286
2193
|
`Detected project structure: ${projectStructure.hasSrc ? "src/" : "root"} based`
|
|
1287
2194
|
)
|
|
1288
2195
|
);
|
|
@@ -1304,40 +2211,40 @@ function initCommand() {
|
|
|
1304
2211
|
await createDirectories(pathConfig);
|
|
1305
2212
|
await createExampleFiles(pathConfig, projectStructure);
|
|
1306
2213
|
await updatePackageScripts();
|
|
1307
|
-
console.log(
|
|
1308
|
-
console.log(
|
|
2214
|
+
console.log(chalk6.green("\n\u2705 FoundryKit initialized successfully!"));
|
|
2215
|
+
console.log(chalk6.cyan("\n\u{1F4E6} Next steps:"));
|
|
1309
2216
|
console.log(
|
|
1310
|
-
|
|
2217
|
+
chalk6.gray(
|
|
1311
2218
|
" 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal"
|
|
1312
2219
|
)
|
|
1313
2220
|
);
|
|
1314
2221
|
console.log(
|
|
1315
|
-
|
|
2222
|
+
chalk6.gray(
|
|
1316
2223
|
" 2. List available components: pnpm dlx @foundrykit/cli list"
|
|
1317
2224
|
)
|
|
1318
2225
|
);
|
|
1319
2226
|
console.log(
|
|
1320
|
-
|
|
2227
|
+
chalk6.gray(
|
|
1321
2228
|
" 3. Check out the docs: https://foundry-docs.umiflow.com"
|
|
1322
2229
|
)
|
|
1323
2230
|
);
|
|
1324
2231
|
} catch (error) {
|
|
1325
|
-
console.error(
|
|
2232
|
+
console.error(chalk6.red("\u274C Failed to initialize FoundryKit:"));
|
|
1326
2233
|
console.error(
|
|
1327
|
-
|
|
2234
|
+
chalk6.red(error instanceof Error ? error.message : String(error))
|
|
1328
2235
|
);
|
|
1329
2236
|
process.exit(1);
|
|
1330
2237
|
}
|
|
1331
2238
|
});
|
|
1332
2239
|
}
|
|
1333
2240
|
async function validateProject2() {
|
|
1334
|
-
const packageJsonPath =
|
|
1335
|
-
if (!
|
|
2241
|
+
const packageJsonPath = path8.join(process.cwd(), "package.json");
|
|
2242
|
+
if (!fs8.existsSync(packageJsonPath)) {
|
|
1336
2243
|
throw new Error(
|
|
1337
2244
|
"No package.json found. Please run this command in a project directory."
|
|
1338
2245
|
);
|
|
1339
2246
|
}
|
|
1340
|
-
const packageJson2 = await
|
|
2247
|
+
const packageJson2 = await fs8.readJson(packageJsonPath);
|
|
1341
2248
|
const deps = {
|
|
1342
2249
|
...packageJson2.dependencies,
|
|
1343
2250
|
...packageJson2.devDependencies
|
|
@@ -1347,14 +2254,16 @@ async function validateProject2() {
|
|
|
1347
2254
|
"Next.js not detected. FoundryKit currently requires Next.js."
|
|
1348
2255
|
);
|
|
1349
2256
|
}
|
|
1350
|
-
console.log(
|
|
2257
|
+
console.log(chalk6.green("\u2705 Next.js project detected"));
|
|
1351
2258
|
}
|
|
1352
2259
|
async function isFoundryKitInitialized() {
|
|
1353
|
-
return
|
|
2260
|
+
return [SETTINGS_FILE, LEGACY_CONFIG_FILE].some(
|
|
2261
|
+
(f) => fs8.existsSync(path8.join(process.cwd(), f))
|
|
2262
|
+
);
|
|
1354
2263
|
}
|
|
1355
2264
|
async function detectProjectStructure() {
|
|
1356
2265
|
const cwd = process.cwd();
|
|
1357
|
-
const hasSrc =
|
|
2266
|
+
const hasSrc = fs8.existsSync(path8.join(cwd, "src"));
|
|
1358
2267
|
let baseDir = "./";
|
|
1359
2268
|
let appPath;
|
|
1360
2269
|
let componentsPath;
|
|
@@ -1362,48 +2271,48 @@ async function detectProjectStructure() {
|
|
|
1362
2271
|
let hooksPath;
|
|
1363
2272
|
let stylesPath;
|
|
1364
2273
|
if (hasSrc) {
|
|
1365
|
-
const srcHasApp =
|
|
2274
|
+
const srcHasApp = fs8.existsSync(path8.join(cwd, "src/app"));
|
|
1366
2275
|
if (srcHasApp) {
|
|
1367
2276
|
baseDir = "./src/";
|
|
1368
2277
|
appPath = "./src/app";
|
|
1369
2278
|
} else {
|
|
1370
|
-
const rootHasApp =
|
|
2279
|
+
const rootHasApp = fs8.existsSync(path8.join(cwd, "app"));
|
|
1371
2280
|
if (rootHasApp) {
|
|
1372
2281
|
appPath = "./app";
|
|
1373
2282
|
baseDir = "./src/";
|
|
1374
2283
|
}
|
|
1375
2284
|
}
|
|
1376
|
-
if (
|
|
2285
|
+
if (fs8.existsSync(path8.join(cwd, "src/components"))) {
|
|
1377
2286
|
componentsPath = "./src/components";
|
|
1378
2287
|
}
|
|
1379
|
-
if (
|
|
2288
|
+
if (fs8.existsSync(path8.join(cwd, "src/lib"))) {
|
|
1380
2289
|
libPath = "./src/lib";
|
|
1381
2290
|
}
|
|
1382
|
-
if (
|
|
2291
|
+
if (fs8.existsSync(path8.join(cwd, "src/hooks"))) {
|
|
1383
2292
|
hooksPath = "./src/hooks";
|
|
1384
2293
|
}
|
|
1385
|
-
if (
|
|
2294
|
+
if (fs8.existsSync(path8.join(cwd, "src/styles"))) {
|
|
1386
2295
|
stylesPath = "./src/styles";
|
|
1387
2296
|
}
|
|
1388
2297
|
} else {
|
|
1389
|
-
const hasApp =
|
|
2298
|
+
const hasApp = fs8.existsSync(path8.join(cwd, "app"));
|
|
1390
2299
|
if (hasApp) {
|
|
1391
2300
|
appPath = "./app";
|
|
1392
2301
|
}
|
|
1393
|
-
if (
|
|
2302
|
+
if (fs8.existsSync(path8.join(cwd, "components"))) {
|
|
1394
2303
|
componentsPath = "./components";
|
|
1395
2304
|
}
|
|
1396
|
-
if (
|
|
2305
|
+
if (fs8.existsSync(path8.join(cwd, "lib"))) {
|
|
1397
2306
|
libPath = "./lib";
|
|
1398
2307
|
}
|
|
1399
|
-
if (
|
|
2308
|
+
if (fs8.existsSync(path8.join(cwd, "hooks"))) {
|
|
1400
2309
|
hooksPath = "./hooks";
|
|
1401
2310
|
}
|
|
1402
|
-
if (
|
|
2311
|
+
if (fs8.existsSync(path8.join(cwd, "styles"))) {
|
|
1403
2312
|
stylesPath = "./styles";
|
|
1404
2313
|
}
|
|
1405
2314
|
}
|
|
1406
|
-
const isTypeScript =
|
|
2315
|
+
const isTypeScript = fs8.existsSync(path8.join(cwd, "tsconfig.json"));
|
|
1407
2316
|
const packageManager = detectPackageManager2();
|
|
1408
2317
|
return {
|
|
1409
2318
|
hasSrc,
|
|
@@ -1426,43 +2335,43 @@ async function detectProjectStructure() {
|
|
|
1426
2335
|
async function getPathConfiguration(structure, skipPrompts) {
|
|
1427
2336
|
const ext = structure.isTypeScript ? ".ts" : ".js";
|
|
1428
2337
|
const defaults = {
|
|
1429
|
-
utils:
|
|
1430
|
-
structure.libPath ||
|
|
2338
|
+
utils: path8.join(
|
|
2339
|
+
structure.libPath || path8.join(structure.baseDir, "lib"),
|
|
1431
2340
|
`utils${ext}`
|
|
1432
2341
|
),
|
|
1433
|
-
primitives:
|
|
1434
|
-
structure.componentsPath ||
|
|
2342
|
+
primitives: path8.join(
|
|
2343
|
+
structure.componentsPath || path8.join(structure.baseDir, "components"),
|
|
1435
2344
|
"primitives"
|
|
1436
2345
|
),
|
|
1437
|
-
components:
|
|
1438
|
-
structure.componentsPath ||
|
|
2346
|
+
components: path8.join(
|
|
2347
|
+
structure.componentsPath || path8.join(structure.baseDir, "components"),
|
|
1439
2348
|
"ui"
|
|
1440
2349
|
),
|
|
1441
|
-
blocks:
|
|
1442
|
-
structure.componentsPath ||
|
|
2350
|
+
blocks: path8.join(
|
|
2351
|
+
structure.componentsPath || path8.join(structure.baseDir, "components"),
|
|
1443
2352
|
"blocks"
|
|
1444
2353
|
),
|
|
1445
|
-
maps:
|
|
1446
|
-
structure.componentsPath ||
|
|
2354
|
+
maps: path8.join(
|
|
2355
|
+
structure.componentsPath || path8.join(structure.baseDir, "components"),
|
|
1447
2356
|
"maps"
|
|
1448
2357
|
),
|
|
1449
|
-
animations:
|
|
1450
|
-
structure.componentsPath ||
|
|
2358
|
+
animations: path8.join(
|
|
2359
|
+
structure.componentsPath || path8.join(structure.baseDir, "components"),
|
|
1451
2360
|
"animations"
|
|
1452
2361
|
),
|
|
1453
|
-
hooks: structure.hooksPath ||
|
|
1454
|
-
lib: structure.libPath ||
|
|
1455
|
-
styles:
|
|
2362
|
+
hooks: structure.hooksPath || path8.join(structure.baseDir, "hooks"),
|
|
2363
|
+
lib: structure.libPath || path8.join(structure.baseDir, "lib"),
|
|
2364
|
+
styles: path8.join(structure.appPath || structure.baseDir, "globals.css")
|
|
1456
2365
|
};
|
|
1457
2366
|
if (structure.appPath) {
|
|
1458
2367
|
const possibleStylePaths = [
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
2368
|
+
path8.join(structure.appPath, "globals.css"),
|
|
2369
|
+
path8.join(structure.appPath, "global.css"),
|
|
2370
|
+
path8.join(structure.stylesPath || "", "globals.css"),
|
|
2371
|
+
path8.join(structure.stylesPath || "", "global.css")
|
|
1463
2372
|
];
|
|
1464
2373
|
for (const stylePath of possibleStylePaths) {
|
|
1465
|
-
if (
|
|
2374
|
+
if (fs8.existsSync(path8.join(process.cwd(), stylePath))) {
|
|
1466
2375
|
defaults.styles = stylePath;
|
|
1467
2376
|
break;
|
|
1468
2377
|
}
|
|
@@ -1470,15 +2379,15 @@ async function getPathConfiguration(structure, skipPrompts) {
|
|
|
1470
2379
|
}
|
|
1471
2380
|
if (skipPrompts) {
|
|
1472
2381
|
console.log(
|
|
1473
|
-
|
|
2382
|
+
chalk6.gray("Using smart defaults based on project structure...")
|
|
1474
2383
|
);
|
|
1475
2384
|
return defaults;
|
|
1476
2385
|
}
|
|
1477
|
-
console.log(
|
|
2386
|
+
console.log(chalk6.blue("\n\u{1F4C2} Configure installation paths:"));
|
|
1478
2387
|
console.log(
|
|
1479
|
-
|
|
2388
|
+
chalk6.gray("Press enter to use the default value shown in parentheses\n")
|
|
1480
2389
|
);
|
|
1481
|
-
const answers = await
|
|
2390
|
+
const answers = await inquirer4.prompt([
|
|
1482
2391
|
{
|
|
1483
2392
|
type: "input",
|
|
1484
2393
|
name: "utils",
|
|
@@ -1541,9 +2450,8 @@ async function getPathConfiguration(structure, skipPrompts) {
|
|
|
1541
2450
|
return answers;
|
|
1542
2451
|
}
|
|
1543
2452
|
async function installDependencies() {
|
|
1544
|
-
console.log(
|
|
2453
|
+
console.log(chalk6.blue("\u{1F4E6} Installing dependencies..."));
|
|
1545
2454
|
const packageManager = detectPackageManager2();
|
|
1546
|
-
const execAsync2 = promisify2(exec2);
|
|
1547
2455
|
const dependencies = [
|
|
1548
2456
|
"clsx",
|
|
1549
2457
|
"tailwind-merge",
|
|
@@ -1566,40 +2474,45 @@ async function installDependencies() {
|
|
|
1566
2474
|
const devDependencies = ["tailwindcss", "autoprefixer", "postcss"];
|
|
1567
2475
|
try {
|
|
1568
2476
|
const installCmd = packageManager === "npm" ? "install" : "add";
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
2477
|
+
validatePackageSpecs([...dependencies, ...devDependencies]);
|
|
2478
|
+
const cwd = process.cwd();
|
|
2479
|
+
await runPackageManager(packageManager, [installCmd, ...dependencies], {
|
|
2480
|
+
cwd
|
|
2481
|
+
});
|
|
1572
2482
|
const devFlag = packageManager === "npm" ? "--save-dev" : "-D";
|
|
1573
|
-
await
|
|
1574
|
-
|
|
2483
|
+
await runPackageManager(
|
|
2484
|
+
packageManager,
|
|
2485
|
+
[installCmd, devFlag, ...devDependencies],
|
|
2486
|
+
{ cwd }
|
|
1575
2487
|
);
|
|
1576
|
-
console.log(
|
|
1577
|
-
} catch {
|
|
1578
|
-
console.error(
|
|
1579
|
-
console.error(
|
|
2488
|
+
console.log(chalk6.green("\u2705 Dependencies installed"));
|
|
2489
|
+
} catch (error) {
|
|
2490
|
+
console.error(chalk6.yellow("\u26A0\uFE0F Failed to install some dependencies"));
|
|
2491
|
+
console.error(chalk6.gray(error.message));
|
|
2492
|
+
console.error(chalk6.gray("You may need to install them manually"));
|
|
1580
2493
|
}
|
|
1581
2494
|
}
|
|
1582
2495
|
function detectPackageManager2() {
|
|
1583
|
-
if (
|
|
1584
|
-
if (
|
|
1585
|
-
if (
|
|
2496
|
+
if (fs8.existsSync(path8.join(process.cwd(), "pnpm-lock.yaml"))) return "pnpm";
|
|
2497
|
+
if (fs8.existsSync(path8.join(process.cwd(), "yarn.lock"))) return "yarn";
|
|
2498
|
+
if (fs8.existsSync(path8.join(process.cwd(), "bun.lockb"))) return "bun";
|
|
1586
2499
|
return "npm";
|
|
1587
2500
|
}
|
|
1588
2501
|
async function setupTailwindV4(pathConfig, projectStructure, skipPrompts) {
|
|
1589
|
-
console.log(
|
|
2502
|
+
console.log(chalk6.blue("\u{1F3A8} Setting up Tailwind CSS v4..."));
|
|
1590
2503
|
const layoutPath = await findLayoutFile(projectStructure);
|
|
1591
2504
|
if (layoutPath) {
|
|
1592
|
-
const layoutContent = await
|
|
2505
|
+
const layoutContent = await fs8.readFile(layoutPath, "utf-8");
|
|
1593
2506
|
if (layoutContent.includes("@foundrykit/tailwind/globals.css")) {
|
|
1594
2507
|
if (skipPrompts) {
|
|
1595
2508
|
console.log(
|
|
1596
|
-
|
|
2509
|
+
chalk6.green(
|
|
1597
2510
|
"\u2705 Keeping existing import from @foundrykit/tailwind/globals.css"
|
|
1598
2511
|
)
|
|
1599
2512
|
);
|
|
1600
2513
|
return;
|
|
1601
2514
|
}
|
|
1602
|
-
const { importPreference } = await
|
|
2515
|
+
const { importPreference } = await inquirer4.prompt([
|
|
1603
2516
|
{
|
|
1604
2517
|
type: "list",
|
|
1605
2518
|
name: "importPreference",
|
|
@@ -1619,7 +2532,7 @@ async function setupTailwindV4(pathConfig, projectStructure, skipPrompts) {
|
|
|
1619
2532
|
]);
|
|
1620
2533
|
if (importPreference === "direct") {
|
|
1621
2534
|
console.log(
|
|
1622
|
-
|
|
2535
|
+
chalk6.green(
|
|
1623
2536
|
"\u2705 Keeping direct import from @foundrykit/tailwind/globals.css"
|
|
1624
2537
|
)
|
|
1625
2538
|
);
|
|
@@ -1635,10 +2548,10 @@ async function setupTailwindV4(pathConfig, projectStructure, skipPrompts) {
|
|
|
1635
2548
|
if (globalsCssImportMatch?.[1]) {
|
|
1636
2549
|
const importPath = globalsCssImportMatch[1];
|
|
1637
2550
|
const resolvedPath = resolveImportPath(layoutPath, importPath);
|
|
1638
|
-
if (
|
|
2551
|
+
if (fs8.existsSync(resolvedPath)) {
|
|
1639
2552
|
await updateExistingGlobalsCss(resolvedPath);
|
|
1640
2553
|
console.log(
|
|
1641
|
-
|
|
2554
|
+
chalk6.green("\u2705 Updated existing globals.css with FoundryKit styles")
|
|
1642
2555
|
);
|
|
1643
2556
|
return;
|
|
1644
2557
|
}
|
|
@@ -1646,7 +2559,7 @@ async function setupTailwindV4(pathConfig, projectStructure, skipPrompts) {
|
|
|
1646
2559
|
}
|
|
1647
2560
|
let setupPreference = "local";
|
|
1648
2561
|
if (!skipPrompts) {
|
|
1649
|
-
const answer = await
|
|
2562
|
+
const answer = await inquirer4.prompt([
|
|
1650
2563
|
{
|
|
1651
2564
|
type: "list",
|
|
1652
2565
|
name: "setupPreference",
|
|
@@ -1674,11 +2587,11 @@ async function setupTailwindV4(pathConfig, projectStructure, skipPrompts) {
|
|
|
1674
2587
|
await updateLayoutImport(layoutPath, pathConfig);
|
|
1675
2588
|
}
|
|
1676
2589
|
}
|
|
1677
|
-
console.log(
|
|
2590
|
+
console.log(chalk6.green("\u2705 Tailwind CSS v4 configured"));
|
|
1678
2591
|
}
|
|
1679
2592
|
async function createOrUpdateGlobalsCss(pathConfig) {
|
|
1680
|
-
const globalsCssPath =
|
|
1681
|
-
if (
|
|
2593
|
+
const globalsCssPath = path8.join(process.cwd(), pathConfig.styles);
|
|
2594
|
+
if (fs8.existsSync(globalsCssPath)) {
|
|
1682
2595
|
await updateExistingGlobalsCss(globalsCssPath);
|
|
1683
2596
|
} else {
|
|
1684
2597
|
const cssContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
@@ -1686,15 +2599,15 @@ async function createOrUpdateGlobalsCss(pathConfig) {
|
|
|
1686
2599
|
|
|
1687
2600
|
/* Your custom styles below */
|
|
1688
2601
|
`;
|
|
1689
|
-
await
|
|
1690
|
-
await
|
|
1691
|
-
console.log(
|
|
2602
|
+
await fs8.ensureDir(path8.dirname(globalsCssPath));
|
|
2603
|
+
await fs8.writeFile(globalsCssPath, cssContent);
|
|
2604
|
+
console.log(chalk6.green(`\u2705 Created ${pathConfig.styles}`));
|
|
1692
2605
|
}
|
|
1693
2606
|
}
|
|
1694
2607
|
async function updateExistingGlobalsCss(globalsCssPath) {
|
|
1695
|
-
const content = await
|
|
2608
|
+
const content = await fs8.readFile(globalsCssPath, "utf-8");
|
|
1696
2609
|
if (content.includes("@foundrykit/tailwind/globals.css")) {
|
|
1697
|
-
console.log(
|
|
2610
|
+
console.log(chalk6.gray("globals.css already imports FoundryKit styles"));
|
|
1698
2611
|
return;
|
|
1699
2612
|
}
|
|
1700
2613
|
if (content.includes('@import "tailwindcss"')) {
|
|
@@ -1703,16 +2616,16 @@ async function updateExistingGlobalsCss(globalsCssPath) {
|
|
|
1703
2616
|
`/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
1704
2617
|
@import "@foundrykit/tailwind/globals.css"`
|
|
1705
2618
|
);
|
|
1706
|
-
await
|
|
1707
|
-
console.log(
|
|
2619
|
+
await fs8.writeFile(globalsCssPath, updatedContent);
|
|
2620
|
+
console.log(chalk6.green("\u2705 Updated globals.css with FoundryKit styles"));
|
|
1708
2621
|
} else {
|
|
1709
2622
|
const updatedContent = `/* Import FoundryKit's Tailwind CSS v4 styles */
|
|
1710
2623
|
@import "@foundrykit/tailwind/globals.css";
|
|
1711
2624
|
|
|
1712
2625
|
/* Your custom styles below */
|
|
1713
2626
|
${content}`;
|
|
1714
|
-
await
|
|
1715
|
-
console.log(
|
|
2627
|
+
await fs8.writeFile(globalsCssPath, updatedContent);
|
|
2628
|
+
console.log(chalk6.green("\u2705 Updated globals.css with FoundryKit styles"));
|
|
1716
2629
|
}
|
|
1717
2630
|
}
|
|
1718
2631
|
async function findLayoutFile(projectStructure) {
|
|
@@ -1720,8 +2633,8 @@ async function findLayoutFile(projectStructure) {
|
|
|
1720
2633
|
if (projectStructure.appPath) {
|
|
1721
2634
|
const ext = projectStructure.isTypeScript ? ".tsx" : ".jsx";
|
|
1722
2635
|
possiblePaths.push(
|
|
1723
|
-
|
|
1724
|
-
|
|
2636
|
+
path8.join(projectStructure.appPath, `layout${ext}`),
|
|
2637
|
+
path8.join(projectStructure.appPath, `layout.js`)
|
|
1725
2638
|
);
|
|
1726
2639
|
}
|
|
1727
2640
|
possiblePaths.push(
|
|
@@ -1733,8 +2646,8 @@ async function findLayoutFile(projectStructure) {
|
|
|
1733
2646
|
"src/app/layout.js"
|
|
1734
2647
|
);
|
|
1735
2648
|
for (const layoutPath of possiblePaths) {
|
|
1736
|
-
const fullPath =
|
|
1737
|
-
if (
|
|
2649
|
+
const fullPath = path8.join(process.cwd(), layoutPath);
|
|
2650
|
+
if (fs8.existsSync(fullPath)) {
|
|
1738
2651
|
return fullPath;
|
|
1739
2652
|
}
|
|
1740
2653
|
}
|
|
@@ -1742,10 +2655,10 @@ async function findLayoutFile(projectStructure) {
|
|
|
1742
2655
|
}
|
|
1743
2656
|
async function updateLayoutImport(layoutPath, pathConfig) {
|
|
1744
2657
|
try {
|
|
1745
|
-
let content = await
|
|
1746
|
-
const fromPath =
|
|
1747
|
-
const toPath =
|
|
1748
|
-
const relativePath =
|
|
2658
|
+
let content = await fs8.readFile(layoutPath, "utf-8");
|
|
2659
|
+
const fromPath = path8.dirname(layoutPath);
|
|
2660
|
+
const toPath = path8.join(process.cwd(), pathConfig.styles);
|
|
2661
|
+
const relativePath = path8.relative(fromPath, toPath).replace(/\\/g, "/");
|
|
1749
2662
|
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
1750
2663
|
const globalImportRegex = /import\s+['"]([^'"]*globals?\.css)['"]/;
|
|
1751
2664
|
const match = content.match(globalImportRegex);
|
|
@@ -1763,19 +2676,19 @@ async function updateLayoutImport(layoutPath, pathConfig) {
|
|
|
1763
2676
|
content = importStatement + content;
|
|
1764
2677
|
}
|
|
1765
2678
|
}
|
|
1766
|
-
await
|
|
2679
|
+
await fs8.writeFile(layoutPath, content);
|
|
1767
2680
|
console.log(
|
|
1768
|
-
|
|
1769
|
-
`Updated ${
|
|
2681
|
+
chalk6.gray(
|
|
2682
|
+
`Updated ${path8.relative(process.cwd(), layoutPath)} with CSS import`
|
|
1770
2683
|
)
|
|
1771
2684
|
);
|
|
1772
2685
|
} catch {
|
|
1773
|
-
console.error(
|
|
2686
|
+
console.error(chalk6.yellow("\u26A0\uFE0F Failed to update layout with CSS import"));
|
|
1774
2687
|
}
|
|
1775
2688
|
}
|
|
1776
2689
|
async function addDirectImportToLayout(layoutPath) {
|
|
1777
2690
|
try {
|
|
1778
|
-
let content = await
|
|
2691
|
+
let content = await fs8.readFile(layoutPath, "utf-8");
|
|
1779
2692
|
const importStatement = `import '@foundrykit/tailwind/globals.css';
|
|
1780
2693
|
`;
|
|
1781
2694
|
if (!content.includes("@foundrykit/tailwind/globals.css")) {
|
|
@@ -1787,27 +2700,27 @@ async function addDirectImportToLayout(layoutPath) {
|
|
|
1787
2700
|
} else {
|
|
1788
2701
|
content = importStatement + content;
|
|
1789
2702
|
}
|
|
1790
|
-
await
|
|
2703
|
+
await fs8.writeFile(layoutPath, content);
|
|
1791
2704
|
console.log(
|
|
1792
|
-
|
|
2705
|
+
chalk6.green("\u2705 Added direct import of FoundryKit styles to layout")
|
|
1793
2706
|
);
|
|
1794
2707
|
}
|
|
1795
2708
|
} catch {
|
|
1796
|
-
console.error(
|
|
2709
|
+
console.error(chalk6.yellow("\u26A0\uFE0F Failed to add CSS import to layout"));
|
|
1797
2710
|
}
|
|
1798
2711
|
}
|
|
1799
2712
|
function resolveImportPath(fromFile, importPath) {
|
|
1800
2713
|
if (importPath.startsWith(".")) {
|
|
1801
|
-
return
|
|
2714
|
+
return path8.join(path8.dirname(fromFile), importPath);
|
|
1802
2715
|
} else if (importPath.startsWith("@/")) {
|
|
1803
|
-
return
|
|
2716
|
+
return path8.join(process.cwd(), importPath.replace("@/", "src/"));
|
|
1804
2717
|
} else if (importPath.startsWith("/")) {
|
|
1805
|
-
return
|
|
2718
|
+
return path8.join(process.cwd(), importPath);
|
|
1806
2719
|
}
|
|
1807
|
-
return
|
|
2720
|
+
return path8.join(process.cwd(), importPath);
|
|
1808
2721
|
}
|
|
1809
2722
|
async function createDirectories(pathConfig) {
|
|
1810
|
-
console.log(
|
|
2723
|
+
console.log(chalk6.blue("\u{1F4C1} Creating component directories..."));
|
|
1811
2724
|
const dirs = [
|
|
1812
2725
|
pathConfig.primitives,
|
|
1813
2726
|
pathConfig.components,
|
|
@@ -1818,15 +2731,15 @@ async function createDirectories(pathConfig) {
|
|
|
1818
2731
|
pathConfig.lib
|
|
1819
2732
|
];
|
|
1820
2733
|
for (const dir of dirs) {
|
|
1821
|
-
const fullPath =
|
|
1822
|
-
await
|
|
1823
|
-
console.log(
|
|
2734
|
+
const fullPath = path8.join(process.cwd(), dir);
|
|
2735
|
+
await fs8.ensureDir(fullPath);
|
|
2736
|
+
console.log(chalk6.gray(`Created ${dir}`));
|
|
1824
2737
|
}
|
|
1825
|
-
console.log(
|
|
2738
|
+
console.log(chalk6.green("\u2705 Directories created"));
|
|
1826
2739
|
}
|
|
1827
2740
|
async function createExampleFiles(pathConfig, structure) {
|
|
1828
|
-
console.log(
|
|
1829
|
-
const utilsPath =
|
|
2741
|
+
console.log(chalk6.blue("\u{1F4DD} Creating example files..."));
|
|
2742
|
+
const utilsPath = path8.join(process.cwd(), pathConfig.utils);
|
|
1830
2743
|
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
1831
2744
|
import { twMerge } from 'tailwind-merge';
|
|
1832
2745
|
|
|
@@ -1834,14 +2747,14 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
1834
2747
|
return twMerge(clsx(inputs));
|
|
1835
2748
|
}
|
|
1836
2749
|
`;
|
|
1837
|
-
await
|
|
1838
|
-
if (!
|
|
1839
|
-
await
|
|
1840
|
-
console.log(
|
|
2750
|
+
await fs8.ensureDir(path8.dirname(utilsPath));
|
|
2751
|
+
if (!fs8.existsSync(utilsPath)) {
|
|
2752
|
+
await fs8.writeFile(utilsPath, utilsContent);
|
|
2753
|
+
console.log(chalk6.gray(`Created ${pathConfig.utils}`));
|
|
1841
2754
|
}
|
|
1842
|
-
const providersPath =
|
|
2755
|
+
const providersPath = path8.join(
|
|
1843
2756
|
process.cwd(),
|
|
1844
|
-
|
|
2757
|
+
path8.dirname(pathConfig.components),
|
|
1845
2758
|
`theme-provider${structure.isTypeScript ? ".tsx" : ".jsx"}`
|
|
1846
2759
|
);
|
|
1847
2760
|
const providersContent = `
|
|
@@ -1865,44 +2778,41 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
|
1865
2778
|
}
|
|
1866
2779
|
|
|
1867
2780
|
`;
|
|
1868
|
-
if (!
|
|
1869
|
-
await
|
|
2781
|
+
if (!fs8.existsSync(providersPath)) {
|
|
2782
|
+
await fs8.writeFile(providersPath, providersContent);
|
|
1870
2783
|
console.log(
|
|
1871
|
-
|
|
2784
|
+
chalk6.gray(
|
|
1872
2785
|
`Created theme-provider.${structure.isTypeScript ? "tsx" : "jsx"}`
|
|
1873
2786
|
)
|
|
1874
2787
|
);
|
|
1875
2788
|
}
|
|
1876
|
-
console.log(
|
|
2789
|
+
console.log(chalk6.green("\u2705 Example files created"));
|
|
1877
2790
|
}
|
|
1878
2791
|
async function updatePackageScripts() {
|
|
1879
|
-
console.log(
|
|
1880
|
-
const packageJsonPath =
|
|
1881
|
-
const packageJson2 = await
|
|
2792
|
+
console.log(chalk6.blue("\u{1F4DD} Updating package.json scripts..."));
|
|
2793
|
+
const packageJsonPath = path8.join(process.cwd(), "package.json");
|
|
2794
|
+
const packageJson2 = await fs8.readJson(packageJsonPath);
|
|
1882
2795
|
packageJson2.scripts = {
|
|
1883
2796
|
...packageJson2.scripts,
|
|
1884
2797
|
"foundrykit:add": "pnpm dlx @foundrykit/cli add",
|
|
1885
2798
|
"foundrykit:update": "pnpm dlx @foundrykit/cli update"
|
|
1886
2799
|
};
|
|
1887
|
-
await
|
|
1888
|
-
console.log(
|
|
2800
|
+
await fs8.writeJson(packageJsonPath, packageJson2, { spaces: 2 });
|
|
2801
|
+
console.log(chalk6.green("\u2705 Package scripts updated"));
|
|
1889
2802
|
}
|
|
1890
2803
|
async function createConfigFile(options, structure, pathConfig) {
|
|
1891
|
-
console.log(
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
console.log(chalk4.yellow("\u26A0\uFE0F Configuration file already exists"));
|
|
2804
|
+
console.log(chalk6.blue("\u{1F4DD} Creating configuration file..."));
|
|
2805
|
+
if (await isFoundryKitInitialized() && !options.force) {
|
|
2806
|
+
console.log(chalk6.yellow("\u26A0\uFE0F Configuration file already exists"));
|
|
1895
2807
|
return;
|
|
1896
2808
|
}
|
|
1897
2809
|
const normalizePath = (p) => {
|
|
1898
|
-
if (p.startsWith("./") || p.startsWith("../") ||
|
|
2810
|
+
if (p.startsWith("./") || p.startsWith("../") || path8.isAbsolute(p)) {
|
|
1899
2811
|
return p;
|
|
1900
2812
|
}
|
|
1901
2813
|
return `./${p}`;
|
|
1902
2814
|
};
|
|
1903
|
-
const
|
|
1904
|
-
version: CLI_VERSION,
|
|
1905
|
-
registry: DEFAULT_REGISTRY_URL,
|
|
2815
|
+
const settings = {
|
|
1906
2816
|
paths: {
|
|
1907
2817
|
utils: normalizePath(pathConfig.utils),
|
|
1908
2818
|
primitives: normalizePath(pathConfig.primitives),
|
|
@@ -1921,18 +2831,35 @@ async function createConfigFile(options, structure, pathConfig) {
|
|
|
1921
2831
|
aliases: {
|
|
1922
2832
|
"@": normalizePath(structure.baseDir.replace(/\/$/, "") || "."),
|
|
1923
2833
|
"@/components": normalizePath(
|
|
1924
|
-
|
|
2834
|
+
path8.dirname(pathConfig.components).replace(/\/$/, "")
|
|
1925
2835
|
),
|
|
1926
2836
|
"@/lib": normalizePath(pathConfig.lib.replace(/\/$/, "")),
|
|
1927
2837
|
"@/hooks": normalizePath(pathConfig.hooks.replace(/\/$/, ""))
|
|
1928
2838
|
}
|
|
1929
2839
|
};
|
|
1930
|
-
await
|
|
1931
|
-
console.log(
|
|
2840
|
+
await createProjectFiles(process.cwd(), settings);
|
|
2841
|
+
console.log(chalk6.green(`\u2705 Created ${SETTINGS_FILE} and ${LOCK_FILE}`));
|
|
2842
|
+
}
|
|
2843
|
+
async function createProjectFiles(root, settings) {
|
|
2844
|
+
validateSettings(settings);
|
|
2845
|
+
const lockPath = path8.join(root, LOCK_FILE);
|
|
2846
|
+
if (await fs8.pathExists(path8.join(root, LEGACY_CONFIG_FILE)) && !await fs8.pathExists(path8.join(root, SETTINGS_FILE))) {
|
|
2847
|
+
await loadProject(root);
|
|
2848
|
+
}
|
|
2849
|
+
await writeFileAtomic(
|
|
2850
|
+
path8.join(root, SETTINGS_FILE),
|
|
2851
|
+
stableStringify({ $schema: SCHEMA_URL, ...settings })
|
|
2852
|
+
);
|
|
2853
|
+
if (!await fs8.pathExists(lockPath)) {
|
|
2854
|
+
await writeFileAtomic(
|
|
2855
|
+
lockPath,
|
|
2856
|
+
stableStringify({ lockfileVersion: 1, components: {} })
|
|
2857
|
+
);
|
|
2858
|
+
}
|
|
1932
2859
|
}
|
|
1933
2860
|
async function installUtils(pathConfig) {
|
|
1934
|
-
console.log(
|
|
1935
|
-
const utilsPath =
|
|
2861
|
+
console.log(chalk6.blue("\u{1F4E6} Installing utility functions..."));
|
|
2862
|
+
const utilsPath = path8.join(process.cwd(), pathConfig.utils);
|
|
1936
2863
|
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
1937
2864
|
import { twMerge } from 'tailwind-merge';
|
|
1938
2865
|
|
|
@@ -1940,67 +2867,139 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
1940
2867
|
return twMerge(clsx(inputs));
|
|
1941
2868
|
}
|
|
1942
2869
|
`;
|
|
1943
|
-
const utilsDir =
|
|
1944
|
-
await
|
|
1945
|
-
if (!
|
|
1946
|
-
await
|
|
1947
|
-
console.log(
|
|
2870
|
+
const utilsDir = path8.dirname(utilsPath);
|
|
2871
|
+
await fs8.ensureDir(utilsDir);
|
|
2872
|
+
if (!fs8.existsSync(utilsPath)) {
|
|
2873
|
+
await fs8.writeFile(utilsPath, utilsContent);
|
|
2874
|
+
console.log(chalk6.green("\u2705 Utility functions installed"));
|
|
1948
2875
|
} else {
|
|
1949
|
-
console.log(
|
|
2876
|
+
console.log(chalk6.gray("Utils file already exists, skipping..."));
|
|
1950
2877
|
}
|
|
1951
2878
|
}
|
|
1952
2879
|
|
|
2880
|
+
// src/commands/link.ts
|
|
2881
|
+
import { Command as Command5 } from "commander";
|
|
2882
|
+
var REF = /^[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/;
|
|
2883
|
+
async function runLink(ref, opts, io, cwd) {
|
|
2884
|
+
try {
|
|
2885
|
+
if (!REF.test(ref))
|
|
2886
|
+
throw new HubError(
|
|
2887
|
+
400,
|
|
2888
|
+
"invalid_request",
|
|
2889
|
+
"Use <org>/<project>, e.g. turquoise/website."
|
|
2890
|
+
);
|
|
2891
|
+
const project = await loadProject(cwd, { readOnly: true });
|
|
2892
|
+
if (project.migration === "pending")
|
|
2893
|
+
throw new ProjectError("Run `foundrykit update` to migrate first.");
|
|
2894
|
+
const { url: hubUrl } = await resolveHub(opts.hub, { ...io, cwd });
|
|
2895
|
+
const { token } = await requireSignedIn(hubUrl, io.home);
|
|
2896
|
+
const { projects } = await hubFetch(
|
|
2897
|
+
hubUrl,
|
|
2898
|
+
token,
|
|
2899
|
+
"GET",
|
|
2900
|
+
"/api/cli/projects"
|
|
2901
|
+
);
|
|
2902
|
+
const found = projects.find((p) => p.ref === ref);
|
|
2903
|
+
if (!found)
|
|
2904
|
+
throw new HubError(
|
|
2905
|
+
404,
|
|
2906
|
+
"not_found",
|
|
2907
|
+
`No project ${ref} on ${hubUrl} that you can see.`
|
|
2908
|
+
);
|
|
2909
|
+
project.settings.hub = {
|
|
2910
|
+
...project.settings.hub,
|
|
2911
|
+
project: ref,
|
|
2912
|
+
...opts.hub && { url: normalizeHubUrl(opts.hub) }
|
|
2913
|
+
};
|
|
2914
|
+
await project.saveSettings();
|
|
2915
|
+
io.out(
|
|
2916
|
+
opts.json ? JSON.stringify({
|
|
2917
|
+
project: {
|
|
2918
|
+
ref,
|
|
2919
|
+
name: found.name,
|
|
2920
|
+
organization: found.organization
|
|
2921
|
+
}
|
|
2922
|
+
}) : `Linked to ${ref} (${found.name}).`
|
|
2923
|
+
);
|
|
2924
|
+
return 0;
|
|
2925
|
+
} catch (e) {
|
|
2926
|
+
return fail(io, opts.json, e);
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
function linkCommand() {
|
|
2930
|
+
return new Command5("link").description("Link this project to a project on the Foundry hub").argument("<project>", "<org>/<project>, e.g. turquoise/website").option("--hub <url>", "hub URL (saved to foundrykit.json)").option("--json", "print JSON").action(async (ref, opts) => {
|
|
2931
|
+
const io = defaultIO();
|
|
2932
|
+
process.exitCode = await runLink(
|
|
2933
|
+
ref,
|
|
2934
|
+
{ ...opts, json: Boolean(opts.json) },
|
|
2935
|
+
io,
|
|
2936
|
+
io.cwd
|
|
2937
|
+
);
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2940
|
+
|
|
1953
2941
|
// src/commands/list.ts
|
|
1954
|
-
import
|
|
1955
|
-
import { Command as
|
|
2942
|
+
import chalk7 from "chalk";
|
|
2943
|
+
import { Command as Command6 } from "commander";
|
|
2944
|
+
async function loadRegistrySettings(cwd) {
|
|
2945
|
+
try {
|
|
2946
|
+
return (await loadProject(cwd, { readOnly: true })).settings;
|
|
2947
|
+
} catch (error) {
|
|
2948
|
+
if (error instanceof ProjectError || error instanceof SettingsError) {
|
|
2949
|
+
return void 0;
|
|
2950
|
+
}
|
|
2951
|
+
throw error;
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
1956
2954
|
function listCommand() {
|
|
1957
|
-
return new
|
|
2955
|
+
return new Command6("list").description("List all available FoundryKit components and blocks").option(
|
|
1958
2956
|
"-c, --category <category>",
|
|
1959
2957
|
"filter by category (primitives, components, blocks, animations)"
|
|
1960
2958
|
).option("-s, --search <term>", "search components by name or description").action(async (options) => {
|
|
1961
2959
|
try {
|
|
1962
|
-
console.log(
|
|
1963
|
-
const
|
|
2960
|
+
console.log(chalk7.blue("\u{1F4E6} Available FoundryKit components:"));
|
|
2961
|
+
const settings = await loadRegistrySettings(process.cwd());
|
|
2962
|
+
const registry = getRegistry(void 0, settings);
|
|
1964
2963
|
if (options.category) {
|
|
1965
2964
|
const validCategories = REGISTRY_CATEGORY_ORDER;
|
|
1966
2965
|
if (!validCategories.includes(options.category)) {
|
|
1967
|
-
console.error(
|
|
2966
|
+
console.error(chalk7.red(`Invalid category: ${options.category}`));
|
|
1968
2967
|
console.log(
|
|
1969
|
-
|
|
2968
|
+
chalk7.gray(`Valid categories: ${validCategories.join(", ")}`)
|
|
1970
2969
|
);
|
|
1971
2970
|
process.exit(1);
|
|
1972
2971
|
}
|
|
1973
2972
|
}
|
|
1974
|
-
console.log(
|
|
2973
|
+
console.log(chalk7.gray("Fetching from registry..."));
|
|
1975
2974
|
const components = await registry.getComponents(
|
|
1976
2975
|
options.category,
|
|
1977
2976
|
options.search
|
|
1978
2977
|
);
|
|
1979
2978
|
if (components.length === 0) {
|
|
1980
2979
|
console.log(
|
|
1981
|
-
|
|
2980
|
+
chalk7.yellow("\nNo components found matching your criteria.")
|
|
1982
2981
|
);
|
|
1983
2982
|
if (options.search) {
|
|
1984
|
-
console.log(
|
|
2983
|
+
console.log(chalk7.gray(`Search term: "${options.search}"`));
|
|
1985
2984
|
}
|
|
1986
2985
|
if (options.category) {
|
|
1987
|
-
console.log(
|
|
2986
|
+
console.log(chalk7.gray(`Category: ${options.category}`));
|
|
1988
2987
|
}
|
|
1989
2988
|
return;
|
|
1990
2989
|
}
|
|
1991
2990
|
displayComponents(components);
|
|
1992
|
-
console.log(
|
|
2991
|
+
console.log(chalk7.cyan("\n\u{1F4A1} Usage:"));
|
|
1993
2992
|
console.log(
|
|
1994
|
-
|
|
2993
|
+
chalk7.gray(" foundrykit add # Interactive mode")
|
|
1995
2994
|
);
|
|
1996
2995
|
console.log(
|
|
1997
|
-
|
|
2996
|
+
chalk7.gray(" foundrykit add <id> # Add specific component")
|
|
1998
2997
|
);
|
|
1999
|
-
console.log(
|
|
2998
|
+
console.log(chalk7.gray(" foundrykit add button # Example"));
|
|
2000
2999
|
} catch (error) {
|
|
2001
|
-
console.error(
|
|
3000
|
+
console.error(chalk7.red("\u274C Failed to fetch component registry:"));
|
|
2002
3001
|
console.error(
|
|
2003
|
-
|
|
3002
|
+
chalk7.red(error instanceof Error ? error.message : String(error))
|
|
2004
3003
|
);
|
|
2005
3004
|
process.exit(1);
|
|
2006
3005
|
}
|
|
@@ -2030,30 +3029,30 @@ function displayComponents(components) {
|
|
|
2030
3029
|
const items = grouped[category];
|
|
2031
3030
|
if (!items || items.length === 0) continue;
|
|
2032
3031
|
console.log(`
|
|
2033
|
-
${
|
|
2034
|
-
console.log(
|
|
3032
|
+
${chalk7.cyan.bold(category.toUpperCase())}`);
|
|
3033
|
+
console.log(chalk7.gray("\u2500".repeat(40)));
|
|
2035
3034
|
for (const item of items) {
|
|
2036
3035
|
console.log(
|
|
2037
|
-
`${
|
|
3036
|
+
`${chalk7.green("\u25CF")} ${chalk7.bold(item.name)} ${chalk7.gray(
|
|
2038
3037
|
`(${item.id})`
|
|
2039
3038
|
)}`
|
|
2040
3039
|
);
|
|
2041
|
-
console.log(` ${
|
|
3040
|
+
console.log(` ${chalk7.gray(item.description)}`);
|
|
2042
3041
|
if (item.tags && item.tags.length > 0) {
|
|
2043
3042
|
console.log(
|
|
2044
|
-
` ${
|
|
3043
|
+
` ${chalk7.blue(item.tags.map((tag) => `#${tag}`).join(" "))}`
|
|
2045
3044
|
);
|
|
2046
3045
|
}
|
|
2047
3046
|
if (item.registryDependencies && item.registryDependencies.length > 0) {
|
|
2048
3047
|
console.log(
|
|
2049
|
-
` ${
|
|
3048
|
+
` ${chalk7.yellow("Requires:")} ${item.registryDependencies.join(
|
|
2050
3049
|
", "
|
|
2051
3050
|
)}`
|
|
2052
3051
|
);
|
|
2053
3052
|
}
|
|
2054
3053
|
if (item.packageDependencies && item.packageDependencies.length > 0) {
|
|
2055
3054
|
console.log(
|
|
2056
|
-
` ${
|
|
3055
|
+
` ${chalk7.magenta("NPM packages:")} ${item.packageDependencies.join(
|
|
2057
3056
|
", "
|
|
2058
3057
|
)}`
|
|
2059
3058
|
);
|
|
@@ -2063,201 +3062,678 @@ ${chalk5.cyan.bold(category.toUpperCase())}`);
|
|
|
2063
3062
|
}
|
|
2064
3063
|
const total = components.length;
|
|
2065
3064
|
const byCategory = Object.entries(grouped).map(([cat, items]) => `${items.length} ${cat}`).join(", ");
|
|
2066
|
-
console.log(
|
|
2067
|
-
console.log(
|
|
3065
|
+
console.log(chalk7.gray("\u2500".repeat(40)));
|
|
3066
|
+
console.log(chalk7.gray(`Total: ${total} components (${byCategory})`));
|
|
2068
3067
|
}
|
|
2069
3068
|
|
|
2070
|
-
// src/commands/
|
|
2071
|
-
import
|
|
2072
|
-
import
|
|
2073
|
-
import { Command as
|
|
2074
|
-
import
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
3069
|
+
// src/commands/login.ts
|
|
3070
|
+
import { execFile } from "child_process";
|
|
3071
|
+
import { setTimeout as sleep } from "timers/promises";
|
|
3072
|
+
import { Command as Command7 } from "commander";
|
|
3073
|
+
import inquirer5 from "inquirer";
|
|
3074
|
+
|
|
3075
|
+
// src/lib/hub/device.ts
|
|
3076
|
+
var CLIENT_ID = "foundrykit-cli";
|
|
3077
|
+
var str = (v) => typeof v === "string";
|
|
3078
|
+
async function post(hubUrl, path10, body) {
|
|
3079
|
+
let res;
|
|
3080
|
+
try {
|
|
3081
|
+
res = await fetch(`${hubUrl}${path10}`, {
|
|
3082
|
+
method: "POST",
|
|
3083
|
+
redirect: "error",
|
|
3084
|
+
headers: {
|
|
3085
|
+
accept: "application/json",
|
|
3086
|
+
"content-type": "application/json"
|
|
3087
|
+
},
|
|
3088
|
+
body: JSON.stringify(body)
|
|
3089
|
+
});
|
|
3090
|
+
} catch {
|
|
3091
|
+
throw unreachable(hubUrl);
|
|
3092
|
+
}
|
|
3093
|
+
let json = {};
|
|
3094
|
+
try {
|
|
3095
|
+
const parsed = await res.json();
|
|
3096
|
+
if (parsed && typeof parsed === "object")
|
|
3097
|
+
json = parsed;
|
|
3098
|
+
} catch {
|
|
3099
|
+
}
|
|
3100
|
+
return { status: res.status, ok: res.ok, json };
|
|
3101
|
+
}
|
|
3102
|
+
var flatError = (status, json) => str(json.error) ? new HubError(
|
|
3103
|
+
status,
|
|
3104
|
+
json.error,
|
|
3105
|
+
str(json.error_description) && json.error_description ? json.error_description : json.error
|
|
3106
|
+
) : unexpectedResponse(status);
|
|
3107
|
+
async function deviceLogin(hubUrl, deps) {
|
|
3108
|
+
const start = await post(hubUrl, "/api/auth/device/code", {
|
|
3109
|
+
client_id: CLIENT_ID
|
|
3110
|
+
});
|
|
3111
|
+
const c = start.json;
|
|
3112
|
+
if (!start.ok) throw flatError(start.status, c);
|
|
3113
|
+
if (!str(c.device_code) || !str(c.user_code) || !str(c.verification_uri) || !str(c.verification_uri_complete))
|
|
3114
|
+
throw unexpectedResponse(start.status);
|
|
3115
|
+
deps.onCode({ userCode: c.user_code, url: c.verification_uri_complete });
|
|
3116
|
+
let interval = Math.max(1, Number(c.interval) || 5) * 1e3;
|
|
3117
|
+
const budget = Math.min(Number(c.expires_in) || 600, 1800) * 1e3;
|
|
3118
|
+
let waited = 0;
|
|
3119
|
+
while (waited + interval <= budget) {
|
|
3120
|
+
await deps.sleep(interval);
|
|
3121
|
+
waited += interval;
|
|
3122
|
+
const r = await post(hubUrl, "/api/auth/device/token", {
|
|
3123
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
3124
|
+
device_code: c.device_code,
|
|
3125
|
+
client_id: CLIENT_ID
|
|
3126
|
+
});
|
|
3127
|
+
if (r.ok) {
|
|
3128
|
+
if (str(r.json.access_token)) return r.json.access_token;
|
|
3129
|
+
throw unexpectedResponse(r.status);
|
|
3130
|
+
}
|
|
3131
|
+
const error = r.json.error;
|
|
3132
|
+
if (error === "authorization_pending") continue;
|
|
3133
|
+
if (error === "slow_down") {
|
|
3134
|
+
interval += 5e3;
|
|
3135
|
+
continue;
|
|
3136
|
+
}
|
|
3137
|
+
if (error === "access_denied")
|
|
3138
|
+
throw new HubError(400, error, "Sign-in was denied.");
|
|
3139
|
+
if (error === "expired_token") break;
|
|
3140
|
+
throw flatError(r.status, r.json);
|
|
3141
|
+
}
|
|
3142
|
+
throw new HubError(
|
|
3143
|
+
400,
|
|
3144
|
+
"expired_token",
|
|
3145
|
+
"The code expired. Run `foundrykit login` again."
|
|
3146
|
+
);
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
// src/commands/login.ts
|
|
3150
|
+
function openerCommand(platform, href) {
|
|
3151
|
+
if (platform === "darwin") return ["open", [href]];
|
|
3152
|
+
if (platform === "win32")
|
|
3153
|
+
return ["rundll32", ["url.dll,FileProtocolHandler", href]];
|
|
3154
|
+
return ["xdg-open", [href]];
|
|
3155
|
+
}
|
|
3156
|
+
function openUrl(href) {
|
|
3157
|
+
const [cmd, args] = openerCommand(process.platform, href);
|
|
3158
|
+
try {
|
|
3159
|
+
execFile(cmd, args, () => {
|
|
3160
|
+
}).on("error", () => {
|
|
3161
|
+
});
|
|
3162
|
+
} catch {
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
function safeHref(url, hubUrl) {
|
|
3166
|
+
try {
|
|
3167
|
+
const u = new URL(url);
|
|
3168
|
+
if (u.protocol !== "http:" && u.protocol !== "https:") return null;
|
|
3169
|
+
return u.origin === new URL(hubUrl).origin ? u.href : null;
|
|
3170
|
+
} catch {
|
|
3171
|
+
return null;
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
async function whoami(hubUrl, token) {
|
|
3175
|
+
const me = await hubFetch(
|
|
3176
|
+
hubUrl,
|
|
3177
|
+
token,
|
|
3178
|
+
"GET",
|
|
3179
|
+
"/api/cli/whoami"
|
|
3180
|
+
);
|
|
3181
|
+
if (typeof me?.user?.email !== "string") throw unexpectedResponse(200);
|
|
3182
|
+
return me;
|
|
3183
|
+
}
|
|
3184
|
+
async function runLogin(opts, io, deps) {
|
|
3185
|
+
try {
|
|
3186
|
+
const { url: hubUrl, fromSettings } = await resolveHub(opts.hub, io);
|
|
3187
|
+
const say = opts.json ? io.err : io.out;
|
|
3188
|
+
if (fromSettings && hubUrl !== DEFAULT_HUB_URL) {
|
|
3189
|
+
if (await readCredential(hubUrl, io.home))
|
|
3190
|
+
io.err(`Signing in to ${hubUrl} (from foundrykit.json)`);
|
|
3191
|
+
else {
|
|
3192
|
+
if (opts.json || !io.isTTY)
|
|
3193
|
+
throw new HubError(
|
|
3194
|
+
0,
|
|
3195
|
+
"invalid_request",
|
|
3196
|
+
`${hubUrl} comes from foundrykit.json. To sign in to it, run \`foundrykit login --hub ${hubUrl}\`.`
|
|
3197
|
+
);
|
|
3198
|
+
const { confirm } = await deps.prompt([
|
|
3199
|
+
{
|
|
3200
|
+
type: "confirm",
|
|
3201
|
+
name: "confirm",
|
|
3202
|
+
message: `Sign in to ${hubUrl} (from foundrykit.json)?`,
|
|
3203
|
+
default: false
|
|
3204
|
+
}
|
|
3205
|
+
]);
|
|
3206
|
+
if (!confirm) {
|
|
3207
|
+
io.out("Not signed in.");
|
|
3208
|
+
return 1;
|
|
3209
|
+
}
|
|
2095
3210
|
}
|
|
2096
|
-
return;
|
|
2097
3211
|
}
|
|
2098
|
-
const
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
)
|
|
3212
|
+
const token = await deviceLogin(hubUrl, {
|
|
3213
|
+
sleep: deps.sleep,
|
|
3214
|
+
onCode: ({ userCode, url }) => {
|
|
3215
|
+
say(`Your code: ${userCode}`);
|
|
3216
|
+
say(`Approve it at ${url}`);
|
|
3217
|
+
if (!opts.browser || !io.isTTY) return;
|
|
3218
|
+
const href = safeHref(url, hubUrl);
|
|
3219
|
+
if (!href) {
|
|
3220
|
+
io.err(
|
|
3221
|
+
`Didn't open your browser: the link isn't on the hub's address (${hubUrl}).`
|
|
3222
|
+
);
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
io.err("Opening your browser\u2026");
|
|
3226
|
+
deps.openUrl(href);
|
|
3227
|
+
}
|
|
3228
|
+
});
|
|
3229
|
+
const me = await whoami(hubUrl, token);
|
|
3230
|
+
await saveCredential(
|
|
3231
|
+
hubUrl,
|
|
3232
|
+
{ token, user: { email: me.user.email } },
|
|
3233
|
+
io.home
|
|
3234
|
+
);
|
|
3235
|
+
io.out(
|
|
3236
|
+
opts.json ? JSON.stringify(me) : `Signed in to ${hubUrl} as ${me.user.email}.`
|
|
3237
|
+
);
|
|
3238
|
+
return 0;
|
|
3239
|
+
} catch (e) {
|
|
3240
|
+
return fail(io, opts.json, e);
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
async function runLogout(opts, io) {
|
|
3244
|
+
try {
|
|
3245
|
+
const hubUrl = await hubUrlFor(opts.hub, io);
|
|
3246
|
+
const signedOut = await deleteCredential(hubUrl, io.home);
|
|
3247
|
+
io.out(
|
|
3248
|
+
opts.json ? JSON.stringify({ hub: hubUrl, signedOut }) : signedOut ? `Signed out of ${hubUrl}.` : `Not signed in to ${hubUrl}.`
|
|
3249
|
+
);
|
|
3250
|
+
return 0;
|
|
3251
|
+
} catch (e) {
|
|
3252
|
+
return fail(io, opts.json, e);
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
async function runWhoami(opts, io) {
|
|
3256
|
+
try {
|
|
3257
|
+
const hubUrl = await hubUrlFor(void 0, io);
|
|
3258
|
+
const { token } = await requireSignedIn(hubUrl, io.home);
|
|
3259
|
+
const me = await whoami(hubUrl, token);
|
|
3260
|
+
const role = me.umiAdmin ? " (Umi admin)" : me.umiStaff ? " (Umi staff)" : "";
|
|
3261
|
+
io.out(
|
|
3262
|
+
opts.json ? JSON.stringify(me) : `${me.user.email} on ${hubUrl}${role}`
|
|
3263
|
+
);
|
|
3264
|
+
return 0;
|
|
3265
|
+
} catch (e) {
|
|
3266
|
+
return fail(io, opts.json, e);
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
function loginCommand() {
|
|
3270
|
+
return new Command7("login").description("Sign in to the Foundry hub").option("--hub <url>", "hub URL").option("--no-browser", "do not open a browser").option("--json", "print JSON").action(
|
|
3271
|
+
async (opts) => {
|
|
3272
|
+
process.exitCode = await runLogin(
|
|
3273
|
+
{ ...opts, json: Boolean(opts.json) },
|
|
3274
|
+
defaultIO(),
|
|
3275
|
+
{ prompt: inquirer5.prompt, sleep: (ms) => sleep(ms), openUrl }
|
|
2104
3276
|
);
|
|
2105
|
-
process.exit(1);
|
|
2106
3277
|
}
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
3278
|
+
);
|
|
3279
|
+
}
|
|
3280
|
+
function logoutCommand() {
|
|
3281
|
+
return new Command7("logout").description("Sign out of the Foundry hub (removes the saved token)").option("--hub <url>", "hub URL").option("--json", "print JSON").action(async (opts) => {
|
|
3282
|
+
process.exitCode = await runLogout(
|
|
3283
|
+
{ ...opts, json: Boolean(opts.json) },
|
|
3284
|
+
defaultIO()
|
|
3285
|
+
);
|
|
3286
|
+
});
|
|
3287
|
+
}
|
|
3288
|
+
function whoamiCommand() {
|
|
3289
|
+
return new Command7("whoami").description("Show who you are signed in as on the Foundry hub").option("--json", "print JSON").action(async (opts) => {
|
|
3290
|
+
process.exitCode = await runWhoami(
|
|
3291
|
+
{ json: Boolean(opts.json) },
|
|
3292
|
+
defaultIO()
|
|
3293
|
+
);
|
|
3294
|
+
});
|
|
3295
|
+
}
|
|
3296
|
+
|
|
3297
|
+
// src/commands/provision.ts
|
|
3298
|
+
import chalk8 from "chalk";
|
|
3299
|
+
import { Command as Command8 } from "commander";
|
|
3300
|
+
import inquirer6 from "inquirer";
|
|
3301
|
+
|
|
3302
|
+
// src/lib/git.ts
|
|
3303
|
+
import { execFile as execFile2, spawn as spawn2 } from "child_process";
|
|
3304
|
+
import { promisify } from "util";
|
|
3305
|
+
var run = promisify(execFile2);
|
|
3306
|
+
var env = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
|
|
3307
|
+
var realGit = {
|
|
3308
|
+
isRepo: (cwd) => run("git", ["rev-parse", "--is-inside-work-tree"], { cwd, env }).then(
|
|
3309
|
+
(r) => r.stdout.trim() === "true",
|
|
3310
|
+
() => false
|
|
3311
|
+
),
|
|
3312
|
+
hasOrigin: (cwd) => run("git", ["remote", "get-url", "origin"], { cwd, env }).then(
|
|
3313
|
+
() => true,
|
|
3314
|
+
() => false
|
|
3315
|
+
),
|
|
3316
|
+
addOrigin: async (cwd, url) => {
|
|
3317
|
+
await run("git", ["remote", "add", "origin", url], { cwd, env });
|
|
3318
|
+
},
|
|
3319
|
+
// git's stdout goes to stderr so `--json` stdout stays one document; prompts/progress still show.
|
|
3320
|
+
pushProd: (cwd) => new Promise((resolve, reject) => {
|
|
3321
|
+
spawn2("git", ["push", "-u", "origin", "HEAD:prod"], {
|
|
3322
|
+
cwd,
|
|
3323
|
+
env,
|
|
3324
|
+
stdio: ["inherit", 2, "inherit"]
|
|
3325
|
+
}).on("error", reject).on(
|
|
3326
|
+
"exit",
|
|
3327
|
+
(code) => code === 0 ? resolve() : reject(new Error(`git push exited with ${code}`))
|
|
3328
|
+
);
|
|
3329
|
+
})
|
|
3330
|
+
};
|
|
3331
|
+
|
|
3332
|
+
// src/commands/provision.ts
|
|
3333
|
+
var COLOR = {
|
|
3334
|
+
create: chalk8.green,
|
|
3335
|
+
skip: chalk8.gray,
|
|
3336
|
+
exists: chalk8.yellow,
|
|
3337
|
+
adopt: chalk8.cyan
|
|
3338
|
+
};
|
|
3339
|
+
var REPO = /^[\w.-]+\/[\w.-]+$/;
|
|
3340
|
+
var APPLY_TIMEOUT_MS = 15 * 6e4;
|
|
3341
|
+
var STILL_PROVISIONING = "The hub is still provisioning; run `foundrykit provision` again to see where it got to.";
|
|
3342
|
+
var ADOPT_HINT = "Found existing resources not recorded in the hub. Re-run with --adopt to record them instead of creating them.";
|
|
3343
|
+
async function maybePush(repo, opts, io, cwd, deps) {
|
|
3344
|
+
const say = opts.json ? io.err : io.out;
|
|
3345
|
+
const url = `https://github.com/${repo}`;
|
|
3346
|
+
const manual = (origin) => {
|
|
3347
|
+
if (origin) say(` git remote add origin ${url}.git`);
|
|
3348
|
+
say(" git push -u origin HEAD:prod");
|
|
3349
|
+
};
|
|
3350
|
+
if (opts.push === false) return "skipped";
|
|
3351
|
+
if (!REPO.test(repo)) {
|
|
3352
|
+
say(
|
|
3353
|
+
"The hub returned a repo name that isn't owner/name, so nothing was pushed."
|
|
3354
|
+
);
|
|
3355
|
+
return "skipped";
|
|
3356
|
+
}
|
|
3357
|
+
try {
|
|
3358
|
+
if (!await deps.git.isRepo(cwd)) {
|
|
3359
|
+
say("This folder is not a git repo. To trigger the first deploy, run:");
|
|
3360
|
+
say(' git init && git add -A && git commit -m "Initial commit"');
|
|
3361
|
+
manual(true);
|
|
3362
|
+
return "skipped";
|
|
3363
|
+
}
|
|
3364
|
+
if (await deps.git.hasOrigin(cwd)) {
|
|
3365
|
+
say(
|
|
3366
|
+
`origin is already set, so nothing was pushed. Push to the prod branch of ${url} to trigger the first deploy.`
|
|
3367
|
+
);
|
|
3368
|
+
return "origin-exists";
|
|
2118
3369
|
}
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
3370
|
+
if (!opts.yes && !opts.push) {
|
|
3371
|
+
if (opts.json || !io.isTTY) {
|
|
3372
|
+
say("Not pushed. To trigger the first deploy, run:");
|
|
3373
|
+
manual(true);
|
|
3374
|
+
return "skipped";
|
|
3375
|
+
}
|
|
3376
|
+
const { confirm } = await deps.prompt([
|
|
3377
|
+
{
|
|
3378
|
+
type: "confirm",
|
|
3379
|
+
name: "confirm",
|
|
3380
|
+
message: `Add ${url}.git as origin and push this branch as prod?`,
|
|
3381
|
+
default: true
|
|
3382
|
+
}
|
|
3383
|
+
]);
|
|
3384
|
+
if (!confirm) {
|
|
3385
|
+
say("Not pushed. To trigger the first deploy, run:");
|
|
3386
|
+
manual(true);
|
|
3387
|
+
return "skipped";
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
await deps.git.addOrigin(cwd, `${url}.git`);
|
|
3391
|
+
await deps.git.pushProd(cwd);
|
|
3392
|
+
return "pushed";
|
|
3393
|
+
} catch (e) {
|
|
3394
|
+
say(chalk8.red(`Push failed: ${e.message}`));
|
|
3395
|
+
say("Resources were provisioned. Push manually:");
|
|
3396
|
+
manual(!await deps.git.hasOrigin(cwd).catch(() => false));
|
|
3397
|
+
return "failed";
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
async function runProvision(opts, io, cwd, deps) {
|
|
3401
|
+
try {
|
|
3402
|
+
const project = await loadProject(cwd, { readOnly: true });
|
|
3403
|
+
const ref = project.settings.hub?.project;
|
|
3404
|
+
if (!ref)
|
|
3405
|
+
throw new HubError(
|
|
3406
|
+
0,
|
|
3407
|
+
"invalid_request",
|
|
3408
|
+
"Not linked to a hub project. Run `foundrykit link <org>/<project>`."
|
|
2125
3409
|
);
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
3410
|
+
const hubUrl = await hubUrlFor(void 0, { ...io, cwd });
|
|
3411
|
+
const { token } = await requireSignedIn(hubUrl, io.home);
|
|
3412
|
+
const body = { project: ref, adopt: opts.adopt };
|
|
3413
|
+
const plan = await hubFetch(
|
|
3414
|
+
hubUrl,
|
|
3415
|
+
token,
|
|
3416
|
+
"POST",
|
|
3417
|
+
"/api/cli/provision/plan",
|
|
3418
|
+
body
|
|
3419
|
+
);
|
|
3420
|
+
if (!opts.json)
|
|
3421
|
+
for (const s of plan.steps)
|
|
3422
|
+
io.out(`${COLOR[s.action](s.action)} ${s.kind} ${s.summary}`);
|
|
3423
|
+
const exists = plan.steps.some((s) => s.action === "exists");
|
|
3424
|
+
if (opts.dryRun) {
|
|
3425
|
+
if (opts.json) io.out(JSON.stringify(plan));
|
|
3426
|
+
else if (exists) io.out(chalk8.yellow(ADOPT_HINT));
|
|
3427
|
+
return 0;
|
|
3428
|
+
}
|
|
3429
|
+
if (exists) throw new HubError(0, "adopt_required", ADOPT_HINT);
|
|
3430
|
+
const n = plan.steps.filter(
|
|
3431
|
+
(s) => s.action === "create" || s.action === "adopt"
|
|
3432
|
+
).length;
|
|
3433
|
+
if (!n) {
|
|
3434
|
+
io.out(opts.json ? JSON.stringify(plan) : "Nothing to provision.");
|
|
3435
|
+
return 0;
|
|
3436
|
+
}
|
|
3437
|
+
if (!opts.yes) {
|
|
3438
|
+
if (opts.json)
|
|
3439
|
+
throw new HubError(
|
|
3440
|
+
0,
|
|
3441
|
+
"invalid_request",
|
|
3442
|
+
"provision --json needs --yes."
|
|
2134
3443
|
);
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
} catch {
|
|
3444
|
+
if (!io.isTTY)
|
|
3445
|
+
throw new HubError(
|
|
3446
|
+
0,
|
|
3447
|
+
"invalid_request",
|
|
3448
|
+
"provision needs --yes when not run in a terminal."
|
|
3449
|
+
);
|
|
3450
|
+
const { confirm } = await deps.prompt([
|
|
3451
|
+
{
|
|
3452
|
+
type: "confirm",
|
|
3453
|
+
name: "confirm",
|
|
3454
|
+
message: `Provision ${n} resources for ${ref}?`,
|
|
3455
|
+
default: false
|
|
2148
3456
|
}
|
|
3457
|
+
]);
|
|
3458
|
+
if (!confirm) {
|
|
3459
|
+
io.out("Cancelled.");
|
|
3460
|
+
return 0;
|
|
2149
3461
|
}
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
3462
|
+
}
|
|
3463
|
+
const res = await hubFetch(
|
|
3464
|
+
hubUrl,
|
|
3465
|
+
token,
|
|
3466
|
+
"POST",
|
|
3467
|
+
"/api/cli/provision/apply",
|
|
3468
|
+
body,
|
|
3469
|
+
{ timeoutMs: deps.applyTimeoutMs ?? APPLY_TIMEOUT_MS }
|
|
3470
|
+
).catch((e) => {
|
|
3471
|
+
if (e instanceof HubError && e.code === "timeout")
|
|
3472
|
+
e.message = STILL_PROVISIONING;
|
|
3473
|
+
throw e;
|
|
3474
|
+
});
|
|
3475
|
+
const ok = res.status === "succeeded";
|
|
3476
|
+
const push = () => ok && res.repo ? maybePush(res.repo, opts, io, project.root, deps) : Promise.resolve(null);
|
|
3477
|
+
if (opts.json) {
|
|
3478
|
+
const pushed = await push();
|
|
3479
|
+
io.out(JSON.stringify({ ...res, push: pushed }));
|
|
3480
|
+
return ok && pushed !== "failed" ? 0 : 1;
|
|
3481
|
+
}
|
|
3482
|
+
for (const r of res.resources)
|
|
3483
|
+
io.out(`${r.action} ${r.kind} ${r.url ?? r.externalId}`);
|
|
3484
|
+
for (const item of res.checklist) io.out(`- ${item}`);
|
|
3485
|
+
if (!ok) {
|
|
3486
|
+
io.out(chalk8.red(res.error?.message ?? "Provisioning failed."));
|
|
3487
|
+
io.out("Re-run `foundrykit provision` to continue.");
|
|
3488
|
+
return 1;
|
|
3489
|
+
}
|
|
3490
|
+
return await push() === "failed" ? 1 : 0;
|
|
3491
|
+
} catch (e) {
|
|
3492
|
+
return fail(io, opts.json, e);
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
function provisionCommand() {
|
|
3496
|
+
return new Command8("provision").description("Create the linked project\u2019s resources through the hub").option("--dry-run", "show the plan and stop").option(
|
|
3497
|
+
"--yes",
|
|
3498
|
+
"apply without asking; also adds origin and pushes to prod (which deploys) unless --no-push"
|
|
3499
|
+
).option("--adopt", "record existing resources instead of creating them").option("--push", "push this branch as prod after provisioning").option("--no-push", "never push").option("--json", "print JSON (non-interactive; needs --yes to apply)").action(
|
|
3500
|
+
async (opts) => {
|
|
3501
|
+
const io = defaultIO();
|
|
3502
|
+
process.exitCode = await runProvision(
|
|
3503
|
+
{
|
|
3504
|
+
dryRun: Boolean(opts.dryRun),
|
|
3505
|
+
yes: Boolean(opts.yes),
|
|
3506
|
+
adopt: Boolean(opts.adopt),
|
|
3507
|
+
push: opts.push,
|
|
3508
|
+
json: Boolean(opts.json)
|
|
3509
|
+
},
|
|
3510
|
+
io,
|
|
3511
|
+
io.cwd,
|
|
3512
|
+
{ prompt: inquirer6.prompt, git: realGit }
|
|
3513
|
+
);
|
|
3514
|
+
}
|
|
3515
|
+
);
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
// src/commands/update.ts
|
|
3519
|
+
import path9 from "path";
|
|
3520
|
+
import chalk9 from "chalk";
|
|
3521
|
+
import { Command as Command9 } from "commander";
|
|
3522
|
+
import fs9 from "fs-extra";
|
|
3523
|
+
import inquirer7 from "inquirer";
|
|
3524
|
+
function updateCommand() {
|
|
3525
|
+
return new Command9("update").description("Update tracked components").argument("[ids...]", "Component or block IDs (omit to update all tracked)").option(
|
|
3526
|
+
"-o, --opt",
|
|
3527
|
+
"interactively select which components to update, showing available upgrades"
|
|
3528
|
+
).option("-f, --force", "bypass cache when checking versions (with --opt)").option("--overwrite", "overwrite files edited locally or not yet tracked").action(async (ids, options) => {
|
|
3529
|
+
try {
|
|
3530
|
+
if (options.opt && (!process.stdin.isTTY || !process.stdout.isTTY)) {
|
|
3531
|
+
console.error(
|
|
3532
|
+
chalk9.red(
|
|
3533
|
+
"\u274C --opt needs an interactive terminal. Pass component ids instead."
|
|
2155
3534
|
)
|
|
2156
3535
|
);
|
|
3536
|
+
process.exitCode = 1;
|
|
2157
3537
|
return;
|
|
2158
3538
|
}
|
|
3539
|
+
const project = await loadProject(process.cwd());
|
|
3540
|
+
process.chdir(project.root);
|
|
3541
|
+
let targets = ids;
|
|
3542
|
+
if (targets.length === 0) {
|
|
3543
|
+
const tracked = Object.keys(project.lock.components);
|
|
3544
|
+
const packages = await getInstalledFoundryKitPackageVersions(
|
|
3545
|
+
project.root
|
|
3546
|
+
);
|
|
3547
|
+
if (tracked.length === 0) {
|
|
3548
|
+
console.log(
|
|
3549
|
+
chalk9.yellow("No tracked components. Use `foundrykit add`.")
|
|
3550
|
+
);
|
|
3551
|
+
}
|
|
3552
|
+
targets = [
|
|
3553
|
+
...tracked,
|
|
3554
|
+
...Object.keys(packages).filter((id) => !tracked.includes(id))
|
|
3555
|
+
];
|
|
3556
|
+
if (targets.length === 0) return;
|
|
3557
|
+
if (options.opt) {
|
|
3558
|
+
targets = await selectUpdates(project, targets, packages, options);
|
|
3559
|
+
if (targets.length === 0) return;
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
2159
3562
|
console.log(
|
|
2160
|
-
|
|
2161
|
-
`Found ${installedIds.length} installed component(s) via filesystem scan.`
|
|
2162
|
-
)
|
|
3563
|
+
chalk9.blue(`\u{1F504} Updating ${targets.length} component(s)...`)
|
|
2163
3564
|
);
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
)
|
|
3565
|
+
let outcome;
|
|
3566
|
+
try {
|
|
3567
|
+
outcome = await runUpdates(project, targets, {
|
|
3568
|
+
overwrite: Boolean(options.overwrite),
|
|
3569
|
+
prompt: interactivePrompt()
|
|
3570
|
+
});
|
|
3571
|
+
} finally {
|
|
3572
|
+
await project.saveLock();
|
|
3573
|
+
}
|
|
3574
|
+
printReport(outcome);
|
|
3575
|
+
if (outcome.failed.length > 0) process.exitCode = 1;
|
|
3576
|
+
} catch (error) {
|
|
3577
|
+
console.error(chalk9.red("\u274C Update failed:"));
|
|
3578
|
+
console.error(
|
|
3579
|
+
chalk9.red(error instanceof Error ? error.message : String(error))
|
|
2170
3580
|
);
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
3581
|
+
process.exitCode = 1;
|
|
3582
|
+
}
|
|
3583
|
+
});
|
|
3584
|
+
}
|
|
3585
|
+
async function runUpdates(project, ids, opts) {
|
|
3586
|
+
const targets = ids.length > 0 ? ids : Object.keys(project.lock.components);
|
|
3587
|
+
const registry = getRegistry(void 0, project.settings);
|
|
3588
|
+
const results = [];
|
|
3589
|
+
const failed = /* @__PURE__ */ new Set();
|
|
3590
|
+
const apply = async (data, overwrite = opts.overwrite) => {
|
|
3591
|
+
const result = await applyComponent(project, data, { ...opts, overwrite });
|
|
3592
|
+
results.push(result);
|
|
3593
|
+
if (result.failed.length > 0) failed.add(data.id);
|
|
3594
|
+
};
|
|
3595
|
+
const fail2 = (id, error) => {
|
|
3596
|
+
console.error(
|
|
3597
|
+
chalk9.red(
|
|
3598
|
+
`\u274C Failed to update ${id}: ${error instanceof Error ? error.message : String(error)}`
|
|
3599
|
+
)
|
|
3600
|
+
);
|
|
3601
|
+
failed.add(id);
|
|
3602
|
+
};
|
|
3603
|
+
for (const id of targets) {
|
|
3604
|
+
console.log(chalk9.blue(`
|
|
3605
|
+
\u{1F504} Updating ${id}...`));
|
|
3606
|
+
try {
|
|
3607
|
+
const data = await registry.getComponent(id, true);
|
|
3608
|
+
if (data.files.length > 0) await apply(data);
|
|
3609
|
+
for (const dep of data.registryDependencies ?? []) {
|
|
3610
|
+
if (["hooks", "types"].includes(dep) || project.lock.components[dep])
|
|
3611
|
+
continue;
|
|
2175
3612
|
try {
|
|
2176
|
-
const
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
installed: installedVersion,
|
|
2185
|
-
latest: latestVersion
|
|
2186
|
-
});
|
|
2187
|
-
} else {
|
|
2188
|
-
upToDate.push(compId);
|
|
2189
|
-
}
|
|
2190
|
-
} catch {
|
|
2191
|
-
withUpdates.push({
|
|
2192
|
-
id: compId,
|
|
2193
|
-
installed: installed[compId]?.version ?? null,
|
|
2194
|
-
latest: null
|
|
2195
|
-
});
|
|
3613
|
+
const depData = await registry.getComponent(dep, true);
|
|
3614
|
+
if (depData.files.length > 0) await apply(depData, false);
|
|
3615
|
+
} catch (error) {
|
|
3616
|
+
console.log(
|
|
3617
|
+
chalk9.yellow(
|
|
3618
|
+
` \u26A0 Could not install dependency "${dep}": ${error instanceof Error ? error.message : String(error)}`
|
|
3619
|
+
)
|
|
3620
|
+
);
|
|
2196
3621
|
}
|
|
2197
3622
|
}
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
3623
|
+
await handlePackageDependencies(data, { force: true });
|
|
3624
|
+
} catch (error) {
|
|
3625
|
+
fail2(id, error);
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
return { results, failed: [...failed] };
|
|
3629
|
+
}
|
|
3630
|
+
function printReport({
|
|
3631
|
+
results,
|
|
3632
|
+
failed
|
|
3633
|
+
}) {
|
|
3634
|
+
console.log("");
|
|
3635
|
+
for (const result of results) reportApply(result);
|
|
3636
|
+
const count = (key) => results.reduce((n, r) => n + r[key].length, 0);
|
|
3637
|
+
const summary = [
|
|
3638
|
+
`${count("written")} written`,
|
|
3639
|
+
`${count("upToDate")} up to date`,
|
|
3640
|
+
`${count("kept")} kept`,
|
|
3641
|
+
`${count("skippedEdited")} skipped (edited)`,
|
|
3642
|
+
`${count("skippedUnknown")} skipped (untracked)`,
|
|
3643
|
+
`${count("droppedFromLock")} no longer tracked`
|
|
3644
|
+
].join(", ");
|
|
3645
|
+
console.log(chalk9.bold(`
|
|
3646
|
+
${summary}`));
|
|
3647
|
+
if (failed.length > 0) {
|
|
3648
|
+
console.error(
|
|
3649
|
+
chalk9.red(`\u274C ${failed.length} component(s) failed: ${failed.join(", ")}`)
|
|
3650
|
+
);
|
|
3651
|
+
} else {
|
|
3652
|
+
console.log(chalk9.green("\u2705 Update complete."));
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
async function selectUpdates(project, targets, packages, options) {
|
|
3656
|
+
console.log(
|
|
3657
|
+
chalk9.blue(
|
|
3658
|
+
`\u{1F50D} Checking for updates across ${targets.length} component(s)...`
|
|
3659
|
+
)
|
|
3660
|
+
);
|
|
3661
|
+
const registry = getRegistry(void 0, project.settings);
|
|
3662
|
+
const withUpdates = [];
|
|
3663
|
+
const upToDate = [];
|
|
3664
|
+
for (const compId of targets) {
|
|
3665
|
+
const installedVersion = packages[compId] ?? project.lock.components[compId]?.version ?? null;
|
|
3666
|
+
try {
|
|
3667
|
+
const data = await registry.getComponent(compId, options.force);
|
|
3668
|
+
const latestVersion = data.version ?? null;
|
|
3669
|
+
const hasUpdate = latestVersion !== null && installedVersion !== null && compareVersions2(latestVersion, installedVersion) > 0;
|
|
3670
|
+
const unknownVersion = installedVersion === null || latestVersion === null;
|
|
3671
|
+
if (hasUpdate || unknownVersion) {
|
|
3672
|
+
withUpdates.push({
|
|
3673
|
+
id: compId,
|
|
3674
|
+
installed: installedVersion,
|
|
3675
|
+
latest: latestVersion
|
|
3676
|
+
});
|
|
3677
|
+
} else {
|
|
3678
|
+
upToDate.push(compId);
|
|
2207
3679
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
3680
|
+
} catch {
|
|
3681
|
+
withUpdates.push({
|
|
3682
|
+
id: compId,
|
|
3683
|
+
installed: installedVersion,
|
|
3684
|
+
latest: null
|
|
3685
|
+
});
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
if (upToDate.length > 0) {
|
|
3689
|
+
console.log(chalk9.gray(`
|
|
3690
|
+
\u2713 Already up to date: ${upToDate.join(", ")}`));
|
|
3691
|
+
}
|
|
3692
|
+
if (withUpdates.length === 0) {
|
|
3693
|
+
console.log(chalk9.green("\n\u2705 All components are up to date."));
|
|
3694
|
+
return [];
|
|
3695
|
+
}
|
|
3696
|
+
const choices = withUpdates.map(({ id: compId, installed: inst, latest }) => {
|
|
3697
|
+
let versionLabel;
|
|
3698
|
+
if (inst === null && latest === null) {
|
|
3699
|
+
versionLabel = chalk9.gray("(version unknown)");
|
|
3700
|
+
} else if (latest === null) {
|
|
3701
|
+
versionLabel = chalk9.gray(
|
|
3702
|
+
`(installed: ${inst} \u2014 registry version unknown)`
|
|
2230
3703
|
);
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
name: "selectedIds",
|
|
2235
|
-
message: "Select components to update:",
|
|
2236
|
-
choices,
|
|
2237
|
-
pageSize: 20
|
|
2238
|
-
}
|
|
2239
|
-
]);
|
|
2240
|
-
if (selectedIds.length === 0) {
|
|
2241
|
-
console.log(chalk6.yellow("No components selected."));
|
|
2242
|
-
return;
|
|
2243
|
-
}
|
|
2244
|
-
await runUpdates(selectedIds, options);
|
|
2245
|
-
} else {
|
|
2246
|
-
console.log(
|
|
2247
|
-
chalk6.blue(
|
|
2248
|
-
`\u{1F504} Updating all ${installedIds.length} installed component(s)...`
|
|
2249
|
-
)
|
|
3704
|
+
} else if (inst === null) {
|
|
3705
|
+
versionLabel = chalk9.cyan(
|
|
3706
|
+
`(latest: ${latest} \u2014 install version not tracked)`
|
|
2250
3707
|
);
|
|
2251
|
-
|
|
3708
|
+
} else {
|
|
3709
|
+
versionLabel = chalk9.cyan(`(${inst} \u2192 ${latest})`);
|
|
2252
3710
|
}
|
|
3711
|
+
return {
|
|
3712
|
+
name: `${compId} ${versionLabel}`,
|
|
3713
|
+
value: compId,
|
|
3714
|
+
checked: true
|
|
3715
|
+
};
|
|
2253
3716
|
});
|
|
3717
|
+
const { selectedIds } = await inquirer7.prompt([
|
|
3718
|
+
{
|
|
3719
|
+
type: "checkbox",
|
|
3720
|
+
name: "selectedIds",
|
|
3721
|
+
message: "Select components to update:",
|
|
3722
|
+
choices,
|
|
3723
|
+
pageSize: 20
|
|
3724
|
+
}
|
|
3725
|
+
]);
|
|
3726
|
+
if (selectedIds.length === 0) {
|
|
3727
|
+
console.log(chalk9.yellow("No components selected."));
|
|
3728
|
+
}
|
|
3729
|
+
return selectedIds;
|
|
2254
3730
|
}
|
|
2255
|
-
async function getInstalledFoundryKitPackageVersions() {
|
|
2256
|
-
const packageJsonPath =
|
|
2257
|
-
if (!
|
|
3731
|
+
async function getInstalledFoundryKitPackageVersions(root) {
|
|
3732
|
+
const packageJsonPath = path9.join(root, "package.json");
|
|
3733
|
+
if (!fs9.existsSync(packageJsonPath)) {
|
|
2258
3734
|
return {};
|
|
2259
3735
|
}
|
|
2260
|
-
const packageJson2 = await
|
|
3736
|
+
const packageJson2 = await fs9.readJson(packageJsonPath);
|
|
2261
3737
|
const dependencies = {
|
|
2262
3738
|
...packageJson2.dependencies,
|
|
2263
3739
|
...packageJson2.devDependencies,
|
|
@@ -2286,36 +3762,6 @@ function normalizeVersionSpec(version) {
|
|
|
2286
3762
|
}
|
|
2287
3763
|
return version.replace(/^[^\d]*/, "").split("-")[0]?.replace(/[^\d.]/g, "") || "0";
|
|
2288
3764
|
}
|
|
2289
|
-
async function runUpdates(ids, options) {
|
|
2290
|
-
let failed = 0;
|
|
2291
|
-
for (const compId of ids) {
|
|
2292
|
-
try {
|
|
2293
|
-
console.log(chalk6.blue(`
|
|
2294
|
-
\u{1F504} Updating ${compId}...`));
|
|
2295
|
-
await addSingleComponent(compId, {
|
|
2296
|
-
...options,
|
|
2297
|
-
overwrite: true,
|
|
2298
|
-
force: true
|
|
2299
|
-
});
|
|
2300
|
-
} catch (error) {
|
|
2301
|
-
console.error(chalk6.red(`\u274C Failed to update ${compId}:`));
|
|
2302
|
-
console.error(
|
|
2303
|
-
chalk6.red(error instanceof Error ? error.message : String(error))
|
|
2304
|
-
);
|
|
2305
|
-
failed++;
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
if (failed > 0) {
|
|
2309
|
-
console.log(chalk6.yellow(`
|
|
2310
|
-
\u26A0 ${failed} component(s) failed to update.`));
|
|
2311
|
-
process.exit(1);
|
|
2312
|
-
} else {
|
|
2313
|
-
console.log(
|
|
2314
|
-
chalk6.green(`
|
|
2315
|
-
\u2705 ${ids.length} component(s) updated successfully!`)
|
|
2316
|
-
);
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
3765
|
|
|
2320
3766
|
// src/index.ts
|
|
2321
3767
|
var __filename = fileURLToPath(import.meta.url);
|
|
@@ -2323,12 +3769,19 @@ var __dirname = dirname(__filename);
|
|
|
2323
3769
|
var packageJson = JSON.parse(
|
|
2324
3770
|
readFileSync(join(__dirname, "..", "package.json"), "utf-8")
|
|
2325
3771
|
);
|
|
2326
|
-
var program = new
|
|
3772
|
+
var program = new Command10();
|
|
2327
3773
|
program.name("foundrykit").description("FoundryKit CLI - Component library management tool").version(packageJson.version);
|
|
2328
3774
|
program.addCommand(initCommand());
|
|
2329
3775
|
program.addCommand(listCommand());
|
|
2330
3776
|
program.addCommand(addCommand());
|
|
2331
3777
|
program.addCommand(updateCommand());
|
|
2332
3778
|
program.addCommand(doctorCommand());
|
|
3779
|
+
program.addCommand(loginCommand());
|
|
3780
|
+
program.addCommand(logoutCommand());
|
|
3781
|
+
program.addCommand(whoamiCommand());
|
|
3782
|
+
program.addCommand(linkCommand());
|
|
3783
|
+
program.addCommand(connectCommand());
|
|
3784
|
+
program.addCommand(connectionsCommand());
|
|
3785
|
+
program.addCommand(provisionCommand());
|
|
2333
3786
|
program.parse();
|
|
2334
3787
|
//# sourceMappingURL=index.js.map
|