@yamada-ui/cli 2.0.0-dev-20250817141319 → 2.0.0-dev-20250821011016

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.
Files changed (3) hide show
  1. package/dist/index.js +182 -121
  2. package/package.json +4 -5
  3. package/bin/index.js +0 -7
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import semverDiff from "semver/functions/diff.js";
18
18
  import semverGt from "semver/functions/gt.js";
19
19
  import semver from "semver";
20
20
  import boxen from "boxen";
21
- import { getObject, isArray, isObject, isString, isUndefined, omitObject } from "@yamada-ui/utils";
21
+ import { getObject, isArray, isObject, isString, isUndefined, merge, omitObject } from "@yamada-ui/utils";
22
22
  import { mkdir, readFile, readdir, writeFile } from "fs/promises";
23
23
  import { Listr } from "listr2";
24
24
  import ora from "ora";
@@ -27,6 +27,7 @@ import { execa } from "execa";
27
27
  import "validate-npm-package-name";
28
28
  import YAML from "yamljs";
29
29
  import { glob } from "glob";
30
+ import { ESLint } from "eslint";
30
31
  import { format as format$1, resolveConfig, resolveConfigFile } from "prettier";
31
32
  import { build } from "esbuild";
32
33
  import nodeEval from "node-eval";
@@ -35,7 +36,6 @@ import { HttpsProxyAgent } from "https-proxy-agent";
35
36
  import fetch from "node-fetch";
36
37
  import { diffLines } from "diff";
37
38
  import { rimraf } from "rimraf";
38
- import { ESLint } from "eslint";
39
39
 
40
40
  //#region rolldown:runtime
41
41
  var __create = Object.create;
@@ -71,11 +71,11 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
71
71
  var require_polyfills$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js": ((exports, module) => {
72
72
  var constants$1 = __require("constants");
73
73
  var origCwd$1 = process.cwd;
74
- var cwd$1 = null;
74
+ var cwd$2 = null;
75
75
  var platform$1 = process.env.GRACEFUL_FS_PLATFORM || process.platform;
76
76
  process.cwd = function() {
77
- if (!cwd$1) cwd$1 = origCwd$1.call(process);
78
- return cwd$1;
77
+ if (!cwd$2) cwd$2 = origCwd$1.call(process);
78
+ return cwd$2;
79
79
  };
80
80
  try {
81
81
  process.cwd();
@@ -83,7 +83,7 @@ var require_polyfills$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm
83
83
  if (typeof process.chdir === "function") {
84
84
  var chdir$1 = process.chdir;
85
85
  process.chdir = function(d) {
86
- cwd$1 = null;
86
+ cwd$2 = null;
87
87
  chdir$1.call(process, d);
88
88
  };
89
89
  if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir$1);
@@ -520,8 +520,8 @@ var require_graceful_fs$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pn
520
520
  }
521
521
  }
522
522
  var fs$writeFile = fs$9.writeFile;
