@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
|
@@ -0,0 +1,1085 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
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
|
+
var init_cjs_shims = __esm({
|
|
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
|
+
"use strict";
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// src/command/index.ts
|
|
41
|
+
var command_exports = {};
|
|
42
|
+
__export(command_exports, {
|
|
43
|
+
actionTheme: () => actionTheme,
|
|
44
|
+
actionTokens: () => actionTokens,
|
|
45
|
+
themePath: () => themePath
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(command_exports);
|
|
48
|
+
init_cjs_shims();
|
|
49
|
+
|
|
50
|
+
// src/command/tokens/index.ts
|
|
51
|
+
init_cjs_shims();
|
|
52
|
+
var import_promises = require("fs/promises");
|
|
53
|
+
var import_path3 = __toESM(require("path"));
|
|
54
|
+
var p = __toESM(require("@clack/prompts"));
|
|
55
|
+
var import_bundle_n_require = require("bundle-n-require");
|
|
56
|
+
|
|
57
|
+
// ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
|
|
58
|
+
init_cjs_shims();
|
|
59
|
+
|
|
60
|
+
// ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
61
|
+
init_cjs_shims();
|
|
62
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
63
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
64
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
65
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
66
|
+
var styles = {
|
|
67
|
+
modifier: {
|
|
68
|
+
reset: [0, 0],
|
|
69
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
70
|
+
bold: [1, 22],
|
|
71
|
+
dim: [2, 22],
|
|
72
|
+
italic: [3, 23],
|
|
73
|
+
underline: [4, 24],
|
|
74
|
+
overline: [53, 55],
|
|
75
|
+
inverse: [7, 27],
|
|
76
|
+
hidden: [8, 28],
|
|
77
|
+
strikethrough: [9, 29]
|
|
78
|
+
},
|
|
79
|
+
color: {
|
|
80
|
+
black: [30, 39],
|
|
81
|
+
red: [31, 39],
|
|
82
|
+
green: [32, 39],
|
|
83
|
+
yellow: [33, 39],
|
|
84
|
+
blue: [34, 39],
|
|
85
|
+
magenta: [35, 39],
|
|
86
|
+
cyan: [36, 39],
|
|
87
|
+
white: [37, 39],
|
|
88
|
+
// Bright color
|
|
89
|
+
blackBright: [90, 39],
|
|
90
|
+
gray: [90, 39],
|
|
91
|
+
// Alias of `blackBright`
|
|
92
|
+
grey: [90, 39],
|
|
93
|
+
// Alias of `blackBright`
|
|
94
|
+
redBright: [91, 39],
|
|
95
|
+
greenBright: [92, 39],
|
|
96
|
+
yellowBright: [93, 39],
|
|
97
|
+
blueBright: [94, 39],
|
|
98
|
+
magentaBright: [95, 39],
|
|
99
|
+
cyanBright: [96, 39],
|
|
100
|
+
whiteBright: [97, 39]
|
|
101
|
+
},
|
|
102
|
+
bgColor: {
|
|
103
|
+
bgBlack: [40, 49],
|
|
104
|
+
bgRed: [41, 49],
|
|
105
|
+
bgGreen: [42, 49],
|
|
106
|
+
bgYellow: [43, 49],
|
|
107
|
+
bgBlue: [44, 49],
|
|
108
|
+
bgMagenta: [45, 49],
|
|
109
|
+
bgCyan: [46, 49],
|
|
110
|
+
bgWhite: [47, 49],
|
|
111
|
+
// Bright color
|
|
112
|
+
bgBlackBright: [100, 49],
|
|
113
|
+
bgGray: [100, 49],
|
|
114
|
+
// Alias of `bgBlackBright`
|
|
115
|
+
bgGrey: [100, 49],
|
|
116
|
+
// Alias of `bgBlackBright`
|
|
117
|
+
bgRedBright: [101, 49],
|
|
118
|
+
bgGreenBright: [102, 49],
|
|
119
|
+
bgYellowBright: [103, 49],
|
|
120
|
+
bgBlueBright: [104, 49],
|
|
121
|
+
bgMagentaBright: [105, 49],
|
|
122
|
+
bgCyanBright: [106, 49],
|
|
123
|
+
bgWhiteBright: [107, 49]
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
127
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
128
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
129
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
130
|
+
function assembleStyles() {
|
|
131
|
+
const codes = /* @__PURE__ */ new Map();
|
|
132
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
133
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
134
|
+
styles[styleName] = {
|
|
135
|
+
open: `\x1B[${style[0]}m`,
|
|
136
|
+
close: `\x1B[${style[1]}m`
|
|
137
|
+
};
|
|
138
|
+
group[styleName] = styles[styleName];
|
|
139
|
+
codes.set(style[0], style[1]);
|
|
140
|
+
}
|
|
141
|
+
Object.defineProperty(styles, groupName, {
|
|
142
|
+
value: group,
|
|
143
|
+
enumerable: false
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
Object.defineProperty(styles, "codes", {
|
|
147
|
+
value: codes,
|
|
148
|
+
enumerable: false
|
|
149
|
+
});
|
|
150
|
+
styles.color.close = "\x1B[39m";
|
|
151
|
+
styles.bgColor.close = "\x1B[49m";
|
|
152
|
+
styles.color.ansi = wrapAnsi16();
|
|
153
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
154
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
155
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
156
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
157
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
158
|
+
Object.defineProperties(styles, {
|
|
159
|
+
rgbToAnsi256: {
|
|
160
|
+
value(red, green, blue) {
|
|
161
|
+
if (red === green && green === blue) {
|
|
162
|
+
if (red < 8) {
|
|
163
|
+
return 16;
|
|
164
|
+
}
|
|
165
|
+
if (red > 248) {
|
|
166
|
+
return 231;
|
|
167
|
+
}
|
|
168
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
169
|
+
}
|
|
170
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
171
|
+
},
|
|
172
|
+
enumerable: false
|
|
173
|
+
},
|
|
174
|
+
hexToRgb: {
|
|
175
|
+
value(hex) {
|
|
176
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
177
|
+
if (!matches) {
|
|
178
|
+
return [0, 0, 0];
|
|
179
|
+
}
|
|
180
|
+
let [colorString] = matches;
|
|
181
|
+
if (colorString.length === 3) {
|
|
182
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
183
|
+
}
|
|
184
|
+
const integer = Number.parseInt(colorString, 16);
|
|
185
|
+
return [
|
|
186
|
+
/* eslint-disable no-bitwise */
|
|
187
|
+
integer >> 16 & 255,
|
|
188
|
+
integer >> 8 & 255,
|
|
189
|
+
integer & 255
|
|
190
|
+
/* eslint-enable no-bitwise */
|
|
191
|
+
];
|
|
192
|
+
},
|
|
193
|
+
enumerable: false
|
|
194
|
+
},
|
|
195
|
+
hexToAnsi256: {
|
|
196
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
197
|
+
enumerable: false
|
|
198
|
+
},
|
|
199
|
+
ansi256ToAnsi: {
|
|
200
|
+
value(code) {
|
|
201
|
+
if (code < 8) {
|
|
202
|
+
return 30 + code;
|
|
203
|
+
}
|
|
204
|
+
if (code < 16) {
|
|
205
|
+
return 90 + (code - 8);
|
|
206
|
+
}
|
|
207
|
+
let red;
|
|
208
|
+
let green;
|
|
209
|
+
let blue;
|
|
210
|
+
if (code >= 232) {
|
|
211
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
212
|
+
green = red;
|
|
213
|
+
blue = red;
|
|
214
|
+
} else {
|
|
215
|
+
code -= 16;
|
|
216
|
+
const remainder = code % 36;
|
|
217
|
+
red = Math.floor(code / 36) / 5;
|
|
218
|
+
green = Math.floor(remainder / 6) / 5;
|
|
219
|
+
blue = remainder % 6 / 5;
|
|
220
|
+
}
|
|
221
|
+
const value = Math.max(red, green, blue) * 2;
|
|
222
|
+
if (value === 0) {
|
|
223
|
+
return 30;
|
|
224
|
+
}
|
|
225
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
226
|
+
if (value === 2) {
|
|
227
|
+
result += 60;
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
},
|
|
231
|
+
enumerable: false
|
|
232
|
+
},
|
|
233
|
+
rgbToAnsi: {
|
|
234
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
235
|
+
enumerable: false
|
|
236
|
+
},
|
|
237
|
+
hexToAnsi: {
|
|
238
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
239
|
+
enumerable: false
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return styles;
|
|
243
|
+
}
|
|
244
|
+
var ansiStyles = assembleStyles();
|
|
245
|
+
var ansi_styles_default = ansiStyles;
|
|
246
|
+
|
|
247
|
+
// ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js
|
|
248
|
+
init_cjs_shims();
|
|
249
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
250
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
251
|
+
var import_node_tty = __toESM(require("tty"), 1);
|
|
252
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
|
|
253
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
254
|
+
const position = argv.indexOf(prefix + flag);
|
|
255
|
+
const terminatorPosition = argv.indexOf("--");
|
|
256
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
257
|
+
}
|
|
258
|
+
var { env } = import_node_process.default;
|
|
259
|
+
var flagForceColor;
|
|
260
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
261
|
+
flagForceColor = 0;
|
|
262
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
263
|
+
flagForceColor = 1;
|
|
264
|
+
}
|
|
265
|
+
function envForceColor() {
|
|
266
|
+
if ("FORCE_COLOR" in env) {
|
|
267
|
+
if (env.FORCE_COLOR === "true") {
|
|
268
|
+
return 1;
|
|
269
|
+
}
|
|
270
|
+
if (env.FORCE_COLOR === "false") {
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function translateLevel(level) {
|
|
277
|
+
if (level === 0) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
level,
|
|
282
|
+
hasBasic: true,
|
|
283
|
+
has256: level >= 2,
|
|
284
|
+
has16m: level >= 3
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
288
|
+
const noFlagForceColor = envForceColor();
|
|
289
|
+
if (noFlagForceColor !== void 0) {
|
|
290
|
+
flagForceColor = noFlagForceColor;
|
|
291
|
+
}
|
|
292
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
293
|
+
if (forceColor === 0) {
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
if (sniffFlags) {
|
|
297
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
298
|
+
return 3;
|
|
299
|
+
}
|
|
300
|
+
if (hasFlag("color=256")) {
|
|
301
|
+
return 2;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
305
|
+
return 1;
|
|
306
|
+
}
|
|
307
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
308
|
+
return 0;
|
|
309
|
+
}
|
|
310
|
+
const min = forceColor || 0;
|
|
311
|
+
if (env.TERM === "dumb") {
|
|
312
|
+
return min;
|
|
313
|
+
}
|
|
314
|
+
if (import_node_process.default.platform === "win32") {
|
|
315
|
+
const osRelease = import_node_os.default.release().split(".");
|
|
316
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
317
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
318
|
+
}
|
|
319
|
+
return 1;
|
|
320
|
+
}
|
|
321
|
+
if ("CI" in env) {
|
|
322
|
+
if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
|
|
323
|
+
return 3;
|
|
324
|
+
}
|
|
325
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
326
|
+
return 1;
|
|
327
|
+
}
|
|
328
|
+
return min;
|
|
329
|
+
}
|
|
330
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
331
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
332
|
+
}
|
|
333
|
+
if (env.COLORTERM === "truecolor") {
|
|
334
|
+
return 3;
|
|
335
|
+
}
|
|
336
|
+
if (env.TERM === "xterm-kitty") {
|
|
337
|
+
return 3;
|
|
338
|
+
}
|
|
339
|
+
if ("TERM_PROGRAM" in env) {
|
|
340
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
341
|
+
switch (env.TERM_PROGRAM) {
|
|
342
|
+
case "iTerm.app": {
|
|
343
|
+
return version >= 3 ? 3 : 2;
|
|
344
|
+
}
|
|
345
|
+
case "Apple_Terminal": {
|
|
346
|
+
return 2;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
351
|
+
return 2;
|
|
352
|
+
}
|
|
353
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
354
|
+
return 1;
|
|
355
|
+
}
|
|
356
|
+
if ("COLORTERM" in env) {
|
|
357
|
+
return 1;
|
|
358
|
+
}
|
|
359
|
+
return min;
|
|
360
|
+
}
|
|
361
|
+
function createSupportsColor(stream, options = {}) {
|
|
362
|
+
const level = _supportsColor(stream, {
|
|
363
|
+
streamIsTTY: stream && stream.isTTY,
|
|
364
|
+
...options
|
|
365
|
+
});
|
|
366
|
+
return translateLevel(level);
|
|
367
|
+
}
|
|
368
|
+
var supportsColor = {
|
|
369
|
+
stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
|
|
370
|
+
stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
|
|
371
|
+
};
|
|
372
|
+
var supports_color_default = supportsColor;
|
|
373
|
+
|
|
374
|
+
// ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/utilities.js
|
|
375
|
+
init_cjs_shims();
|
|
376
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
377
|
+
let index = string.indexOf(substring);
|
|
378
|
+
if (index === -1) {
|
|
379
|
+
return string;
|
|
380
|
+
}
|
|
381
|
+
const substringLength = substring.length;
|
|
382
|
+
let endIndex = 0;
|
|
383
|
+
let returnValue = "";
|
|
384
|
+
do {
|
|
385
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
386
|
+
endIndex = index + substringLength;
|
|
387
|
+
index = string.indexOf(substring, endIndex);
|
|
388
|
+
} while (index !== -1);
|
|
389
|
+
returnValue += string.slice(endIndex);
|
|
390
|
+
return returnValue;
|
|
391
|
+
}
|
|
392
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
393
|
+
let endIndex = 0;
|
|
394
|
+
let returnValue = "";
|
|
395
|
+
do {
|
|
396
|
+
const gotCR = string[index - 1] === "\r";
|
|
397
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
398
|
+
endIndex = index + 1;
|
|
399
|
+
index = string.indexOf("\n", endIndex);
|
|
400
|
+
} while (index !== -1);
|
|
401
|
+
returnValue += string.slice(endIndex);
|
|
402
|
+
return returnValue;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ../../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
|
|
406
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
407
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
408
|
+
var STYLER = Symbol("STYLER");
|
|
409
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
410
|
+
var levelMapping = [
|
|
411
|
+
"ansi",
|
|
412
|
+
"ansi",
|
|
413
|
+
"ansi256",
|
|
414
|
+
"ansi16m"
|
|
415
|
+
];
|
|
416
|
+
var styles2 = /* @__PURE__ */ Object.create(null);
|
|
417
|
+
var applyOptions = (object, options = {}) => {
|
|
418
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
419
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
420
|
+
}
|
|
421
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
422
|
+
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
423
|
+
};
|
|
424
|
+
var chalkFactory = (options) => {
|
|
425
|
+
const chalk2 = (...strings) => strings.join(" ");
|
|
426
|
+
applyOptions(chalk2, options);
|
|
427
|
+
Object.setPrototypeOf(chalk2, createChalk.prototype);
|
|
428
|
+
return chalk2;
|
|
429
|
+
};
|
|
430
|
+
function createChalk(options) {
|
|
431
|
+
return chalkFactory(options);
|
|
432
|
+
}
|
|
433
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
434
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
435
|
+
styles2[styleName] = {
|
|
436
|
+
get() {
|
|
437
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
438
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
439
|
+
return builder;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
styles2.visible = {
|
|
444
|
+
get() {
|
|
445
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
446
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
447
|
+
return builder;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
451
|
+
if (model === "rgb") {
|
|
452
|
+
if (level === "ansi16m") {
|
|
453
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
454
|
+
}
|
|
455
|
+
if (level === "ansi256") {
|
|
456
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
457
|
+
}
|
|
458
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
459
|
+
}
|
|
460
|
+
if (model === "hex") {
|
|
461
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
462
|
+
}
|
|
463
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
464
|
+
};
|
|
465
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
466
|
+
for (const model of usedModels) {
|
|
467
|
+
styles2[model] = {
|
|
468
|
+
get() {
|
|
469
|
+
const { level } = this;
|
|
470
|
+
return function(...arguments_) {
|
|
471
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
472
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
477
|
+
styles2[bgModel] = {
|
|
478
|
+
get() {
|
|
479
|
+
const { level } = this;
|
|
480
|
+
return function(...arguments_) {
|
|
481
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
482
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
var proto = Object.defineProperties(() => {
|
|
488
|
+
}, {
|
|
489
|
+
...styles2,
|
|
490
|
+
level: {
|
|
491
|
+
enumerable: true,
|
|
492
|
+
get() {
|
|
493
|
+
return this[GENERATOR].level;
|
|
494
|
+
},
|
|
495
|
+
set(level) {
|
|
496
|
+
this[GENERATOR].level = level;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
var createStyler = (open, close, parent) => {
|
|
501
|
+
let openAll;
|
|
502
|
+
let closeAll;
|
|
503
|
+
if (parent === void 0) {
|
|
504
|
+
openAll = open;
|
|
505
|
+
closeAll = close;
|
|
506
|
+
} else {
|
|
507
|
+
openAll = parent.openAll + open;
|
|
508
|
+
closeAll = close + parent.closeAll;
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
open,
|
|
512
|
+
close,
|
|
513
|
+
openAll,
|
|
514
|
+
closeAll,
|
|
515
|
+
parent
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
519
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
520
|
+
Object.setPrototypeOf(builder, proto);
|
|
521
|
+
builder[GENERATOR] = self;
|
|
522
|
+
builder[STYLER] = _styler;
|
|
523
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
524
|
+
return builder;
|
|
525
|
+
};
|
|
526
|
+
var applyStyle = (self, string) => {
|
|
527
|
+
if (self.level <= 0 || !string) {
|
|
528
|
+
return self[IS_EMPTY] ? "" : string;
|
|
529
|
+
}
|
|
530
|
+
let styler = self[STYLER];
|
|
531
|
+
if (styler === void 0) {
|
|
532
|
+
return string;
|
|
533
|
+
}
|
|
534
|
+
const { openAll, closeAll } = styler;
|
|
535
|
+
if (string.includes("\x1B")) {
|
|
536
|
+
while (styler !== void 0) {
|
|
537
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
538
|
+
styler = styler.parent;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const lfIndex = string.indexOf("\n");
|
|
542
|
+
if (lfIndex !== -1) {
|
|
543
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
544
|
+
}
|
|
545
|
+
return openAll + string + closeAll;
|
|
546
|
+
};
|
|
547
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
548
|
+
var chalk = createChalk();
|
|
549
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
550
|
+
var source_default = chalk;
|
|
551
|
+
|
|
552
|
+
// src/command/tokens/index.ts
|
|
553
|
+
var import_chokidar = __toESM(require("chokidar"));
|
|
554
|
+
|
|
555
|
+
// src/command/tokens/create-theme-typings.ts
|
|
556
|
+
init_cjs_shims();
|
|
557
|
+
|
|
558
|
+
// src/utils/assertion.ts
|
|
559
|
+
init_cjs_shims();
|
|
560
|
+
var isObject = (obj) => obj !== null && (typeof obj === "object" || typeof obj === "function") && !isArray(obj);
|
|
561
|
+
var isArray = (value) => Array.isArray(value);
|
|
562
|
+
|
|
563
|
+
// src/utils/prettier.ts
|
|
564
|
+
init_cjs_shims();
|
|
565
|
+
var import_path = __toESM(require("path"));
|
|
566
|
+
var import_prettier = require("prettier");
|
|
567
|
+
var prettier = async (content, options) => {
|
|
568
|
+
const prettierConfig = await (0, import_prettier.resolveConfig)(
|
|
569
|
+
import_path.default.join(process.cwd(), ".prettierrc")
|
|
570
|
+
);
|
|
571
|
+
try {
|
|
572
|
+
return (0, import_prettier.format)(content, {
|
|
573
|
+
...prettierConfig,
|
|
574
|
+
parser: "typescript",
|
|
575
|
+
...options
|
|
576
|
+
});
|
|
577
|
+
} catch {
|
|
578
|
+
return content;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// src/utils/object.ts
|
|
583
|
+
init_cjs_shims();
|
|
584
|
+
var omitObject = (obj, keys) => {
|
|
585
|
+
const result = {};
|
|
586
|
+
Object.keys(obj).forEach((key) => {
|
|
587
|
+
if (keys.includes(key)) return;
|
|
588
|
+
result[key] = obj[key];
|
|
589
|
+
});
|
|
590
|
+
return result;
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
// src/command/tokens/config.ts
|
|
594
|
+
init_cjs_shims();
|
|
595
|
+
var config = [
|
|
596
|
+
{ key: "borders" },
|
|
597
|
+
{ key: "breakpoints", filter: (value) => Number.isNaN(Number(value)) },
|
|
598
|
+
{ key: "colors", maxScanDepth: 3 },
|
|
599
|
+
{ key: "fonts" },
|
|
600
|
+
{ key: "fontSizes" },
|
|
601
|
+
{ key: "fontWeights" },
|
|
602
|
+
{ key: "letterSpacings" },
|
|
603
|
+
{ key: "lineHeights" },
|
|
604
|
+
{ key: "radii" },
|
|
605
|
+
{ key: "shadows" },
|
|
606
|
+
{ key: "blurs" },
|
|
607
|
+
{ key: "sizes", maxScanDepth: 2 },
|
|
608
|
+
{ key: "spaces", flatMap: (value) => [value, `-${value}`] },
|
|
609
|
+
{ key: "zIndices" },
|
|
610
|
+
{ key: "animations", omitScanKeys: ["keyframes"] },
|
|
611
|
+
{ key: "gradients" }
|
|
612
|
+
];
|
|
613
|
+
|
|
614
|
+
// src/command/tokens/create-theme-typings.ts
|
|
615
|
+
var tones = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
616
|
+
var printComponent = (components) => `components: { ${Object.entries(components).map(
|
|
617
|
+
([key, unions]) => `${key.match(/^[a-zA-Z0-9\-_]+$/) ? key : `"${key}"`}: { ${print(
|
|
618
|
+
unions
|
|
619
|
+
)}}`
|
|
620
|
+
).join(`
|
|
621
|
+
`)} }`;
|
|
622
|
+
var print = (unions) => Object.entries(unions).sort(([a], [b]) => a.localeCompare(b)).map(
|
|
623
|
+
([key, union]) => `${key}: ${union.map((value) => `"${value}"`).concat(["(string & {})"]).join(" | ")};`
|
|
624
|
+
).join("\n");
|
|
625
|
+
var extractComponents = ({ components = {} }) => Object.entries(components).reduce(
|
|
626
|
+
(obj, [key, { sizes, variants }]) => {
|
|
627
|
+
if (sizes || variants) {
|
|
628
|
+
obj[key] = {
|
|
629
|
+
sizes: Object.keys(sizes ?? {}),
|
|
630
|
+
variants: Object.keys(variants ?? {})
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
return obj;
|
|
634
|
+
},
|
|
635
|
+
{}
|
|
636
|
+
);
|
|
637
|
+
var extractTransitions = (theme) => {
|
|
638
|
+
let transitionProperty = [];
|
|
639
|
+
let transitionDuration = [];
|
|
640
|
+
let transitionEasing = [];
|
|
641
|
+
const { transitions, semantics } = theme;
|
|
642
|
+
if (!isObject(transitions))
|
|
643
|
+
return { transitionProperty, transitionDuration, transitionEasing };
|
|
644
|
+
const { property, duration, easing } = semantics.transitions ?? {};
|
|
645
|
+
Object.entries(transitions).forEach(([key, value]) => {
|
|
646
|
+
switch (key) {
|
|
647
|
+
case "property":
|
|
648
|
+
transitionProperty = [...extractPaths(value), ...extractPaths(property)];
|
|
649
|
+
break;
|
|
650
|
+
case "duration":
|
|
651
|
+
transitionDuration = [...extractPaths(value), ...extractPaths(duration)];
|
|
652
|
+
break;
|
|
653
|
+
case "easing":
|
|
654
|
+
transitionEasing = [...extractPaths(value), ...extractPaths(easing)];
|
|
655
|
+
break;
|
|
656
|
+
default:
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
return { transitionProperty, transitionDuration, transitionEasing };
|
|
661
|
+
};
|
|
662
|
+
var isTone = (value) => {
|
|
663
|
+
if (!isObject(value)) return false;
|
|
664
|
+
const keys = Object.keys(value);
|
|
665
|
+
return tones.every((key) => keys.includes(key.toString()));
|
|
666
|
+
};
|
|
667
|
+
var extractColorSchemes = (theme) => {
|
|
668
|
+
const { colors, semantics } = theme;
|
|
669
|
+
const results = {
|
|
670
|
+
colorSchemes: [],
|
|
671
|
+
colorSchemeColors: []
|
|
672
|
+
};
|
|
673
|
+
if (!isObject(colors)) return results;
|
|
674
|
+
Object.entries(colors).forEach(([key, value]) => {
|
|
675
|
+
if (!isTone(value)) return;
|
|
676
|
+
results.colorSchemes.push(key);
|
|
677
|
+
const semanticKeys = Object.entries(semantics?.colorSchemes ?? {}).filter(([, relatedKey]) => key === relatedKey).map(([key2]) => key2) ?? [];
|
|
678
|
+
if (!semanticKeys.length) return;
|
|
679
|
+
results.colorSchemes.push(...semanticKeys);
|
|
680
|
+
results.colorSchemeColors.push(
|
|
681
|
+
...semanticKeys.map(
|
|
682
|
+
(semanticKey) => Object.keys(value).map((hue) => `${semanticKey}.${hue}`)
|
|
683
|
+
).flat()
|
|
684
|
+
);
|
|
685
|
+
});
|
|
686
|
+
return results;
|
|
687
|
+
};
|
|
688
|
+
var extractThemeSchemes = (theme) => {
|
|
689
|
+
const { themeSchemes } = theme;
|
|
690
|
+
if (!isObject(themeSchemes)) return ["base"];
|
|
691
|
+
return ["base", ...Object.keys(themeSchemes)];
|
|
692
|
+
};
|
|
693
|
+
var extractPaths = (target, maxDepth = 3, omitKeys = []) => {
|
|
694
|
+
if (!isObject(target) && !isArray(target) || !maxDepth) return [];
|
|
695
|
+
return Object.entries(target).reduce((array, [key, value]) => {
|
|
696
|
+
if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2))) {
|
|
697
|
+
extractPaths(value, maxDepth - 1, omitKeys).forEach(
|
|
698
|
+
(nestedKey) => array.push(`${key}.${nestedKey}`)
|
|
699
|
+
);
|
|
700
|
+
} else {
|
|
701
|
+
array.push(key);
|
|
702
|
+
}
|
|
703
|
+
return array;
|
|
704
|
+
}, []);
|
|
705
|
+
};
|
|
706
|
+
var extractKeys = (theme, key) => {
|
|
707
|
+
const keys = key.split(".");
|
|
708
|
+
const property = keys.reduce((obj, key2) => obj[key2] ?? {}, theme);
|
|
709
|
+
if (!isObject(property)) return [];
|
|
710
|
+
return Object.keys(property);
|
|
711
|
+
};
|
|
712
|
+
var createThemeTypings = async (theme) => {
|
|
713
|
+
const tokens = config.reduce(
|
|
714
|
+
(prev, {
|
|
715
|
+
key,
|
|
716
|
+
maxScanDepth,
|
|
717
|
+
omitScanKeys,
|
|
718
|
+
filter = () => true,
|
|
719
|
+
flatMap = (value) => value
|
|
720
|
+
}) => {
|
|
721
|
+
const target = theme[key];
|
|
722
|
+
prev[key] = [];
|
|
723
|
+
if (isObject(target) || isArray(target)) {
|
|
724
|
+
prev[key] = extractPaths(target, maxScanDepth, omitScanKeys).filter(filter).flatMap(flatMap);
|
|
725
|
+
}
|
|
726
|
+
if (isObject(theme.semantics)) {
|
|
727
|
+
const semanticKeys = extractKeys(
|
|
728
|
+
omitObject(theme.semantics, ["colorSchemes"]),
|
|
729
|
+
key
|
|
730
|
+
).filter(filter).flatMap(flatMap);
|
|
731
|
+
prev[key].push(...semanticKeys);
|
|
732
|
+
}
|
|
733
|
+
return prev;
|
|
734
|
+
},
|
|
735
|
+
{}
|
|
736
|
+
);
|
|
737
|
+
const textStyles = extractKeys(theme, "styles.textStyles");
|
|
738
|
+
const layerStyles = extractKeys(theme, "styles.layerStyles");
|
|
739
|
+
const { colorSchemes, colorSchemeColors } = extractColorSchemes(theme);
|
|
740
|
+
const themeSchemes = extractThemeSchemes(theme);
|
|
741
|
+
const { transitionProperty, transitionDuration, transitionEasing } = extractTransitions(theme);
|
|
742
|
+
const componentTypes = extractComponents(theme);
|
|
743
|
+
tokens.colors = [...tokens.colors, ...colorSchemeColors];
|
|
744
|
+
return prettier(
|
|
745
|
+
`import type { UITheme } from './ui-theme.types'
|
|
746
|
+
|
|
747
|
+
export interface GeneratedTheme extends UITheme { ${print(
|
|
748
|
+
{
|
|
749
|
+
...tokens,
|
|
750
|
+
textStyles,
|
|
751
|
+
layerStyles,
|
|
752
|
+
colorSchemes,
|
|
753
|
+
themeSchemes,
|
|
754
|
+
transitionProperty,
|
|
755
|
+
transitionDuration,
|
|
756
|
+
transitionEasing
|
|
757
|
+
}
|
|
758
|
+
)} ${printComponent(componentTypes)} }`
|
|
759
|
+
);
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// src/command/tokens/resolve-output-path.ts
|
|
763
|
+
init_cjs_shims();
|
|
764
|
+
var import_path2 = __toESM(require("path"));
|
|
765
|
+
var import_glob = require("glob");
|
|
766
|
+
var themePath = [
|
|
767
|
+
"node_modules",
|
|
768
|
+
"@yamada-ui",
|
|
769
|
+
"core",
|
|
770
|
+
"dist",
|
|
771
|
+
"generated-theme.types.d.ts"
|
|
772
|
+
];
|
|
773
|
+
var resolveThemePath = async () => {
|
|
774
|
+
const paths = [
|
|
775
|
+
import_path2.default.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
|
|
776
|
+
import_path2.default.join(...themePath),
|
|
777
|
+
import_path2.default.posix.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
|
|
778
|
+
import_path2.default.posix.join(...themePath)
|
|
779
|
+
];
|
|
780
|
+
const triedPaths = await Promise.all(
|
|
781
|
+
paths.map(async (possiblePath) => {
|
|
782
|
+
const paths2 = await (0, import_glob.glob)(possiblePath);
|
|
783
|
+
if (paths2.length) return paths2[0];
|
|
784
|
+
return "";
|
|
785
|
+
})
|
|
786
|
+
);
|
|
787
|
+
const resolvedPath = triedPaths.find(Boolean);
|
|
788
|
+
if (!resolvedPath) return;
|
|
789
|
+
return import_path2.default.resolve(process.cwd(), resolvedPath);
|
|
790
|
+
};
|
|
791
|
+
var resolveOutputPath = async (outPath) => {
|
|
792
|
+
if (outPath) return import_path2.default.resolve(process.cwd(), outPath);
|
|
793
|
+
const themePath2 = await resolveThemePath();
|
|
794
|
+
if (!themePath2)
|
|
795
|
+
throw new Error(
|
|
796
|
+
"Could not find @yamada-ui/core in node_modules. Please provide `--out` parameter."
|
|
797
|
+
);
|
|
798
|
+
return themePath2;
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
// src/command/tokens/index.ts
|
|
802
|
+
var generateThemeTypings = async ({
|
|
803
|
+
theme,
|
|
804
|
+
outFile
|
|
805
|
+
}) => {
|
|
806
|
+
p.intro(source_default.magenta(`Generating Yamada UI theme typings`));
|
|
807
|
+
const s = p.spinner();
|
|
808
|
+
try {
|
|
809
|
+
const start = process.hrtime.bigint();
|
|
810
|
+
s.start(`Parsing the theme`);
|
|
811
|
+
const generatedTheme = await createThemeTypings(theme);
|
|
812
|
+
s.stop(`Parsed the theme`);
|
|
813
|
+
s.start(`Resolving the output path`);
|
|
814
|
+
const outPath = await resolveOutputPath(outFile);
|
|
815
|
+
s.stop(`Resolved the output path`);
|
|
816
|
+
s.start(`Writing file "${outPath}"`);
|
|
817
|
+
await (0, import_promises.writeFile)(outPath, generatedTheme, "utf8");
|
|
818
|
+
s.stop(`Wrote file`);
|
|
819
|
+
p.note(outPath, "Output path");
|
|
820
|
+
const end = process.hrtime.bigint();
|
|
821
|
+
const duration = (Number(end - start) / 1e9).toFixed(2);
|
|
822
|
+
p.outro(source_default.green(`Done in ${duration}s
|
|
823
|
+
`));
|
|
824
|
+
} catch (e) {
|
|
825
|
+
s.stop(`An error occurred`, 500);
|
|
826
|
+
p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
var actionTokens = async (themePath2, { out: outFile, watch: watchFile }) => {
|
|
830
|
+
const readFile2 = async () => {
|
|
831
|
+
const filePath = import_path3.default.resolve(themePath2);
|
|
832
|
+
const { mod: theme, dependencies } = await (0, import_bundle_n_require.bundleNRequire)(filePath);
|
|
833
|
+
return { theme, dependencies };
|
|
834
|
+
};
|
|
835
|
+
let file = await readFile2();
|
|
836
|
+
const buildFile = async () => {
|
|
837
|
+
await generateThemeTypings({ theme: file.theme, outFile });
|
|
838
|
+
if (watchFile) console.log("\n", "\u231B\uFE0F Watching for changes...");
|
|
839
|
+
};
|
|
840
|
+
if (watchFile) {
|
|
841
|
+
const watchPath = typeof watchFile === "string" ? watchFile : file.dependencies;
|
|
842
|
+
import_chokidar.default.watch(watchPath).on("ready", buildFile).on("change", async (filePath) => {
|
|
843
|
+
console.log("\u{1F4E6} File changed", filePath);
|
|
844
|
+
file = await readFile2();
|
|
845
|
+
return buildFile();
|
|
846
|
+
});
|
|
847
|
+
} else {
|
|
848
|
+
await buildFile();
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
// src/command/theme/index.ts
|
|
853
|
+
init_cjs_shims();
|
|
854
|
+
var import_dns = __toESM(require("dns"));
|
|
855
|
+
var import_fs2 = require("fs");
|
|
856
|
+
var import_promises2 = require("fs/promises");
|
|
857
|
+
var import_node_stream = require("stream");
|
|
858
|
+
var import_promises3 = require("stream/promises");
|
|
859
|
+
var import_path4 = __toESM(require("path"));
|
|
860
|
+
var p2 = __toESM(require("@clack/prompts"));
|
|
861
|
+
var import_tar = require("tar");
|
|
862
|
+
var import_typescript = require("typescript");
|
|
863
|
+
|
|
864
|
+
// src/utils/fs.ts
|
|
865
|
+
init_cjs_shims();
|
|
866
|
+
var import_fs = __toESM(require("fs"));
|
|
867
|
+
var isWriteable = async (directory) => {
|
|
868
|
+
try {
|
|
869
|
+
await import_fs.default.promises.access(directory, (import_fs.default.constants || import_fs.default).W_OK);
|
|
870
|
+
return true;
|
|
871
|
+
} catch (err) {
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
// src/command/theme/index.ts
|
|
877
|
+
var ORG_NAME = "yamada-ui";
|
|
878
|
+
var REPO_NAME = "yamada-ui";
|
|
879
|
+
var DEFAULT_BRANCH_NAME = "main";
|
|
880
|
+
var isOnline = () => {
|
|
881
|
+
return new Promise((resolve) => {
|
|
882
|
+
import_dns.default.lookup("github.com", (err) => {
|
|
883
|
+
if (err && err.code === "ENOTFOUND") {
|
|
884
|
+
resolve(false);
|
|
885
|
+
} else {
|
|
886
|
+
resolve(true);
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
};
|
|
891
|
+
var checkHasReact = async (cwd) => {
|
|
892
|
+
try {
|
|
893
|
+
const packageJson = await (0, import_promises2.readFile)(import_path4.default.join(cwd, "package.json"), "utf-8");
|
|
894
|
+
const { dependencies, devDependencies } = JSON.parse(packageJson);
|
|
895
|
+
return !!dependencies?.["@yamada-ui/react"] || !!devDependencies?.["@yamada-ui/react"];
|
|
896
|
+
} catch {
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
var getSource = async (branch) => {
|
|
901
|
+
if (!await isOnline()) {
|
|
902
|
+
throw new Error(
|
|
903
|
+
"No internet connection, please check your connection and try again."
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
const url = `https://codeload.github.com/${ORG_NAME}/${REPO_NAME}/tar.gz/${branch}`;
|
|
907
|
+
const { body } = await fetch(url);
|
|
908
|
+
if (!body) throw new Error(`Failed to download: ${url}`);
|
|
909
|
+
return import_node_stream.Readable.fromWeb(body);
|
|
910
|
+
};
|
|
911
|
+
var getFileMap = async (cwd, branch) => {
|
|
912
|
+
const source = await getSource(branch);
|
|
913
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
914
|
+
const targetPath = `${REPO_NAME}-${branch.replace("/", "-")}/packages/theme/src`;
|
|
915
|
+
const filter = (path5) => {
|
|
916
|
+
return path5.startsWith(targetPath);
|
|
917
|
+
};
|
|
918
|
+
const onReadEntry = (entry) => {
|
|
919
|
+
if (entry.type !== "Directory") {
|
|
920
|
+
const filePath = entry.path.replace(`${targetPath}/`, "");
|
|
921
|
+
let content = "";
|
|
922
|
+
entry.on("data", (chunk) => {
|
|
923
|
+
content += chunk.toString();
|
|
924
|
+
});
|
|
925
|
+
entry.on("end", () => {
|
|
926
|
+
fileMap.set(filePath, content);
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
await (0, import_promises3.pipeline)(
|
|
931
|
+
source,
|
|
932
|
+
(0, import_tar.t)({
|
|
933
|
+
cwd,
|
|
934
|
+
filter,
|
|
935
|
+
onReadEntry,
|
|
936
|
+
strip: 4,
|
|
937
|
+
newer: true
|
|
938
|
+
})
|
|
939
|
+
);
|
|
940
|
+
return fileMap;
|
|
941
|
+
};
|
|
942
|
+
var transformSourceFile = (sourceFile) => {
|
|
943
|
+
const ImportDeclarations = [];
|
|
944
|
+
const ImportTypeDeclarations = [];
|
|
945
|
+
const transformer = (context) => (sourceFile2) => {
|
|
946
|
+
const visitor = (node) => {
|
|
947
|
+
if ((0, import_typescript.isImportDeclaration)(node)) {
|
|
948
|
+
const moduleSpecifier = node.moduleSpecifier.getText().slice(1, -1);
|
|
949
|
+
if (moduleSpecifier.startsWith("@yamada-ui/")) {
|
|
950
|
+
if (node.importClause?.isTypeOnly) {
|
|
951
|
+
ImportTypeDeclarations.push(node);
|
|
952
|
+
} else {
|
|
953
|
+
ImportDeclarations.push(node);
|
|
954
|
+
}
|
|
955
|
+
return import_typescript.factory.createEmptyStatement();
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return (0, import_typescript.visitEachChild)(node, visitor, context);
|
|
959
|
+
};
|
|
960
|
+
return (0, import_typescript.visitNode)(sourceFile2, visitor);
|
|
961
|
+
};
|
|
962
|
+
const { transformed } = (0, import_typescript.transform)(sourceFile, [transformer]);
|
|
963
|
+
const transformedSourceFile = transformed[0];
|
|
964
|
+
return { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile };
|
|
965
|
+
};
|
|
966
|
+
var createImportDeclaration = (isTypeOnly, declarations) => {
|
|
967
|
+
const elements = declarations.flatMap(
|
|
968
|
+
({ importClause: importClause2 }) => importClause2?.namedBindings && (0, import_typescript.isNamedImports)(importClause2.namedBindings) ? importClause2.namedBindings.elements : []
|
|
969
|
+
);
|
|
970
|
+
const namedBindings = import_typescript.factory.createNamedImports(elements);
|
|
971
|
+
const importClause = import_typescript.factory.createImportClause(
|
|
972
|
+
isTypeOnly,
|
|
973
|
+
void 0,
|
|
974
|
+
namedBindings
|
|
975
|
+
);
|
|
976
|
+
return import_typescript.factory.createImportDeclaration(
|
|
977
|
+
void 0,
|
|
978
|
+
importClause,
|
|
979
|
+
import_typescript.factory.createStringLiteral("@yamada-ui/react")
|
|
980
|
+
);
|
|
981
|
+
};
|
|
982
|
+
var replaceContent = (content) => {
|
|
983
|
+
const sourceFile = (0, import_typescript.createSourceFile)(
|
|
984
|
+
"temp.ts",
|
|
985
|
+
content,
|
|
986
|
+
import_typescript.ScriptTarget.Latest,
|
|
987
|
+
true
|
|
988
|
+
);
|
|
989
|
+
const printer = (0, import_typescript.createPrinter)({ newLine: import_typescript.NewLineKind.LineFeed });
|
|
990
|
+
const { ImportDeclarations, ImportTypeDeclarations, transformedSourceFile } = transformSourceFile(sourceFile);
|
|
991
|
+
const statements = [...transformedSourceFile.statements];
|
|
992
|
+
if (ImportTypeDeclarations.length) {
|
|
993
|
+
const newImportTypeDeclarations = createImportDeclaration(
|
|
994
|
+
true,
|
|
995
|
+
ImportTypeDeclarations
|
|
996
|
+
);
|
|
997
|
+
statements.unshift(newImportTypeDeclarations);
|
|
998
|
+
}
|
|
999
|
+
if (ImportDeclarations.length) {
|
|
1000
|
+
const newImportDeclarations = createImportDeclaration(
|
|
1001
|
+
false,
|
|
1002
|
+
ImportDeclarations
|
|
1003
|
+
);
|
|
1004
|
+
statements.unshift(newImportDeclarations);
|
|
1005
|
+
}
|
|
1006
|
+
const updatedSourceFile = import_typescript.factory.updateSourceFile(
|
|
1007
|
+
transformedSourceFile,
|
|
1008
|
+
statements
|
|
1009
|
+
);
|
|
1010
|
+
let printedContent = printer.printFile(updatedSourceFile);
|
|
1011
|
+
printedContent = printedContent.replace(/^;$/gm, "");
|
|
1012
|
+
printedContent = printedContent.replace(/\s\n*(?=import)/g, "");
|
|
1013
|
+
printedContent = printedContent.replace(/(import .*\n)+(?!import)/, "$&\n");
|
|
1014
|
+
return printedContent;
|
|
1015
|
+
};
|
|
1016
|
+
var replaceIndex = (content) => {
|
|
1017
|
+
const index = content.indexOf("export const baseTheme");
|
|
1018
|
+
content = content.slice(0, index);
|
|
1019
|
+
content = content.replace(/export const baseTheme/, "export const theme");
|
|
1020
|
+
content = content.replace(/\nimport { config } from ".\/config"/, "");
|
|
1021
|
+
content += "\nexport { config } from './config'";
|
|
1022
|
+
return content;
|
|
1023
|
+
};
|
|
1024
|
+
var generateTheme = async (outPath, fileMap, isReactReplace, isForceReplace) => {
|
|
1025
|
+
if (!await isWriteable(import_path4.default.dirname(outPath))) {
|
|
1026
|
+
throw new Error(
|
|
1027
|
+
"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."
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
await (0, import_promises2.mkdir)(outPath, { recursive: true });
|
|
1031
|
+
await Promise.all(
|
|
1032
|
+
[...fileMap.entries()].map(async ([filePath, _content]) => {
|
|
1033
|
+
const targetPath = import_path4.default.join(outPath, filePath);
|
|
1034
|
+
let content = _content;
|
|
1035
|
+
if (filePath === "index.ts") {
|
|
1036
|
+
content = replaceIndex(content);
|
|
1037
|
+
} else {
|
|
1038
|
+
if (isReactReplace) content = replaceContent(content);
|
|
1039
|
+
}
|
|
1040
|
+
const formattedContent = await prettier(content);
|
|
1041
|
+
try {
|
|
1042
|
+
if (!isForceReplace && (0, import_fs2.existsSync)(targetPath)) return;
|
|
1043
|
+
await (0, import_promises2.writeFile)(targetPath, formattedContent, "utf-8");
|
|
1044
|
+
} catch (e) {
|
|
1045
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
1046
|
+
const dirPath = import_path4.default.dirname(targetPath);
|
|
1047
|
+
await (0, import_promises2.mkdir)(dirPath, { recursive: true });
|
|
1048
|
+
if (!isForceReplace && (0, import_fs2.existsSync)(targetPath)) return;
|
|
1049
|
+
await (0, import_promises2.writeFile)(targetPath, formattedContent, "utf-8");
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
})
|
|
1053
|
+
);
|
|
1054
|
+
};
|
|
1055
|
+
var actionTheme = async (_outPath, { branch = DEFAULT_BRANCH_NAME, cwd, replace = false }) => {
|
|
1056
|
+
p2.intro(source_default.magenta(`Generating Yamada UI theme`));
|
|
1057
|
+
const s = p2.spinner();
|
|
1058
|
+
try {
|
|
1059
|
+
const start = process.hrtime.bigint();
|
|
1060
|
+
cwd ??= import_path4.default.resolve();
|
|
1061
|
+
const outPath = import_path4.default.join(cwd, _outPath);
|
|
1062
|
+
s.start(`Checking "package.json"`);
|
|
1063
|
+
const hasReact = await checkHasReact(cwd);
|
|
1064
|
+
s.stop(`Checked "package.json"`);
|
|
1065
|
+
s.start(`Downloading the theme`);
|
|
1066
|
+
const fileMap = await getFileMap(outPath, branch);
|
|
1067
|
+
s.stop(`Downloaded the theme`);
|
|
1068
|
+
s.start(`Writing the theme "${outPath}"`);
|
|
1069
|
+
await generateTheme(outPath, fileMap, hasReact, replace);
|
|
1070
|
+
s.stop(`Wrote the theme`);
|
|
1071
|
+
const end = process.hrtime.bigint();
|
|
1072
|
+
const duration = (Number(end - start) / 1e9).toFixed(2);
|
|
1073
|
+
p2.outro(source_default.green(`Done in ${duration}s
|
|
1074
|
+
`));
|
|
1075
|
+
} catch (e) {
|
|
1076
|
+
s.stop(`An error occurred`, 500);
|
|
1077
|
+
p2.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1081
|
+
0 && (module.exports = {
|
|
1082
|
+
actionTheme,
|
|
1083
|
+
actionTokens,
|
|
1084
|
+
themePath
|
|
1085
|
+
});
|