@yamada-ui/cli 2.0.0-dev-20250816072830 → 2.0.0-dev-20250820102029

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 +375 -161
  2. package/package.json +6 -5
  3. package/bin/index.js +0 -7
package/dist/index.js CHANGED
@@ -18,22 +18,24 @@ 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";
25
25
  import prompts from "prompts";
26
- import { execSync } from "child_process";
26
+ import { execa } from "execa";
27
27
  import "validate-npm-package-name";
28
28
  import YAML from "yamljs";
29
+ import { glob } from "glob";
30
+ import { ESLint } from "eslint";
29
31
  import { format as format$1, resolveConfig, resolveConfigFile } from "prettier";
30
32
  import { build } from "esbuild";
31
33
  import nodeEval from "node-eval";
32
34
  import { Script } from "vm";
33
35
  import { HttpsProxyAgent } from "https-proxy-agent";
34
36
  import fetch from "node-fetch";
37
+ import { diffLines } from "diff";
35
38
  import { rimraf } from "rimraf";
36
- import { ESLint } from "eslint";
37
39
 
38
40
  //#region rolldown:runtime
39
41
  var __create = Object.create;
@@ -69,11 +71,11 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
69
71
  var require_polyfills$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js": ((exports, module) => {
70
72
  var constants$1 = __require("constants");
71
73
  var origCwd$1 = process.cwd;
72
- var cwd$1 = null;
74
+ var cwd$2 = null;
73
75
  var platform$1 = process.env.GRACEFUL_FS_PLATFORM || process.platform;
74
76
  process.cwd = function() {
75
- if (!cwd$1) cwd$1 = origCwd$1.call(process);
76
- return cwd$1;
77
+ if (!cwd$2) cwd$2 = origCwd$1.call(process);
78
+ return cwd$2;
77
79
  };
78
80
  try {
79
81
  process.cwd();
@@ -81,7 +83,7 @@ var require_polyfills$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm
81
83
  if (typeof process.chdir === "function") {
82
84
  var chdir$1 = process.chdir;
83
85
  process.chdir = function(d) {
84
- cwd$1 = null;
86
+ cwd$2 = null;
85
87
  chdir$1.call(process, d);
86
88
  };
87
89
  if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir$1);
@@ -518,8 +520,8 @@ var require_graceful_fs$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pn
518
520
  }
519
521
  }
520
522
  var fs$writeFile = fs$9.writeFile;