523
- fs$9.writeFile = writeFile$1;
524
- function writeFile$1(path$9, data, options, cb) {
523
+ fs$9.writeFile = writeFile$2;
524
+ function writeFile$2(path$9, data, options, cb) {
525
525
  if (typeof options === "function") cb = options, options = null;
526
526
  return go$writeFile(path$9, data, options, cb);
527
527
  function go$writeFile(path$10, data$1, options$1, cb$1, startTime) {
@@ -2885,11 +2885,11 @@ function registryUrl(scope) {
2885
2885
  var require_polyfills = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/graceful-fs@4.2.10/node_modules/graceful-fs/polyfills.js": ((exports, module) => {
2886
2886
  var constants = __require("constants");
2887
2887
  var origCwd = process.cwd;
2888
- var cwd = null;
2888
+ var cwd$1 = null;
2889
2889
  var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
2890
2890
  process.cwd = function() {
2891
- if (!cwd) cwd = origCwd.call(process);
2892
- return cwd;
2891
+ if (!cwd$1) cwd$1 = origCwd.call(process);
2892
+ return cwd$1;
2893
2893
  };
2894
2894
  try {
2895
2895
  process.cwd();
@@ -2897,7 +2897,7 @@ var require_polyfills = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/g
2897
2897
  if (typeof process.chdir === "function") {
2898
2898
  var chdir = process.chdir;
2899
2899
  process.chdir = function(d) {
2900
- cwd = null;
2900
+ cwd$1 = null;
2901
2901
  chdir.call(process, d);
2902
2902
  };
2903
2903
  if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
@@ -3334,8 +3334,8 @@ var require_graceful_fs = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm
3334
3334
  }
3335
3335
  }
3336
3336
  var fs$writeFile = fs$9.writeFile;
3337
- fs$9.writeFile = writeFile$1;
3338
- function writeFile$1(path$9, data, options, cb) {
3337
+ fs$9.writeFile = writeFile$2;
3338
+ function writeFile$2(path$9, data, options, cb) {
3339
3339
  if (typeof options === "function") cb = options, options = null;
3340
3340
  return go$writeFile(path$9, data, options, cb);
3341
3341
  function go$writeFile(path$10, data$1, options$1, cb$1, startTime) {
@@ -5205,7 +5205,7 @@ var keywords = [
5205
5205
  var author = "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>";
5206
5206
  var license = "MIT";
5207
5207
  var main = "dist/index.js";
5208
- var files = ["dist", "bin"];
5208
+ var files = ["dist"];
5209
5209
  var sideEffects = false;
5210
5210
  var publishConfig = { "access": "public" };
5211
5211
  var homepage = "https://yamada-ui.com";
@@ -5215,10 +5215,10 @@ var repository = {
5215
5215
  "directory": "packages/cli"
5216
5216
  };
5217
5217
  var bugs = { "url": "https://github.com/yamada-ui/yamada-ui/issues" };
5218
- var bin = { "yamada-cli": "bin/index.js" };
5218
+ var bin = { "yamada-cli": "dist/index.js" };
5219
5219
  var scripts = {
5220
5220
  "clean": "rimraf node_modules dist trace coverage .turbo .eslintcache",
5221
- "start": "tsx src/index.ts --run",
5221
+ "dev": "tsx src/index.ts",
5222
5222
  "build": "tsdown",
5223
5223
  "typecheck": " tsc --noEmit",
5224
5224
  "typetrace": "tsc --noEmit --generateTrace ./trace --incremental false",
@@ -5281,8 +5281,43 @@ var package_default = {
5281
5281
  devDependencies
5282
5282
  };
5283
5283
 
5284
+ //#endregion
5285
+ //#region src/utils/lint.ts
5286
+ async function lint(content, { cwd: cwd$3, enabled = true, filePath } = {}) {
5287
+ if (!enabled) return content;
5288
+ try {
5289
+ const eslint = new ESLint({
5290
+ cwd: cwd$3,
5291
+ fix: true
5292
+ });
5293
+ const [result] = await eslint.lintText(content, { filePath });
5294
+ if (result?.output) content = result.output;
5295
+ return content;
5296
+ } catch {
5297
+ return content;
5298
+ }
5299
+ }
5300
+
5301
+ //#endregion
5302
+ //#region src/utils/prettier.ts
5303
+ async function format$2(content, { configPath, enabled = true,...options } = {}) {
5304
+ if (!enabled) return content;
5305
+ try {
5306
+ configPath ??= await resolveConfigFile();
5307
+ const config$1 = configPath ? await resolveConfig(configPath) : {};
5308
+ return format$1(content, {
5309
+ ...config$1,
5310
+ parser: "typescript",
5311
+ ...options
5312
+ });
5313
+ } catch {
5314
+ return content;
5315
+ }
5316
+ }
5317
+
5284
5318
  //#endregion
5285
5319
  //#region src/utils/fs.ts
5320
+ const cwd = process.env.INIT_CWD ?? process.cwd();
5286
5321
  async function isWriteable(directory) {
5287
5322
  try {
5288
5323
  await fs.promises.access(directory, ("constants" in fs ? fs.constants : fs).W_OK);
@@ -5291,12 +5326,20 @@ async function isWriteable(directory) {
5291
5326
  return false;
5292
5327
  }
5293
5328
  }
5329
+ async function writeFile$1(path$9, content, { format: formatConfig, lint: lintConfig,...rest } = {}) {
5330
+ content = await lint(content, {
5331
+ cwd: rest.cwd ?? cwd,
5332
+ ...lintConfig
5333
+ });
5334
+ content = await format$2(content, formatConfig);
5335
+ await writeFile(path$9, content, rest.encoding ?? "utf-8");
5336
+ }
5294
5337
  async function writeFileSafe(path$9, content, options) {
5295
5338
  if (path$9.includes("/")) {
5296
5339
  const dirPath = path$9.split("/").slice(0, -1).join("/");
5297
5340
  if (!existsSync(dirPath)) await mkdir(dirPath, { recursive: true });
5298
5341
  }
5299
- await writeFile(path$9, content, options);
5342
+ await writeFile$1(path$9, content, options);
5300
5343
  }
5301
5344
  async function validateDir(path$9) {
5302
5345
  const writeable = await isWriteable(path$9);
@@ -5342,22 +5385,6 @@ async function getComponentFiles(componentName, { srcPath }) {
5342
5385
  return files$1;
5343
5386
  }
5344
5387
 
5345
- //#endregion
5346
- //#region src/utils/prettier.ts
5347
- async function format$2(content, options) {
5348
- const path$9 = await resolveConfigFile();
5349
- const config$1 = path$9 ? await resolveConfig(path$9) : {};
5350
- try {
5351
- return format$1(content, {
5352
- ...config$1,
5353
- parser: "typescript",
5354
- ...options
5355
- });
5356
- } catch {
5357
- return content;
5358
- }
5359
- }
5360
-
5361
5388
  //#endregion
5362
5389
  //#region src/utils/package.ts
5363
5390
  function getPackageManager() {
@@ -5367,9 +5394,9 @@ function getPackageManager() {
5367
5394
  if (userAgent$1.startsWith("bun")) return "bun";
5368
5395
  return "npm";
5369
5396
  }
5370
- async function getPackageJson(cwd$2) {
5397
+ async function getPackageJson(cwd$3) {
5371
5398
  try {
5372
- const packageJson$2 = await readFile(path$1.resolve(cwd$2, "package.json"), "utf8");
5399
+ const packageJson$2 = await readFile(path$1.resolve(cwd$3, "package.json"), "utf8");
5373
5400
  return JSON.parse(packageJson$2);
5374
5401
  } catch {
5375
5402
  throw new Error(`No package.json found. Please run ${c.cyan(`${getPackageManager()} init`)}.`);
@@ -5437,7 +5464,7 @@ function packageExecuteCommands(packageManager) {
5437
5464
  };
5438
5465
  }
5439
5466
  }
5440
- async function installDependencies(dependencies$1, { cwd: cwd$2, dev, exact = true } = {}) {
5467
+ async function installDependencies(dependencies$1, { cwd: cwd$3, dev, exact = true } = {}) {
5441
5468
  const packageManager = getPackageManager();
5442
5469
  if (dependencies$1?.length) {
5443
5470
  const args = packageAddArgs(packageManager, {
@@ -5445,40 +5472,41 @@ async function installDependencies(dependencies$1, { cwd: cwd$2, dev, exact = tr
5445
5472
  exact
5446
5473
  });
5447
5474
  await execa(packageManager, [...args, ...dependencies$1], {
5448
- cwd: cwd$2,
5475
+ cwd: cwd$3,
5449
5476
  stdout: "ignore"
5450
5477
  });
5451
5478
  } else await execa(packageManager, ["install"], {
5452
- cwd: cwd$2,
5479
+ cwd: cwd$3,
5453
5480
  stdout: "ignore"
5454
5481
  });
5455
5482
  }
5456
- async function addWorkspace(cwd$2, workspacePath) {
5483
+ async function addWorkspace(cwd$3, workspacePath, config$1) {
5457
5484
  const packageManager = getPackageManager();
5458
5485
  switch (packageManager) {
5459
- case "pnpm":
5460
- if (existsSync(path$1.resolve(cwd$2, "pnpm-workspace.yaml"))) {
5461
- const content = await readFile(path$1.resolve(cwd$2, "pnpm-workspace.yaml"), "utf8");
5486
+ case "pnpm": {
5487
+ const targetPath = path$1.resolve(cwd$3, "pnpm-workspace.yaml");
5488
+ if (existsSync(targetPath)) {
5489
+ const content = await readFile(targetPath, "utf8");
5462
5490
  const json$1 = YAML.parse(content);
5463
5491
  json$1.packages ??= [];
5464
5492
  if (!json$1.packages.includes(workspacePath)) {
5465
5493
  json$1.packages.push(workspacePath);
5466
- const content$1 = await format$2(YAML.stringify(json$1), { parser: "yaml" });
5467
- await writeFileSafe(path$1.resolve(cwd$2, "pnpm-workspace.yaml"), content$1);
5494
+ await writeFileSafe(targetPath, YAML.stringify(json$1), merge(config$1, { format: { parser: "yaml" } }));
5468
5495
  }
5469
5496
  } else {
5470
- const data = YAML.stringify({ packages: [workspacePath] });
5471
- const content = await format$2(data, { parser: "yaml" });
5472
- await writeFileSafe(path$1.resolve(cwd$2, "pnpm-workspace.yaml"), content);
5497
+ const content = YAML.stringify({ packages: [workspacePath] });
5498
+ await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "yaml" } }));
5473
5499
  }
5474
5500
  break;
5501
+ }
5475
5502
  default: {
5476
- const packageJson$2 = await getPackageJson(cwd$2);
5503
+ const packageJson$2 = await getPackageJson(cwd$3);
5477
5504
  packageJson$2.workspaces ??= [];
5478
5505
  if (!packageJson$2.workspaces.includes(workspacePath)) {
5479
5506
  packageJson$2.workspaces.push(workspacePath);
5480
- const content = await format$2(JSON.stringify(packageJson$2), { parser: "json" });
5481
- await writeFileSafe(path$1.resolve(cwd$2, "package.json"), content);
5507
+ const targetPath = path$1.resolve(cwd$3, "package.json");
5508
+ const content = JSON.stringify(packageJson$2);
5509
+ await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
5482
5510
  }
5483
5511
  break;
5484
5512
  }
@@ -5487,11 +5515,13 @@ async function addWorkspace(cwd$2, workspacePath) {
5487
5515
 
5488
5516
  //#endregion
5489
5517
  //#region src/utils/config.ts
5490
- async function getConfig(cwd$2, configPath) {
5518
+ async function getConfig(cwd$3, configPath, { format: format$3, lint: lint$1 } = {}) {
5491
5519
  try {
5492
- const data = await readFile(path$1.resolve(cwd$2, configPath), "utf8");
5520
+ const data = await readFile(path$1.resolve(cwd$3, configPath), "utf8");
5493
5521
  const userConfig = JSON.parse(data);
5494
- const rootPath = path$1.resolve(cwd$2, userConfig.path ?? (userConfig.monorepo ? DEFAULT_PATH.monorepo : DEFAULT_PATH.polyrepo));
5522
+ if (!isUndefined(format$3)) userConfig.format = { enabled: format$3 };
5523
+ if (!isUndefined(lint$1)) userConfig.lint = { enabled: lint$1 };
5524
+ const rootPath = path$1.resolve(cwd$3, userConfig.path ?? (userConfig.monorepo ? DEFAULT_PATH.monorepo : DEFAULT_PATH.polyrepo));
5495
5525
  const src = existsSync(path$1.resolve(rootPath, "src"));
5496
5526
  const srcPath = src ? path$1.resolve(rootPath, "src") : rootPath;
5497
5527
  const sectionMap = Object.fromEntries(SECTION_NAMES.map((section) => {
@@ -5499,6 +5529,8 @@ async function getConfig(cwd$2, configPath) {
5499
5529
  const replacedSection = path$9.replace(/(\.\.\/|\.\/)/g, "").replace(/(^\/|\/$)/g, "");
5500
5530
  return [section, replacedSection];
5501
5531
  }));
5532
+ userConfig.lint ??= {};
5533
+ userConfig.lint.filePath ??= path$1.resolve(srcPath, "index.ts");
5502
5534
  function getSectionAbsolutePath(section) {
5503
5535
  return path$1.resolve(srcPath, userConfig[section]?.path ?? DEFAULT_PATH[section]);
5504
5536
  }
@@ -5533,7 +5565,7 @@ async function getConfig(cwd$2, configPath) {
5533
5565
  return {
5534
5566
  ...userConfig,
5535
5567
  src,
5536
- cwd: cwd$2,
5568
+ cwd: cwd$3,
5537
5569
  getSection,
5538
5570
  getSectionAbsolutePath,
5539
5571
  getSectionPath,
@@ -5550,9 +5582,9 @@ async function getConfig(cwd$2, configPath) {
5550
5582
 
5551
5583
  //#endregion
5552
5584
  //#region src/utils/module.ts
5553
- async function getModule(file$1, cwd$2) {
5585
+ async function getModule(file$1, cwd$3) {
5554
5586
  const result = await build({
5555
- absWorkingDir: cwd$2,
5587
+ absWorkingDir: cwd$3,
5556
5588
  bundle: true,
5557
5589
  entryPoints: [file$1],
5558
5590
  format: "cjs",
@@ -5726,11 +5758,11 @@ async function generateSources(dirPath, { section, sources }, config$1, generate
5726
5758
  const targetPath = path$1.resolve(dirPath, fileName);
5727
5759
  if (content) {
5728
5760
  content = transformContent(section, content, config$1, generatedNames);
5729
- await writeFileSafe(targetPath, await format$2(content));
5761
+ await writeFileSafe(targetPath, content, config$1);
5730
5762
  } else if (template && data) await Promise.all(data.map(async ({ name: fileName$1,...rest }) => {
5731
5763
  content = transformTemplateContent(template, rest);
5732
5764
  content = transformContent(section, content, config$1, generatedNames);
5733
- await writeFileSafe(path$1.resolve(targetPath, fileName$1), await format$2(content));
5765
+ await writeFileSafe(path$1.resolve(targetPath, fileName$1), content, config$1);
5734
5766
  }));
5735
5767
  }));
5736
5768
  }
@@ -5777,7 +5809,7 @@ const SECTION_NAMES = [
5777
5809
  "hooks",
5778
5810
  "providers"
5779
5811
  ];
5780
- const DEFAULT_SECTION_CONFIG = {
5812
+ const DEFAULT_CONFIG = {
5781
5813
  components: { overwrite: true },
5782
5814
  hooks: { overwrite: true },
5783
5815
  providers: { overwrite: true }
@@ -5831,15 +5863,19 @@ const TSCONFIG_JSON = {
5831
5863
 
5832
5864
  //#endregion
5833
5865
  //#region src/commands/add/index.ts
5834
- const add = new Command("add").description("Add a component to your project").argument("[components...]", "Components to add").option("--cwd <path>", "Current working directory", process.cwd()).option("-c, --config <path>", "Path to the config file", CONFIG_FILE_NAME).option("-o, --overwrite", "overwrite existing files.", false).option("-a, --all", "Add all available components").option("-i, --install", "Install dependencies", false).action(async function(componentNames, { all = !componentNames.length, config: configPath, cwd: cwd$2, install, overwrite }) {
5866
+ const add = new Command("add").description("Add a component to your project").argument("[components...]", "Components to add").option("--cwd <path>", "Current working directory", cwd).option("-c, --config <path>", "Path to the config file", CONFIG_FILE_NAME).option("-o, --overwrite", "overwrite existing files.", false).option("-i, --install", "Install dependencies", false).option("-f, --format", "Format the output files.", false).option("-l, --lint", "Lint the output files.", false).action(async function(componentNames, { config: configPath, cwd: cwd$3, format: format$3, install, lint: lint$1, overwrite }) {
5835
5867
  const spinner = ora();
5836
5868
  try {
5837
5869
  const { end } = timer();
5870
+ const all = !componentNames.length;
5838
5871
  spinner.start("Validating directory");
5839
- await validateDir(cwd$2);
5872
+ await validateDir(cwd$3);
5840
5873
  spinner.succeed("Validated directory");
5841
5874
  spinner.start("Fetching config");
5842
- const config$1 = await getConfig(cwd$2, configPath);
5875
+ const config$1 = await getConfig(cwd$3, configPath, {
5876
+ format: format$3,
5877
+ lint: lint$1
5878
+ });
5843
5879
  spinner.succeed("Fetched config");
5844
5880
  let generatedNameMap;
5845
5881
  const omittedGeneratedNames = [];
@@ -5911,9 +5947,8 @@ const add = new Command("add").description("Add a component to your project").ar
5911
5947
  if (existsSync(path$1.resolve(config$1.srcPath, "index.ts"))) tasks.add({
5912
5948
  task: async (_, task) => {
5913
5949
  const targetPath = path$1.resolve(config$1.srcPath, "index.ts");
5914
- const data = replaceIndex(targetNames, await readFile(targetPath, "utf-8"), config$1);
5915
- const content = await format$2(data);
5916
- await writeFileSafe(targetPath, content);
5950
+ const content = replaceIndex(targetNames, await readFile(targetPath, "utf-8"), config$1);
5951
+ await writeFileSafe(targetPath, content, config$1);
5917
5952
  task.title = `Updated ${c.cyan("index.ts")}`;
5918
5953
  },
5919
5954
  title: `Updating ${c.cyan("index.ts")}`
@@ -5922,9 +5957,8 @@ const add = new Command("add").description("Add a component to your project").ar
5922
5957
  task: async (_, task) => {
5923
5958
  const { sources } = await fetchRegistry("index");
5924
5959
  const targetPath = path$1.resolve(config$1.srcPath, "index.ts");
5925
- const data = replaceIndex(targetNames, sources[0].content, config$1);
5926
- const content = await format$2(data);
5927
- await writeFileSafe(targetPath, content);
5960
+ const content = replaceIndex(targetNames, sources[0].content, config$1);
5961
+ await writeFileSafe(targetPath, content, config$1);
5928
5962
  task.title = `Generated ${c.cyan("index.ts")}`;
5929
5963
  },
5930
5964
  title: `Generating ${c.cyan("index.ts")}`
@@ -5952,7 +5986,7 @@ const add = new Command("add").description("Add a component to your project").ar
5952
5986
  if (dirent.isDirectory()) return;
5953
5987
  const targetPath = path$1.join(dirent.parentPath, dirent.name);
5954
5988
  const content = transformContent(section, await readFile(targetPath, "utf-8"), config$1, targetNames);
5955
- await writeFileSafe(targetPath, await format$2(content));
5989
+ await writeFileSafe(targetPath, content, config$1);
5956
5990
  }));
5957
5991
  task.title = `Updated ${c.cyan(name$1)}`;
5958
5992
  },
@@ -5962,7 +5996,7 @@ const add = new Command("add").description("Add a component to your project").ar
5962
5996
  });
5963
5997
  }
5964
5998
  if (dependencies$1.length) {
5965
- const targetPath = config$1.monorepo ? config$1.rootPath : cwd$2;
5999
+ const targetPath = config$1.monorepo ? config$1.rootPath : cwd$3;
5966
6000
  spinner.start(`Checking ${c.cyan("package.json")} dependencies`);
5967
6001
  const packageJson$2 = await getPackageJson(targetPath);
5968
6002
  const notInstalledDependencies = getNotInstalledDependencies(packageJson$2, dependencies$1);
@@ -6034,7 +6068,7 @@ async function getDiff(generatedNames, data, registries, config$1) {
6034
6068
  }));
6035
6069
  return changes;
6036
6070
  }
6037
- const diff = new Command("diff").description("Check for updates against the registry").argument("[component]", "Component to check").option("--cwd <path>", "Current working directory", process.cwd()).option("-c, --config <path>", "Path to the config file", CONFIG_FILE_NAME).option("-d, --detail", "Show detailed changes", false).action(async function(componentName, { config: configPath, cwd: cwd$2, detail = false }) {
6071
+ const diff = new Command("diff").description("Check for updates against the registry").argument("[component]", "Component to check").option("--cwd <path>", "Current working directory", cwd).option("-c, --config <path>", "Path to the config file", CONFIG_FILE_NAME).option("-d, --detail", "Show detailed changes", false).action(async function(componentName, { config: configPath, cwd: cwd$3, detail = false }) {
6038
6072
  const spinner = ora();
6039
6073
  try {
6040
6074
  const { end } = timer();
@@ -6044,10 +6078,10 @@ const diff = new Command("diff").description("Check for updates against the regi
6044
6078
  const addCommand = c.cyan(`${prefix} ${package_default.name}@latest add`);
6045
6079
  const diffCommand = c.cyan(`${prefix} ${package_default.name}@latest diff`);
6046
6080
  spinner.start("Validating directory");
6047
- await validateDir(cwd$2);
6081
+ await validateDir(cwd$3);
6048
6082
  spinner.succeed("Validated directory");
6049
6083
  spinner.start("Fetching config");
6050
- const config$1 = await getConfig(cwd$2, configPath);
6084
+ const config$1 = await getConfig(cwd$3, configPath);
6051
6085
  spinner.succeed("Fetched config");
6052
6086
  const componentNames = [];
6053
6087
  spinner.start("Getting generated components");
@@ -6123,17 +6157,17 @@ const diff = new Command("diff").description("Check for updates against the regi
6123
6157
 
6124
6158
  //#endregion
6125
6159
  //#region src/commands/init/index.ts
6126
- const init = new Command("init").description("Initialize your project and install dependencies").option("--cwd <path>", "Current working directory", process.cwd()).option("-c, --config <path>", "Path to the config file", CONFIG_FILE_NAME).option("-o, --overwrite", "Overwrite existing files.", false).action(async function({ config: configPath, cwd: cwd$2, overwrite }) {
6160
+ const init = new Command("init").description("Initialize your project and install dependencies").option("--cwd <path>", "Current working directory", cwd).option("-c, --config <path>", "Path to the config file", CONFIG_FILE_NAME).option("-o, --overwrite", "Overwrite existing files.", false).action(async function({ config: configPath, cwd: cwd$3, overwrite }) {
6127
6161
  const spinner = ora();
6128
6162
  try {
6129
6163
  const { end } = timer();
6130
- await validateDir(cwd$2);
6164
+ await validateDir(cwd$3);
6131
6165
  const configFileName = configPath.includes("/") ? configPath.split("/").at(-1) : configPath;
6132
- const config$1 = { ...DEFAULT_SECTION_CONFIG };
6133
- configPath = path$1.resolve(cwd$2, configPath);
6166
+ const config$1 = { ...DEFAULT_CONFIG };
6167
+ configPath = path$1.resolve(cwd$3, configPath);
6134
6168
  let dependencies$1;
6135
6169
  let devDependencies$1;
6136
- let { src = true, monorepo = true, outdir = "", packageName = "" } = await prompts([
6170
+ let { src = true, format: format$3 = true, lint: lint$1 = true, monorepo = true, outdir = "", packageName = "" } = await prompts([
6137
6171
  {
6138
6172
  type: "toggle",
6139
6173
  name: "monorepo",
@@ -6161,6 +6195,22 @@ const init = new Command("init").description("Initialize your project and instal
6161
6195
  inactive: "No",
6162
6196
  initial: true,
6163
6197
  message: c.reset("Would you like your code inside a `src/` directory?")
6198
+ },
6199
+ {
6200
+ type: "toggle",
6201
+ name: "format",
6202
+ active: "Yes",
6203
+ inactive: "No",
6204
+ initial: true,
6205
+ message: c.reset(`Would you like to use Prettier?`)
6206
+ },
6207
+ {
6208
+ type: "toggle",
6209
+ name: "lint",
6210
+ active: "Yes",
6211
+ inactive: "No",
6212
+ initial: true,
6213
+ message: c.reset(`Would you like to use ESLint?`)
6164
6214
  }
6165
6215
  ]);
6166
6216
  outdir = outdir.replace(/\x17/g, "").trim();
@@ -6169,6 +6219,8 @@ const init = new Command("init").description("Initialize your project and instal
6169
6219
  packageName ||= DEFAULT_PACKAGE_NAME;
6170
6220
  config$1.monorepo = monorepo;
6171
6221
  config$1.path = outdir;
6222
+ config$1.format = { enabled: format$3 };
6223
+ config$1.lint = { enabled: lint$1 };
6172
6224
  const { generate } = await prompts({
6173
6225
  type: "confirm",
6174
6226
  name: "generate",
@@ -6186,9 +6238,9 @@ const init = new Command("init").description("Initialize your project and instal
6186
6238
  if (!overwrite$1) process.exit(0);
6187
6239
  }
6188
6240
  spinner.start(`Generating ${c.cyan(configFileName)}`);
6189
- await writeFileSafe(configPath, await format$2(JSON.stringify(config$1), { parser: "json" }));
6241
+ await writeFileSafe(configPath, JSON.stringify(config$1), merge(config$1, { format: { parser: "json" } }));
6190
6242
  spinner.succeed(`Generated ${c.cyan(configFileName)}`);
6191
- const outdirPath = path$1.resolve(cwd$2, outdir);
6243
+ const outdirPath = path$1.resolve(cwd$3, outdir);
6192
6244
  if (!overwrite && existsSync(outdirPath)) {
6193
6245
  const { overwrite: overwrite$1 } = await prompts({
6194
6246
  type: "confirm",
@@ -6213,12 +6265,11 @@ const init = new Command("init").description("Initialize your project and instal
6213
6265
  {
6214
6266
  task: async (_, task) => {
6215
6267
  const targetPath = path$1.resolve(outdirPath, "package.json");
6216
- const data = JSON.stringify({
6268
+ const content = JSON.stringify({
6217
6269
  name: packageName,
6218
6270
  ...DEFAULT_PACKAGE_JSON
6219
6271
  });
6220
- const content = await format$2(data, { parser: "json" });
6221
- await writeFileSafe(targetPath, content);
6272
+ await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
6222
6273
  task.title = `Generated ${c.cyan("package.json")}`;
6223
6274
  },
6224
6275
  title: `Generating ${c.cyan("package.json")}`
@@ -6226,9 +6277,8 @@ const init = new Command("init").description("Initialize your project and instal
6226
6277
  {
6227
6278
  task: async (_, task) => {
6228
6279
  const targetPath = path$1.resolve(outdirPath, "tsconfig.json");
6229
- const data = JSON.stringify({ ...TSCONFIG_JSON });
6230
- const content = await format$2(data, { parser: "json" });
6231
- await writeFileSafe(targetPath, content);
6280
+ const content = JSON.stringify({ ...TSCONFIG_JSON });
6281
+ await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
6232
6282
  task.title = `Generated ${c.cyan("tsconfig.json")}`;
6233
6283
  },
6234
6284
  title: `Generating ${c.cyan("tsconfig.json")}`
@@ -6237,8 +6287,8 @@ const init = new Command("init").description("Initialize your project and instal
6237
6287
  task: async (_, task) => {
6238
6288
  const targetPath = path$1.resolve(outdirPath, src ? "src" : "", "index.ts");
6239
6289
  const { sources } = await fetchRegistry("index");
6240
- const content = await format$2(sources[0].content);
6241
- await writeFileSafe(targetPath, content);
6290
+ const content = sources[0].content;
6291
+ await writeFileSafe(targetPath, content, config$1);
6242
6292
  task.title = `Generated ${c.cyan("index.ts")}`;
6243
6293
  },
6244
6294
  title: `Generating ${c.cyan("index.ts")}`
@@ -6247,8 +6297,8 @@ const init = new Command("init").description("Initialize your project and instal
6247
6297
  task: async (_, task) => {
6248
6298
  if (outdir.includes("/")) {
6249
6299
  const path$9 = `${outdir.replace(/^\.\//, "").split("/")[0]}/**`;
6250
- await addWorkspace(cwd$2, path$9);
6251
- } else await addWorkspace(cwd$2, outdir);
6300
+ await addWorkspace(cwd$3, path$9, config$1);
6301
+ } else await addWorkspace(cwd$3, outdir, config$1);
6252
6302
  task.title = "Added workspace";
6253
6303
  },
6254
6304
  title: "Adding workspace"
@@ -6267,7 +6317,7 @@ const init = new Command("init").description("Initialize your project and instal
6267
6317
  const notInstalledDevDependencies = [];
6268
6318
  const tasks = new Listr([{
6269
6319
  task: async (_, task) => {
6270
- const packageJson$2 = await getPackageJson(cwd$2);
6320
+ const packageJson$2 = await getPackageJson(cwd$3);
6271
6321
  notInstalledDependencies.push(...getNotInstalledDependencies(packageJson$2, [...REQUIRED_DEPENDENCIES, "@yamada-ui/react@dev"]));
6272
6322
  notInstalledDevDependencies.push(...getNotInstalledDependencies(packageJson$2, REQUIRED_DEV_DEPENDENCIES));
6273
6323
  task.title = `Checked ${c.cyan("package.json")} dependencies`;
@@ -6277,8 +6327,8 @@ const init = new Command("init").description("Initialize your project and instal
6277
6327
  task: async (_, task) => {
6278
6328
  const { sources } = await fetchRegistry("index");
6279
6329
  const targetPath = path$1.resolve(outdirPath, "index.ts");
6280
- const content = await format$2(sources[0].content);
6281
- await writeFileSafe(targetPath, content);
6330
+ const content = sources[0].content;
6331
+ await writeFileSafe(targetPath, content, config$1);
6282
6332
  task.title = `Generated ${c.cyan("index.ts")}`;
6283
6333
  },
6284
6334
  title: `Generating ${c.cyan("index.ts")}`
@@ -6300,9 +6350,9 @@ const init = new Command("init").description("Initialize your project and instal
6300
6350
  }
6301
6351
  if (dependencies$1 || devDependencies$1) {
6302
6352
  spinner.start("Installing dependencies");
6303
- if (dependencies$1) await installDependencies(dependencies$1, { cwd: cwd$2 });
6353
+ if (dependencies$1) await installDependencies(dependencies$1, { cwd: cwd$3 });
6304
6354
  if (devDependencies$1) await installDependencies(devDependencies$1, {
6305
- cwd: cwd$2,
6355
+ cwd: cwd$3,
6306
6356
  dev: true
6307
6357
  });
6308
6358
  if (monorepo) await installDependencies(["@yamada-ui/react@dev"], { cwd: outdirPath });
@@ -6438,7 +6488,7 @@ function extractKeys(obj, key) {
6438
6488
  if (!isObject(property)) return [];
6439
6489
  return Object.keys(property);
6440
6490
  }
6441
- async function generateThemeTokens(theme, { internal = false, theme: { responsive = false } = {} }) {
6491
+ function generateThemeTokens(theme, { internal = false, theme: { responsive = false } = {} }) {
6442
6492
  let shouldProcess = () => true;
6443
6493
  if (responsive && isObject(theme.breakpoints)) {
6444
6494
  const keys = ["base", ...Object.keys(theme.breakpoints)];
@@ -6479,7 +6529,7 @@ async function generateThemeTokens(theme, { internal = false, theme: { responsiv
6479
6529
  ]), { maxDepth: 2 });
6480
6530
  const { colorSchemes } = extractColorSchemes(theme, tokens$1.colors);
6481
6531
  const themeSchemes = extractThemeSchemes(theme);
6482
- if (internal) return await format$2([
6532
+ if (internal) return [
6483
6533
  `import type { UsageThemeTokens } from "./system"`,
6484
6534
  ``,
6485
6535
  `export interface GeneratedThemeTokens extends UsageThemeTokens {`,
@@ -6492,8 +6542,8 @@ async function generateThemeTokens(theme, { internal = false, theme: { responsiv
6492
6542
  themeSchemes
6493
6543
  }),
6494
6544
  `}`
6495
- ].join("\n"));
6496
- else return format$2([
6545
+ ].join("\n");
6546
+ else return [
6497
6547
  `import type { UsageThemeTokens } from "@yamada-ui/react"`,
6498
6548
  ``,
6499
6549
  `declare module '@yamada-ui/react' {`,
@@ -6508,10 +6558,10 @@ async function generateThemeTokens(theme, { internal = false, theme: { responsiv
6508
6558
  })}`,
6509
6559
  ` }`,
6510
6560
  `}`
6511
- ].join("\n"));
6561
+ ].join("\n");
6512
6562
  }
6513
- async function getTheme(path$9, cwd$2) {
6514
- const { dependencies: dependencies$1, mod } = await getModule(path$9, cwd$2);
6563
+ async function getTheme(path$9, cwd$3) {
6564
+ const { dependencies: dependencies$1, mod } = await getModule(path$9, cwd$3);
6515
6565
  const theme = mod?.default ?? mod?.theme ?? mod?.customTheme ?? mod?.defaultTheme ?? {};
6516
6566
  const config$1 = mod?.config ?? mod?.customConfig ?? mod?.defaultConfig ?? {};
6517
6567
  return {
@@ -6520,31 +6570,45 @@ async function getTheme(path$9, cwd$2) {
6520
6570
  theme
6521
6571
  };
6522
6572
  }
6523
- const tokens = new Command("tokens").description("Generate theme typings").argument("<path>", "Path to the theme file").option("--cwd <path>", "Current working directory", process.cwd()).option("-o, --out <path>", `Output path`).option("-l, --lint", "Lint the output file", false).option("--internal", "Generate internal tokens", false).action(async function(inputPath, { cwd: cwd$2, internal, lint, out: outPath }) {
6573
+ const tokens = new Command("tokens").description("Generate theme typings").argument("<path>", "Path to the theme file").option("--cwd <path>", "Current working directory", cwd).option("-c, --config <path>", "Path to the config file", CONFIG_FILE_NAME).option("-o, --out <path>", `Output path`).option("-f, --format", "Format the output file").option("-l, --lint", "Lint the output file").option("--internal", "Generate internal tokens", false).action(async function(inputPath, { config: configPath, cwd: cwd$3, format: format$3, internal, lint: lint$1, out: outPath }) {
6524
6574
  const spinner = ora();
6525
6575
  try {
6526
- const eslint = new ESLint({ fix: true });
6527
6576
  const { end } = timer();
6577
+ spinner.start("Validating directory");
6578
+ await validateDir(cwd$3);
6579
+ spinner.succeed("Validated directory");
6580
+ let config$1;
6581
+ if (!internal) {
6582
+ spinner.start("Fetching config");
6583
+ config$1 = await getConfig(cwd$3, configPath, {
6584
+ format: format$3,
6585
+ lint: lint$1
6586
+ });
6587
+ spinner.succeed("Fetched config");
6588
+ }
6528
6589
  spinner.start(`Getting theme`);
6529
- cwd$2 = path$1.resolve(cwd$2);
6530
- inputPath = path$1.resolve(cwd$2, inputPath);
6531
- if (outPath) outPath = path$1.resolve(cwd$2, outPath);
6590
+ cwd$3 = path$1.resolve(cwd$3);
6591
+ inputPath = path$1.resolve(cwd$3, inputPath);
6592
+ if (outPath) outPath = path$1.resolve(cwd$3, outPath);
6532
6593
  else if (inputPath.includes("/")) {
6533
6594
  const dirPath = inputPath.split("/").slice(0, -1).join("/");
6534
6595
  outPath = path$1.join(dirPath, "index.types.ts");
6535
- } else outPath = path$1.join(cwd$2, "index.types.ts");
6536
- const { config: config$1, theme } = await getTheme(inputPath, cwd$2);
6596
+ } else outPath = path$1.join(cwd$3, "index.types.ts");
6597
+ const { config: themeConfig, theme } = await getTheme(inputPath, cwd$3);
6537
6598
  spinner.succeed(`Got theme`);
6538
6599
  spinner.start(`Generating theme typings`);
6539
- let content = await generateThemeTokens(theme, {
6540
- ...config$1,
6600
+ const content = generateThemeTokens(theme, {
6601
+ ...themeConfig,
6541
6602
  internal
6542
6603
  });
6543
- if (lint) {
6544
- const [result] = await eslint.lintText(content, { filePath: inputPath });
6545
- if (result?.output) content = result.output;
6546
- }
6547
- await writeFile(outPath, content, "utf8");
6604
+ await writeFileSafe(outPath, content, config$1 ? merge(config$1, { lint: { filePath: inputPath } }) : {
6605
+ cwd: cwd$3,
6606
+ format: { enabled: format$3 },
6607
+ lint: {
6608
+ enabled: lint$1,
6609
+ filePath: inputPath
6610
+ }
6611
+ });
6548
6612
  spinner.succeed(`Generated theme typings`);
6549
6613
  end();
6550
6614
  } catch (e) {
@@ -6572,10 +6636,7 @@ async function run() {
6572
6636
  program.addCommand(tokens);
6573
6637
  program.parse();
6574
6638
  }
6575
- if (process.argv.includes("--run")) {
6576
- process.argv = process.argv.filter((arg) => arg !== "--run");
6577
- run();
6578
- }
6639
+ run();
6579
6640
 
6580
6641
  //#endregion
6581
6642
  export { run };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yamada-ui/cli",
3
3
  "type": "module",
4
- "version": "2.0.0-dev-20250817141319",
4
+ "version": "2.0.0-dev-20250821011016",
5
5
  "description": "The official CLI for Yamada UI projects",
6
6
  "keywords": [
7
7
  "theme",
@@ -17,8 +17,7 @@
17
17
  "license": "MIT",
18
18
  "main": "dist/index.js",
19
19
  "files": [
20
- "dist",
21
- "bin"
20
+ "dist"
22
21
  ],
23
22
  "sideEffects": false,
24
23
  "publishConfig": {
@@ -34,7 +33,7 @@
34
33
  "url": "https://github.com/yamada-ui/yamada-ui/issues"
35
34
  },
36
35
  "bin": {
37
- "yamada-cli": "bin/index.js"
36
+ "yamada-cli": "dist/index.js"
38
37
  },
39
38
  "dependencies": {
40
39
  "boxen": "^8.0.1",
@@ -72,7 +71,7 @@
72
71
  },
73
72
  "scripts": {
74
73
  "clean": "rimraf node_modules dist trace coverage .turbo .eslintcache",
75
- "start": "tsx src/index.ts --run",
74
+ "dev": "tsx src/index.ts",
76
75
  "build": "tsdown",
77
76
  "typecheck": " tsc --noEmit",
78
77
  "typetrace": "tsc --noEmit --generateTrace ./trace --incremental false",
package/bin/index.js DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- import { run } from "../dist/index.js"
3
-
4
- run().catch((e) => {
5
- console.error(e)
6
- process.exit(1)
7
- })