@foundrykit/cli 3.0.0 → 3.1.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/dist/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { readFileSync } from "fs";
5
5
  import { dirname, join } from "path";
6
6
  import { fileURLToPath } from "url";
7
- import { Command as Command10 } from "commander";
7
+ import { Command as Command11 } from "commander";
8
8
 
9
9
  // src/commands/add.ts
10
10
  import path5 from "path";
@@ -21,7 +21,7 @@ import fs3 from "fs-extra";
21
21
  import inquirer from "inquirer";
22
22
 
23
23
  // src/lib/constants.ts
24
- var DEFAULT_REGISTRY_URL = "https://foundry.umiflow.com";
24
+ var DEFAULT_REGISTRY_URL = "https://foundrykit.dokploy.umisites.com";
25
25
  var NPM_REGISTRY_URL = "https://registry.npmjs.org";
26
26
  var CACHE_TTL = 24 * 60 * 60 * 1e3;
27
27
  var CACHE_DIR = ".foundrykit";
@@ -54,7 +54,7 @@ var LOCK_FILE = "foundrykit.lock.json";
54
54
  var LEGACY_CONFIG_FILE = "foundrykit.config.json";
55
55
  var SCHEMA_URL = "https://unpkg.com/@foundrykit/cli@3/schema.json";
56
56
  var LEGACY_DEFAULT_REGISTRY_URL = "https://foundry.umiflow.com";
57
- var DEFAULT_HUB_URL = "http://localhost:3003";
57
+ var DEFAULT_HUB_URL = "https://foundrykit.dokploy.umisites.com";
58
58
  var CREDENTIALS_FILE = "credentials.json";
59
59
 
60
60
  // src/lib/project/files.ts
@@ -106,7 +106,8 @@ import path2 from "path";
106
106
  import chalk from "chalk";
107
107
  import fs2 from "fs-extra";
108
108
  function resolveRegistryUrl(settings) {
109
- return process.env.FOUNDRYKIT_REGISTRY_URL || settings?.registry || DEFAULT_REGISTRY_URL;
109
+ const url = process.env.FOUNDRYKIT_REGISTRY_URL || settings?.registry || DEFAULT_REGISTRY_URL;
110
+ return url === LEGACY_DEFAULT_REGISTRY_URL ? DEFAULT_REGISTRY_URL : url;
110
111
  }