521
- fs$9.writeFile = writeFile$1;
522
- function writeFile$1(path$9, data, options, cb) {
523
+ fs$9.writeFile = writeFile$2;
524
+ function writeFile$2(path$9, data, options, cb) {
523
525
  if (typeof options === "function") cb = options, options = null;
524
526
  return go$writeFile(path$9, data, options, cb);
525
527
  function go$writeFile(path$10, data$1, options$1, cb$1, startTime) {
@@ -2883,11 +2885,11 @@ function registryUrl(scope) {
2883
2885
  var require_polyfills = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/graceful-fs@4.2.10/node_modules/graceful-fs/polyfills.js": ((exports, module) => {
2884
2886
  var constants = __require("constants");
2885
2887
  var origCwd = process.cwd;
2886
- var cwd = null;
2888
+ var cwd$1 = null;
2887
2889
  var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
2888
2890
  process.cwd = function() {
2889
- if (!cwd) cwd = origCwd.call(process);
2890
- return cwd;
2891
+ if (!cwd$1) cwd$1 = origCwd.call(process);
2892
+ return cwd$1;
2891
2893
  };
2892
2894
  try {
2893
2895
  process.cwd();
@@ -2895,7 +2897,7 @@ var require_polyfills = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/g
2895
2897
  if (typeof process.chdir === "function") {
2896
2898
  var chdir = process.chdir;
2897
2899
  process.chdir = function(d) {
2898
- cwd = null;
2900
+ cwd$1 = null;
2899
2901
  chdir.call(process, d);
2900
2902
  };
2901
2903
  if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
@@ -3332,8 +3334,8 @@ var require_graceful_fs = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm
3332
3334
  }
3333
3335
  }
3334
3336
  var fs$writeFile = fs$9.writeFile;
3335
- fs$9.writeFile = writeFile$1;
3336
- function writeFile$1(path$9, data, options, cb) {
3337
+ fs$9.writeFile = writeFile$2;
3338
+ function writeFile$2(path$9, data, options, cb) {
3337
3339
  if (typeof options === "function") cb = options, options = null;
3338
3340
  return go$writeFile(path$9, data, options, cb);
3339
3341
  function go$writeFile(path$10, data$1, options$1, cb$1, startTime) {
@@ -5203,7 +5205,7 @@ var keywords = [
5203
5205
  var author = "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>";
5204
5206
  var license = "MIT";
5205
5207
  var main = "dist/index.js";
5206
- var files = ["dist", "bin"];
5208
+ var files = ["dist"];
5207
5209
  var sideEffects = false;
5208
5210
  var publishConfig = { "access": "public" };
5209
5211
  var homepage = "https://yamada-ui.com";
@@ -5213,10 +5215,10 @@ var repository = {
5213
5215
  "directory": "packages/cli"
5214
5216
  };
5215
5217
  var bugs = { "url": "https://github.com/yamada-ui/yamada-ui/issues" };
5216
- var bin = { "yamada-cli": "bin/index.js" };
5218
+ var bin = { "yamada-cli": "dist/index.js" };
5217
5219
  var scripts = {
5218
5220
  "clean": "rimraf node_modules dist trace coverage .turbo .eslintcache",
5219
- "start": "tsx src/index.ts --run",
5221
+ "dev": "tsx src/index.ts",
5220
5222
  "build": "tsdown",
5221
5223
  "typecheck": " tsc --noEmit",
5222
5224
  "typetrace": "tsc --noEmit --generateTrace ./trace --incremental false",
@@ -5230,8 +5232,10 @@ var dependencies = {
5230
5232
  "cli-check-node": "^1.3.4",
5231
5233
  "cli-handle-unhandled": "^1.1.2",
5232
5234
  "commander": "^14.0.0",
5235
+ "diff": "^8.0.2",
5233
5236
  "esbuild": "^0.25.8",
5234
5237
  "eslint": "^9.32.0",
5238
+ "execa": "9.3.1",
5235
5239
  "glob": "^11.0.3",
5236
5240
  "https-proxy-agent": "^7.0.6",
5237
5241
  "listr2": "^9.0.1",
@@ -5277,8 +5281,43 @@ var package_default = {
5277
5281
  devDependencies
5278
5282
  };
5279
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
+
5280
5318
  //#endregion
5281
5319
  //#region src/utils/fs.ts
5320
+ const cwd = process.env.INIT_CWD ?? process.cwd();
5282
5321
  async function isWriteable(directory) {
5283
5322
  try {
5284
5323
  await fs.promises.access(directory, ("constants" in fs ? fs.constants : fs).W_OK);
@@ -5287,12 +5326,20 @@ async function isWriteable(directory) {
5287
5326
  return false;
5288
5327
  }
5289
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
+ }
5290
5337
  async function writeFileSafe(path$9, content, options) {
5291
5338
  if (path$9.includes("/")) {
5292
5339
  const dirPath = path$9.split("/").slice(0, -1).join("/");
5293
5340
  if (!existsSync(dirPath)) await mkdir(dirPath, { recursive: true });
5294
5341
  }
5295
- await writeFile(path$9, content, options);
5342
+ await writeFile$1(path$9, content, options);
5296
5343
  }
5297
5344
  async function validateDir(path$9) {
5298
5345
  const writeable = await isWriteable(path$9);
@@ -5306,28 +5353,36 @@ function timer() {
5306
5353
  const end = () => {
5307
5354
  const end$1 = process.hrtime.bigint();
5308
5355
  const duration = (Number(end$1 - start) / 1e9).toFixed(2);
5309
- console.log("\n", c.green(`Done in ${duration}s`));
5356
+ console.log("");
5357
+ console.log(c.green(`Done in ${duration}s`));
5310
5358
  };
5311
5359
  return {
5312
5360
  end,
5313
5361
  start
5314
5362
  };
5315
5363
  }
5316
-
5317
- //#endregion
5318
- //#region src/utils/prettier.ts
5319
- async function format$2(content, options) {
5320
- const path$9 = await resolveConfigFile();
5321
- const config$1 = path$9 ? await resolveConfig(path$9) : {};
5322
- try {
5323
- return format$1(content, {
5324
- ...config$1,
5325
- parser: "typescript",
5326
- ...options
5327
- });
5328
- } catch {
5329
- return content;
5330
- }
5364
+ async function getComponentFiles(componentName, { srcPath }) {
5365
+ const files$1 = {};
5366
+ const [dirPath] = await glob(path$1.join(srcPath, "**", componentName));
5367
+ if (!dirPath) return files$1;
5368
+ const dirents = await readdir(dirPath, { withFileTypes: true });
5369
+ await Promise.all(dirents.map(async (dirent) => {
5370
+ const name$1 = dirent.name;
5371
+ if (dirent.isDirectory()) {
5372
+ const data = await readdir(path$1.join(dirent.parentPath, name$1), { withFileTypes: true });
5373
+ await Promise.all(data.map(async (dirent$1) => {
5374
+ if (dirent$1.isDirectory()) return;
5375
+ const targetPath = path$1.join(dirent$1.parentPath, dirent$1.name);
5376
+ const data$1 = await readFile(targetPath, "utf-8");
5377
+ files$1[`${name$1}/${dirent$1.name}`] = data$1;
5378
+ }));
5379
+ } else {
5380
+ const targetPath = path$1.join(dirent.parentPath, dirent.name);
5381
+ const data = await readFile(targetPath, "utf-8");
5382
+ files$1[name$1] = data;
5383
+ }
5384
+ }));
5385
+ return files$1;
5331
5386
  }
5332
5387
 
5333
5388
  //#endregion
@@ -5339,9 +5394,9 @@ function getPackageManager() {
5339
5394
  if (userAgent$1.startsWith("bun")) return "bun";
5340
5395
  return "npm";
5341
5396
  }
5342
- async function getPackageJson(cwd$2) {
5397
+ async function getPackageJson(cwd$3) {
5343
5398
  try {
5344
- 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");
5345
5400
  return JSON.parse(packageJson$2);
5346
5401
  } catch {
5347
5402
  throw new Error(`No package.json found. Please run ${c.cyan(`${getPackageManager()} init`)}.`);
@@ -5380,65 +5435,78 @@ function splitVersion(value) {
5380
5435
  function getPackageName(value) {
5381
5436
  return isObject(value) ? `${value.name}@${value.wanted}` : value;
5382
5437
  }
5383
- function packageAddCommand(packageManager, { dev = false, exact = false } = {}) {
5384
- const command = [packageManager];
5385
- if (packageManager === "npm") command.push("install");
5386
- else command.push("add");
5387
- if (dev) if (packageManager === "npm") command.push("--save-dev");
5388
- else command.push("--dev");
5389
- if (exact) command.push("--save-exact");
5390
- return command.join(" ");
5438
+ function packageAddArgs(packageManager, { dev = false, exact = false } = {}) {
5439
+ const args = [];
5440
+ if (packageManager === "npm") args.push("install");
5441
+ else args.push("add");
5442
+ if (dev) if (packageManager === "npm") args.push("--save-dev");
5443
+ else args.push("--dev");
5444
+ if (exact) args.push("--save-exact");
5445
+ return args;
5391
5446
  }
5392
- function packageExecuteCommand(packageManager) {
5447
+ function packageExecuteCommands(packageManager) {
5393
5448
  switch (packageManager) {
5394
- case "npm": return "npx";
5395
- case "pnpm": return "pnpm dlx";
5396
- case "yarn": return "yarn dlx";
5397
- case "bun": return "bunx --bun";
5449
+ case "npm": return {
5450
+ args: [],
5451
+ command: "npx"
5452
+ };
5453
+ case "pnpm": return {
5454
+ args: ["dlx"],
5455
+ command: "pnpm"
5456
+ };
5457
+ case "yarn": return {
5458
+ args: ["dlx"],
5459
+ command: "yarn"
5460
+ };
5461
+ case "bun": return {
5462
+ args: ["--bun"],
5463
+ command: "bunx"
5464
+ };
5398
5465
  }
5399
5466
  }
5400
- function installDependencies(dependencies$1, { cwd: cwd$2, dev, exact = true } = {}) {
5467
+ async function installDependencies(dependencies$1, { cwd: cwd$3, dev, exact = true } = {}) {
5401
5468
  const packageManager = getPackageManager();
5402
5469
  if (dependencies$1?.length) {
5403
- const command = packageAddCommand(packageManager, {
5470
+ const args = packageAddArgs(packageManager, {
5404
5471
  dev,
5405
5472
  exact
5406
5473
  });
5407
- execSync(`${command} ${dependencies$1.join(" ")}`, {
5408
- cwd: cwd$2,
5409
- stdio: "ignore"
5474
+ await execa(packageManager, [...args, ...dependencies$1], {
5475
+ cwd: cwd$3,
5476
+ stdout: "ignore"
5410
5477
  });
5411
- } else execSync(`${packageManager} install`, {
5412
- cwd: cwd$2,
5413
- stdio: "ignore"
5478
+ } else await execa(packageManager, ["install"], {
5479
+ cwd: cwd$3,
5480
+ stdout: "ignore"
5414
5481
  });
5415
5482
  }
5416
- async function addWorkspace(cwd$2, workspacePath) {
5483
+ async function addWorkspace(cwd$3, workspacePath, config$1) {
5417
5484
  const packageManager = getPackageManager();
5418
5485
  switch (packageManager) {
5419
- case "pnpm":
5420
- if (existsSync(path$1.resolve(cwd$2, "pnpm-workspace.yaml"))) {
5421
- 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");
5422
5490
  const json$1 = YAML.parse(content);
5423
5491
  json$1.packages ??= [];
5424
5492
  if (!json$1.packages.includes(workspacePath)) {
5425
5493
  json$1.packages.push(workspacePath);
5426
- const content$1 = await format$2(YAML.stringify(json$1), { parser: "yaml" });
5427
- 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" } }));
5428
5495
  }
5429
5496
  } else {
5430
- const data = YAML.stringify({ packages: [workspacePath] });
5431
- const content = await format$2(data, { parser: "yaml" });
5432
- 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" } }));
5433
5499
  }
5434
5500
  break;
5501
+ }
5435
5502
  default: {
5436
- const packageJson$2 = await getPackageJson(cwd$2);
5503
+ const packageJson$2 = await getPackageJson(cwd$3);
5437
5504
  packageJson$2.workspaces ??= [];
5438
5505
  if (!packageJson$2.workspaces.includes(workspacePath)) {
5439
5506
  packageJson$2.workspaces.push(workspacePath);
5440
- const content = await format$2(JSON.stringify(packageJson$2), { parser: "json" });
5441
- 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" } }));
5442
5510
  }
5443
5511
  break;
5444
5512
  }
@@ -5447,11 +5515,13 @@ async function addWorkspace(cwd$2, workspacePath) {
5447
5515
 
5448
5516
  //#endregion
5449
5517
  //#region src/utils/config.ts
5450
- async function getConfig(cwd$2, configPath) {
5518
+ async function getConfig(cwd$3, configPath, { format: format$3, lint: lint$1 } = {}) {
5451
5519
  try {
5452
- const data = await readFile(path$1.resolve(cwd$2, configPath), "utf8");
5520
+ const data = await readFile(path$1.resolve(cwd$3, configPath), "utf8");
5453
5521
  const userConfig = JSON.parse(data);
5454
- 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));
5455
5525
  const src = existsSync(path$1.resolve(rootPath, "src"));
5456
5526
  const srcPath = src ? path$1.resolve(rootPath, "src") : rootPath;
5457
5527
  const sectionMap = Object.fromEntries(SECTION_NAMES.map((section) => {
@@ -5459,6 +5529,8 @@ async function getConfig(cwd$2, configPath) {
5459
5529
  const replacedSection = path$9.replace(/(\.\.\/|\.\/)/g, "").replace(/(^\/|\/$)/g, "");
5460
5530
  return [section, replacedSection];
5461
5531
  }));
5532
+ userConfig.lint ??= {};
5533
+ userConfig.lint.filePath ??= path$1.resolve(srcPath, "index.ts");
5462
5534
  function getSectionAbsolutePath(section) {
5463
5535
  return path$1.resolve(srcPath, userConfig[section]?.path ?? DEFAULT_PATH[section]);
5464
5536
  }
@@ -5493,7 +5565,7 @@ async function getConfig(cwd$2, configPath) {
5493
5565
  return {
5494
5566
  ...userConfig,
5495
5567
  src,
5496
- cwd: cwd$2,
5568
+ cwd: cwd$3,
5497
5569
  getSection,
5498
5570
  getSectionAbsolutePath,
5499
5571
  getSectionPath,
@@ -5502,16 +5574,17 @@ async function getConfig(cwd$2, configPath) {
5502
5574
  };
5503
5575
  } catch {
5504
5576
  const packageManager = getPackageManager();
5505
- const command = packageExecuteCommand(packageManager);
5506
- throw new Error(`No config found. Please run ${c.cyan(`${command} ${package_default.name}@latest init`)}.`);
5577
+ const { args, command } = packageExecuteCommands(packageManager);
5578
+ const prefix = `${command}${args.length ? ` ${args.join(" ")}` : ""}`;
5579
+ throw new Error(`No config found. Please run ${c.cyan(`${prefix} ${package_default.name}@latest init`)}.`);
5507
5580
  }
5508
5581
  }
5509
5582
 
5510
5583
  //#endregion
5511
5584
  //#region src/utils/module.ts
5512
- async function getModule(file$1, cwd$2) {
5585
+ async function getModule(file$1, cwd$3) {
5513
5586
  const result = await build({
5514
- absWorkingDir: cwd$2,
5587
+ absWorkingDir: cwd$3,
5515
5588
  bundle: true,
5516
5589
  entryPoints: [file$1],
5517
5590
  format: "cjs",
@@ -5630,7 +5703,7 @@ async function getGeneratedNameMap(config$1) {
5630
5703
  }));
5631
5704
  return Object.fromEntries(results);
5632
5705
  }
5633
- function transformTemplate(targetSection, content, { getSection }, generatedNames) {
5706
+ function transformContent(targetSection, content, { getSection }, generatedNames) {
5634
5707
  const matches = content.matchAll(/from\s+["']([^"']+)["']/g);
5635
5708
  matches.forEach((match) => {
5636
5709
  const [searchValue, value] = match;
@@ -5684,12 +5757,12 @@ async function generateSources(dirPath, { section, sources }, config$1, generate
5684
5757
  await Promise.all(sources.map(async ({ name: fileName, content, data, template }) => {
5685
5758
  const targetPath = path$1.resolve(dirPath, fileName);
5686
5759
  if (content) {
5687
- content = transformTemplate(section, content, config$1, generatedNames);
5688
- await writeFileSafe(targetPath, await format$2(content));
5760
+ content = transformContent(section, content, config$1, generatedNames);
5761
+ await writeFileSafe(targetPath, content, config$1);
5689
5762
  } else if (template && data) await Promise.all(data.map(async ({ name: fileName$1,...rest }) => {
5690
5763
  content = transformTemplateContent(template, rest);
5691
- content = transformTemplate(section, content, config$1, generatedNames);
5692
- await writeFileSafe(path$1.resolve(targetPath, fileName$1), await format$2(content));
5764
+ content = transformContent(section, content, config$1, generatedNames);
5765
+ await writeFileSafe(path$1.resolve(targetPath, fileName$1), content, config$1);
5693
5766
  }));
5694
5767
  }));
5695
5768
  }
@@ -5736,7 +5809,7 @@ const SECTION_NAMES = [
5736
5809
  "hooks",
5737
5810
  "providers"
5738
5811
  ];
5739
- const DEFAULT_SECTION_CONFIG = {
5812
+ const DEFAULT_CONFIG = {
5740
5813
  components: { overwrite: true },
5741
5814
  hooks: { overwrite: true },
5742
5815
  providers: { overwrite: true }
@@ -5790,15 +5863,19 @@ const TSCONFIG_JSON = {
5790
5863
 
5791
5864
  //#endregion
5792
5865
  //#region src/commands/add/index.ts
5793
- 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 }) {
5794
5867
  const spinner = ora();
5795
5868
  try {
5796
5869
  const { end } = timer();
5870
+ const all = !componentNames.length;
5797
5871
  spinner.start("Validating directory");
5798
- await validateDir(cwd$2);
5872
+ await validateDir(cwd$3);
5799
5873
  spinner.succeed("Validated directory");
5800
5874
  spinner.start("Fetching config");
5801
- 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
+ });
5802
5879
  spinner.succeed("Fetched config");
5803
5880
  let generatedNameMap;
5804
5881
  const omittedGeneratedNames = [];
@@ -5823,18 +5900,18 @@ const add = new Command("add").description("Add a component to your project").ar
5823
5900
  componentNames = await fetchRegistryNames();
5824
5901
  spinner.succeed("Fetched all available components");
5825
5902
  } else {
5826
- spinner.start("Getting generated data");
5903
+ spinner.start("Getting generated components");
5827
5904
  generatedNameMap = await getGeneratedNameMap(config$1);
5828
5905
  const generatedNames = Object.values(generatedNameMap).flat();
5829
5906
  const existsNames = componentNames.filter((name$1) => generatedNames.includes(name$1));
5830
- spinner.succeed("Got generated data");
5907
+ spinner.succeed("Got generated components");
5831
5908
  if (!overwrite && existsNames.length) {
5832
5909
  const colorizedNames = existsNames.map((name$1) => c.yellow(name$1));
5833
5910
  const { overwrite: overwrite$1 } = await prompts({
5834
5911
  type: "confirm",
5835
5912
  name: "overwrite",
5836
5913
  initial: false,
5837
- message: c.reset(`The ${colorizedNames.join(", ")} components already exist. Do you want to overwrite them?`)
5914
+ message: c.reset([`The ${colorizedNames.join(", ")} components already exist.`, "Do you want to overwrite them?"].join(" "))
5838
5915
  });
5839
5916
  if (!overwrite$1) process.exit(0);
5840
5917
  }
@@ -5870,9 +5947,8 @@ const add = new Command("add").description("Add a component to your project").ar
5870
5947
  if (existsSync(path$1.resolve(config$1.srcPath, "index.ts"))) tasks.add({
5871
5948
  task: async (_, task) => {
5872
5949
  const targetPath = path$1.resolve(config$1.srcPath, "index.ts");
5873
- const data = replaceIndex(targetNames, await readFile(targetPath, "utf-8"), config$1);
5874
- const content = await format$2(data);
5875
- await writeFileSafe(targetPath, content);
5950
+ const content = replaceIndex(targetNames, await readFile(targetPath, "utf-8"), config$1);
5951
+ await writeFileSafe(targetPath, content, config$1);
5876
5952
  task.title = `Updated ${c.cyan("index.ts")}`;
5877
5953
  },
5878
5954
  title: `Updating ${c.cyan("index.ts")}`
@@ -5881,9 +5957,8 @@ const add = new Command("add").description("Add a component to your project").ar
5881
5957
  task: async (_, task) => {
5882
5958
  const { sources } = await fetchRegistry("index");
5883
5959
  const targetPath = path$1.resolve(config$1.srcPath, "index.ts");
5884
- const data = replaceIndex(targetNames, sources[0].content, config$1);
5885
- const content = await format$2(data);
5886
- await writeFileSafe(targetPath, content);
5960
+ const content = replaceIndex(targetNames, sources[0].content, config$1);
5961
+ await writeFileSafe(targetPath, content, config$1);
5887
5962
  task.title = `Generated ${c.cyan("index.ts")}`;
5888
5963
  },
5889
5964
  title: `Generating ${c.cyan("index.ts")}`
@@ -5895,7 +5970,7 @@ const add = new Command("add").description("Add a component to your project").ar
5895
5970
  type: "confirm",
5896
5971
  name: "update",
5897
5972
  initial: true,
5898
- message: c.reset(`The following generated files will be updated: ${colorizedNames.join(", ")}. Do you want to update them?`)
5973
+ message: c.reset([`The following generated files will be updated: ${colorizedNames.join(", ")}.`, "Do you want to update them?"].join(" "))
5899
5974
  });
5900
5975
  if (update) overwrite = update;
5901
5976
  }
@@ -5910,8 +5985,8 @@ const add = new Command("add").description("Add a component to your project").ar
5910
5985
  await Promise.all(dirents.map(async (dirent) => {
5911
5986
  if (dirent.isDirectory()) return;
5912
5987
  const targetPath = path$1.join(dirent.parentPath, dirent.name);
5913
- const content = transformTemplate(section, await readFile(targetPath, "utf-8"), config$1, targetNames);
5914
- await writeFileSafe(targetPath, await format$2(content));
5988
+ const content = transformContent(section, await readFile(targetPath, "utf-8"), config$1, targetNames);
5989
+ await writeFileSafe(targetPath, content, config$1);
5915
5990
  }));
5916
5991
  task.title = `Updated ${c.cyan(name$1)}`;
5917
5992
  },
@@ -5921,7 +5996,7 @@ const add = new Command("add").description("Add a component to your project").ar
5921
5996
  });
5922
5997
  }
5923
5998
  if (dependencies$1.length) {
5924
- const targetPath = config$1.monorepo ? config$1.rootPath : cwd$2;
5999
+ const targetPath = config$1.monorepo ? config$1.rootPath : cwd$3;
5925
6000
  spinner.start(`Checking ${c.cyan("package.json")} dependencies`);
5926
6001
  const packageJson$2 = await getPackageJson(targetPath);
5927
6002
  const notInstalledDependencies = getNotInstalledDependencies(packageJson$2, dependencies$1);
@@ -5932,13 +6007,13 @@ const add = new Command("add").description("Add a component to your project").ar
5932
6007
  type: "confirm",
5933
6008
  name: "proceed",
5934
6009
  initial: true,
5935
- message: c.reset(`The following dependencies are not installed: ${colorizedNames.join(", ")}. Do you want to install them?`)
6010
+ message: c.reset([`The following dependencies are not installed: ${colorizedNames.join(", ")}.`, "Do you want to install them?"].join(" "))
5936
6011
  });
5937
6012
  install = proceed;
5938
6013
  }
5939
6014
  if (install) tasks.add({
5940
- task: (_, task) => {
5941
- installDependencies(notInstalledDependencies.map(getPackageName), { cwd: targetPath });
6015
+ task: async (_, task) => {
6016
+ await installDependencies(notInstalledDependencies.map(getPackageName), { cwd: targetPath });
5942
6017
  task.title = "Installed dependencies";
5943
6018
  },
5944
6019
  title: "Installing dependencies"
@@ -5954,17 +6029,125 @@ const add = new Command("add").description("Add a component to your project").ar
5954
6029
 
5955
6030
  //#endregion
5956
6031
  //#region src/commands/diff/index.ts
5957
- 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).action(async function(componentName, { config: configPath, cwd: cwd$2 }) {
6032
+ async function getData(componentNames, config$1) {
6033
+ const data = {};
6034
+ const registries = {};
6035
+ const tasks = new Listr([...componentNames.map((componentName) => ({
6036
+ task: async (_, task) => {
6037
+ data[componentName] = await getComponentFiles(componentName, config$1);
6038
+ task.title = `Got ${c.cyan(componentName)} files`;
6039
+ },
6040
+ title: `Getting ${c.cyan(componentName)} files`
6041
+ })), ...componentNames.map((componentName) => ({
6042
+ task: async (_, task) => {
6043
+ registries[componentName] = await fetchRegistry(componentName);
6044
+ task.title = `Fetched ${c.cyan(componentName)} registry`;
6045
+ },
6046
+ title: `Fetching ${c.cyan(componentName)} registry`
6047
+ }))], { concurrent: true });
6048
+ await tasks.run();
6049
+ return {
6050
+ data,
6051
+ registries
6052
+ };
6053
+ }
6054
+ async function getDiff(generatedNames, data, registries, config$1) {
6055
+ const changes = {};
6056
+ await Promise.all(Object.entries(data).map(async ([name$1, files$1]) => {
6057
+ const registry = registries[name$1];
6058
+ if (!registry) return;
6059
+ await Promise.all(Object.entries(files$1).map(async ([fileName, file$1]) => {
6060
+ const registryFile = registry.sources.find(({ name: name$2 }) => name$2 === fileName);
6061
+ if (!registryFile?.content) return;
6062
+ const content = await format$2(transformContent(registry.section, registryFile.content, config$1, generatedNames));
6063
+ const diff$1 = diffLines(file$1, content);
6064
+ if (diff$1.length < 2) return;
6065
+ changes[name$1] ??= {};
6066
+ changes[name$1][fileName] = diff$1;
6067
+ }));
6068
+ }));
6069
+ return changes;
6070
+ }
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 }) {
5958
6072
  const spinner = ora();
5959
6073
  try {
5960
6074
  const { end } = timer();
6075
+ const packageManager = getPackageManager();
6076
+ const { args, command } = packageExecuteCommands(packageManager);
6077
+ const prefix = `${command}${args.length ? ` ${args.join(" ")}` : ""}`;
6078
+ const addCommand = c.cyan(`${prefix} ${package_default.name}@latest add`);
6079
+ const diffCommand = c.cyan(`${prefix} ${package_default.name}@latest diff`);
5961
6080
  spinner.start("Validating directory");
5962
- await validateDir(cwd$2);
6081
+ await validateDir(cwd$3);
5963
6082
  spinner.succeed("Validated directory");
5964
6083
  spinner.start("Fetching config");
5965
- const config$1 = await getConfig(cwd$2, configPath);
5966
- console.log(config$1);
6084
+ const config$1 = await getConfig(cwd$3, configPath);
5967
6085
  spinner.succeed("Fetched config");
6086
+ const componentNames = [];
6087
+ spinner.start("Getting generated components");
6088
+ const generatedNameMap = await getGeneratedNameMap(config$1);
6089
+ const generatedNames = Object.values(generatedNameMap).flat();
6090
+ spinner.succeed("Got generated components");
6091
+ if (componentName) if (generatedNames.includes(componentName)) componentNames.push(componentName);
6092
+ else throw new Error([
6093
+ `No ${c.yellow(componentName)} found in generated components.`,
6094
+ `Please run ${addCommand} ${c.green(componentName)}`,
6095
+ "to add it."
6096
+ ].join(" "));
6097
+ else componentNames.push(...generatedNames);
6098
+ if (!componentNames.length) throw new Error([
6099
+ "No components found.",
6100
+ `Please run ${addCommand} ${c.green("<component>")}`,
6101
+ "to add components."
6102
+ ].join(" "));
6103
+ const { data, registries } = await getData(componentNames, config$1);
6104
+ const changes = await getDiff(generatedNames, data, registries, config$1);
6105
+ const hasChanges = Object.keys(changes).length;
6106
+ console.log("---------------------------------");
6107
+ if (!hasChanges) console.log(c.cyan("No updates found."));
6108
+ else if (componentName) {
6109
+ const diff$1 = changes[componentName];
6110
+ if (!diff$1) return;
6111
+ Object.entries(diff$1).forEach(([fileName, diff$2], index) => {
6112
+ if (!!index) console.log("");
6113
+ console.log(`- ${c.cyan(fileName)}`);
6114
+ console.log("");
6115
+ diff$2.forEach(({ added, removed, value }) => {
6116
+ if (added) return process.stdout.write(c.green(value));
6117
+ else if (removed) return process.stdout.write(c.red(value));
6118
+ else if (detail) return process.stdout.write(value);
6119
+ });
6120
+ });
6121
+ } else {
6122
+ componentNames.forEach((name$1) => {
6123
+ const diff$1 = changes[name$1];
6124
+ if (!diff$1) return;
6125
+ console.log(`- ${name$1}`);
6126
+ Object.entries(diff$1).forEach(([fileName, diff$2]) => {
6127
+ const added = diff$2.reduce((prev, { added: added$1, count }) => {
6128
+ if (added$1) return prev + count;
6129
+ return prev;
6130
+ }, 0);
6131
+ const removed = diff$2.reduce((prev, { count, removed: removed$1 }) => {
6132
+ if (removed$1) return prev + count;
6133
+ return prev;
6134
+ }, 0);
6135
+ console.log(` - ${c.cyan(fileName)} ${c.green(added)} insertions ${c.red(removed)} deletions`);
6136
+ });
6137
+ });
6138
+ console.log("");
6139
+ console.log(boxen([
6140
+ "Run",
6141
+ c.cyan(diffCommand),
6142
+ c.green("<component>"),
6143
+ "to see the changes."
6144
+ ].join(" "), {
6145
+ borderColor: "yellow",
6146
+ borderStyle: "round",
6147
+ padding: 1,
6148
+ textAlignment: "center"
6149
+ }));
6150
+ }
5968
6151
  end();
5969
6152
  } catch (e) {
5970
6153
  if (e instanceof Error) spinner.fail(e.message);
@@ -5974,17 +6157,17 @@ const diff = new Command("diff").description("Check for updates against the regi
5974
6157
 
5975
6158
  //#endregion
5976
6159
  //#region src/commands/init/index.ts
5977
- 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 }) {
5978
6161
  const spinner = ora();
5979
6162
  try {
5980
6163
  const { end } = timer();
5981
- await validateDir(cwd$2);
6164
+ await validateDir(cwd$3);
5982
6165
  const configFileName = configPath.includes("/") ? configPath.split("/").at(-1) : configPath;
5983
- const config$1 = { ...DEFAULT_SECTION_CONFIG };
5984
- configPath = path$1.resolve(cwd$2, configPath);
6166
+ const config$1 = { ...DEFAULT_CONFIG };
6167
+ configPath = path$1.resolve(cwd$3, configPath);
5985
6168
  let dependencies$1;
5986
6169
  let devDependencies$1;
5987
- 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([
5988
6171
  {
5989
6172
  type: "toggle",
5990
6173
  name: "monorepo",
@@ -6012,6 +6195,22 @@ const init = new Command("init").description("Initialize your project and instal
6012
6195
  inactive: "No",
6013
6196
  initial: true,
6014
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?`)
6015
6214
  }
6016
6215
  ]);
6017
6216
  outdir = outdir.replace(/\x17/g, "").trim();
@@ -6020,6 +6219,8 @@ const init = new Command("init").description("Initialize your project and instal
6020
6219
  packageName ||= DEFAULT_PACKAGE_NAME;
6021
6220
  config$1.monorepo = monorepo;
6022
6221
  config$1.path = outdir;
6222
+ config$1.format = { enabled: format$3 };
6223
+ config$1.lint = { enabled: lint$1 };
6023
6224
  const { generate } = await prompts({
6024
6225
  type: "confirm",
6025
6226
  name: "generate",
@@ -6037,15 +6238,15 @@ const init = new Command("init").description("Initialize your project and instal
6037
6238
  if (!overwrite$1) process.exit(0);
6038
6239
  }
6039
6240
  spinner.start(`Generating ${c.cyan(configFileName)}`);
6040
- 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" } }));
6041
6242
  spinner.succeed(`Generated ${c.cyan(configFileName)}`);
6042
- const outdirPath = path$1.resolve(cwd$2, outdir);
6243
+ const outdirPath = path$1.resolve(cwd$3, outdir);
6043
6244
  if (!overwrite && existsSync(outdirPath)) {
6044
6245
  const { overwrite: overwrite$1 } = await prompts({
6045
6246
  type: "confirm",
6046
6247
  name: "overwrite",
6047
6248
  initial: false,
6048
- message: c.reset(`The ${c.yellow(outdir)} directory already exists. Do you want to overwrite it?`)
6249
+ message: c.reset([`The ${c.yellow(outdir)} directory already exists.`, "Do you want to overwrite it?"].join(" "))
6049
6250
  });
6050
6251
  if (!overwrite$1) process.exit(0);
6051
6252
  spinner.start("Clearing directory");
@@ -6064,12 +6265,11 @@ const init = new Command("init").description("Initialize your project and instal
6064
6265
  {
6065
6266
  task: async (_, task) => {
6066
6267
  const targetPath = path$1.resolve(outdirPath, "package.json");
6067
- const data = JSON.stringify({
6268
+ const content = JSON.stringify({
6068
6269
  name: packageName,
6069
6270
  ...DEFAULT_PACKAGE_JSON
6070
6271
  });
6071
- const content = await format$2(data, { parser: "json" });
6072
- await writeFileSafe(targetPath, content);
6272
+ await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
6073
6273
  task.title = `Generated ${c.cyan("package.json")}`;
6074
6274
  },
6075
6275
  title: `Generating ${c.cyan("package.json")}`
@@ -6077,9 +6277,8 @@ const init = new Command("init").description("Initialize your project and instal
6077
6277
  {
6078
6278
  task: async (_, task) => {
6079
6279
  const targetPath = path$1.resolve(outdirPath, "tsconfig.json");
6080
- const data = JSON.stringify({ ...TSCONFIG_JSON });
6081
- const content = await format$2(data, { parser: "json" });
6082
- await writeFileSafe(targetPath, content);
6280
+ const content = JSON.stringify({ ...TSCONFIG_JSON });
6281
+ await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
6083
6282
  task.title = `Generated ${c.cyan("tsconfig.json")}`;
6084
6283
  },
6085
6284
  title: `Generating ${c.cyan("tsconfig.json")}`
@@ -6088,8 +6287,8 @@ const init = new Command("init").description("Initialize your project and instal
6088
6287
  task: async (_, task) => {
6089
6288
  const targetPath = path$1.resolve(outdirPath, src ? "src" : "", "index.ts");
6090
6289
  const { sources } = await fetchRegistry("index");
6091
- const content = await format$2(sources[0].content);
6092
- await writeFileSafe(targetPath, content);
6290
+ const content = sources[0].content;
6291
+ await writeFileSafe(targetPath, content, config$1);
6093
6292
  task.title = `Generated ${c.cyan("index.ts")}`;
6094
6293
  },
6095
6294
  title: `Generating ${c.cyan("index.ts")}`
@@ -6098,8 +6297,8 @@ const init = new Command("init").description("Initialize your project and instal
6098
6297
  task: async (_, task) => {
6099
6298
  if (outdir.includes("/")) {
6100
6299
  const path$9 = `${outdir.replace(/^\.\//, "").split("/")[0]}/**`;
6101
- await addWorkspace(cwd$2, path$9);
6102
- } else await addWorkspace(cwd$2, outdir);
6300
+ await addWorkspace(cwd$3, path$9, config$1);
6301
+ } else await addWorkspace(cwd$3, outdir, config$1);
6103
6302
  task.title = "Added workspace";
6104
6303
  },
6105
6304
  title: "Adding workspace"
@@ -6118,7 +6317,7 @@ const init = new Command("init").description("Initialize your project and instal
6118
6317
  const notInstalledDevDependencies = [];
6119
6318
  const tasks = new Listr([{
6120
6319
  task: async (_, task) => {
6121
- const packageJson$2 = await getPackageJson(cwd$2);
6320
+ const packageJson$2 = await getPackageJson(cwd$3);
6122
6321
  notInstalledDependencies.push(...getNotInstalledDependencies(packageJson$2, [...REQUIRED_DEPENDENCIES, "@yamada-ui/react@dev"]));
6123
6322
  notInstalledDevDependencies.push(...getNotInstalledDependencies(packageJson$2, REQUIRED_DEV_DEPENDENCIES));
6124
6323
  task.title = `Checked ${c.cyan("package.json")} dependencies`;
@@ -6128,8 +6327,8 @@ const init = new Command("init").description("Initialize your project and instal
6128
6327
  task: async (_, task) => {
6129
6328
  const { sources } = await fetchRegistry("index");
6130
6329
  const targetPath = path$1.resolve(outdirPath, "index.ts");
6131
- const content = await format$2(sources[0].content);
6132
- await writeFileSafe(targetPath, content);
6330
+ const content = sources[0].content;
6331
+ await writeFileSafe(targetPath, content, config$1);
6133
6332
  task.title = `Generated ${c.cyan("index.ts")}`;
6134
6333
  },
6135
6334
  title: `Generating ${c.cyan("index.ts")}`
@@ -6141,7 +6340,7 @@ const init = new Command("init").description("Initialize your project and instal
6141
6340
  type: "confirm",
6142
6341
  name: "install",
6143
6342
  initial: true,
6144
- message: c.reset(`The following dependencies are not installed: ${colorizedNames.join(", ")}. Do you want to install them?`)
6343
+ message: c.reset([`The following dependencies are not installed: ${colorizedNames.join(", ")}.`, "Do you want to install them?"].join(" "))
6145
6344
  });
6146
6345
  if (install) {
6147
6346
  dependencies$1 = notInstalledDependencies.map(getPackageName);
@@ -6151,21 +6350,25 @@ const init = new Command("init").description("Initialize your project and instal
6151
6350
  }
6152
6351
  if (dependencies$1 || devDependencies$1) {
6153
6352
  spinner.start("Installing dependencies");
6154
- if (dependencies$1) installDependencies(dependencies$1, { cwd: cwd$2 });
6155
- if (devDependencies$1) installDependencies(devDependencies$1, {
6156
- cwd: cwd$2,
6353
+ if (dependencies$1) await installDependencies(dependencies$1, { cwd: cwd$3 });
6354
+ if (devDependencies$1) await installDependencies(devDependencies$1, {
6355
+ cwd: cwd$3,
6157
6356
  dev: true
6158
6357
  });
6159
- if (monorepo) installDependencies(["@yamada-ui/react@dev"], { cwd: outdirPath });
6358
+ if (monorepo) await installDependencies(["@yamada-ui/react@dev"], { cwd: outdirPath });
6160
6359
  spinner.succeed("Installed dependencies");
6161
6360
  }
6162
6361
  if (monorepo) {
6163
6362
  const packageManager = getPackageManager();
6164
- const command = packageAddCommand(packageManager);
6165
- console.log(boxen(`Run ${c.cyan(`${command} "${packageName}@workspace:*"`)} in your application.`, {
6363
+ const args = packageAddArgs(packageManager);
6364
+ console.log("");
6365
+ console.log(boxen([
6366
+ "Run",
6367
+ c.cyan(`${packageManager} ${args.join(" ")} "${packageName}@workspace:*"`),
6368
+ "in your application."
6369
+ ].join(" "), {
6166
6370
  borderColor: "yellow",
6167
6371
  borderStyle: "round",
6168
- margin: 1,
6169
6372
  padding: 1,
6170
6373
  textAlignment: "center"
6171
6374
  }));
@@ -6285,7 +6488,7 @@ function extractKeys(obj, key) {
6285
6488
  if (!isObject(property)) return [];
6286
6489
  return Object.keys(property);
6287
6490
  }
6288
- async function generateThemeTokens(theme, { internal = false, theme: { responsive = false } = {} }) {
6491
+ function generateThemeTokens(theme, { internal = false, theme: { responsive = false } = {} }) {
6289
6492
  let shouldProcess = () => true;
6290
6493
  if (responsive && isObject(theme.breakpoints)) {
6291
6494
  const keys = ["base", ...Object.keys(theme.breakpoints)];
@@ -6326,7 +6529,7 @@ async function generateThemeTokens(theme, { internal = false, theme: { responsiv
6326
6529
  ]), { maxDepth: 2 });
6327
6530
  const { colorSchemes } = extractColorSchemes(theme, tokens$1.colors);
6328
6531
  const themeSchemes = extractThemeSchemes(theme);
6329
- if (internal) return await format$2([
6532
+ if (internal) return [
6330
6533
  `import type { UsageThemeTokens } from "./system"`,
6331
6534
  ``,
6332
6535
  `export interface GeneratedThemeTokens extends UsageThemeTokens {`,
@@ -6339,8 +6542,8 @@ async function generateThemeTokens(theme, { internal = false, theme: { responsiv
6339
6542
  themeSchemes
6340
6543
  }),
6341
6544
  `}`
6342
- ].join("\n"));
6343
- else return format$2([
6545
+ ].join("\n");
6546
+ else return [
6344
6547
  `import type { UsageThemeTokens } from "@yamada-ui/react"`,
6345
6548
  ``,
6346
6549
  `declare module '@yamada-ui/react' {`,
@@ -6355,10 +6558,10 @@ async function generateThemeTokens(theme, { internal = false, theme: { responsiv
6355
6558
  })}`,
6356
6559
  ` }`,
6357
6560
  `}`
6358
- ].join("\n"));
6561
+ ].join("\n");
6359
6562
  }
6360
- async function getTheme(path$9, cwd$2) {
6361
- 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);
6362
6565
  const theme = mod?.default ?? mod?.theme ?? mod?.customTheme ?? mod?.defaultTheme ?? {};
6363
6566
  const config$1 = mod?.config ?? mod?.customConfig ?? mod?.defaultConfig ?? {};
6364
6567
  return {
@@ -6367,31 +6570,45 @@ async function getTheme(path$9, cwd$2) {
6367
6570
  theme
6368
6571
  };
6369
6572
  }
6370
- 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 }) {
6371
6574
  const spinner = ora();
6372
6575
  try {
6373
- const eslint = new ESLint({ fix: true });
6374
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
+ }
6375
6589
  spinner.start(`Getting theme`);
6376
- cwd$2 = path$1.resolve(cwd$2);
6377
- inputPath = path$1.resolve(cwd$2, inputPath);
6378
- 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);
6379
6593
  else if (inputPath.includes("/")) {
6380
6594
  const dirPath = inputPath.split("/").slice(0, -1).join("/");
6381
6595
  outPath = path$1.join(dirPath, "index.types.ts");
6382
- } else outPath = path$1.join(cwd$2, "index.types.ts");
6383
- 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);
6384
6598
  spinner.succeed(`Got theme`);
6385
6599
  spinner.start(`Generating theme typings`);
6386
- let content = await generateThemeTokens(theme, {
6387
- ...config$1,
6600
+ const content = generateThemeTokens(theme, {
6601
+ ...themeConfig,
6388
6602
  internal
6389
6603
  });
6390
- if (lint) {
6391
- const [result] = await eslint.lintText(content, { filePath: inputPath });
6392
- if (result?.output) content = result.output;
6393
- }
6394
- 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
+ });
6395
6612
  spinner.succeed(`Generated theme typings`);
6396
6613
  end();
6397
6614
  } catch (e) {
@@ -6419,10 +6636,7 @@ async function run() {
6419
6636
  program.addCommand(tokens);
6420
6637
  program.parse();
6421
6638
  }
6422
- if (process.argv.includes("--run")) {
6423
- process.argv = process.argv.filter((arg) => arg !== "--run");
6424
- run();
6425
- }
6639
+ run();
6426
6640
 
6427
6641
  //#endregion
6428
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-20250816072830",
4
+ "version": "2.0.0-dev-20250820102029",
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,15 +33,17 @@
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",
41
40
  "cli-check-node": "^1.3.4",
42
41
  "cli-handle-unhandled": "^1.1.2",
43
42
  "commander": "^14.0.0",
43
+ "diff": "^8.0.2",
44
44
  "esbuild": "^0.25.8",
45
45
  "eslint": "^9.32.0",
46
+ "execa": "9.3.1",
46
47
  "glob": "^11.0.3",
47
48
  "https-proxy-agent": "^7.0.6",
48
49
  "listr2": "^9.0.1",
@@ -70,7 +71,7 @@
70
71
  },
71
72
  "scripts": {
72
73
  "clean": "rimraf node_modules dist trace coverage .turbo .eslintcache",
73
- "start": "tsx src/index.ts --run",
74
+ "dev": "tsx src/index.ts",
74
75
  "build": "tsdown",
75
76
  "typecheck": " tsc --noEmit",
76
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
- })