@yamada-ui/cli 1.2.1 → 1.2.2-dev-20241010144848

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.
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // ../../node_modules/.pnpm/tsup@8.3.0_@swc+core@1.7.26_@swc+helpers@0.5.5__jiti@2.0.0_postcss@8.4.47_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
33
+ // ../../node_modules/.pnpm/tsup@8.3.0_@swc+core@1.7.26_@swc+helpers@0.5.5__jiti@2.3.3_postcss@8.4.47_tsx@4.19.1_typescript@5.6.3_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
34
34
  var init_cjs_shims = __esm({
35
- "../../node_modules/.pnpm/tsup@8.3.0_@swc+core@1.7.26_@swc+helpers@0.5.5__jiti@2.0.0_postcss@8.4.47_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js"() {
35
+ "../../node_modules/.pnpm/tsup@8.3.0_@swc+core@1.7.26_@swc+helpers@0.5.5__jiti@2.3.3_postcss@8.4.47_tsx@4.19.1_typescript@5.6.3_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js"() {
36
36
  "use strict";
37
37
  }
38
38
  });
@@ -47,10 +47,8 @@ __export(command_exports, {
47
47
  module.exports = __toCommonJS(command_exports);
48
48
  init_cjs_shims();
49
49
 
50
- // src/command/tokens/index.ts
50
+ // src/command/theme/index.ts
51
51
  init_cjs_shims();
52
- var import_promises = require("fs/promises");
53
- var import_path3 = __toESM(require("path"));
54
52
  var p = __toESM(require("@clack/prompts"));
55
53
 
56
54
  // ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
@@ -548,14 +546,63 @@ var chalk = createChalk();
548
546
  var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
549
547
  var source_default = chalk;
550
548
 
551
- // src/command/tokens/index.ts
552
- var import_chokidar = __toESM(require("chokidar"));
549
+ // src/command/theme/index.ts
550
+ var import_dns = __toESM(require("dns"));
551
+ var import_fs3 = require("fs");
552
+ var import_promises = require("fs/promises");
553
+ var import_node_stream = require("stream");
554
+ var import_promises2 = require("stream/promises");
555
+ var import_path2 = __toESM(require("path"));
556
+ var import_tar = require("tar");
557
+ var import_typescript = require("typescript");
553
558
 
554
559
  // src/utils/assertion.ts
555
560
  init_cjs_shims();
556
561
  var isObject = (obj) => obj !== null && (typeof obj === "object" || typeof obj === "function") && !isArray(obj);
557
562
  var isArray = (value) => Array.isArray(value);
558
563
 
564
+ // src/utils/module.ts
565
+ init_cjs_shims();
566
+ var import_esbuild = require("esbuild");
567
+ var import_fs = require("fs");
568
+ var import_node_eval = __toESM(require("node-eval"));
569
+ var import_vm = require("vm");
570
+ var getModule = async (file, cwd) => {
571
+ const result = await (0, import_esbuild.build)({
572
+ absWorkingDir: cwd,
573
+ bundle: true,
574
+ entryPoints: [file],
575
+ format: "cjs",
576
+ mainFields: ["module", "main"],
577
+ metafile: true,
578
+ outfile: "out.js",
579
+ platform: "node",
580
+ sourcemap: false,
581
+ write: false
582
+ });
583
+ const { text: code } = result.outputFiles[0] ?? {};
584
+ const dependencies = isObject(result.metafile) ? Object.keys(result.metafile.inputs) : [];
585
+ try {
586
+ const realFileName = import_fs.realpathSync.native(file);
587
+ if (!code) throw new Error("code is undefined");
588
+ const script = new import_vm.Script(code, { filename: realFileName });
589
+ const mod = { exports: {} };
590
+ const require2 = (id) => id === realFileName ? mod.exports : require2(id);
591
+ script.runInThisContext()(mod.exports, require2, mod);
592
+ return { code, dependencies, mod };
593
+ } catch {
594
+ const mod = (0, import_node_eval.default)(code);
595
+ return { code, dependencies, mod };
596
+ }
597
+ };
598
+
599
+ // src/utils/object.ts
600
+ init_cjs_shims();
601
+ var getObject = (obj, path5) => {
602
+ const keys = path5.split(".");
603
+ return keys.reduce((obj2, key) => obj2[key] ?? {}, obj);
604
+ };
605
+
559
606
  // src/utils/prettier.ts
560
607
  init_cjs_shims();
561
608
  var import_path = __toESM(require("path"));
@@ -575,47 +622,233 @@ var prettier = async (content, options) => {
575
622
  }
576
623
  };
577
624
 
578
- // src/utils/object.ts
625
+ // src/utils/fs.ts
579
626
  init_cjs_shims();
580
- var getObject = (obj, path5) => {
581
- const keys = path5.split(".");
582
- return keys.reduce((obj2, key) => obj2[key] ?? {}, obj);
627
+ var import_fs2 = __toESM(require("fs"));
628
+ var isWriteable = async (directory) => {
629
+ try {
630
+ await import_fs2.default.promises.access(
631
+ directory,
632
+ ("constants" in import_fs2.default ? import_fs2.default.constants : import_fs2.default).W_OK
633
+ );
634
+ return true;
635
+ } catch {
636
+ return false;
637
+ }
583
638
  };
584
639
 
585
- // src/utils/module.ts
586
- init_cjs_shims();
587
- var import_fs = require("fs");
588
- var import_vm = require("vm");
589
- var import_esbuild = require("esbuild");
590
- var import_node_eval = __toESM(require("node-eval"));
591
- var getModule = async (file, cwd) => {
592
- const result = await (0, import_esbuild.build)({
593
- platform: "node",
594
- format: "cjs",
595
- mainFields: ["module", "main"],
596
- absWorkingDir: cwd,
597
- entryPoints: [file],
598
- outfile: "out.js",
599
- write: false,
600
- bundle: true,
601
- sourcemap: false,
602
- metafile: true
640
+ // src/command/theme/index.ts
641
+ var ORG_NAME = "yamada-ui";
642
+ var REPO_NAME = "yamada-ui";
643
+ var DEFAULT_BRANCH_NAME = "main";
644
+ var isOnline = async () => {
645
+ return new Promise((resolve) => {
646
+ import_dns.default.lookup("github.com", (err) => {
647
+ if (err && err.code === "ENOTFOUND") {
648
+ resolve(false);
649
+ } else {
650
+ resolve(true);
651
+ }
652
+ });
603
653
  });
604
- const { text: code } = result.outputFiles[0];
605
- const dependencies = result.metafile ? Object.keys(result.metafile.inputs) : [];
654
+ };
655
+ var checkHasReact = async (cwd) => {
606
656
  try {
607
- const realFileName = import_fs.realpathSync.native(file);
608
- const script = new import_vm.Script(code, { filename: realFileName });
609
- const mod = { exports: {} };
610
- const require2 = (id) => id === realFileName ? mod.exports : require2(id);
611
- script.runInThisContext()(mod.exports, require2, mod);
612
- return { mod, code, dependencies };
657
+ const packageJson = await (0, import_promises.readFile)(import_path2.default.join(cwd, "package.json"), "utf-8");
658
+ const { dependencies, devDependencies } = JSON.parse(packageJson);
659
+ return !!dependencies?.["@yamada-ui/react"] || !!devDependencies?.["@yamada-ui/react"];
613
660
  } catch {
614
- const mod = (0, import_node_eval.default)(code);
615
- return { mod, code, dependencies };
661
+ return false;
662
+ }
663
+ };
664
+ var getSource = async (branch) => {
665
+ if (!await isOnline()) {
666
+ throw new Error(
667
+ "No internet connection, please check your connection and try again."
668
+ );
669
+ }
670
+ const url = `https://codeload.github.com/${ORG_NAME}/${REPO_NAME}/tar.gz/${branch}`;
671
+ const { body } = await fetch(url);
672
+ if (!body) throw new Error(`Failed to download: ${url}`);
673
+ return import_node_stream.Readable.fromWeb(body);
674
+ };
675
+ var getFileMap = async (cwd, branch) => {
676
+ const source = await getSource(branch);
677
+ const fileMap = /* @__PURE__ */ new Map();
678
+ const targetPath = `${REPO_NAME}-${branch.replace("/", "-")}/packages/theme/src`;
679
+ const filter = (path5) => {
680
+ return path5.startsWith(targetPath);
681
+ };
682
+ const onReadEntry = (entry) => {
683
+ if (entry.type !== "Directory") {
684
+ const filePath = entry.path.replace(`${targetPath}/`, "");
685
+ let content = "";
686
+ entry.on("data", (chunk) => {
687
+ content += chunk.toString();
688
+ });
689
+ entry.on("end", () => {
690
+ fileMap.set(filePath, content);
691
+ });
692
+ }
693
+ };
694
+ await (0, import_promises2.pipeline)(
695
+ source,
696
+ (0, import_tar.t)({
697
+ cwd,
698
+ filter,
699
+ newer: true,
700
+ strip: 4,
701
+ onReadEntry
702
+ })
703
+ );
704
+ return fileMap;
705
+ };
706
+ var transformSourceFile = (sourceFile) => {
707
+ const ImportDeclarations = [];
708
+ const ImportTypeDeclarations = [];
709
+ const transformer = (context) => (sourceFile2) => {
710
+ const visitor = (node) => {
711
+ if ((0, import_typescript.isImportDeclaration)(node)) {
712
+ const moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);
713
+ if (moduleSpecifier.startsWith("@yamada-ui/")) {
714
+ if (node.importClause?.isTypeOnly) {
715
+ ImportTypeDeclarations.push(node);
716
+ } else {
717
+ ImportDeclarations.push(node);
718
+ }
719
+ return import_typescript.factory.createEmptyStatement();
720
+ }
721
+ }
722
+ return (0, import_typescript.visitEachChild)(node, visitor, context);
723
+ };
724
+ return (0, import_typescript.visitNode)(sourceFile2, visitor);
725
+ };
726
+ const { transformed } = (0, import_typescript.transform)(sourceFile, [transformer]);
727
+ const transformedSourceFile = transformed[0];
728
+ return { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile };
729
+ };
730
+ var createImportDeclaration = (isTypeOnly, declarations) => {
731
+ const elements = declarations.flatMap(
732
+ ({ importClause: importClause2 }) => importClause2?.namedBindings && (0, import_typescript.isNamedImports)(importClause2.namedBindings) ? importClause2.namedBindings.elements : []
733
+ );
734
+ const namedBindings = import_typescript.factory.createNamedImports(elements);
735
+ const importClause = import_typescript.factory.createImportClause(
736
+ isTypeOnly,
737
+ void 0,
738
+ namedBindings
739
+ );
740
+ return import_typescript.factory.createImportDeclaration(
741
+ void 0,
742
+ importClause,
743
+ import_typescript.factory.createStringLiteral("@yamada-ui/react")
744
+ );
745
+ };
746
+ var replaceContent = (content) => {
747
+ const sourceFile = (0, import_typescript.createSourceFile)(
748
+ "temp.ts",
749
+ content,
750
+ import_typescript.ScriptTarget.Latest,
751
+ true
752
+ );
753
+ const printer = (0, import_typescript.createPrinter)({ newLine: import_typescript.NewLineKind.LineFeed });
754
+ const { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile } = transformSourceFile(sourceFile);
755
+ const statements = [...transformedSourceFile.statements];
756
+ if (ImportTypeDeclarations.length) {
757
+ const newImportTypeDeclarations = createImportDeclaration(
758
+ true,
759
+ ImportTypeDeclarations
760
+ );
761
+ statements.unshift(newImportTypeDeclarations);
762
+ }
763
+ if (ImportDeclarations.length) {
764
+ const newImportDeclarations = createImportDeclaration(
765
+ false,
766
+ ImportDeclarations
767
+ );
768
+ statements.unshift(newImportDeclarations);
769
+ }
770
+ const updatedSourceFile = import_typescript.factory.updateSourceFile(
771
+ transformedSourceFile,
772
+ statements
773
+ );
774
+ let printedContent = printer.printFile(updatedSourceFile);
775
+ printedContent = printedContent.replace(/^;$/gm, "");
776
+ printedContent = printedContent.replace(/\s\n*(?=import)/g, "");
777
+ printedContent = printedContent.replace(/(import .*\n)+(?!import)/, "$&\n");
778
+ return printedContent;
779
+ };
780
+ var replaceIndex = (content) => {
781
+ const index = content.indexOf("export const baseTheme");
782
+ content = content.slice(0, index);
783
+ content = content.replace(/export const baseTheme/, "export const theme");
784
+ content = content.replace(/\nimport { config } from ".\/config"/, "");
785
+ content += "\nexport { config } from './config'";
786
+ return content;
787
+ };
788
+ var generateTheme = async (outPath, fileMap, isReactReplace, isForceReplace) => {
789
+ if (!await isWriteable(import_path2.default.dirname(outPath))) {
790
+ throw new Error(
791
+ "The provided path is not writable, please check folder permissions and try again. It is likely you do not have write permissions for this folder."
792
+ );
793
+ }
794
+ await (0, import_promises.mkdir)(outPath, { recursive: true });
795
+ await Promise.all(
796
+ [...fileMap.entries()].map(async ([filePath, _content]) => {
797
+ const targetPath = import_path2.default.join(outPath, filePath);
798
+ let content = _content;
799
+ if (filePath === "index.ts") {
800
+ content = replaceIndex(content);
801
+ } else {
802
+ if (isReactReplace) content = replaceContent(content);
803
+ }
804
+ const formattedContent = await prettier(content);
805
+ try {
806
+ if (!isForceReplace && (0, import_fs3.existsSync)(targetPath)) return;
807
+ await (0, import_promises.writeFile)(targetPath, formattedContent, "utf-8");
808
+ } catch (e) {
809
+ if (e instanceof Error && "code" in e && e.code === "ENOENT") {
810
+ const dirPath = import_path2.default.dirname(targetPath);
811
+ await (0, import_promises.mkdir)(dirPath, { recursive: true });
812
+ if (!isForceReplace && (0, import_fs3.existsSync)(targetPath)) return;
813
+ await (0, import_promises.writeFile)(targetPath, formattedContent, "utf-8");
814
+ }
815
+ }
816
+ })
817
+ );
818
+ };
819
+ var actionTheme = async (_outPath, { branch = DEFAULT_BRANCH_NAME, cwd, replace = false }) => {
820
+ p.intro(source_default.magenta(`Generating Yamada UI theme`));
821
+ const s = p.spinner();
822
+ try {
823
+ const start = process.hrtime.bigint();
824
+ cwd ??= import_path2.default.resolve();
825
+ const outPath = import_path2.default.join(cwd, _outPath);
826
+ s.start(`Checking "package.json"`);
827
+ const hasReact = await checkHasReact(cwd);
828
+ s.stop(`Checked "package.json"`);
829
+ s.start(`Downloading the theme`);
830
+ const fileMap = await getFileMap(outPath, branch);
831
+ s.stop(`Downloaded the theme`);
832
+ s.start(`Writing the theme "${outPath}"`);
833
+ await generateTheme(outPath, fileMap, hasReact, replace);
834
+ s.stop(`Wrote the theme`);
835
+ const end = process.hrtime.bigint();
836
+ const duration = (Number(end - start) / 1e9).toFixed(2);
837
+ p.outro(`${source_default.green(`Done`)} in ${source_default.dim(`${duration}s`)}
838
+ `);
839
+ } catch (e) {
840
+ s.stop(`An error occurred`, 500);
841
+ p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
616
842
  }
617
843
  };
618
844
 
845
+ // src/command/tokens/index.ts
846
+ init_cjs_shims();
847
+ var p2 = __toESM(require("@clack/prompts"));
848
+ var import_chokidar = __toESM(require("chokidar"));
849
+ var import_promises3 = require("fs/promises");
850
+ var import_path4 = __toESM(require("path"));
851
+
619
852
  // src/command/tokens/create-theme-typings.ts
620
853
  init_cjs_shims();
621
854
 
@@ -654,18 +887,15 @@ var printComponent = (components) => `components: { ${Object.entries(components)
654
887
  var print = (unions) => Object.entries(unions).sort(([a], [b]) => a.localeCompare(b)).map(
655
888
  ([key, union]) => `${key}: ${union.map((value) => `"${value}"`).concat(["(string & {})"]).join(" | ")};`
656
889
  ).join("\n");
657
- var extractComponents = ({ components = {} }) => Object.entries(components).reduce(
658
- (obj, [key, { sizes, variants }]) => {
659
- if (sizes || variants) {
660
- obj[key] = {
661
- sizes: Object.keys(sizes ?? {}),
662
- variants: Object.keys(variants ?? {})
663
- };
664
- }
665
- return obj;
666
- },
667
- {}
668
- );
890
+ var extractComponents = ({ components = {} }) => Object.entries(components).reduce((obj, [key, { sizes, variants }]) => {
891
+ if (sizes || variants) {
892
+ obj[key] = {
893
+ sizes: Object.keys(sizes ?? {}),
894
+ variants: Object.keys(variants ?? {})
895
+ };
896
+ }
897
+ return obj;
898
+ }, {});
669
899
  var isTone = (value) => {
670
900
  if (!isObject(value)) return false;
671
901
  const keys = Object.keys(value);
@@ -675,13 +905,13 @@ var extractColorSchemes = (theme) => {
675
905
  const { colors, semantics } = theme;
676
906
  let colorSchemes = [];
677
907
  let colorSchemeColors = [];
678
- if (!isObject(colors)) return { colorSchemes, colorSchemeColors };
908
+ if (!isObject(colors)) return { colorSchemeColors, colorSchemes };
679
909
  Object.entries(colors).forEach(([key, value]) => {
680
910
  if (!isTone(value)) return;
681
911
  colorSchemes.push(key);
682
912
  });
683
913
  if (!isObject(semantics?.colorSchemes))
684
- return { colorSchemes, colorSchemeColors };
914
+ return { colorSchemeColors, colorSchemes };
685
915
  Object.entries(semantics.colorSchemes).forEach(([key, value]) => {
686
916
  if (isTone(value)) {
687
917
  colorSchemes.push(key);
@@ -693,7 +923,7 @@ var extractColorSchemes = (theme) => {
693
923
  colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
694
924
  }
695
925
  });
696
- return { colorSchemes, colorSchemeColors };
926
+ return { colorSchemeColors, colorSchemes };
697
927
  };
698
928
  var extractThemeSchemes = (theme) => {
699
929
  const { themeSchemes } = theme;
@@ -733,10 +963,10 @@ var createThemeTypings = async (theme, { responsive = false }) => {
733
963
  const tokens = config.reduce(
734
964
  (prev, {
735
965
  key,
736
- replaceKey,
966
+ flatMap = (value) => value,
737
967
  maxScanDepth,
738
968
  omitScanKeys,
739
- flatMap = (value) => value
969
+ replaceKey
740
970
  }) => {
741
971
  const target = getObject(theme, key);
742
972
  prev[replaceKey ?? key] = [];
@@ -756,7 +986,7 @@ var createThemeTypings = async (theme, { responsive = false }) => {
756
986
  omitScanKeys,
757
987
  shouldProcess
758
988
  ).flatMap(flatMap);
759
- prev[replaceKey ?? key].push(...semanticKeys);
989
+ prev[replaceKey ?? key]?.push(...semanticKeys);
760
990
  }
761
991
  return prev;
762
992
  },
@@ -764,10 +994,10 @@ var createThemeTypings = async (theme, { responsive = false }) => {
764
994
  );
765
995
  const textStyles = extractKeys(theme, "styles.textStyles");
766
996
  const layerStyles = extractKeys(theme, "styles.layerStyles");
767
- const { colorSchemes, colorSchemeColors } = extractColorSchemes(theme);
997
+ const { colorSchemeColors, colorSchemes } = extractColorSchemes(theme);
768
998
  const themeSchemes = extractThemeSchemes(theme);
769
999
  const components = extractComponents(theme);
770
- tokens.colors = [...tokens.colors, ...colorSchemeColors];
1000
+ tokens.colors = [...tokens.colors ?? [], ...colorSchemeColors];
771
1001
  return prettier(
772
1002
  [
773
1003
  `import type { UITheme } from './ui-theme.types'`,
@@ -775,9 +1005,9 @@ var createThemeTypings = async (theme, { responsive = false }) => {
775
1005
  `export interface GeneratedTheme extends UITheme {`,
776
1006
  print({
777
1007
  ...tokens,
778
- textStyles,
779
- layerStyles,
780
1008
  colorSchemes,
1009
+ layerStyles,
1010
+ textStyles,
781
1011
  themeSchemes
782
1012
  }),
783
1013
  printComponent(components),
@@ -788,8 +1018,8 @@ var createThemeTypings = async (theme, { responsive = false }) => {
788
1018
 
789
1019
  // src/command/tokens/resolve-output-path.ts
790
1020
  init_cjs_shims();
791
- var import_path2 = __toESM(require("path"));
792
1021
  var import_glob = require("glob");
1022
+ var import_path3 = __toESM(require("path"));
793
1023
  var themePath = [
794
1024
  "node_modules",
795
1025
  "@yamada-ui",
@@ -799,10 +1029,10 @@ var themePath = [
799
1029
  ];
800
1030
  var resolveThemePath = async () => {
801
1031
  const paths = [
802
- import_path2.default.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
803
- import_path2.default.join(...themePath),
804
- import_path2.default.posix.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
805
- import_path2.default.posix.join(...themePath)
1032
+ import_path3.default.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
1033
+ import_path3.default.join(...themePath),
1034
+ import_path3.default.posix.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
1035
+ import_path3.default.posix.join(...themePath)
806
1036
  ];
807
1037
  const triedPaths = await Promise.all(
808
1038
  paths.map(async (possiblePath) => {
@@ -813,10 +1043,10 @@ var resolveThemePath = async () => {
813
1043
  );
814
1044
  const resolvedPath = triedPaths.find(Boolean);
815
1045
  if (!resolvedPath) return;
816
- return import_path2.default.resolve(process.cwd(), resolvedPath);
1046
+ return import_path3.default.resolve(process.cwd(), resolvedPath);
817
1047
  };
818
1048
  var resolveOutputPath = async (outPath) => {
819
- if (outPath) return import_path2.default.resolve(process.cwd(), outPath);
1049
+ if (outPath) return import_path3.default.resolve(process.cwd(), outPath);
820
1050
  const themePath2 = await resolveThemePath();
821
1051
  if (!themePath2)
822
1052
  throw new Error(
@@ -827,12 +1057,12 @@ var resolveOutputPath = async (outPath) => {
827
1057
 
828
1058
  // src/command/tokens/index.ts
829
1059
  var generateThemeTypings = async ({
830
- theme,
831
1060
  config: config2,
832
- outFile
1061
+ outFile,
1062
+ theme
833
1063
  }) => {
834
- p.intro(source_default.magenta(`Generating Yamada UI theme typings`));
835
- const s = p.spinner();
1064
+ p2.intro(source_default.magenta(`Generating Yamada UI theme typings`));
1065
+ const s = p2.spinner();
836
1066
  try {
837
1067
  const start = process.hrtime.bigint();
838
1068
  s.start(`Parsing the theme`);
@@ -842,30 +1072,30 @@ var generateThemeTypings = async ({
842
1072
  const outPath = await resolveOutputPath(outFile);
843
1073
  s.stop(`Resolved the output path`);
844
1074
  s.start(`Writing file "${outPath}"`);
845
- await (0, import_promises.writeFile)(outPath, generatedTheme, "utf8");
1075
+ await (0, import_promises3.writeFile)(outPath, generatedTheme, "utf8");
846
1076
  s.stop(`Wrote file`);
847
- p.note(outPath, "Output path");
1077
+ p2.note(outPath, "Output path");
848
1078
  const end = process.hrtime.bigint();
849
1079
  const duration = (Number(end - start) / 1e9).toFixed(2);
850
- p.outro(`${source_default.green(`Done`)} in ${source_default.dim(`${duration}s`)}
1080
+ p2.outro(`${source_default.green(`Done`)} in ${source_default.dim(`${duration}s`)}
851
1081
  `);
852
1082
  } catch (e) {
853
1083
  s.stop(`An error occurred`, 500);
854
- p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
1084
+ p2.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
855
1085
  }
856
1086
  };
857
- var actionTokens = async (themePath2, { cwd = import_path3.default.resolve(), out: outFile, watch: watchFile }) => {
1087
+ var actionTokens = async (themePath2, { cwd = import_path4.default.resolve(), out: outFile, watch: watchFile }) => {
858
1088
  const readFile2 = async () => {
859
- const filePath = import_path3.default.resolve(themePath2);
860
- const { mod, dependencies: dependencies2 } = await getModule(filePath, cwd);
1089
+ const filePath = import_path4.default.resolve(themePath2);
1090
+ const { dependencies: dependencies2, mod } = await getModule(filePath, cwd);
861
1091
  const theme2 = mod?.default ?? mod?.theme ?? mod?.customTheme ?? mod?.defaultTheme ?? {};
862
1092
  const config3 = mod?.config ?? mod?.customConfig ?? mod?.defaultConfig ?? {};
863
- return { theme: theme2, config: config3, dependencies: dependencies2 };
1093
+ return { config: config3, dependencies: dependencies2, theme: theme2 };
864
1094
  };
865
1095
  let file = await readFile2();
866
- const { theme, config: config2, dependencies } = file;
1096
+ const { config: config2, dependencies, theme } = file;
867
1097
  const buildFile = async () => {
868
- await generateThemeTypings({ theme, config: config2, outFile });
1098
+ await generateThemeTypings({ config: config2, outFile, theme });
869
1099
  if (watchFile) console.log("\n", "\u231B\uFE0F Watching for changes...");
870
1100
  };
871
1101
  if (watchFile) {
@@ -879,235 +1109,6 @@ var actionTokens = async (themePath2, { cwd = import_path3.default.resolve(), ou
879
1109
  await buildFile();
880
1110
  }
881
1111
  };
882
-
883
- // src/command/theme/index.ts
884
- init_cjs_shims();
885
- var import_dns = __toESM(require("dns"));
886
- var import_fs3 = require("fs");
887
- var import_promises2 = require("fs/promises");
888
- var import_node_stream = require("stream");
889
- var import_promises3 = require("stream/promises");
890
- var import_path4 = __toESM(require("path"));
891
- var p2 = __toESM(require("@clack/prompts"));
892
- var import_tar = require("tar");
893
- var import_typescript = require("typescript");
894
-
895
- // src/utils/fs.ts
896
- init_cjs_shims();
897
- var import_fs2 = __toESM(require("fs"));
898
- var isWriteable = async (directory) => {
899
- try {
900
- await import_fs2.default.promises.access(directory, (import_fs2.default.constants || import_fs2.default).W_OK);
901
- return true;
902
- } catch {
903
- return false;
904
- }
905
- };
906
-
907
- // src/command/theme/index.ts
908
- var ORG_NAME = "yamada-ui";
909
- var REPO_NAME = "yamada-ui";
910
- var DEFAULT_BRANCH_NAME = "main";
911
- var isOnline = () => {
912
- return new Promise((resolve) => {
913
- import_dns.default.lookup("github.com", (err) => {
914
- if (err && err.code === "ENOTFOUND") {
915
- resolve(false);
916
- } else {
917
- resolve(true);
918
- }
919
- });
920
- });
921
- };
922
- var checkHasReact = async (cwd) => {
923
- try {
924
- const packageJson = await (0, import_promises2.readFile)(import_path4.default.join(cwd, "package.json"), "utf-8");
925
- const { dependencies, devDependencies } = JSON.parse(packageJson);
926
- return !!dependencies?.["@yamada-ui/react"] || !!devDependencies?.["@yamada-ui/react"];
927
- } catch {
928
- return false;
929
- }
930
- };
931
- var getSource = async (branch) => {
932
- if (!await isOnline()) {
933
- throw new Error(
934
- "No internet connection, please check your connection and try again."
935
- );
936
- }
937
- const url = `https://codeload.github.com/${ORG_NAME}/${REPO_NAME}/tar.gz/${branch}`;
938
- const { body } = await fetch(url);
939
- if (!body) throw new Error(`Failed to download: ${url}`);
940
- return import_node_stream.Readable.fromWeb(body);
941
- };
942
- var getFileMap = async (cwd, branch) => {
943
- const source = await getSource(branch);
944
- const fileMap = /* @__PURE__ */ new Map();
945
- const targetPath = `${REPO_NAME}-${branch.replace("/", "-")}/packages/theme/src`;
946
- const filter = (path5) => {
947
- return path5.startsWith(targetPath);
948
- };
949
- const onReadEntry = (entry) => {
950
- if (entry.type !== "Directory") {
951
- const filePath = entry.path.replace(`${targetPath}/`, "");
952
- let content = "";
953
- entry.on("data", (chunk) => {
954
- content += chunk.toString();
955
- });
956
- entry.on("end", () => {
957
- fileMap.set(filePath, content);
958
- });
959
- }
960
- };
961
- await (0, import_promises3.pipeline)(
962
- source,
963
- (0, import_tar.t)({
964
- cwd,
965
- filter,
966
- onReadEntry,
967
- strip: 4,
968
- newer: true
969
- })
970
- );
971
- return fileMap;
972
- };
973
- var transformSourceFile = (sourceFile) => {
974
- const ImportDeclarations = [];
975
- const ImportTypeDeclarations = [];
976
- const transformer = (context) => (sourceFile2) => {
977
- const visitor = (node) => {
978
- if ((0, import_typescript.isImportDeclaration)(node)) {
979
- const moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);
980
- if (moduleSpecifier.startsWith("@yamada-ui/")) {
981
- if (node.importClause?.isTypeOnly) {
982
- ImportTypeDeclarations.push(node);
983
- } else {
984
- ImportDeclarations.push(node);
985
- }
986
- return import_typescript.factory.createEmptyStatement();
987
- }
988
- }
989
- return (0, import_typescript.visitEachChild)(node, visitor, context);
990
- };
991
- return (0, import_typescript.visitNode)(sourceFile2, visitor);
992
- };
993
- const { transformed } = (0, import_typescript.transform)(sourceFile, [transformer]);
994
- const transformedSourceFile = transformed[0];
995
- return { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile };
996
- };
997
- var createImportDeclaration = (isTypeOnly, declarations) => {
998
- const elements = declarations.flatMap(
999
- ({ importClause: importClause2 }) => importClause2?.namedBindings && (0, import_typescript.isNamedImports)(importClause2.namedBindings) ? importClause2.namedBindings.elements : []
1000
- );
1001
- const namedBindings = import_typescript.factory.createNamedImports(elements);
1002
- const importClause = import_typescript.factory.createImportClause(
1003
- isTypeOnly,
1004
- void 0,
1005
- namedBindings
1006
- );
1007
- return import_typescript.factory.createImportDeclaration(
1008
- void 0,
1009
- importClause,
1010
- import_typescript.factory.createStringLiteral("@yamada-ui/react")
1011
- );
1012
- };
1013
- var replaceContent = (content) => {
1014
- const sourceFile = (0, import_typescript.createSourceFile)(
1015
- "temp.ts",
1016
- content,
1017
- import_typescript.ScriptTarget.Latest,
1018
- true
1019
- );
1020
- const printer = (0, import_typescript.createPrinter)({ newLine: import_typescript.NewLineKind.LineFeed });
1021
- const { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile } = transformSourceFile(sourceFile);
1022
- const statements = [...transformedSourceFile.statements];
1023
- if (ImportTypeDeclarations.length) {
1024
- const newImportTypeDeclarations = createImportDeclaration(
1025
- true,
1026
- ImportTypeDeclarations
1027
- );
1028
- statements.unshift(newImportTypeDeclarations);
1029
- }
1030
- if (ImportDeclarations.length) {
1031
- const newImportDeclarations = createImportDeclaration(
1032
- false,
1033
- ImportDeclarations
1034
- );
1035
- statements.unshift(newImportDeclarations);
1036
- }
1037
- const updatedSourceFile = import_typescript.factory.updateSourceFile(
1038
- transformedSourceFile,
1039
- statements
1040
- );
1041
- let printedContent = printer.printFile(updatedSourceFile);
1042
- printedContent = printedContent.replace(/^;$/gm, "");
1043
- printedContent = printedContent.replace(/\s\n*(?=import)/g, "");
1044
- printedContent = printedContent.replace(/(import .*\n)+(?!import)/, "$&\n");
1045
- return printedContent;
1046
- };
1047
- var replaceIndex = (content) => {
1048
- const index = content.indexOf("export const baseTheme");
1049
- content = content.slice(0, index);
1050
- content = content.replace(/export const baseTheme/, "export const theme");
1051
- content = content.replace(/\nimport { config } from ".\/config"/, "");
1052
- content += "\nexport { config } from './config'";
1053
- return content;
1054
- };
1055
- var generateTheme = async (outPath, fileMap, isReactReplace, isForceReplace) => {
1056
- if (!await isWriteable(import_path4.default.dirname(outPath))) {
1057
- throw new Error(
1058
- "The provided path is not writable, please check folder permissions and try again. It is likely you do not have write permissions for this folder."
1059
- );
1060
- }
1061
- await (0, import_promises2.mkdir)(outPath, { recursive: true });
1062
- await Promise.all(
1063
- [...fileMap.entries()].map(async ([filePath, _content]) => {
1064
- const targetPath = import_path4.default.join(outPath, filePath);
1065
- let content = _content;
1066
- if (filePath === "index.ts") {
1067
- content = replaceIndex(content);
1068
- } else {
1069
- if (isReactReplace) content = replaceContent(content);
1070
- }
1071
- const formattedContent = await prettier(content);
1072
- try {
1073
- if (!isForceReplace && (0, import_fs3.existsSync)(targetPath)) return;
1074
- await (0, import_promises2.writeFile)(targetPath, formattedContent, "utf-8");
1075
- } catch (e) {
1076
- if (e instanceof Error && "code" in e && e.code === "ENOENT") {
1077
- const dirPath = import_path4.default.dirname(targetPath);
1078
- await (0, import_promises2.mkdir)(dirPath, { recursive: true });
1079
- if (!isForceReplace && (0, import_fs3.existsSync)(targetPath)) return;
1080
- await (0, import_promises2.writeFile)(targetPath, formattedContent, "utf-8");
1081
- }
1082
- }
1083
- })
1084
- );
1085
- };
1086
- var actionTheme = async (_outPath, { branch = DEFAULT_BRANCH_NAME, cwd, replace = false }) => {
1087
- p2.intro(source_default.magenta(`Generating Yamada UI theme`));
1088
- const s = p2.spinner();
1089
- try {
1090
- const start = process.hrtime.bigint();
1091
- cwd ??= import_path4.default.resolve();
1092
- const outPath = import_path4.default.join(cwd, _outPath);
1093
- s.start(`Checking "package.json"`);
1094
- const hasReact = await checkHasReact(cwd);
1095
- s.stop(`Checked "package.json"`);
1096
- s.start(`Downloading the theme`);
1097
- const fileMap = await getFileMap(outPath, branch);
1098
- s.stop(`Downloaded the theme`);
1099
- s.start(`Writing the theme "${outPath}"`);
1100
- await generateTheme(outPath, fileMap, hasReact, replace);
1101
- s.stop(`Wrote the theme`);
1102
- const end = process.hrtime.bigint();
1103
- const duration = (Number(end - start) / 1e9).toFixed(2);
1104
- p2.outro(`${source_default.green(`Done`)} in ${source_default.dim(`${duration}s`)}
1105
- `);
1106
- } catch (e) {
1107
- s.stop(`An error occurred`, 500);
1108
- p2.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
1109
- }
1110
- };
1111
1112
  // Annotate the CommonJS export names for ESM import in node:
1112
1113
  0 && (module.exports = {
1113
1114
  actionTheme,