111
112
  var DEFAULT_CONFIG = {
112
113
  cacheDir: path2.join(os.homedir(), CACHE_DIR, "cache"),
@@ -743,8 +744,8 @@ var KNOWN_TOP_LEVEL = new Set(RULES.map(([p]) => p.split(".")[0]));
743
744
  var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
744
745
  function validateSettings(raw) {
745
746
  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];
747
+ for (const [path12, type, required, pattern] of RULES) {
748
+ const [parent, child] = path12.includes(".") ? [path12.slice(0, path12.indexOf(".")), path12.slice(path12.indexOf(".") + 1)] : [void 0, path12];
748
749
  let holder = raw;
749
750
  if (parent) {
750
751
  holder = raw[parent];
@@ -752,7 +753,7 @@ function validateSettings(raw) {
752
753
  if (!isObject(holder)) {
753
754
  if (required)
754
755
  throw new SettingsError(
755
- path10,
756
+ path12,
756
757
  `${type} (parent "${parent}" must be an object)`
757
758
  );
758
759
  throw new SettingsError(parent, "an object");
@@ -760,12 +761,12 @@ function validateSettings(raw) {
760
761
  }
761
762
  const value = holder[child];
762
763
  if (value === void 0) {
763
- if (required) throw new SettingsError(path10, `a ${type} (missing)`);
764
+ if (required) throw new SettingsError(path12, `a ${type} (missing)`);
764
765
  continue;
765
766
  }
766
- if (typeof value !== type) throw new SettingsError(path10, `a ${type}`);
767
+ if (typeof value !== type) throw new SettingsError(path12, `a ${type}`);
767
768
  if (pattern && !pattern.test(value))
768
- throw new SettingsError(path10, `a string matching ${pattern.source}`);
769
+ throw new SettingsError(path12, `a string matching ${pattern.source}`);
769
770
  }
770
771
  const warnings = Object.keys(raw).filter((k) => !KNOWN_TOP_LEVEL.has(k)).map((k) => `foundrykit.json: unknown key "${k}" (ignored)`);
771
772
  return { settings: raw, warnings };
@@ -1722,10 +1723,10 @@ async function deleteCredential(hubUrl, home) {
1722
1723
  // src/lib/hub/client.ts
1723
1724
  var isTimeout = (e) => e?.name === "TimeoutError";
1724
1725
  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
+ async function hubFetch(hubUrl, token, method, path12, body, opts = {}) {
1726
1727
  let res;
1727
1728
  try {
1728
- res = await fetch(`${hubUrl}${path10}`, {
1729
+ res = await fetch(`${hubUrl}${path12}`, {
1729
1730
  method,
1730
1731
  // A 307/308 would resend the body (tokens, secrets) to wherever it points.
1731
1732
  redirect: "error",
@@ -3075,10 +3076,10 @@ import inquirer5 from "inquirer";
3075
3076
  // src/lib/hub/device.ts
3076
3077
  var CLIENT_ID = "foundrykit-cli";
3077
3078
  var str = (v) => typeof v === "string";
3078
- async function post(hubUrl, path10, body) {
3079
+ async function post(hubUrl, path12, body) {
3079
3080
  let res;
3080
3081
  try {
3081
- res = await fetch(`${hubUrl}${path10}`, {
3082
+ res = await fetch(`${hubUrl}${path12}`, {
3082
3083
  method: "POST",
3083
3084
  redirect: "error",
3084
3085
  headers: {
@@ -3763,18 +3764,220 @@ function normalizeVersionSpec(version) {
3763
3764
  return version.replace(/^[^\d]*/, "").split("-")[0]?.replace(/[^\d.]/g, "") || "0";
3764
3765
  }
3765
3766
 
3767
+ // src/commands/upgrade.ts
3768
+ import { execFile as execFile3 } from "child_process";
3769
+ import path11 from "path";
3770
+ import { promisify as promisify2 } from "util";
3771
+ import chalk10 from "chalk";
3772
+ import { Command as Command10 } from "commander";
3773
+ import fs11 from "fs-extra";
3774
+ import inquirer8 from "inquirer";
3775
+
3776
+ // src/lib/codemods.ts
3777
+ import path10 from "path";
3778
+ import fs10 from "fs-extra";
3779
+ import { glob } from "glob";
3780
+ var DEP_FIELDS = [
3781
+ "dependencies",
3782
+ "devDependencies",
3783
+ "peerDependencies",
3784
+ "optionalDependencies"
3785
+ ];
3786
+ var SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,json,md,mdx,css,scss}";
3787
+ var IGNORE = [
3788
+ "**/node_modules/**",
3789
+ "**/.next/**",
3790
+ "**/dist/**",
3791
+ "**/build/**",
3792
+ "**/.git/**",
3793
+ "**/package-lock.json",
3794
+ "**/CHANGELOG.md"
3795
+ ];
3796
+ var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3797
+ function renameDependency(pkg, from, to, range) {
3798
+ let changed = false;
3799
+ for (const field of DEP_FIELDS) {
3800
+ const deps = pkg[field];
3801
+ if (!deps || !(from in deps)) continue;
3802
+ pkg[field] = Object.fromEntries(
3803
+ Object.entries(deps).map(([k, v]) => k === from ? [to, range] : [k, v])
3804
+ );
3805
+ changed = true;
3806
+ }
3807
+ return changed;
3808
+ }
3809
+ function renamePackage(from, to, range) {
3810
+ const specifier = new RegExp(`${escapeRe(from)}(?![a-z0-9._~-])`, "g");
3811
+ return {
3812
+ id: `rename:${from}`,
3813
+ detect(pkg) {
3814
+ for (const field of DEP_FIELDS) {
3815
+ const version = pkg[field]?.[from];
3816
+ if (version) return `${from}@${version} \u2192 ${to}@${range}`;
3817
+ }
3818
+ return null;
3819
+ },
3820
+ async run(root, opts = {}) {
3821
+ const files = await glob(SOURCE_GLOB, {
3822
+ cwd: root,
3823
+ ignore: IGNORE,
3824
+ nodir: true
3825
+ });
3826
+ const changed = [];
3827
+ for (const rel of files.sort()) {
3828
+ const file = path10.join(root, rel);
3829
+ const text = await fs10.readFile(file, "utf8");
3830
+ if (!text.includes(from)) continue;
3831
+ let next = text;
3832
+ if (path10.basename(rel) === "package.json") {
3833
+ const pkg = JSON.parse(text);
3834
+ if (renameDependency(pkg, from, to, range)) {
3835
+ const indent = text.match(/^[ \t]+(?=")/m)?.[0] ?? " ";
3836
+ next = `${JSON.stringify(pkg, null, indent)}
3837
+ `;
3838
+ }
3839
+ }
3840
+ next = next.replace(specifier, to);
3841
+ if (next === text) continue;
3842
+ if (!opts.dryRun) await fs10.writeFile(file, next);
3843
+ changed.push(rel);
3844
+ }
3845
+ return changed;
3846
+ }
3847
+ };
3848
+ }
3849
+ var CODEMODS = [
3850
+ renamePackage(
3851
+ "@foundrykit/advanced-forms-plugin",
3852
+ "@foundrykit/form-plugin",
3853
+ "^1.16.4"
3854
+ ),
3855
+ renamePackage(
3856
+ "@foundrykit/advanced-seo-plugin",
3857
+ "@foundrykit/seo-plugin",
3858
+ "^0.3.1"
3859
+ )
3860
+ ];
3861
+
3862
+ // src/commands/upgrade.ts
3863
+ async function hasUncommittedChanges(cwd) {
3864
+ try {
3865
+ const { stdout } = await promisify2(execFile3)(
3866
+ "git",
3867
+ ["status", "--porcelain"],
3868
+ { cwd }
3869
+ );
3870
+ return stdout.trim() !== "";
3871
+ } catch {
3872
+ return false;
3873
+ }
3874
+ }
3875
+ async function runUpgrade(opts, cwd, prompt = inquirer8.prompt) {
3876
+ const pkgPath = path11.join(cwd, "package.json");
3877
+ if (!await fs11.pathExists(pkgPath)) {
3878
+ console.error(
3879
+ chalk10.red("No package.json here. Run this in your project root.")
3880
+ );
3881
+ return 1;
3882
+ }
3883
+ const pkg = await fs11.readJson(pkgPath);
3884
+ const found = CODEMODS.map((mod) => ({ mod, summary: mod.detect(pkg) })).filter(
3885
+ (f) => f.summary !== null
3886
+ );
3887
+ if (found.length === 0) {
3888
+ console.log(
3889
+ chalk10.green("Nothing to upgrade. No codemods apply to this project.")
3890
+ );
3891
+ return 0;
3892
+ }
3893
+ console.log(chalk10.bold("These codemods apply to this project:"));
3894
+ for (const f of found) console.log(` \u2022 ${f.summary}`);
3895
+ let selected = found;
3896
+ if (!opts.yes && !opts.dryRun) {
3897
+ if (await hasUncommittedChanges(cwd)) {
3898
+ const { go } = await prompt([
3899
+ {
3900
+ type: "confirm",
3901
+ name: "go",
3902
+ message: "You have uncommitted changes. Codemods edit files in place; continue anyway?",
3903
+ default: false
3904
+ }
3905
+ ]);
3906
+ if (!go) return 1;
3907
+ }
3908
+ const { ids } = await prompt([
3909
+ {
3910
+ type: "checkbox",
3911
+ name: "ids",
3912
+ message: "Run which codemods?",
3913
+ choices: found.map((f) => ({
3914
+ name: f.summary,
3915
+ value: f.mod.id,
3916
+ checked: true
3917
+ }))
3918
+ }
3919
+ ]);
3920
+ selected = found.filter((f) => ids.includes(f.mod.id));
3921
+ if (selected.length === 0) return 0;
3922
+ }
3923
+ const changed = /* @__PURE__ */ new Set();
3924
+ for (const { mod, summary } of selected) {
3925
+ const files = await mod.run(cwd, { dryRun: opts.dryRun });
3926
+ console.log(`
3927
+ ${chalk10.cyan(summary)}: ${files.length} file(s)`);
3928
+ for (const file of files) {
3929
+ console.log(` ${file}`);
3930
+ changed.add(file);
3931
+ }
3932
+ }
3933
+ if (opts.dryRun) {
3934
+ console.log(chalk10.yellow("\nDry run: nothing was written."));
3935
+ return 0;
3936
+ }
3937
+ const pm = await detectPackageManager();
3938
+ if (opts.install !== false) {
3939
+ console.log(chalk10.blue(`
3940
+ Running ${pm} install...`));
3941
+ try {
3942
+ await runPackageManager(pm, ["install"], { cwd });
3943
+ } catch (e) {
3944
+ console.error(chalk10.red(e.message));
3945
+ console.log(`Run \`${pm} install\` yourself to finish.`);
3946
+ return 1;
3947
+ }
3948
+ }
3949
+ console.log(chalk10.green(`
3950
+ Done. ${changed.size} file(s) changed.`));
3951
+ console.log("Next:");
3952
+ console.log(
3953
+ ` \u2022 Payload site? Run \`${pm} payload generate:importmap\` to regenerate the admin import map.`
3954
+ );
3955
+ console.log(
3956
+ " \u2022 Review with `git diff`, then build and test before committing."
3957
+ );
3958
+ return 0;
3959
+ }
3960
+ function upgradeCommand() {
3961
+ return new Command10("upgrade").description(
3962
+ "Find and run codemods for renamed or changed FoundryKit packages"
3963
+ ).option("-y, --yes", "run every applicable codemod without asking").option("--dry-run", "list the files that would change and stop").option("--no-install", "skip the package manager install afterwards").action(async (opts) => {
3964
+ process.exitCode = await runUpgrade(opts, process.cwd());
3965
+ });
3966
+ }
3967
+
3766
3968
  // src/index.ts
3767
3969
  var __filename = fileURLToPath(import.meta.url);
3768
3970
  var __dirname = dirname(__filename);
3769
3971
  var packageJson = JSON.parse(
3770
3972
  readFileSync(join(__dirname, "..", "package.json"), "utf-8")
3771
3973
  );
3772
- var program = new Command10();
3974
+ var program = new Command11();
3773
3975
  program.name("foundrykit").description("FoundryKit CLI - Component library management tool").version(packageJson.version);
3774
3976
  program.addCommand(initCommand());
3775
3977
  program.addCommand(listCommand());
3776
3978
  program.addCommand(addCommand());
3777
3979
  program.addCommand(updateCommand());
3980
+ program.addCommand(upgradeCommand());
3778
3981
  program.addCommand(doctorCommand());
3779
3982
  program.addCommand(loginCommand());
3780
3983
  program.addCommand(logoutCommand());