@yamada-ui/cli 1.0.6 → 1.1.0-dev-20240806133333
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command/index.js +1085 -0
- package/dist/command/{colors → theme}/index.js +219 -48
- package/dist/command/tokens/create-theme-typings.js +2 -2
- package/dist/command/tokens/index.js +4 -4
- package/dist/index.js +1658 -1736
- package/dist/utils/cli.js +1344 -1596
- package/dist/utils/fs.js +48 -0
- package/dist/utils/index.js +1346 -1598
- package/dist/utils/string.js +33 -0
- package/package.json +4 -3
|
@@ -30,20 +30,26 @@ 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.2.3_@swc+core@1.7.
|
|
33
|
+
// ../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.3_@swc+helpers@0.5.5__jiti@1.21.6_postcss@8.4.40_tsx@4.16.2_typescript@5.5.4_yaml@2.5.0/node_modules/tsup/assets/cjs_shims.js
|
|
34
34
|
var init_cjs_shims = __esm({
|
|
35
|
-
"../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.
|
|
35
|
+
"../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.3_@swc+helpers@0.5.5__jiti@1.21.6_postcss@8.4.40_tsx@4.16.2_typescript@5.5.4_yaml@2.5.0/node_modules/tsup/assets/cjs_shims.js"() {
|
|
36
36
|
"use strict";
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
// src/command/
|
|
41
|
-
var
|
|
42
|
-
__export(
|
|
43
|
-
|
|
40
|
+
// src/command/theme/index.ts
|
|
41
|
+
var theme_exports = {};
|
|
42
|
+
__export(theme_exports, {
|
|
43
|
+
actionTheme: () => actionTheme
|
|
44
44
|
});
|
|
45
|
-
module.exports = __toCommonJS(
|
|
45
|
+
module.exports = __toCommonJS(theme_exports);
|
|
46
46
|
init_cjs_shims();
|
|
47
|
+
var import_dns = __toESM(require("dns"));
|
|
48
|
+
var import_fs2 = require("fs");
|
|
49
|
+
var import_promises = require("fs/promises");
|
|
50
|
+
var import_node_stream = require("stream");
|
|
51
|
+
var import_promises2 = require("stream/promises");
|
|
52
|
+
var import_path2 = __toESM(require("path"));
|
|
47
53
|
var p = __toESM(require("@clack/prompts"));
|
|
48
54
|
|
|
49
55
|
// ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
|
|
@@ -541,8 +547,9 @@ var chalk = createChalk();
|
|
|
541
547
|
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
542
548
|
var source_default = chalk;
|
|
543
549
|
|
|
544
|
-
// src/command/
|
|
545
|
-
var
|
|
550
|
+
// src/command/theme/index.ts
|
|
551
|
+
var import_tar = require("tar");
|
|
552
|
+
var import_typescript = require("typescript");
|
|
546
553
|
|
|
547
554
|
// src/utils/prettier.ts
|
|
548
555
|
init_cjs_shims();
|
|
@@ -563,53 +570,217 @@ var prettier = async (content, options) => {
|
|
|
563
570
|
}
|
|
564
571
|
};
|
|
565
572
|
|
|
566
|
-
// src/
|
|
567
|
-
|
|
568
|
-
var
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
573
|
+
// src/utils/fs.ts
|
|
574
|
+
init_cjs_shims();
|
|
575
|
+
var import_fs = __toESM(require("fs"));
|
|
576
|
+
var isWriteable = async (directory) => {
|
|
577
|
+
try {
|
|
578
|
+
await import_fs.default.promises.access(directory, (import_fs.default.constants || import_fs.default).W_OK);
|
|
579
|
+
return true;
|
|
580
|
+
} catch (err) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/command/theme/index.ts
|
|
586
|
+
var ORG_NAME = "yamada-ui";
|
|
587
|
+
var REPO_NAME = "yamada-ui";
|
|
588
|
+
var DEFAULT_BRANCH_NAME = "main";
|
|
589
|
+
var isOnline = () => {
|
|
590
|
+
return new Promise((resolve) => {
|
|
591
|
+
import_dns.default.lookup("github.com", (err) => {
|
|
592
|
+
if (err && err.code === "ENOTFOUND") {
|
|
593
|
+
resolve(false);
|
|
580
594
|
} else {
|
|
581
|
-
|
|
595
|
+
resolve(true);
|
|
582
596
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
};
|
|
600
|
+
var checkHasReact = async (cwd) => {
|
|
601
|
+
try {
|
|
602
|
+
const packageJson = await (0, import_promises.readFile)(import_path2.default.join(cwd, "package.json"), "utf-8");
|
|
603
|
+
const { dependencies, devDependencies } = JSON.parse(packageJson);
|
|
604
|
+
return !!dependencies?.["@yamada-ui/react"] || !!devDependencies?.["@yamada-ui/react"];
|
|
605
|
+
} catch {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
var getSource = async (branch) => {
|
|
610
|
+
if (!await isOnline()) {
|
|
611
|
+
throw new Error(
|
|
612
|
+
"No internet connection, please check your connection and try again."
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
const url = `https://codeload.github.com/${ORG_NAME}/${REPO_NAME}/tar.gz/${branch}`;
|
|
616
|
+
const { body } = await fetch(url);
|
|
617
|
+
if (!body) throw new Error(`Failed to download: ${url}`);
|
|
618
|
+
return import_node_stream.Readable.fromWeb(body);
|
|
619
|
+
};
|
|
620
|
+
var getFileMap = async (cwd, branch) => {
|
|
621
|
+
const source = await getSource(branch);
|
|
622
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
623
|
+
const targetPath = `${REPO_NAME}-${branch.replace("/", "-")}/packages/theme/src`;
|
|
624
|
+
const filter = (path3) => {
|
|
625
|
+
return path3.startsWith(targetPath);
|
|
626
|
+
};
|
|
627
|
+
const onReadEntry = (entry) => {
|
|
628
|
+
if (entry.type !== "Directory") {
|
|
629
|
+
const filePath = entry.path.replace(`${targetPath}/`, "");
|
|
630
|
+
let content = "";
|
|
631
|
+
entry.on("data", (chunk) => {
|
|
632
|
+
content += chunk.toString();
|
|
633
|
+
});
|
|
634
|
+
entry.on("end", () => {
|
|
635
|
+
fileMap.set(filePath, content);
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
await (0, import_promises2.pipeline)(
|
|
640
|
+
source,
|
|
641
|
+
(0, import_tar.t)({
|
|
642
|
+
cwd,
|
|
643
|
+
filter,
|
|
644
|
+
onReadEntry,
|
|
645
|
+
strip: 4,
|
|
646
|
+
newer: true
|
|
647
|
+
})
|
|
588
648
|
);
|
|
649
|
+
return fileMap;
|
|
589
650
|
};
|
|
590
|
-
var
|
|
591
|
-
|
|
651
|
+
var transformSourceFile = (sourceFile) => {
|
|
652
|
+
const ImportDeclarations = [];
|
|
653
|
+
const ImportTypeDeclarations = [];
|
|
654
|
+
const transformer = (context) => (sourceFile2) => {
|
|
655
|
+
const visitor = (node) => {
|
|
656
|
+
if ((0, import_typescript.isImportDeclaration)(node)) {
|
|
657
|
+
const moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);
|
|
658
|
+
if (moduleSpecifier.startsWith("@yamada-ui/")) {
|
|
659
|
+
if (node.importClause?.isTypeOnly) {
|
|
660
|
+
ImportTypeDeclarations.push(node);
|
|
661
|
+
} else {
|
|
662
|
+
ImportDeclarations.push(node);
|
|
663
|
+
}
|
|
664
|
+
return import_typescript.factory.createEmptyStatement();
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return (0, import_typescript.visitEachChild)(node, visitor, context);
|
|
668
|
+
};
|
|
669
|
+
return (0, import_typescript.visitNode)(sourceFile2, visitor);
|
|
670
|
+
};
|
|
671
|
+
const { transformed } = (0, import_typescript.transform)(sourceFile, [transformer]);
|
|
672
|
+
const transformedSourceFile = transformed[0];
|
|
673
|
+
return { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile };
|
|
674
|
+
};
|
|
675
|
+
var createImportDeclaration = (isTypeOnly, declarations) => {
|
|
676
|
+
const elements = declarations.flatMap(
|
|
677
|
+
({ importClause: importClause2 }) => importClause2?.namedBindings && (0, import_typescript.isNamedImports)(importClause2.namedBindings) ? importClause2.namedBindings.elements : []
|
|
678
|
+
);
|
|
679
|
+
const namedBindings = import_typescript.factory.createNamedImports(elements);
|
|
680
|
+
const importClause = import_typescript.factory.createImportClause(
|
|
681
|
+
isTypeOnly,
|
|
682
|
+
void 0,
|
|
683
|
+
namedBindings
|
|
684
|
+
);
|
|
685
|
+
return import_typescript.factory.createImportDeclaration(
|
|
686
|
+
void 0,
|
|
687
|
+
importClause,
|
|
688
|
+
import_typescript.factory.createStringLiteral("@yamada-ui/react")
|
|
689
|
+
);
|
|
690
|
+
};
|
|
691
|
+
var replaceContent = (content) => {
|
|
692
|
+
const sourceFile = (0, import_typescript.createSourceFile)(
|
|
693
|
+
"temp.ts",
|
|
694
|
+
content,
|
|
695
|
+
import_typescript.ScriptTarget.Latest,
|
|
696
|
+
true
|
|
697
|
+
);
|
|
698
|
+
const printer = (0, import_typescript.createPrinter)({ newLine: import_typescript.NewLineKind.LineFeed });
|
|
699
|
+
const { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile } = transformSourceFile(sourceFile);
|
|
700
|
+
const statements = [...transformedSourceFile.statements];
|
|
701
|
+
if (ImportTypeDeclarations.length) {
|
|
702
|
+
const newImportTypeDeclarations = createImportDeclaration(
|
|
703
|
+
true,
|
|
704
|
+
ImportTypeDeclarations
|
|
705
|
+
);
|
|
706
|
+
statements.unshift(newImportTypeDeclarations);
|
|
707
|
+
}
|
|
708
|
+
if (ImportDeclarations.length) {
|
|
709
|
+
const newImportDeclarations = createImportDeclaration(
|
|
710
|
+
false,
|
|
711
|
+
ImportDeclarations
|
|
712
|
+
);
|
|
713
|
+
statements.unshift(newImportDeclarations);
|
|
714
|
+
}
|
|
715
|
+
const updatedSourceFile = import_typescript.factory.updateSourceFile(
|
|
716
|
+
transformedSourceFile,
|
|
717
|
+
statements
|
|
718
|
+
);
|
|
719
|
+
let printedContent = printer.printFile(updatedSourceFile);
|
|
720
|
+
printedContent = printedContent.replace(/^;$/gm, "");
|
|
721
|
+
printedContent = printedContent.replace(/\s\n*(?=import)/g, "");
|
|
722
|
+
printedContent = printedContent.replace(/(import .*\n)+(?!import)/, "$&\n");
|
|
723
|
+
return printedContent;
|
|
724
|
+
};
|
|
725
|
+
var replaceIndex = (content) => {
|
|
726
|
+
const index = content.indexOf("export const baseTheme");
|
|
727
|
+
content = content.slice(0, index);
|
|
728
|
+
content = content.replace(/export const baseTheme/, "export const theme");
|
|
729
|
+
content = content.replace(/\nimport { config } from ".\/config"/, "");
|
|
730
|
+
content += "\nexport { config } from './config'";
|
|
731
|
+
return content;
|
|
732
|
+
};
|
|
733
|
+
var generateTheme = async (outPath, fileMap, isReactReplace, isForceReplace) => {
|
|
734
|
+
if (!await isWriteable(import_path2.default.dirname(outPath))) {
|
|
735
|
+
throw new Error(
|
|
736
|
+
"The provided path is not writable, please check folder permissions and try again.\nIt is likely you do not have write permissions for this folder."
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
await (0, import_promises.mkdir)(outPath, { recursive: true });
|
|
740
|
+
await Promise.all(
|
|
741
|
+
[...fileMap.entries()].map(async ([filePath, _content]) => {
|
|
742
|
+
const targetPath = import_path2.default.join(outPath, filePath);
|
|
743
|
+
let content = _content;
|
|
744
|
+
if (filePath === "index.ts") {
|
|
745
|
+
content = replaceIndex(content);
|
|
746
|
+
} else {
|
|
747
|
+
if (isReactReplace) content = replaceContent(content);
|
|
748
|
+
}
|
|
749
|
+
const formattedContent = await prettier(content);
|
|
750
|
+
try {
|
|
751
|
+
if (!isForceReplace && (0, import_fs2.existsSync)(targetPath)) return;
|
|
752
|
+
await (0, import_promises.writeFile)(targetPath, formattedContent, "utf-8");
|
|
753
|
+
} catch (e) {
|
|
754
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
755
|
+
const dirPath = import_path2.default.dirname(targetPath);
|
|
756
|
+
await (0, import_promises.mkdir)(dirPath, { recursive: true });
|
|
757
|
+
if (!isForceReplace && (0, import_fs2.existsSync)(targetPath)) return;
|
|
758
|
+
await (0, import_promises.writeFile)(targetPath, formattedContent, "utf-8");
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
})
|
|
762
|
+
);
|
|
763
|
+
};
|
|
764
|
+
var actionTheme = async (_outPath, { branch = DEFAULT_BRANCH_NAME, cwd, replace = false }) => {
|
|
765
|
+
p.intro(source_default.magenta(`Generating Yamada UI theme`));
|
|
592
766
|
const s = p.spinner();
|
|
593
767
|
try {
|
|
594
768
|
const start = process.hrtime.bigint();
|
|
595
|
-
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
s.stop(`
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
).join("\n"),
|
|
607
|
-
"Generated the colors"
|
|
608
|
-
);
|
|
769
|
+
cwd ??= import_path2.default.resolve();
|
|
770
|
+
const outPath = import_path2.default.join(cwd, _outPath);
|
|
771
|
+
s.start(`Checking "package.json"`);
|
|
772
|
+
const hasReact = await checkHasReact(cwd);
|
|
773
|
+
s.stop(`Checked "package.json"`);
|
|
774
|
+
s.start(`Downloading the theme`);
|
|
775
|
+
const fileMap = await getFileMap(outPath, branch);
|
|
776
|
+
s.stop(`Downloaded the theme`);
|
|
777
|
+
s.start(`Writing the theme "${outPath}"`);
|
|
778
|
+
await generateTheme(outPath, fileMap, hasReact, replace);
|
|
779
|
+
s.stop(`Wrote the theme`);
|
|
609
780
|
const end = process.hrtime.bigint();
|
|
610
781
|
const duration = (Number(end - start) / 1e9).toFixed(2);
|
|
611
|
-
p.outro(source_default.green(`Done in ${duration}s
|
|
612
|
-
|
|
782
|
+
p.outro(source_default.green(`Done in ${duration}s
|
|
783
|
+
`));
|
|
613
784
|
} catch (e) {
|
|
614
785
|
s.stop(`An error occurred`, 500);
|
|
615
786
|
p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
|
|
@@ -617,5 +788,5 @@ var actionColors = async (color, { name, out }) => {
|
|
|
617
788
|
};
|
|
618
789
|
// Annotate the CommonJS export names for ESM import in node:
|
|
619
790
|
0 && (module.exports = {
|
|
620
|
-
|
|
791
|
+
actionTheme
|
|
621
792
|
});
|
|
@@ -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.2.3_@swc+core@1.7.
|
|
33
|
+
// ../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.3_@swc+helpers@0.5.5__jiti@1.21.6_postcss@8.4.40_tsx@4.16.2_typescript@5.5.4_yaml@2.5.0/node_modules/tsup/assets/cjs_shims.js
|
|
34
34
|
var init_cjs_shims = __esm({
|
|
35
|
-
"../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.
|
|
35
|
+
"../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.3_@swc+helpers@0.5.5__jiti@1.21.6_postcss@8.4.40_tsx@4.16.2_typescript@5.5.4_yaml@2.5.0/node_modules/tsup/assets/cjs_shims.js"() {
|
|
36
36
|
"use strict";
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -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.2.3_@swc+core@1.7.
|
|
33
|
+
// ../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.3_@swc+helpers@0.5.5__jiti@1.21.6_postcss@8.4.40_tsx@4.16.2_typescript@5.5.4_yaml@2.5.0/node_modules/tsup/assets/cjs_shims.js
|
|
34
34
|
var init_cjs_shims = __esm({
|
|
35
|
-
"../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.
|
|
35
|
+
"../../node_modules/.pnpm/tsup@8.2.3_@swc+core@1.7.3_@swc+helpers@0.5.5__jiti@1.21.6_postcss@8.4.40_tsx@4.16.2_typescript@5.5.4_yaml@2.5.0/node_modules/tsup/assets/cjs_shims.js"() {
|
|
36
36
|
"use strict";
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -822,9 +822,9 @@ var generateThemeTypings = async ({
|
|
|
822
822
|
p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
|
|
823
823
|
}
|
|
824
824
|
};
|
|
825
|
-
var actionTokens = async (
|
|
825
|
+
var actionTokens = async (themePath2, { out: outFile, watch: watchFile }) => {
|
|
826
826
|
const readFile = async () => {
|
|
827
|
-
const filePath = import_path3.default.resolve(
|
|
827
|
+
const filePath = import_path3.default.resolve(themePath2);
|
|
828
828
|
const { mod: theme, dependencies } = await (0, import_bundle_n_require.bundleNRequire)(filePath);
|
|
829
829
|
return { theme, dependencies };
|
|
830
830
|
};
|