@yamada-ui/cli 2.0.0-dev-20250823155214 → 2.0.0-dev-20250825083810

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 (2) hide show
  1. package/dist/index.js +351 -211
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
2
  import checkNode from "cli-check-node";
3
- import unhandledError from "cli-handle-unhandled";
4
3
  import { Command } from "commander";
5
4
  import c from "picocolors";
6
5
  import process$1, { env } from "node:process";
@@ -29,6 +28,7 @@ import YAML from "yamljs";
29
28
  import { glob } from "glob";
30
29
  import { ESLint } from "eslint";
31
30
  import { format as format$1, resolveConfig, resolveConfigFile } from "prettier";
31
+ import { transform } from "sucrase";
32
32
  import { build } from "esbuild";
33
33
  import nodeEval from "node-eval";
34
34
  import { Script } from "vm";
@@ -5062,13 +5062,13 @@ var MissingValueError = class extends Error {
5062
5062
  this.key = key;
5063
5063
  }
5064
5064
  };
5065
- function pupa(template, data, { ignoreMissing = false, transform = ({ value }) => value } = {}) {
5065
+ function pupa(template, data, { ignoreMissing = false, transform: transform$1 = ({ value }) => value } = {}) {
5066
5066
  if (typeof template !== "string") throw new TypeError(`Expected a \`string\` in the first argument, got \`${typeof template}\``);
5067
5067
  if (typeof data !== "object") throw new TypeError(`Expected an \`object\` or \`Array\` in the second argument, got \`${typeof data}\``);
5068
5068
  const replace = (placeholder, key) => {
5069
5069
  let value = data;
5070
5070
  for (const property of key.split(".")) value = value ? value[property] : void 0;
5071
- const transformedValue = transform({
5071
+ const transformedValue = transform$1({
5072
5072
  value,
5073
5073
  key
5074
5074
  });
@@ -5230,7 +5230,6 @@ var dependencies = {
5230
5230
  "@yamada-ui/utils": "workspace:*",
5231
5231
  "boxen": "^8.0.1",
5232
5232
  "cli-check-node": "^1.3.4",
5233
- "cli-handle-unhandled": "^1.1.2",
5234
5233
  "commander": "^14.0.0",
5235
5234
  "diff": "^8.0.2",
5236
5235
  "esbuild": "^0.25.8",
@@ -5247,6 +5246,7 @@ var dependencies = {
5247
5246
  "prompts": "^2.4.2",
5248
5247
  "rimraf": "^6.0.1",
5249
5248
  "semver": "^7.7.2",
5249
+ "sucrase": "^3.35.0",
5250
5250
  "validate-npm-package-name": "^6.0.2",
5251
5251
  "yamljs": "^0.3.0"
5252
5252
  };
@@ -5388,14 +5388,15 @@ async function getFiles(pattern) {
5388
5388
  await Promise.all(dirents.map(async (dirent) => {
5389
5389
  const name$1 = dirent.name;
5390
5390
  if (dirent.isDirectory()) {
5391
- const data = await readdir(path$1.join(dirent.parentPath, name$1), { withFileTypes: true });
5392
- await Promise.all(data.map(async (dirent$1) => {
5391
+ const dirents$1 = await readdir(path$1.join(dirent.parentPath, name$1), { withFileTypes: true });
5392
+ await Promise.all(dirents$1.map(async (dirent$1) => {
5393
5393
  if (dirent$1.isDirectory()) return;
5394
+ if (dirent$1.name === REGISTRY_FILE_NAME) return;
5394
5395
  const targetPath = path$1.join(dirent$1.parentPath, dirent$1.name);
5395
- const data$1 = await readFile(targetPath, "utf-8");
5396
- files$1[`${name$1}/${dirent$1.name}`] = data$1;
5396
+ const data = await readFile(targetPath, "utf-8");
5397
+ files$1[`${name$1}/${dirent$1.name}`] = data;
5397
5398
  }));
5398
- } else if (!name$1.endsWith(".json")) {
5399
+ } else if (name$1 !== REGISTRY_FILE_NAME) {
5399
5400
  const targetPath = path$1.join(dirent.parentPath, dirent.name);
5400
5401
  const data = await readFile(targetPath, "utf-8");
5401
5402
  files$1[name$1] = data;
@@ -5426,7 +5427,6 @@ async function getPackageJson(cwd$3) {
5426
5427
  }
5427
5428
  function getVersion({ dependencies: dependencies$1, devDependencies: devDependencies$1 }, nameWithVersion) {
5428
5429
  const [name$1, version$1] = splitVersion(nameWithVersion);
5429
- if (!name$1) return;
5430
5430
  let currentVersion;
5431
5431
  if (isObject(dependencies$1) && name$1 in dependencies$1) currentVersion = dependencies$1[name$1];
5432
5432
  else if (isObject(devDependencies$1) && name$1 in devDependencies$1) currentVersion = devDependencies$1[name$1];
@@ -5455,6 +5455,9 @@ function splitVersion(value) {
5455
5455
  } else return value.split("@");
5456
5456
  }
5457
5457
  function getPackageName(value) {
5458
+ return splitVersion(value)[0];
5459
+ }
5460
+ function getPackageNameWithVersion(value) {
5458
5461
  return isObject(value) ? `${value.name}@${value.wanted}` : value;
5459
5462
  }
5460
5463
  function packageAddArgs(packageManager, { dev = false, exact = false } = {}) {
@@ -5545,14 +5548,40 @@ async function addWorkspace(cwd$3, workspacePath, config$1) {
5545
5548
  }
5546
5549
  }
5547
5550
 
5551
+ //#endregion
5552
+ //#region src/utils/typescript.ts
5553
+ function transformExtension(value, jsx) {
5554
+ if (!jsx) return value;
5555
+ const extension = value.split(".").at(-1);
5556
+ if (extension === "tsx") return value.replace(/\.tsx$/, ".jsx");
5557
+ if (extension === "ts") return value.replace(/\.ts$/, ".js");
5558
+ return value;
5559
+ }
5560
+ function isTsx(value) {
5561
+ return value.endsWith(".tsx");
5562
+ }
5563
+ function isJsx(value) {
5564
+ return value.endsWith(".jsx");
5565
+ }
5566
+ function transformTsxToJsx(content) {
5567
+ return transform(content, {
5568
+ jsxRuntime: "preserve",
5569
+ transforms: ["jsx", "typescript"]
5570
+ }).code;
5571
+ }
5572
+ function transformTsToJs(content) {
5573
+ return transform(content, { transforms: ["typescript"] }).code;
5574
+ }
5575
+
5548
5576
  //#endregion
5549
5577
  //#region src/utils/config.ts
5550
- async function getConfig(cwd$3, configPath, { format: format$2, lint } = {}) {
5578
+ async function getConfig(cwd$3, configPath, { format: format$2, jsx, lint } = {}) {
5551
5579
  try {
5552
5580
  const data = await readFile(path$1.resolve(cwd$3, configPath), "utf-8");
5553
5581
  const userConfig = JSON.parse(data);
5554
5582
  if (!isUndefined(format$2)) userConfig.format = { enabled: format$2 };
5555
5583
  if (!isUndefined(lint)) userConfig.lint = { enabled: lint };
5584
+ if (!isUndefined(jsx)) userConfig.jsx = jsx;
5556
5585
  const rootPath = path$1.resolve(cwd$3, userConfig.path ?? (userConfig.monorepo ? DEFAULT_PATH.monorepo : DEFAULT_PATH.polyrepo));
5557
5586
  const src = existsSync(path$1.resolve(rootPath, "src"));
5558
5587
  const srcPath = src ? path$1.resolve(rootPath, "src") : rootPath;
@@ -5561,13 +5590,13 @@ async function getConfig(cwd$3, configPath, { format: format$2, lint } = {}) {
5561
5590
  const replacedSection = path$9.replace(/(\.\.\/|\.\/)/g, "").replace(/(^\/|\/$)/g, "");
5562
5591
  return [section, replacedSection];
5563
5592
  }));
5564
- const indexPath = path$1.resolve(srcPath, "index.ts");
5593
+ const indexPath = path$1.resolve(srcPath, transformExtension("index.ts", userConfig.jsx));
5565
5594
  const registryPath = path$1.resolve(srcPath, REGISTRY_FILE_NAME);
5566
5595
  if (userConfig.theme?.path) userConfig.theme.path = path$1.resolve(cwd$3, userConfig.theme.path);
5567
5596
  function isSection(section) {
5568
5597
  return SECTION_NAMES.includes(section);
5569
5598
  }
5570
- function getSectionAbsolutePath(section) {
5599
+ function getSectionResolvedPath(section) {
5571
5600
  return path$1.resolve(srcPath, userConfig[section]?.path ?? DEFAULT_PATH[section]);
5572
5601
  }
5573
5602
  function getSectionPath(section) {
@@ -5582,8 +5611,8 @@ async function getConfig(cwd$3, configPath, { format: format$2, lint } = {}) {
5582
5611
  const section = value;
5583
5612
  return {
5584
5613
  ...userConfig[section],
5585
- absolutePath: getSectionAbsolutePath(section),
5586
5614
  path: getSectionPath(section),
5615
+ resolvedPath: getSectionResolvedPath(section),
5587
5616
  section
5588
5617
  };
5589
5618
  } else {
@@ -5592,8 +5621,8 @@ async function getConfig(cwd$3, configPath, { format: format$2, lint } = {}) {
5592
5621
  const section = result;
5593
5622
  return {
5594
5623
  ...userConfig[section],
5595
- absolutePath: getSectionAbsolutePath(section),
5596
5624
  path: getSectionPath(section),
5625
+ resolvedPath: getSectionResolvedPath(section),
5597
5626
  section
5598
5627
  };
5599
5628
  }
@@ -5603,8 +5632,8 @@ async function getConfig(cwd$3, configPath, { format: format$2, lint } = {}) {
5603
5632
  src,
5604
5633
  cwd: cwd$3,
5605
5634
  getSection,
5606
- getSectionAbsolutePath,
5607
5635
  getSectionPath,
5636
+ getSectionResolvedPath,
5608
5637
  indexPath,
5609
5638
  isSection,
5610
5639
  registryPath,
@@ -5736,7 +5765,7 @@ async function fetchLocaleRegistry(path$9) {
5736
5765
  async function getGeneratedNameMap(config$1) {
5737
5766
  const results = await Promise.all(SECTION_NAMES.map(async (section) => {
5738
5767
  try {
5739
- const sectionPath = config$1.getSectionAbsolutePath(section);
5768
+ const sectionPath = config$1.getSectionResolvedPath(section);
5740
5769
  const dirents = await readdir(sectionPath, { withFileTypes: true });
5741
5770
  return [section, dirents.filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name)];
5742
5771
  } catch {
@@ -5789,8 +5818,9 @@ function transformContent(targetSection, content, { getSection }, generatedNames
5789
5818
  return content;
5790
5819
  }
5791
5820
  async function transformContentWithFormatAndLint(filePath, section, content, config$1, generatedNames) {
5792
- const { cwd: cwd$3, format: format$2, lint } = config$1;
5821
+ const { cwd: cwd$3, format: format$2, jsx, lint } = config$1;
5793
5822
  content = transformContent(section, content, config$1, generatedNames);
5823
+ if (jsx) content = isJsx(filePath) ? transformTsxToJsx(content) : transformTsToJs(content);
5794
5824
  content = await lintText(content, {
5795
5825
  ...lint,
5796
5826
  cwd: cwd$3,
@@ -5832,23 +5862,29 @@ function transformIndex(generatedNames, content, { getSection }) {
5832
5862
  return content;
5833
5863
  }
5834
5864
  async function transformIndexWithFormatAndLint(content, config$1, generatedNames) {
5835
- const { cwd: cwd$3, format: format$2, lint } = config$1;
5865
+ const { cwd: cwd$3, format: format$2, indexPath, jsx, lint } = config$1;
5836
5866
  content = transformIndex(generatedNames, content, config$1);
5867
+ if (jsx) content = transformTsToJs(content);
5837
5868
  content = await lintText(content, {
5838
5869
  ...lint,
5839
5870
  cwd: cwd$3,
5840
- filePath: config$1.indexPath
5871
+ filePath: indexPath
5841
5872
  });
5842
5873
  content = await formatText(content, format$2);
5843
5874
  return content;
5844
5875
  }
5845
5876
  async function generateSource(dirPath, section, { name: fileName, content, data, template }, config$1, generatedNames = []) {
5877
+ fileName = transformExtension(fileName, config$1.jsx);
5846
5878
  const targetPath = path$1.resolve(dirPath, fileName);
5847
5879
  if (content) {
5848
5880
  content = transformContent(section, content, config$1, generatedNames);
5881
+ if (config$1.jsx) content = isJsx(fileName) ? transformTsxToJsx(content) : transformTsToJs(content);
5849
5882
  await writeFileSafe(targetPath, content, config$1);
5850
5883
  } else if (template && data) await Promise.all(data.map(async ({ name: fileName$1,...rest }) => {
5851
- const content$1 = transformContent(section, transformTemplateContent(template, rest), config$1, generatedNames);
5884
+ fileName$1 = transformExtension(fileName$1, config$1.jsx);
5885
+ let content$1 = transformTemplateContent(template, rest);
5886
+ content$1 = transformContent(section, content$1, config$1, generatedNames);
5887
+ if (config$1.jsx) content$1 = isJsx(fileName$1) ? transformTsxToJsx(content$1) : transformTsToJs(content$1);
5852
5888
  await writeFileSafe(path$1.resolve(targetPath, fileName$1), content$1, config$1);
5853
5889
  }));
5854
5890
  }
@@ -5867,7 +5903,7 @@ const DEFAULT_PATH = {
5867
5903
  components: "./components",
5868
5904
  hooks: "./hooks",
5869
5905
  monorepo: "./workspaces/ui",
5870
- polyrepo: "./ui",
5906
+ polyrepo: "./components/ui",
5871
5907
  providers: "./providers"
5872
5908
  };
5873
5909
  const SECTION_NAMES = [
@@ -5887,14 +5923,22 @@ const DEFAULT_PACKAGE_JSON = {
5887
5923
  type: "module",
5888
5924
  private: true,
5889
5925
  scripts: {},
5890
- exports: {
5926
+ dependencies: Object.fromEntries(REQUIRED_DEPENDENCIES.map((dependency) => splitVersion(dependency))),
5927
+ devDependencies: Object.fromEntries(REQUIRED_DEV_DEPENDENCIES.map((dependency) => splitVersion(dependency)))
5928
+ };
5929
+ const DEFAULT_PACKAGE_JSON_EXPORTS = {
5930
+ TSX: {
5891
5931
  ".": "./src/index.ts",
5892
5932
  "./components/*": "./src/components/*/index.ts",
5893
5933
  "./hooks/*": "./src/hooks/*/index.ts",
5894
5934
  "./providers/*": "./src/providers/*/index.ts"
5895
5935
  },
5896
- dependencies: Object.fromEntries(REQUIRED_DEPENDENCIES.map((dependency) => splitVersion(dependency))),
5897
- devDependencies: Object.fromEntries(REQUIRED_DEV_DEPENDENCIES.map((dependency) => splitVersion(dependency)))
5936
+ JSX: {
5937
+ ".": "./src/index.js",
5938
+ "./components/*": "./src/components/*/index.js",
5939
+ "./hooks/*": "./src/hooks/*/index.js",
5940
+ "./providers/*": "./src/providers/*/index.js"
5941
+ }
5898
5942
  };
5899
5943
  const TSCONFIG_JSON = {
5900
5944
  compilerOptions: {
@@ -6009,7 +6053,7 @@ const add = new Command("add").description("add a component to your project").ar
6009
6053
  const targetNames = [...new Set([...omittedGeneratedNames, ...registryNames])];
6010
6054
  const tasks = new Listr(Object.entries(registries).map(([name$1, registry]) => {
6011
6055
  if (!config$1.isSection(registry.section)) return;
6012
- const sectionPath = config$1.getSectionAbsolutePath(registry.section);
6056
+ const sectionPath = config$1.getSectionResolvedPath(registry.section);
6013
6057
  const dirPath = path$1.join(sectionPath, name$1);
6014
6058
  return {
6015
6059
  task: async (_, task) => {
@@ -6035,14 +6079,26 @@ const add = new Command("add").description("add a component to your project").ar
6035
6079
  if (!affectedNames.includes(name$1)) return;
6036
6080
  tasks.add({
6037
6081
  task: async (_, task) => {
6038
- const sectionPath = config$1.getSectionAbsolutePath(section);
6082
+ const sectionPath = config$1.getSectionResolvedPath(section);
6039
6083
  const dirPath = path$1.join(sectionPath, name$1);
6040
6084
  const dirents = await readdir(dirPath, { withFileTypes: true });
6041
6085
  await Promise.all(dirents.map(async (dirent) => {
6042
- if (dirent.isDirectory()) return;
6043
- const targetPath = path$1.join(dirent.parentPath, dirent.name);
6044
- const content = transformContent(section, await readFile(targetPath, "utf-8"), config$1, targetNames);
6045
- await writeFileSafe(targetPath, content, config$1);
6086
+ if (dirent.isDirectory()) {
6087
+ const dirents$1 = await readdir(path$1.join(dirent.parentPath, name$1), { withFileTypes: true });
6088
+ await Promise.all(dirents$1.map(async (dirent$1) => {
6089
+ if (dirent$1.isDirectory()) return;
6090
+ if (dirent$1.name === REGISTRY_FILE_NAME) return;
6091
+ const targetPath = path$1.join(dirent$1.parentPath, dirent$1.name);
6092
+ let content = await readFile(targetPath, "utf-8");
6093
+ content = transformContent(section, content, config$1, targetNames);
6094
+ await writeFileSafe(targetPath, content, config$1);
6095
+ }));
6096
+ } else if (dirent.name !== REGISTRY_FILE_NAME) {
6097
+ const targetPath = path$1.join(dirent.parentPath, dirent.name);
6098
+ let content = await readFile(targetPath, "utf-8");
6099
+ content = transformContent(section, content, config$1, targetNames);
6100
+ await writeFileSafe(targetPath, content, config$1);
6101
+ }
6046
6102
  }));
6047
6103
  task.title = `Updated ${c.cyan(name$1)}`;
6048
6104
  },
@@ -6051,22 +6107,25 @@ const add = new Command("add").description("add a component to your project").ar
6051
6107
  });
6052
6108
  });
6053
6109
  }
6110
+ const indexFileName = transformExtension("index.ts", config$1.jsx);
6054
6111
  if (existsSync(config$1.indexPath)) tasks.add({
6055
6112
  task: async (_, task) => {
6056
- const content = transformIndex(targetNames, await readFile(config$1.indexPath, "utf-8"), config$1);
6113
+ let content = await readFile(config$1.indexPath, "utf-8");
6114
+ content = transformIndex(targetNames, content, config$1);
6057
6115
  await writeFileSafe(config$1.indexPath, content, config$1);
6058
- task.title = `Updated ${c.cyan("index.ts")}`;
6116
+ task.title = `Updated ${c.cyan(indexFileName)}`;
6059
6117
  },
6060
- title: `Updating ${c.cyan("index.ts")}`
6118
+ title: `Updating ${c.cyan(indexFileName)}`
6061
6119
  });
6062
6120
  else tasks.add({
6063
6121
  task: async (_, task) => {
6064
6122
  const { sources: [source] } = await fetchRegistry("index");
6065
- const content = transformIndex(targetNames, source.content, config$1);
6123
+ let content = transformIndex(targetNames, source.content, config$1);
6124
+ if (config$1.jsx) content = transformTsToJs(content);
6066
6125
  await writeFileSafe(config$1.indexPath, content, config$1);
6067
- task.title = `Generated ${c.cyan("index.ts")}`;
6126
+ task.title = `Generated ${c.cyan(indexFileName)}`;
6068
6127
  },
6069
- title: `Generating ${c.cyan("index.ts")}`
6128
+ title: `Generating ${c.cyan(indexFileName)}`
6070
6129
  });
6071
6130
  if (dependencies$1.length) {
6072
6131
  const targetPath = config$1.monorepo ? config$1.rootPath : cwd$3;
@@ -6086,7 +6145,7 @@ const add = new Command("add").description("add a component to your project").ar
6086
6145
  }
6087
6146
  if (install) tasks.add({
6088
6147
  task: async (_, task) => {
6089
- await installDependencies(notInstalledDependencies.map(getPackageName), { cwd: targetPath });
6148
+ await installDependencies(notInstalledDependencies.map(getPackageNameWithVersion), { cwd: targetPath });
6090
6149
  task.title = "Installed dependencies";
6091
6150
  },
6092
6151
  title: "Installing dependencies"
@@ -6104,7 +6163,7 @@ const add = new Command("add").description("add a component to your project").ar
6104
6163
  //#region src/commands/update/print-conflicts.ts
6105
6164
  function printConflicts(conflictMap, config$1) {
6106
6165
  Object.entries(conflictMap).forEach(([name$1, files$1]) => {
6107
- if (name$1 === "index") console.log(`- ${c.yellow("index.ts")}: ${config$1.indexPath.replace(`${config$1.cwd}/`, "")}`);
6166
+ if (name$1 === "index") console.log(`- ${c.yellow(transformExtension("index.ts", config$1.jsx))}: ${config$1.indexPath.replace(`${config$1.cwd}/`, "")}`);
6108
6167
  else {
6109
6168
  console.log(`- ${name$1}`);
6110
6169
  Object.entries(files$1).forEach(([fileName, path$9]) => {
@@ -6116,69 +6175,159 @@ function printConflicts(conflictMap, config$1) {
6116
6175
 
6117
6176
  //#endregion
6118
6177
  //#region src/commands/diff/get-diff.ts
6119
- function getFilePath(section, name$1, fileName, config$1) {
6120
- return config$1.isSection(section) ? path$1.join(config$1.getSectionAbsolutePath(section), name$1, fileName) : path$1.join(config$1.srcPath, section === "theme" ? name$1 : "", fileName);
6178
+ function getDirPath(section, name$1, config$1) {
6179
+ return config$1.isSection(section) ? path$1.join(config$1.getSectionResolvedPath(section), name$1) : section === "theme" ? config$1.theme.path : config$1.srcPath;
6121
6180
  }
6122
6181
  async function getDiff(generatedNames, { locale, remote }, config$1, concurrent = true) {
6123
- const changes = {};
6124
- const tasks = new Listr(Object.entries(remote).map(([componentName, { section, sources }]) => ({
6182
+ const changeMap = {};
6183
+ const dependencyMap = {
6184
+ add: [],
6185
+ remove: [],
6186
+ update: []
6187
+ };
6188
+ const tasks = new Listr(Object.entries(remote).map(([componentName, { dependencies: dependencies$1, section, sources }]) => ({
6125
6189
  task: async (_, task) => {
6126
6190
  const localeRegistry = locale[componentName];
6127
6191
  if (componentName === "index") {
6128
6192
  const [source] = sources;
6129
- const fileName = source.name;
6130
- const [remoteContent, localeContent] = await Promise.all([transformIndexWithFormatAndLint(source.content, config$1, generatedNames), transformIndexWithFormatAndLint(localeRegistry.sources[0].content, config$1, generatedNames)]);
6131
- const diff$1 = diffLines(localeContent, remoteContent);
6193
+ const fileName = transformExtension(source.name, config$1.jsx);
6194
+ const [remote$1, locale$1] = await Promise.all([transformIndexWithFormatAndLint(source.content, config$1, generatedNames), transformIndexWithFormatAndLint(localeRegistry.sources[0].content, config$1, generatedNames)]);
6195
+ const diff$1 = diffLines(locale$1, remote$1);
6132
6196
  if (diff$1.length < 2) return;
6133
- changes[componentName] ??= {};
6134
- changes[componentName][fileName] = diff$1;
6135
- } else await Promise.all(sources.map(async ({ name: name$1, content, data, template }) => {
6136
- const filePath = getFilePath(section, componentName, name$1, config$1);
6137
- const source = localeRegistry.sources.find((source$1) => source$1.name === name$1);
6138
- if (content) if (source) {
6139
- const [remoteContent, localeContent] = await Promise.all([transformContentWithFormatAndLint(filePath, section, content, config$1, generatedNames), transformContentWithFormatAndLint(filePath, section, source.content, config$1, generatedNames)]);
6140
- const diff$1 = diffLines(localeContent, remoteContent);
6141
- if (diff$1.length < 2) return;
6142
- changes[componentName] ??= {};
6143
- changes[componentName][name$1] = diff$1;
6144
- } else {
6145
- const remoteContent = transformContent(section, content, config$1, generatedNames);
6146
- changes[componentName] ??= {};
6147
- changes[componentName][name$1] = [{
6148
- added: true,
6149
- count: remoteContent.length,
6150
- removed: false,
6151
- value: remoteContent
6152
- }];
6197
+ changeMap[componentName] ??= {};
6198
+ changeMap[componentName][fileName] = {
6199
+ diff: diff$1,
6200
+ locale: locale$1,
6201
+ remote: remote$1
6202
+ };
6203
+ } else {
6204
+ const dirPath = getDirPath(section, componentName, config$1);
6205
+ if (dependencies$1 || localeRegistry.dependencies) {
6206
+ const remoteDependencies = dependencies$1?.externals ?? [];
6207
+ const localeDependencies = localeRegistry.dependencies?.externals ?? [];
6208
+ const remotePackageNames = remoteDependencies.map(getPackageName);
6209
+ const localePackageNames = localeDependencies.map(getPackageName);
6210
+ const add$1 = remotePackageNames.filter((name$1) => !localePackageNames.includes(name$1));
6211
+ const remove = localePackageNames.filter((name$1) => !remotePackageNames.includes(name$1));
6212
+ const update$1 = localeDependencies.map((name$1) => {
6213
+ const [packageName, current] = splitVersion(name$1);
6214
+ const remoteDependency = remoteDependencies.find((name$2) => getPackageName(name$2) === packageName);
6215
+ if (!remoteDependency) return;
6216
+ const [, wanted] = splitVersion(remoteDependency);
6217
+ if (current === wanted) return;
6218
+ return {
6219
+ name: packageName,
6220
+ current,
6221
+ wanted
6222
+ };
6223
+ }).filter((data) => !isUndefined(data));
6224
+ dependencyMap.add.push(...add$1);
6225
+ dependencyMap.remove.push(...remove);
6226
+ dependencyMap.update.push(...update$1);
6153
6227
  }
6154
- else if (template && data) await Promise.all(data.map(async ({ name: fileName,...remoteRest }) => {
6155
- const localeData = source?.data?.find(({ name: name$2 }) => name$2 === fileName);
6156
- if (localeData) {
6157
- if (template === source?.template) return;
6158
- const { name: _name,...localeRest } = localeData;
6159
- const [remoteContent, localeContent] = await Promise.all([transformContentWithFormatAndLint(path$1.join(filePath, fileName), section, transformTemplateContent(template, remoteRest), config$1, generatedNames), transformContentWithFormatAndLint(path$1.join(filePath, fileName), section, transformTemplateContent(source.template, localeRest), config$1, generatedNames)]);
6160
- const diff$1 = diffLines(localeContent, remoteContent);
6228
+ await Promise.all(sources.map(async ({ name: name$1, content, data, template }) => {
6229
+ const source = localeRegistry.sources.find((source$1) => source$1.name === name$1);
6230
+ name$1 = transformExtension(name$1, config$1.jsx);
6231
+ const targetPath = path$1.join(dirPath, name$1);
6232
+ if (content) if (source) {
6233
+ const [remote$1, locale$1] = await Promise.all([transformContentWithFormatAndLint(targetPath, section, content, config$1, generatedNames), transformContentWithFormatAndLint(targetPath, section, source.content, config$1, generatedNames)]);
6234
+ const diff$1 = diffLines(locale$1, remote$1);
6161
6235
  if (diff$1.length < 2) return;
6162
- changes[componentName] ??= {};
6163
- changes[componentName][`${name$1}/${fileName}`] = diff$1;
6236
+ changeMap[componentName] ??= {};
6237
+ changeMap[componentName][name$1] = {
6238
+ diff: diff$1,
6239
+ locale: locale$1,
6240
+ remote: remote$1
6241
+ };
6164
6242
  } else {
6165
- const remoteContent = transformContent(section, transformTemplateContent(template, remoteRest), config$1, generatedNames);
6166
- changes[componentName] ??= {};
6167
- changes[componentName][`${name$1}/${fileName}`] = [{
6243
+ let remote$1 = transformContent(section, content, config$1, generatedNames);
6244
+ if (config$1.jsx) remote$1 = isJsx(name$1) ? transformTsxToJsx(remote$1) : transformTsToJs(remote$1);
6245
+ const diff$1 = [{
6168
6246
  added: true,
6169
- count: remoteContent.length,
6247
+ count: remote$1.length,
6170
6248
  removed: false,
6171
- value: remoteContent
6249
+ value: remote$1
6172
6250
  }];
6251
+ changeMap[componentName] ??= {};
6252
+ changeMap[componentName][name$1] = {
6253
+ diff: diff$1,
6254
+ remote: remote$1
6255
+ };
6173
6256
  }
6257
+ else if (template && data) await Promise.all(data.map(async ({ name: fileName,...remoteRest }) => {
6258
+ const localeData = source?.data?.find(({ name: name$2 }) => name$2 === fileName);
6259
+ fileName = transformExtension(fileName, config$1.jsx);
6260
+ if (localeData) {
6261
+ if (template === source?.template) return;
6262
+ const { name: _name,...localeRest } = localeData;
6263
+ const [remote$1, locale$1] = await Promise.all([transformContentWithFormatAndLint(path$1.join(targetPath, fileName), section, transformTemplateContent(template, remoteRest), config$1, generatedNames), transformContentWithFormatAndLint(path$1.join(targetPath, fileName), section, transformTemplateContent(source.template, localeRest), config$1, generatedNames)]);
6264
+ const diff$1 = diffLines(locale$1, remote$1);
6265
+ if (diff$1.length < 2) return;
6266
+ changeMap[componentName] ??= {};
6267
+ changeMap[componentName][`${name$1}/${fileName}`] = {
6268
+ diff: diff$1,
6269
+ locale: locale$1,
6270
+ remote: remote$1
6271
+ };
6272
+ } else {
6273
+ let remote$1 = transformContent(section, transformTemplateContent(template, remoteRest), config$1, generatedNames);
6274
+ if (config$1.jsx) remote$1 = isJsx(fileName) ? transformTsxToJsx(remote$1) : transformTsToJs(remote$1);
6275
+ const diff$1 = [{
6276
+ added: true,
6277
+ count: remote$1.length,
6278
+ removed: false,
6279
+ value: remote$1
6280
+ }];
6281
+ changeMap[componentName] ??= {};
6282
+ changeMap[componentName][`${name$1}/${fileName}`] = {
6283
+ diff: diff$1,
6284
+ remote: remote$1
6285
+ };
6286
+ }
6287
+ }));
6174
6288
  }));
6175
- }));
6289
+ const removeSources = localeRegistry.sources.filter(({ name: name$1 }) => !sources.some((source) => source.name === name$1));
6290
+ removeSources.forEach(({ name: name$1, content, data, template }) => {
6291
+ if (content) {
6292
+ let locale$1 = transformContent(section, content, config$1, generatedNames);
6293
+ if (config$1.jsx) locale$1 = isJsx(name$1) ? transformTsxToJsx(locale$1) : transformTsToJs(locale$1);
6294
+ const diff$1 = [{
6295
+ added: false,
6296
+ count: locale$1.length,
6297
+ removed: true,
6298
+ value: locale$1
6299
+ }];
6300
+ changeMap[componentName] ??= {};
6301
+ changeMap[componentName][name$1] = {
6302
+ diff: diff$1,
6303
+ locale: locale$1
6304
+ };
6305
+ } else if (template && data) data.forEach(({ name: fileName,...remoteRest }) => {
6306
+ let locale$1 = transformContent(section, transformTemplateContent(template, remoteRest), config$1, generatedNames);
6307
+ if (config$1.jsx) locale$1 = isJsx(fileName) ? transformTsxToJsx(locale$1) : transformTsToJs(locale$1);
6308
+ const diff$1 = [{
6309
+ added: true,
6310
+ count: locale$1.length,
6311
+ removed: false,
6312
+ value: locale$1
6313
+ }];
6314
+ changeMap[componentName] ??= {};
6315
+ changeMap[componentName][`${name$1}/${fileName}`] = {
6316
+ diff: diff$1,
6317
+ locale: locale$1
6318
+ };
6319
+ });
6320
+ });
6321
+ }
6176
6322
  task.title = `Checked ${c.cyan(componentName)}`;
6177
6323
  },
6178
6324
  title: `Checking ${c.cyan(componentName)}`
6179
6325
  })), { concurrent });
6180
6326
  await tasks.run();
6181
- return changes;
6327
+ return {
6328
+ changeMap,
6329
+ dependencyMap
6330
+ };
6182
6331
  }
6183
6332
 
6184
6333
  //#endregion
@@ -6209,78 +6358,47 @@ async function mergeContent(remotePath, localePath, currentPath, fallback) {
6209
6358
  content
6210
6359
  };
6211
6360
  }
6212
- async function updateFiles(generatedNames, { locale, remote }, config$1, { concurrent = true, install = false } = {}) {
6361
+ async function updateFiles(changeMap, { add: add$1, remove, update: update$1 }, { remote }, config$1, { concurrent = true, install = false } = {}) {
6213
6362
  const conflictMap = {};
6214
- const notInstalledDependencies = [];
6215
- const shouldUninstallDependencies = [];
6216
6363
  const disabledFormatAndLint = {
6217
6364
  format: { enabled: false },
6218
6365
  lint: { enabled: false }
6219
6366
  };
6220
- const tasks = new Listr(Object.entries(remote).map(([componentName, { dependencies: dependencies$1, section, sources }]) => ({
6367
+ const tasks = new Listr(Object.entries(changeMap).map(([componentName, changes]) => ({
6221
6368
  task: async (_, task) => {
6222
6369
  const tempDirPath = await mkdtemp(path$1.join(tmpdir(), `yamada-ui-${componentName}-`));
6223
- const localeRegistry = locale[componentName];
6224
- if (dependencies$1 || localeRegistry.dependencies) {
6225
- const add$1 = dependencies$1?.externals.filter((name$1) => !localeRegistry.dependencies?.externals.includes(name$1)) ?? [];
6226
- const remove = localeRegistry.dependencies?.externals.filter((name$1) => !dependencies$1?.externals.includes(name$1)) ?? [];
6227
- notInstalledDependencies.push(...add$1);
6228
- shouldUninstallDependencies.push(...remove);
6229
- }
6370
+ const registry = remote[componentName];
6371
+ const dirPath = getDirPath(registry.section, componentName, config$1);
6230
6372
  try {
6231
6373
  if (componentName === "index") {
6232
- const [source] = sources;
6233
- const fileName = source.name;
6234
- const remotePath = path$1.join(tempDirPath, `remote-${fileName}`);
6235
- const localePath = path$1.join(tempDirPath, `locale-${fileName}`);
6236
- const [remoteContent, localeContent] = await Promise.all([transformIndexWithFormatAndLint(sources[0].content, config$1, generatedNames), transformIndexWithFormatAndLint(localeRegistry.sources[0].content, config$1, generatedNames)]);
6237
- await Promise.all([writeFileSafe(remotePath, remoteContent, disabledFormatAndLint), writeFileSafe(localePath, localeContent, disabledFormatAndLint)]);
6238
- const { conflict, content: mergedContent } = await mergeContent(remotePath, localePath, config$1.indexPath, remoteContent);
6374
+ const name$1 = config$1.indexPath.split("/").at(-1);
6375
+ const data = changes[name$1];
6376
+ if (!("locale" in data && "remote" in data)) return;
6377
+ const remotePath = path$1.join(tempDirPath, `remote-${name$1}`);
6378
+ const localePath = path$1.join(tempDirPath, `locale-${name$1}`);
6379
+ await Promise.all([writeFileSafe(remotePath, data.remote, disabledFormatAndLint), writeFileSafe(localePath, data.locale, disabledFormatAndLint)]);
6380
+ const { conflict, content: mergedContent } = await mergeContent(remotePath, localePath, config$1.indexPath, data.remote);
6239
6381
  await writeFileSafe(config$1.indexPath, mergedContent, conflict ? merge(config$1, disabledFormatAndLint) : config$1);
6240
6382
  if (conflict) {
6241
6383
  conflictMap[componentName] ??= {};
6242
- conflictMap[componentName][fileName] = config$1.indexPath;
6384
+ conflictMap[componentName][name$1] = config$1.indexPath;
6243
6385
  }
6244
- } else await Promise.all(sources.map(async ({ name: name$1, content, data, template }) => {
6245
- const currentPath = getFilePath(section, componentName, name$1, config$1);
6246
- const source = localeRegistry.sources.find((source$1) => source$1.name === name$1);
6247
- if (content) if (source) {
6386
+ } else await Promise.all(Object.entries(changes).map(async ([name$1, { ...data }]) => {
6387
+ const currentPath = path$1.join(dirPath, name$1);
6388
+ if ("locale" in data && "remote" in data) {
6248
6389
  const remotePath = path$1.join(tempDirPath, `remote-${name$1}`);
6249
6390
  const localePath = path$1.join(tempDirPath, `locale-${name$1}`);
6250
- const [remoteContent, localeContent] = await Promise.all([transformContentWithFormatAndLint(currentPath, section, content, config$1, generatedNames), transformContentWithFormatAndLint(currentPath, section, source.content, config$1, generatedNames)]);
6251
- await Promise.all([writeFileSafe(remotePath, remoteContent, disabledFormatAndLint), writeFileSafe(localePath, localeContent, disabledFormatAndLint)]);
6252
- const { conflict, content: mergedContent } = await mergeContent(remotePath, localePath, currentPath, remoteContent);
6391
+ await Promise.all([writeFileSafe(remotePath, data.remote, disabledFormatAndLint), writeFileSafe(localePath, data.locale, disabledFormatAndLint)]);
6392
+ const { conflict, content: mergedContent } = await mergeContent(remotePath, localePath, currentPath, data.remote);
6253
6393
  await writeFileSafe(currentPath, mergedContent, conflict ? merge(config$1, disabledFormatAndLint) : config$1);
6254
6394
  if (conflict) {
6255
6395
  conflictMap[componentName] ??= {};
6256
6396
  conflictMap[componentName][name$1] = currentPath;
6257
6397
  }
6258
- } else {
6259
- const remoteContent = transformContent(section, content, config$1, generatedNames);
6260
- await writeFileSafe(currentPath, remoteContent, config$1);
6261
- }
6262
- else if (template && data) await Promise.all(data.map(async ({ name: fileName,...remoteRest }) => {
6263
- const currentFilePath = path$1.join(currentPath, fileName);
6264
- const localeData = source?.data?.find(({ name: name$2 }) => name$2 === fileName);
6265
- if (localeData) {
6266
- if (template === source.template) return;
6267
- const { name: _name,...localeRest } = localeData;
6268
- const remotePath = path$1.join(tempDirPath, `remote-${name$1}-${fileName}`);
6269
- const localePath = path$1.join(tempDirPath, `locale-${name$1}-${fileName}`);
6270
- const [remoteContent, localeContent] = await Promise.all([transformContentWithFormatAndLint(currentFilePath, section, transformTemplateContent(template, remoteRest), config$1, generatedNames), transformContentWithFormatAndLint(currentFilePath, section, transformTemplateContent(source.template, localeRest), config$1, generatedNames)]);
6271
- await Promise.all([writeFileSafe(remotePath, remoteContent, disabledFormatAndLint), writeFileSafe(localePath, localeContent, disabledFormatAndLint)]);
6272
- const { conflict, content: mergedContent } = await mergeContent(remotePath, localePath, currentFilePath, remoteContent);
6273
- await writeFileSafe(currentFilePath, mergedContent, conflict ? merge(config$1, disabledFormatAndLint) : config$1);
6274
- if (conflict) {
6275
- conflictMap[componentName] ??= {};
6276
- conflictMap[componentName][`${name$1}/${fileName}`] = currentFilePath;
6277
- }
6278
- } else {
6279
- const remoteContent = transformContent(section, transformTemplateContent(template, remoteRest), config$1, generatedNames);
6280
- await writeFileSafe(currentFilePath, remoteContent, config$1);
6281
- }
6282
- }));
6398
+ } else if ("remote" in data) await writeFileSafe(currentPath, data.remote, config$1);
6399
+ else await rimraf(currentPath);
6283
6400
  }));
6401
+ await writeFileSafe(path$1.resolve(dirPath, REGISTRY_FILE_NAME), JSON.stringify(registry), merge(config$1, { format: { parser: "json" } }));
6284
6402
  } catch {} finally {
6285
6403
  await rimraf(tempDirPath);
6286
6404
  }
@@ -6289,7 +6407,7 @@ async function updateFiles(generatedNames, { locale, remote }, config$1, { concu
6289
6407
  title: `Changing ${c.cyan(componentName)}`
6290
6408
  })), { concurrent });
6291
6409
  await tasks.run();
6292
- if (!install && (notInstalledDependencies.length || shouldUninstallDependencies.length)) {
6410
+ if (!install && (add$1.length || remove.length || update$1.length)) {
6293
6411
  const { install: install$1 } = await prompts({
6294
6412
  type: "confirm",
6295
6413
  name: "install",
@@ -6299,8 +6417,10 @@ async function updateFiles(generatedNames, { locale, remote }, config$1, { concu
6299
6417
  if (!install$1) return conflictMap;
6300
6418
  }
6301
6419
  const cwd$3 = config$1.monorepo ? config$1.rootPath : config$1.cwd;
6302
- if (shouldUninstallDependencies.length) await uninstallDependencies(shouldUninstallDependencies.map((value) => splitVersion(value)[0]), { cwd: cwd$3 });
6303
- if (notInstalledDependencies.length) await installDependencies(notInstalledDependencies, { cwd: cwd$3 });
6420
+ remove.push(...update$1.map(({ name: name$1 }) => name$1));
6421
+ add$1.push(...update$1.map(getPackageNameWithVersion));
6422
+ if (remove.length) await uninstallDependencies(remove.map(getPackageName), { cwd: cwd$3 });
6423
+ if (add$1.length) await installDependencies(add$1, { cwd: cwd$3 });
6304
6424
  return conflictMap;
6305
6425
  }
6306
6426
 
@@ -6308,21 +6428,22 @@ async function updateFiles(generatedNames, { locale, remote }, config$1, { concu
6308
6428
  //#region src/commands/diff/get-registries-and-files.ts
6309
6429
  async function getRegistriesAndFiles(componentNames, config$1, { concurrent = true, index = false, theme: theme$1 = false } = {}) {
6310
6430
  const fileMap = {};
6311
- const registries = {
6431
+ const registryMap = {
6312
6432
  locale: {},
6313
6433
  remote: {}
6314
6434
  };
6315
6435
  const tasks = new Listr([], { concurrent });
6316
6436
  if (index) tasks.add([{
6317
6437
  task: async (_, task) => {
6318
- fileMap.index = { "index.ts": await readFile(config$1.indexPath, "utf-8") };
6319
- registries.locale.index = await fetchLocaleRegistry(config$1.registryPath);
6438
+ const indexFileName = transformExtension("index.ts", config$1.jsx);
6439
+ fileMap.index = { [indexFileName]: await readFile(config$1.indexPath, "utf-8") };
6440
+ registryMap.locale.index = await fetchLocaleRegistry(config$1.registryPath);
6320
6441
  task.title = `Got ${c.cyan("index")} file`;
6321
6442
  },
6322
6443
  title: `Getting ${c.cyan("index")} file`
6323
6444
  }, {
6324
6445
  task: async (_, task) => {
6325
- registries.remote.index = await fetchRegistry("index");
6446
+ registryMap.remote.index = await fetchRegistry("index");
6326
6447
  task.title = `Fetched ${c.cyan("index")} registry`;
6327
6448
  },
6328
6449
  title: `Fetching ${c.cyan("index")} registry`
@@ -6332,13 +6453,13 @@ async function getRegistriesAndFiles(componentNames, config$1, { concurrent = tr
6332
6453
  if (!config$1.theme?.path) return;
6333
6454
  const { dirPath, files: files$1 } = await getFiles(config$1.theme.path);
6334
6455
  fileMap.theme = files$1;
6335
- registries.locale.theme = await fetchLocaleRegistry(path$1.join(dirPath, REGISTRY_FILE_NAME));
6456
+ registryMap.locale.theme = await fetchLocaleRegistry(path$1.join(dirPath, REGISTRY_FILE_NAME));
6336
6457
  task.title = `Got ${c.cyan("theme")} files`;
6337
6458
  },
6338
6459
  title: `Getting ${c.cyan("theme")} files`
6339
6460
  }, {
6340
6461
  task: async (_, task) => {
6341
- registries.remote.theme = await fetchRegistry("theme");
6462
+ registryMap.remote.theme = await fetchRegistry("theme");
6342
6463
  task.title = `Fetched ${c.cyan("theme")} registry`;
6343
6464
  },
6344
6465
  title: `Fetching ${c.cyan("theme")} registry`
@@ -6347,13 +6468,13 @@ async function getRegistriesAndFiles(componentNames, config$1, { concurrent = tr
6347
6468
  task: async (_, task) => {
6348
6469
  const { dirPath, files: files$1 } = await getFiles(path$1.join(config$1.srcPath, "**", componentName));
6349
6470
  fileMap[componentName] = files$1;
6350
- registries.locale[componentName] = await fetchLocaleRegistry(path$1.join(dirPath, REGISTRY_FILE_NAME));
6471
+ registryMap.locale[componentName] = await fetchLocaleRegistry(path$1.join(dirPath, REGISTRY_FILE_NAME));
6351
6472
  task.title = `Got ${c.cyan(componentName)} files`;
6352
6473
  },
6353
6474
  title: `Getting ${c.cyan(componentName)} files`
6354
6475
  }, {
6355
6476
  task: async (_, task) => {
6356
- registries.remote[componentName] = await fetchRegistry(componentName);
6477
+ registryMap.remote[componentName] = await fetchRegistry(componentName);
6357
6478
  task.title = `Fetched ${c.cyan(componentName)} registry`;
6358
6479
  },
6359
6480
  title: `Fetching ${c.cyan(componentName)} registry`
@@ -6361,41 +6482,57 @@ async function getRegistriesAndFiles(componentNames, config$1, { concurrent = tr
6361
6482
  await tasks.run();
6362
6483
  return {
6363
6484
  fileMap,
6364
- registries
6485
+ registryMap
6365
6486
  };
6366
6487
  }
6367
6488
 
6368
6489
  //#endregion
6369
6490
  //#region src/commands/diff/print-diff.ts
6370
- function printDiff(diff$1, detail = false) {
6371
- if (!diff$1) return;
6372
- Object.entries(diff$1).forEach(([fileName, diff$2]) => {
6491
+ function printDiff(changes, detail = false) {
6492
+ if (!changes) return;
6493
+ Object.entries(changes).forEach(([fileName, { diff: diff$1 }]) => {
6373
6494
  console.log(`- ${c.cyan(fileName)}`);
6374
6495
  console.log("");
6375
- diff$2.forEach(({ added, removed, value }) => {
6496
+ diff$1.forEach(({ added, removed, value }) => {
6376
6497
  if (added) return process.stdout.write(c.green(value));
6377
6498
  else if (removed) return process.stdout.write(c.red(value));
6378
6499
  else if (detail) return process.stdout.write(value);
6379
6500
  });
6380
6501
  });
6381
6502
  }
6382
- function printDiffFiles(name$1, diff$1) {
6383
- if (!diff$1) return;
6503
+ function printDiffFiles(name$1, changes) {
6504
+ if (!changes) return;
6384
6505
  console.log(`- ${name$1}`);
6385
- Object.entries(diff$1).forEach(([fileName, changes]) => {
6386
- printDiffFile(fileName, changes, " ");
6506
+ Object.entries(changes).forEach(([fileName, { diff: diff$1 }]) => {
6507
+ printDiffFile(fileName, diff$1, " ");
6387
6508
  });
6388
6509
  }
6389
- function printDiffFile(name$1, changes = [], space = "") {
6390
- const added = changes.reduce((prev, { added: added$1, count }) => {
6510
+ function printDiffFile(name$1, diff$1 = [], space = "") {
6511
+ const added = diff$1.reduce((prev, { added: added$1, count }) => {
6391
6512
  if (added$1) return prev + count;
6392
6513
  return prev;
6393
6514
  }, 0);
6394
- const removed = changes.reduce((prev, { count, removed: removed$1 }) => {
6515
+ const removed = diff$1.reduce((prev, { count, removed: removed$1 }) => {
6395
6516
  if (removed$1) return prev + count;
6396
6517
  return prev;
6397
6518
  }, 0);
6398
- console.log(`${space}- ${c.cyan(name$1)} ${c.green(added)} insertions ${c.red(removed)} deletions`);
6519
+ if (!added && !removed) return;
6520
+ const result = [`${space}- ${c.cyan(name$1)}`];
6521
+ if (added) result.push(`${c.green(added)} insertions`);
6522
+ if (removed) result.push(`${c.red(removed)} deletions`);
6523
+ console.log(result.join(" "));
6524
+ }
6525
+ function printDiffDependencies({ add: add$1, remove, update: update$1 }) {
6526
+ console.log("- dependencies");
6527
+ if (add$1.length) add$1.forEach((name$1) => {
6528
+ console.log(` - ${c.green(getPackageName(name$1))}`);
6529
+ });
6530
+ if (remove.length) remove.forEach((name$1) => {
6531
+ console.log(` - ${c.red(getPackageName(name$1))}`);
6532
+ });
6533
+ if (update$1.length) update$1.forEach(({ name: name$1, current, wanted }) => {
6534
+ console.log(` - ${name$1}@${c.red(current)}->${c.green(wanted)}`);
6535
+ });
6399
6536
  }
6400
6537
 
6401
6538
  //#endregion
@@ -6443,24 +6580,29 @@ const diff = new Command("diff").description("check for updates against the regi
6443
6580
  `Please run ${getCommand("add")} ${c.green("<component>")}`,
6444
6581
  "to add components."
6445
6582
  ].join(" "));
6446
- const { registries } = await getRegistriesAndFiles(componentNames, config$1, {
6583
+ const { registryMap } = await getRegistriesAndFiles(componentNames, config$1, {
6447
6584
  concurrent: !sequential,
6448
6585
  index,
6449
6586
  theme: theme$1
6450
6587
  });
6451
- const changes = await getDiff(generatedNames, registries, config$1, !sequential);
6452
- const hasChanges = Object.keys(changes).length;
6588
+ const { changeMap, dependencyMap } = await getDiff(generatedNames, registryMap, config$1, !sequential);
6589
+ const hasChanges = !!Object.keys(changeMap).length;
6590
+ const hasDependencyChanges = !!dependencyMap.add.length || !!dependencyMap.remove.length || !!dependencyMap.update.length;
6453
6591
  console.log("---------------------------------");
6454
- if (!hasChanges) console.log(c.cyan("No updates found."));
6592
+ if (!hasChanges && !hasDependencyChanges) console.log(c.cyan("No updates found."));
6455
6593
  else {
6456
- if (targetName) printDiff(changes[targetName], detail);
6594
+ if (targetName) printDiff(changeMap[targetName], detail);
6457
6595
  else {
6458
- if (index) printDiffFile("index.ts", changes.index?.["index.ts"]);
6459
- if (theme$1) printDiffFiles("theme", changes.theme);
6596
+ if (index && changeMap.index) {
6597
+ const indexFileName = transformExtension("index.ts", config$1.jsx);
6598
+ printDiffFile(indexFileName, changeMap.index[indexFileName]?.diff);
6599
+ }
6600
+ if (theme$1 && changeMap.theme) printDiffFiles("theme", changeMap.theme);
6460
6601
  componentNames.forEach((name$1) => {
6461
- printDiffFiles(name$1, changes[name$1]);
6602
+ printDiffFiles(name$1, changeMap[name$1]);
6462
6603
  });
6463
6604
  }
6605
+ if (hasDependencyChanges) printDiffDependencies(dependencyMap);
6464
6606
  console.log("---------------------------------");
6465
6607
  const { update: update$1 } = await prompts({
6466
6608
  type: "confirm",
@@ -6469,12 +6611,7 @@ const diff = new Command("diff").description("check for updates against the regi
6469
6611
  message: c.reset("Do you want to update the files?")
6470
6612
  });
6471
6613
  if (update$1) {
6472
- const changeNames = Object.keys(changes);
6473
- const omittedRegistries = {
6474
- locale: Object.fromEntries(Object.entries(registries.locale).filter(([name$1]) => changeNames.includes(name$1))),
6475
- remote: Object.fromEntries(Object.entries(registries.remote).filter(([name$1]) => changeNames.includes(name$1)))
6476
- };
6477
- const conflictMap = await updateFiles(generatedNames, omittedRegistries, config$1, { concurrent: !sequential });
6614
+ const conflictMap = await updateFiles(changeMap, dependencyMap, registryMap, config$1, { concurrent: !sequential });
6478
6615
  if (Object.keys(conflictMap).length) {
6479
6616
  console.log("---------------------------------");
6480
6617
  spinner.warn("There are conflicts. Please check the following files:");
@@ -6491,11 +6628,12 @@ const diff = new Command("diff").description("check for updates against the regi
6491
6628
 
6492
6629
  //#endregion
6493
6630
  //#region src/commands/init/index.ts
6494
- 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 }) {
6631
+ 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).option("-j, --jsx", "use jsx instead of tsx", false).action(async function({ config: configPath, cwd: cwd$3, jsx, overwrite }) {
6495
6632
  const spinner = ora();
6496
6633
  try {
6497
6634
  const { end } = timer();
6498
6635
  await validateDir(cwd$3);
6636
+ const indexFileName = transformExtension("index.ts", jsx);
6499
6637
  const configFileName = configPath.includes("/") ? configPath.split("/").at(-1) : configPath;
6500
6638
  const config$1 = { ...DEFAULT_CONFIG };
6501
6639
  configPath = path$1.resolve(cwd$3, configPath);
@@ -6551,7 +6689,8 @@ const init = new Command("init").description("initialize your project and instal
6551
6689
  outdir ||= monorepo ? DEFAULT_PATH.monorepo : DEFAULT_PATH.polyrepo;
6552
6690
  packageName = packageName.replace(/\x17/g, "").trim();
6553
6691
  packageName ||= DEFAULT_PACKAGE_NAME;
6554
- config$1.monorepo = monorepo;
6692
+ if (monorepo) config$1.monorepo = monorepo;
6693
+ if (jsx) config$1.jsx = jsx;
6555
6694
  config$1.path = outdir;
6556
6695
  config$1.format = { enabled: format$2 };
6557
6696
  config$1.lint = { enabled: lint };
@@ -6601,31 +6740,24 @@ const init = new Command("init").description("initialize your project and instal
6601
6740
  const targetPath = path$1.resolve(outdirPath, "package.json");
6602
6741
  const content = JSON.stringify({
6603
6742
  name: packageName,
6604
- ...DEFAULT_PACKAGE_JSON
6743
+ ...DEFAULT_PACKAGE_JSON,
6744
+ exports: DEFAULT_PACKAGE_JSON_EXPORTS[jsx ? "JSX" : "TSX"]
6605
6745
  });
6606
6746
  await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
6607
6747
  task.title = `Generated ${c.cyan("package.json")}`;
6608
6748
  },
6609
6749
  title: `Generating ${c.cyan("package.json")}`
6610
6750
  },
6611
- {
6612
- task: async (_, task) => {
6613
- const targetPath = path$1.resolve(outdirPath, "tsconfig.json");
6614
- const content = JSON.stringify({ ...TSCONFIG_JSON });
6615
- await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
6616
- task.title = `Generated ${c.cyan("tsconfig.json")}`;
6617
- },
6618
- title: `Generating ${c.cyan("tsconfig.json")}`
6619
- },
6620
6751
  {
6621
6752
  task: async (_, task) => {
6622
6753
  const targetPath = path$1.resolve(outdirPath, src ? "src" : "");
6623
6754
  const registry = await fetchRegistry("index");
6624
- const content = registry.sources[0].content;
6625
- await Promise.all([writeFileSafe(path$1.join(targetPath, "index.ts"), content, config$1), writeFileSafe(path$1.join(targetPath, REGISTRY_FILE_NAME), JSON.stringify(registry), merge(config$1, { format: { parser: "json" } }))]);
6626
- task.title = `Generated ${c.cyan("index.ts")}`;
6755
+ let content = registry.sources[0].content;
6756
+ if (jsx) content = transformTsToJs(content);
6757
+ await Promise.all([writeFileSafe(path$1.join(targetPath, indexFileName), content, config$1), writeFileSafe(path$1.join(targetPath, REGISTRY_FILE_NAME), JSON.stringify(registry), merge(config$1, { format: { parser: "json" } }))]);
6758
+ task.title = `Generated ${c.cyan(indexFileName)}`;
6627
6759
  },
6628
- title: `Generating ${c.cyan("index.ts")}`
6760
+ title: `Generating ${c.cyan(indexFileName)}`
6629
6761
  },
6630
6762
  {
6631
6763
  task: async (_, task) => {
@@ -6638,6 +6770,15 @@ const init = new Command("init").description("initialize your project and instal
6638
6770
  title: "Adding workspace"
6639
6771
  }
6640
6772
  ], { concurrent: true });
6773
+ if (!jsx) tasks.add({
6774
+ task: async (_, task) => {
6775
+ const targetPath = path$1.resolve(outdirPath, "tsconfig.json");
6776
+ const content = JSON.stringify({ ...TSCONFIG_JSON });
6777
+ await writeFileSafe(targetPath, content, merge(config$1, { format: { parser: "json" } }));
6778
+ task.title = `Generated ${c.cyan("tsconfig.json")}`;
6779
+ },
6780
+ title: `Generating ${c.cyan("tsconfig.json")}`
6781
+ });
6641
6782
  await tasks.run();
6642
6783
  const { install } = await prompts({
6643
6784
  type: "confirm",
@@ -6660,11 +6801,12 @@ const init = new Command("init").description("initialize your project and instal
6660
6801
  }, {
6661
6802
  task: async (_, task) => {
6662
6803
  const registry = await fetchRegistry("index");
6663
- const content = registry.sources[0].content;
6664
- await Promise.all([writeFileSafe(path$1.resolve(outdirPath, "index.ts"), content, config$1), writeFileSafe(path$1.resolve(outdirPath, REGISTRY_FILE_NAME), JSON.stringify(registry), merge(config$1, { format: { parser: "json" } }))]);
6665
- task.title = `Generated ${c.cyan("index.ts")}`;
6804
+ let content = registry.sources[0].content;
6805
+ if (jsx) content = transformTsToJs(content);
6806
+ await Promise.all([writeFileSafe(path$1.resolve(outdirPath, indexFileName), content, config$1), writeFileSafe(path$1.resolve(outdirPath, REGISTRY_FILE_NAME), JSON.stringify(registry), merge(config$1, { format: { parser: "json" } }))]);
6807
+ task.title = `Generated ${c.cyan(indexFileName)}`;
6666
6808
  },
6667
- title: `Generating ${c.cyan("index.ts")}`
6809
+ title: `Generating ${c.cyan(indexFileName)}`
6668
6810
  }], { concurrent: true });
6669
6811
  await tasks.run();
6670
6812
  if (notInstalledDependencies.length || notInstalledDevDependencies.length) {
@@ -6676,8 +6818,8 @@ const init = new Command("init").description("initialize your project and instal
6676
6818
  message: c.reset([`The following dependencies are not installed: ${colorizedNames.join(", ")}.`, "Do you want to install them?"].join(" "))
6677
6819
  });
6678
6820
  if (install) {
6679
- dependencies$1 = notInstalledDependencies.map(getPackageName);
6680
- devDependencies$1 = notInstalledDevDependencies.map(getPackageName);
6821
+ dependencies$1 = notInstalledDependencies.map(getPackageNameWithVersion);
6822
+ devDependencies$1 = notInstalledDevDependencies.map(getPackageNameWithVersion);
6681
6823
  }
6682
6824
  }
6683
6825
  }
@@ -6715,7 +6857,7 @@ const init = new Command("init").description("initialize your project and instal
6715
6857
 
6716
6858
  //#endregion
6717
6859
  //#region src/commands/theme/index.ts
6718
- const theme = new Command("theme").description("generate theme to your project").argument("[path]", "path to the theme directory").option("--cwd <path>", "current working directory", cwd).option("-c, --config <path>", "path to the config file", CONFIG_FILE_NAME).option("-o, --overwrite", "overwrite existing directory.", false).option("-f, --format", "format the output files.").option("-l, --lint", "lint the output files.").action(async function(themePath, { config: configPath, cwd: cwd$3, format: format$2, lint, overwrite }) {
6860
+ const theme = new Command("theme").description("generate theme to your project").argument("[path]", "path to the theme directory").option("--cwd <path>", "current working directory", cwd).option("-c, --config <path>", "path to the config file", CONFIG_FILE_NAME).option("-o, --overwrite", "overwrite existing directory.", false).option("-j, --js", "use js instead of ts").option("-f, --format", "format the output files.").option("-l, --lint", "lint the output files.").action(async function(themePath, { config: configPath, cwd: cwd$3, format: format$2, js, lint, overwrite }) {
6719
6861
  const spinner = ora();
6720
6862
  try {
6721
6863
  const { end } = timer();
@@ -6725,11 +6867,12 @@ const theme = new Command("theme").description("generate theme to your project")
6725
6867
  spinner.start("Fetching config");
6726
6868
  const config$1 = await getConfig(cwd$3, configPath, {
6727
6869
  format: format$2,
6870
+ jsx: js,
6728
6871
  lint
6729
6872
  });
6730
- const themeAbsolutePath = themePath ? path$1.resolve(cwd$3, themePath) : config$1.theme?.path ?? path$1.resolve(cwd$3, THEME_PATH);
6873
+ const resolvedPath = themePath ? path$1.resolve(cwd$3, themePath) : config$1.theme?.path ?? path$1.resolve(cwd$3, THEME_PATH);
6731
6874
  spinner.succeed("Fetched config");
6732
- if (!overwrite && existsSync(themeAbsolutePath)) {
6875
+ if (!overwrite && existsSync(resolvedPath)) {
6733
6876
  const { overwrite: overwrite$1 } = await prompts({
6734
6877
  type: "confirm",
6735
6878
  name: "overwrite",
@@ -6738,7 +6881,7 @@ const theme = new Command("theme").description("generate theme to your project")
6738
6881
  });
6739
6882
  if (!overwrite$1) process.exit(0);
6740
6883
  spinner.start("Clearing directory");
6741
- await rimraf(themeAbsolutePath);
6884
+ await rimraf(resolvedPath);
6742
6885
  spinner.succeed("Cleared directory");
6743
6886
  }
6744
6887
  spinner.start("Fetching registry");
@@ -6748,9 +6891,11 @@ const theme = new Command("theme").description("generate theme to your project")
6748
6891
  task: async (_, task) => {
6749
6892
  await Promise.all([...registry.sources.map(async ({ name: name$1, content }) => {
6750
6893
  if (!content) return;
6751
- const targetPath = path$1.resolve(themeAbsolutePath, name$1);
6894
+ name$1 = transformExtension(name$1, config$1.jsx);
6895
+ const targetPath = path$1.resolve(resolvedPath, name$1);
6896
+ if (config$1.jsx) content = isTsx(name$1) ? transformTsxToJsx(content) : transformTsToJs(content);
6752
6897
  await writeFileSafe(targetPath, content, config$1);
6753
- }), writeFileSafe(path$1.resolve(themeAbsolutePath, REGISTRY_FILE_NAME), JSON.stringify(registry), merge(config$1, { format: { parser: "json" } }))]);
6898
+ }), writeFileSafe(path$1.resolve(resolvedPath, REGISTRY_FILE_NAME), JSON.stringify(registry), merge(config$1, { format: { parser: "json" } }))]);
6754
6899
  task.title = `Generated theme`;
6755
6900
  },
6756
6901
  title: `Generating theme`
@@ -7056,22 +7201,18 @@ const update = new Command("update").description("update components in your proj
7056
7201
  ].join(" "));
7057
7202
  else componentNames.push(...omittedTargetNames);
7058
7203
  } else if (all || !index && !theme$1) componentNames.push(...generatedNames);
7059
- const { registries } = await getRegistriesAndFiles(componentNames, config$1, {
7204
+ const { registryMap } = await getRegistriesAndFiles(componentNames, config$1, {
7060
7205
  concurrent: !sequential,
7061
7206
  index,
7062
7207
  theme: theme$1
7063
7208
  });
7064
- const changes = await getDiff(generatedNames, registries, config$1, !sequential);
7065
- const hasChanges = Object.keys(changes).length;
7209
+ const { changeMap, dependencyMap } = await getDiff(generatedNames, registryMap, config$1, !sequential);
7210
+ const hasChanges = !!Object.keys(changeMap).length;
7211
+ const hasDependencyChanges = !!dependencyMap.add.length || !!dependencyMap.remove.length || !!dependencyMap.update.length;
7066
7212
  console.log("---------------------------------");
7067
- if (!hasChanges) console.log(c.cyan("No updates found."));
7213
+ if (!hasChanges && !hasDependencyChanges) console.log(c.cyan("No updates found."));
7068
7214
  else {
7069
- const changeNames = Object.keys(changes);
7070
- const omittedRegistries = {
7071
- locale: Object.fromEntries(Object.entries(registries.locale).filter(([name$1]) => changeNames.includes(name$1))),
7072
- remote: Object.fromEntries(Object.entries(registries.remote).filter(([name$1]) => changeNames.includes(name$1)))
7073
- };
7074
- const conflictMap = await updateFiles(generatedNames, omittedRegistries, config$1, {
7215
+ const conflictMap = await updateFiles(changeMap, dependencyMap, registryMap, config$1, {
7075
7216
  concurrent: !sequential,
7076
7217
  install
7077
7218
  });
@@ -7090,9 +7231,8 @@ const update = new Command("update").description("update components in your proj
7090
7231
 
7091
7232
  //#endregion
7092
7233
  //#region src/index.ts
7093
- async function run() {
7234
+ function run() {
7094
7235
  checkNode("22");
7095
- await unhandledError();
7096
7236
  updateNotifier({
7097
7237
  pkg: package_default,
7098
7238
  shouldNotifyInNpmScript: true,
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-20250823155214",
4
+ "version": "2.0.0-dev-20250825083810",
5
5
  "description": "The official CLI for Yamada UI projects",
6
6
  "keywords": [
7
7
  "theme",
@@ -38,7 +38,6 @@
38
38
  "dependencies": {
39
39
  "boxen": "^8.0.1",
40
40
  "cli-check-node": "^1.3.4",
41
- "cli-handle-unhandled": "^1.1.2",
42
41
  "commander": "^14.0.0",
43
42
  "diff": "^8.0.2",
44
43
  "esbuild": "^0.25.8",
@@ -55,6 +54,7 @@
55
54
  "prompts": "^2.4.2",
56
55
  "rimraf": "^6.0.1",
57
56
  "semver": "^7.7.2",
57
+ "sucrase": "^3.35.0",
58
58
  "validate-npm-package-name": "^6.0.2",
59
59
  "yamljs": "^0.3.0",
60
60
  "@yamada-ui/utils": "2.0.0"