@yamada-ui/cli 0.0.0-dev-20230608024220

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Hirotomo Yamada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @yamada-ui/cli
2
+
3
+ Generate TypeScript types to provide autocomplete for your custom theme.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ $ pnpm add @yamada-ui/cli
9
+ ```
10
+
11
+ or
12
+
13
+ ```sh
14
+ $ yarn add @yamada-ui/cli
15
+ ```
16
+
17
+ or
18
+
19
+ ```sh
20
+ $ npm install @yamada-ui/cli
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```sh
26
+ pnpm yamada-cli token <path/to/your/theme.(js|ts)>
27
+ ```
28
+
29
+ ### Options
30
+
31
+ - `--out <path>` output file to node_modules/@yamada-ui/core/dist/generated-theme.types.d.ts
32
+ - `--watch [path]` Watch directory for changes and rebuild
33
+ - `--help` display help for command
34
+
35
+ ## Contribution
36
+
37
+ Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](https://github.com/hirotomoyamada/yamada-ui/blob/main/CONTRIBUTING.md) to assist you.
38
+
39
+ ## Licence
40
+
41
+ This package is licensed under the terms of the
42
+ [MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
package/bin/index.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ const { run } = require('../dist/index.js')
3
+
4
+ run().catch((e) => {
5
+ console.error(e)
6
+ process.exit(1)
7
+ })
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "baseUrl": "./",
5
+ "allowJs": true,
6
+ "strict": false,
7
+ "noImplicitAny": false,
8
+ "esModuleInterop": true
9
+ },
10
+ "ts-node": {
11
+ "swc": true,
12
+ "transpileOnly": true
13
+ }
14
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/command/tokens/config.ts
21
+ var config_exports = {};
22
+ __export(config_exports, {
23
+ config: () => config
24
+ });
25
+ module.exports = __toCommonJS(config_exports);
26
+ var config = [
27
+ { key: "borders" },
28
+ { key: "breakpoints", filter: (value) => Number.isNaN(Number(value)) },
29
+ { key: "colors", maxScanDepth: 3 },
30
+ { key: "fonts" },
31
+ { key: "fontSizes" },
32
+ { key: "fontWeights" },
33
+ { key: "letterSpacings" },
34
+ { key: "lineHeights" },
35
+ { key: "radii" },
36
+ { key: "shadows" },
37
+ { key: "sizes", maxScanDepth: 2 },
38
+ { key: "spaces", flatMap: (value) => [value, `-${value}`] },
39
+ { key: "zIndices" }
40
+ ];
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ config
44
+ });
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __esm = (fn, res) => function __init() {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+
23
+ // ../../node_modules/.pnpm/tsup@6.7.0_@swc+core@1.3.62_postcss@8.4.23_ts-node@10.9.1_typescript@4.9.4/node_modules/tsup/assets/cjs_shims.js
24
+ var init_cjs_shims = __esm({
25
+ "../../node_modules/.pnpm/tsup@6.7.0_@swc+core@1.3.62_postcss@8.4.23_ts-node@10.9.1_typescript@4.9.4/node_modules/tsup/assets/cjs_shims.js"() {
26
+ }
27
+ });
28
+
29
+ // src/command/tokens/create-theme-typings.ts
30
+ var create_theme_typings_exports = {};
31
+ __export(create_theme_typings_exports, {
32
+ createThemeTypings: () => createThemeTypings,
33
+ extractColorSchemes: () => extractColorSchemes,
34
+ extractComponents: () => extractComponents,
35
+ extractKeys: () => extractKeys,
36
+ extractPaths: () => extractPaths,
37
+ extractTransitions: () => extractTransitions,
38
+ print: () => print,
39
+ printComponent: () => printComponent
40
+ });
41
+ module.exports = __toCommonJS(create_theme_typings_exports);
42
+ init_cjs_shims();
43
+
44
+ // src/utils/assertion.ts
45
+ init_cjs_shims();
46
+ var isObject = (obj) => obj !== null && (typeof obj === "object" || typeof obj === "function") && !Array.isArray(obj);
47
+ var isArray = (value) => Array.isArray(value);
48
+
49
+ // src/utils/prettier.ts
50
+ init_cjs_shims();
51
+ var import_prettier = require("prettier");
52
+ var prettier = async (content) => {
53
+ const prettierConfig = await (0, import_prettier.resolveConfig)(process.cwd());
54
+ try {
55
+ return (0, import_prettier.format)(content, {
56
+ ...prettierConfig,
57
+ parser: "typescript"
58
+ });
59
+ } catch {
60
+ return content;
61
+ }
62
+ };
63
+
64
+ // src/command/tokens/config.ts
65
+ init_cjs_shims();
66
+ var config = [
67
+ { key: "borders" },
68
+ { key: "breakpoints", filter: (value) => Number.isNaN(Number(value)) },
69
+ { key: "colors", maxScanDepth: 3 },
70
+ { key: "fonts" },
71
+ { key: "fontSizes" },
72
+ { key: "fontWeights" },
73
+ { key: "letterSpacings" },
74
+ { key: "lineHeights" },
75
+ { key: "radii" },
76
+ { key: "shadows" },
77
+ { key: "sizes", maxScanDepth: 2 },
78
+ { key: "spaces", flatMap: (value) => [value, `-${value}`] },
79
+ { key: "zIndices" }
80
+ ];
81
+
82
+ // src/command/tokens/create-theme-typings.ts
83
+ var defaultColors = ["primary", "secondary", "warning", "danger", "link"];
84
+ var hues = ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"];
85
+ var printComponent = (components) => `components: { ${Object.entries(components).map(
86
+ ([key, unions]) => `${key.match(/^[a-zA-Z0-9\-_]+$/) ? key : `"${key}"`}: { ${print(unions)}}`
87
+ ).join(`
88
+ `)} }`;
89
+ var print = (unions) => Object.entries(unions).sort(([a], [b]) => a.localeCompare(b)).map(
90
+ ([key, union]) => `${key}: ${union.map((value) => `"${value}"`).concat(["(string & {})"]).join(" | ")};`
91
+ ).join("\n");
92
+ var extractComponents = ({
93
+ components = {}
94
+ }) => Object.entries(components).reduce(
95
+ (obj, [key, { sizes, variants }]) => {
96
+ if (sizes || variants) {
97
+ obj[key] = {
98
+ sizes: Object.keys(sizes ?? {}),
99
+ variants: Object.keys(variants ?? {})
100
+ };
101
+ }
102
+ return obj;
103
+ },
104
+ {}
105
+ );
106
+ var extractTransitions = (theme) => {
107
+ let transitionProperty = [];
108
+ let transitionDuration = [];
109
+ let transitionEasing = [];
110
+ const { transitions } = theme;
111
+ if (!isObject(transitions))
112
+ return { transitionProperty, transitionDuration, transitionEasing };
113
+ Object.entries(transitions).forEach(([key, value]) => {
114
+ switch (key) {
115
+ case "property":
116
+ transitionProperty = extractPaths(value);
117
+ break;
118
+ case "duration":
119
+ transitionDuration = extractPaths(value);
120
+ break;
121
+ case "easing":
122
+ transitionEasing = extractPaths(value);
123
+ break;
124
+ default:
125
+ return;
126
+ }
127
+ });
128
+ return { transitionProperty, transitionDuration, transitionEasing };
129
+ };
130
+ var isHue = (value) => {
131
+ if (!isObject(value))
132
+ return false;
133
+ const keys = Object.keys(value);
134
+ return hues.every((key) => keys.includes(key));
135
+ };
136
+ var isDefaultColor = (key) => defaultColors.includes(key);
137
+ var extractColorSchemes = (theme) => {
138
+ const { colors } = theme;
139
+ if (!isObject(colors))
140
+ return [];
141
+ return Object.entries(colors).reduce((array, [key, value]) => {
142
+ if (isHue(value) || isDefaultColor(key))
143
+ array.push(key);
144
+ return array;
145
+ }, []);
146
+ };
147
+ var extractPaths = (target, maxDepth = 3) => {
148
+ if (!isObject(target) && !Array.isArray(target) || !maxDepth)
149
+ return [];
150
+ return Object.entries(target).reduce((array, [key, value]) => {
151
+ if (isObject(value)) {
152
+ extractPaths(value, maxDepth - 1).forEach((nestedKey) => array.push(`${key}.${nestedKey}`));
153
+ } else {
154
+ array.push(key);
155
+ }
156
+ return array;
157
+ }, []);
158
+ };
159
+ var extractKeys = (theme, key) => {
160
+ const keys = key.split(".");
161
+ const property = keys.reduce((obj, key2) => obj[key2] ?? {}, theme);
162
+ if (!isObject(property))
163
+ return [];
164
+ return Object.keys(property);
165
+ };
166
+ var createThemeTypings = async (theme) => {
167
+ const unions = config.reduce(
168
+ (obj, { key, maxScanDepth, filter = () => true, flatMap = (value) => value }) => {
169
+ const target = theme[key];
170
+ obj[key] = [];
171
+ if (isObject(target) || isArray(target)) {
172
+ obj[key] = extractPaths(target, maxScanDepth).filter(filter).flatMap(flatMap);
173
+ }
174
+ if (isObject(theme.semantics)) {
175
+ const semanticKeys = extractKeys(theme.semantics, key).filter(filter).flatMap(flatMap);
176
+ obj[key].push(...semanticKeys);
177
+ }
178
+ return obj;
179
+ },
180
+ {}
181
+ );
182
+ const textStyles = extractKeys(theme, "styles.textStyles");
183
+ const layerStyles = extractKeys(theme, "styles.layerStyles");
184
+ const colorSchemes = extractColorSchemes(theme);
185
+ const { transitionProperty, transitionDuration, transitionEasing } = extractTransitions(theme);
186
+ const componentTypes = extractComponents(theme);
187
+ return prettier(
188
+ `import { UITheme } from './ui-theme.types'
189
+
190
+ export interface GeneratedTheme extends UITheme { ${print(
191
+ {
192
+ ...unions,
193
+ textStyles,
194
+ layerStyles,
195
+ colorSchemes,
196
+ transitionProperty,
197
+ transitionDuration,
198
+ transitionEasing
199
+ }
200
+ )} ${printComponent(componentTypes)} }`
201
+ );
202
+ };
203
+ // Annotate the CommonJS export names for ESM import in node:
204
+ 0 && (module.exports = {
205
+ createThemeTypings,
206
+ extractColorSchemes,
207
+ extractComponents,
208
+ extractKeys,
209
+ extractPaths,
210
+ extractTransitions,
211
+ print,
212
+ printComponent
213
+ });