@yamada-ui/cli 1.2.4 → 2.0.0-dev-20250626070331

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.
@@ -1,880 +0,0 @@
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.3.6_@swc+core@1.10.18_jiti@2.4.2_tsx@4.19.3_typescript@5.7.3/node_modules/tsup/assets/cjs_shims.js
34
- var init_cjs_shims = __esm({
35
- "../../node_modules/.pnpm/tsup@8.3.6_@swc+core@1.10.18_jiti@2.4.2_tsx@4.19.3_typescript@5.7.3/node_modules/tsup/assets/cjs_shims.js"() {
36
- "use strict";
37
- }
38
- });
39
-
40
- // src/command/tokens/index.ts
41
- var tokens_exports = {};
42
- __export(tokens_exports, {
43
- actionTokens: () => actionTokens,
44
- themePath: () => themePath
45
- });
46
- module.exports = __toCommonJS(tokens_exports);
47
- init_cjs_shims();
48
- var p = __toESM(require("@clack/prompts"));
49
-
50
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/index.js
51
- init_cjs_shims();
52
-
53
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/vendor/ansi-styles/index.js
54
- init_cjs_shims();
55
- var ANSI_BACKGROUND_OFFSET = 10;
56
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
57
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
58
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
59
- var styles = {
60
- modifier: {
61
- reset: [0, 0],
62
- // 21 isn't widely supported and 22 does the same thing
63
- bold: [1, 22],
64
- dim: [2, 22],
65
- italic: [3, 23],
66
- underline: [4, 24],
67
- overline: [53, 55],
68
- inverse: [7, 27],
69
- hidden: [8, 28],
70
- strikethrough: [9, 29]
71
- },
72
- color: {
73
- black: [30, 39],
74
- red: [31, 39],
75
- green: [32, 39],
76
- yellow: [33, 39],
77
- blue: [34, 39],
78
- magenta: [35, 39],
79
- cyan: [36, 39],
80
- white: [37, 39],
81
- // Bright color
82
- blackBright: [90, 39],
83
- gray: [90, 39],
84
- // Alias of `blackBright`
85
- grey: [90, 39],
86
- // Alias of `blackBright`
87
- redBright: [91, 39],
88
- greenBright: [92, 39],
89
- yellowBright: [93, 39],
90
- blueBright: [94, 39],
91
- magentaBright: [95, 39],
92
- cyanBright: [96, 39],
93
- whiteBright: [97, 39]
94
- },
95
- bgColor: {
96
- bgBlack: [40, 49],
97
- bgRed: [41, 49],
98
- bgGreen: [42, 49],
99
- bgYellow: [43, 49],
100
- bgBlue: [44, 49],
101
- bgMagenta: [45, 49],
102
- bgCyan: [46, 49],
103
- bgWhite: [47, 49],
104
- // Bright color
105
- bgBlackBright: [100, 49],
106
- bgGray: [100, 49],
107
- // Alias of `bgBlackBright`
108
- bgGrey: [100, 49],
109
- // Alias of `bgBlackBright`
110
- bgRedBright: [101, 49],
111
- bgGreenBright: [102, 49],
112
- bgYellowBright: [103, 49],
113
- bgBlueBright: [104, 49],
114
- bgMagentaBright: [105, 49],
115
- bgCyanBright: [106, 49],
116
- bgWhiteBright: [107, 49]
117
- }
118
- };
119
- var modifierNames = Object.keys(styles.modifier);
120
- var foregroundColorNames = Object.keys(styles.color);
121
- var backgroundColorNames = Object.keys(styles.bgColor);
122
- var colorNames = [...foregroundColorNames, ...backgroundColorNames];
123
- function assembleStyles() {
124
- const codes = /* @__PURE__ */ new Map();
125
- for (const [groupName, group] of Object.entries(styles)) {
126
- for (const [styleName, style] of Object.entries(group)) {
127
- styles[styleName] = {
128
- open: `\x1B[${style[0]}m`,
129
- close: `\x1B[${style[1]}m`
130
- };
131
- group[styleName] = styles[styleName];
132
- codes.set(style[0], style[1]);
133
- }
134
- Object.defineProperty(styles, groupName, {
135
- value: group,
136
- enumerable: false
137
- });
138
- }
139
- Object.defineProperty(styles, "codes", {
140
- value: codes,
141
- enumerable: false
142
- });
143
- styles.color.close = "\x1B[39m";
144
- styles.bgColor.close = "\x1B[49m";
145
- styles.color.ansi = wrapAnsi16();
146
- styles.color.ansi256 = wrapAnsi256();
147
- styles.color.ansi16m = wrapAnsi16m();
148
- styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
149
- styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
150
- styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
151
- Object.defineProperties(styles, {
152
- rgbToAnsi256: {
153
- value(red, green, blue) {
154
- if (red === green && green === blue) {
155
- if (red < 8) {
156
- return 16;
157
- }
158
- if (red > 248) {
159
- return 231;
160
- }
161
- return Math.round((red - 8) / 247 * 24) + 232;
162
- }
163
- return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
164
- },
165
- enumerable: false
166
- },
167
- hexToRgb: {
168
- value(hex) {
169
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
170
- if (!matches) {
171
- return [0, 0, 0];
172
- }
173
- let [colorString] = matches;
174
- if (colorString.length === 3) {
175
- colorString = [...colorString].map((character) => character + character).join("");
176
- }
177
- const integer = Number.parseInt(colorString, 16);
178
- return [
179
- /* eslint-disable no-bitwise */
180
- integer >> 16 & 255,
181
- integer >> 8 & 255,
182
- integer & 255
183
- /* eslint-enable no-bitwise */
184
- ];
185
- },
186
- enumerable: false
187
- },
188
- hexToAnsi256: {
189
- value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
190
- enumerable: false
191
- },
192
- ansi256ToAnsi: {
193
- value(code) {
194
- if (code < 8) {
195
- return 30 + code;
196
- }
197
- if (code < 16) {
198
- return 90 + (code - 8);
199
- }
200
- let red;
201
- let green;
202
- let blue;
203
- if (code >= 232) {
204
- red = ((code - 232) * 10 + 8) / 255;
205
- green = red;
206
- blue = red;
207
- } else {
208
- code -= 16;
209
- const remainder = code % 36;
210
- red = Math.floor(code / 36) / 5;
211
- green = Math.floor(remainder / 6) / 5;
212
- blue = remainder % 6 / 5;
213
- }
214
- const value = Math.max(red, green, blue) * 2;
215
- if (value === 0) {
216
- return 30;
217
- }
218
- let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
219
- if (value === 2) {
220
- result += 60;
221
- }
222
- return result;
223
- },
224
- enumerable: false
225
- },
226
- rgbToAnsi: {
227
- value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
228
- enumerable: false
229
- },
230
- hexToAnsi: {
231
- value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
232
- enumerable: false
233
- }
234
- });
235
- return styles;
236
- }
237
- var ansiStyles = assembleStyles();
238
- var ansi_styles_default = ansiStyles;
239
-
240
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/vendor/supports-color/index.js
241
- init_cjs_shims();
242
- var import_node_process = __toESM(require("process"), 1);
243
- var import_node_os = __toESM(require("os"), 1);
244
- var import_node_tty = __toESM(require("tty"), 1);
245
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
246
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
247
- const position = argv.indexOf(prefix + flag);
248
- const terminatorPosition = argv.indexOf("--");
249
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
250
- }
251
- var { env } = import_node_process.default;
252
- var flagForceColor;
253
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
254
- flagForceColor = 0;
255
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
256
- flagForceColor = 1;
257
- }
258
- function envForceColor() {
259
- if ("FORCE_COLOR" in env) {
260
- if (env.FORCE_COLOR === "true") {
261
- return 1;
262
- }
263
- if (env.FORCE_COLOR === "false") {
264
- return 0;
265
- }
266
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
267
- }
268
- }
269
- function translateLevel(level) {
270
- if (level === 0) {
271
- return false;
272
- }
273
- return {
274
- level,
275
- hasBasic: true,
276
- has256: level >= 2,
277
- has16m: level >= 3
278
- };
279
- }
280
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
281
- const noFlagForceColor = envForceColor();
282
- if (noFlagForceColor !== void 0) {
283
- flagForceColor = noFlagForceColor;
284
- }
285
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
286
- if (forceColor === 0) {
287
- return 0;
288
- }
289
- if (sniffFlags) {
290
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
291
- return 3;
292
- }
293
- if (hasFlag("color=256")) {
294
- return 2;
295
- }
296
- }
297
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
298
- return 1;
299
- }
300
- if (haveStream && !streamIsTTY && forceColor === void 0) {
301
- return 0;
302
- }
303
- const min = forceColor || 0;
304
- if (env.TERM === "dumb") {
305
- return min;
306
- }
307
- if (import_node_process.default.platform === "win32") {
308
- const osRelease = import_node_os.default.release().split(".");
309
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
310
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
311
- }
312
- return 1;
313
- }
314
- if ("CI" in env) {
315
- if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
316
- return 3;
317
- }
318
- if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
319
- return 1;
320
- }
321
- return min;
322
- }
323
- if ("TEAMCITY_VERSION" in env) {
324
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
325
- }
326
- if (env.COLORTERM === "truecolor") {
327
- return 3;
328
- }
329
- if (env.TERM === "xterm-kitty") {
330
- return 3;
331
- }
332
- if ("TERM_PROGRAM" in env) {
333
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
334
- switch (env.TERM_PROGRAM) {
335
- case "iTerm.app": {
336
- return version >= 3 ? 3 : 2;
337
- }
338
- case "Apple_Terminal": {
339
- return 2;
340
- }
341
- }
342
- }
343
- if (/-256(color)?$/i.test(env.TERM)) {
344
- return 2;
345
- }
346
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
347
- return 1;
348
- }
349
- if ("COLORTERM" in env) {
350
- return 1;
351
- }
352
- return min;
353
- }
354
- function createSupportsColor(stream, options = {}) {
355
- const level = _supportsColor(stream, {
356
- streamIsTTY: stream && stream.isTTY,
357
- ...options
358
- });
359
- return translateLevel(level);
360
- }
361
- var supportsColor = {
362
- stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
363
- stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
364
- };
365
- var supports_color_default = supportsColor;
366
-
367
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/utilities.js
368
- init_cjs_shims();
369
- function stringReplaceAll(string, substring, replacer) {
370
- let index = string.indexOf(substring);
371
- if (index === -1) {
372
- return string;
373
- }
374
- const substringLength = substring.length;
375
- let endIndex = 0;
376
- let returnValue = "";
377
- do {
378
- returnValue += string.slice(endIndex, index) + substring + replacer;
379
- endIndex = index + substringLength;
380
- index = string.indexOf(substring, endIndex);
381
- } while (index !== -1);
382
- returnValue += string.slice(endIndex);
383
- return returnValue;
384
- }
385
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
386
- let endIndex = 0;
387
- let returnValue = "";
388
- do {
389
- const gotCR = string[index - 1] === "\r";
390
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
391
- endIndex = index + 1;
392
- index = string.indexOf("\n", endIndex);
393
- } while (index !== -1);
394
- returnValue += string.slice(endIndex);
395
- return returnValue;
396
- }
397
-
398
- // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/index.js
399
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
400
- var GENERATOR = Symbol("GENERATOR");
401
- var STYLER = Symbol("STYLER");
402
- var IS_EMPTY = Symbol("IS_EMPTY");
403
- var levelMapping = [
404
- "ansi",
405
- "ansi",
406
- "ansi256",
407
- "ansi16m"
408
- ];
409
- var styles2 = /* @__PURE__ */ Object.create(null);
410
- var applyOptions = (object, options = {}) => {
411
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
412
- throw new Error("The `level` option should be an integer from 0 to 3");
413
- }
414
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
415
- object.level = options.level === void 0 ? colorLevel : options.level;
416
- };
417
- var chalkFactory = (options) => {
418
- const chalk2 = (...strings) => strings.join(" ");
419
- applyOptions(chalk2, options);
420
- Object.setPrototypeOf(chalk2, createChalk.prototype);
421
- return chalk2;
422
- };
423
- function createChalk(options) {
424
- return chalkFactory(options);
425
- }
426
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
427
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
428
- styles2[styleName] = {
429
- get() {
430
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
431
- Object.defineProperty(this, styleName, { value: builder });
432
- return builder;
433
- }
434
- };
435
- }
436
- styles2.visible = {
437
- get() {
438
- const builder = createBuilder(this, this[STYLER], true);
439
- Object.defineProperty(this, "visible", { value: builder });
440
- return builder;
441
- }
442
- };
443
- var getModelAnsi = (model, level, type, ...arguments_) => {
444
- if (model === "rgb") {
445
- if (level === "ansi16m") {
446
- return ansi_styles_default[type].ansi16m(...arguments_);
447
- }
448
- if (level === "ansi256") {
449
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
450
- }
451
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
452
- }
453
- if (model === "hex") {
454
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
455
- }
456
- return ansi_styles_default[type][model](...arguments_);
457
- };
458
- var usedModels = ["rgb", "hex", "ansi256"];
459
- for (const model of usedModels) {
460
- styles2[model] = {
461
- get() {
462
- const { level } = this;
463
- return function(...arguments_) {
464
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
465
- return createBuilder(this, styler, this[IS_EMPTY]);
466
- };
467
- }
468
- };
469
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
470
- styles2[bgModel] = {
471
- get() {
472
- const { level } = this;
473
- return function(...arguments_) {
474
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
475
- return createBuilder(this, styler, this[IS_EMPTY]);
476
- };
477
- }
478
- };
479
- }
480
- var proto = Object.defineProperties(() => {
481
- }, {
482
- ...styles2,
483
- level: {
484
- enumerable: true,
485
- get() {
486
- return this[GENERATOR].level;
487
- },
488
- set(level) {
489
- this[GENERATOR].level = level;
490
- }
491
- }
492
- });
493
- var createStyler = (open, close, parent) => {
494
- let openAll;
495
- let closeAll;
496
- if (parent === void 0) {
497
- openAll = open;
498
- closeAll = close;
499
- } else {
500
- openAll = parent.openAll + open;
501
- closeAll = close + parent.closeAll;
502
- }
503
- return {
504
- open,
505
- close,
506
- openAll,
507
- closeAll,
508
- parent
509
- };
510
- };
511
- var createBuilder = (self, _styler, _isEmpty) => {
512
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
513
- Object.setPrototypeOf(builder, proto);
514
- builder[GENERATOR] = self;
515
- builder[STYLER] = _styler;
516
- builder[IS_EMPTY] = _isEmpty;
517
- return builder;
518
- };
519
- var applyStyle = (self, string) => {
520
- if (self.level <= 0 || !string) {
521
- return self[IS_EMPTY] ? "" : string;
522
- }
523
- let styler = self[STYLER];
524
- if (styler === void 0) {
525
- return string;
526
- }
527
- const { openAll, closeAll } = styler;
528
- if (string.includes("\x1B")) {
529
- while (styler !== void 0) {
530
- string = stringReplaceAll(string, styler.close, styler.open);
531
- styler = styler.parent;
532
- }
533
- }
534
- const lfIndex = string.indexOf("\n");
535
- if (lfIndex !== -1) {
536
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
537
- }
538
- return openAll + string + closeAll;
539
- };
540
- Object.defineProperties(createChalk.prototype, styles2);
541
- var chalk = createChalk();
542
- var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
543
- var source_default = chalk;
544
-
545
- // src/command/tokens/index.ts
546
- var import_chokidar = __toESM(require("chokidar"));
547
- var import_promises = require("fs/promises");
548
- var import_path3 = __toESM(require("path"));
549
-
550
- // src/utils/assertion.ts
551
- init_cjs_shims();
552
- var isObject = (obj) => obj !== null && (typeof obj === "object" || typeof obj === "function") && !isArray(obj);
553
- var isArray = (value) => Array.isArray(value);
554
-
555
- // src/utils/module.ts
556
- init_cjs_shims();
557
- var import_esbuild = require("esbuild");
558
- var import_fs = require("fs");
559
- var import_node_eval = __toESM(require("node-eval"));
560
- var import_vm = require("vm");
561
- var getModule = async (file, cwd) => {
562
- const result = await (0, import_esbuild.build)({
563
- absWorkingDir: cwd,
564
- bundle: true,
565
- entryPoints: [file],
566
- format: "cjs",
567
- mainFields: ["module", "main"],
568
- metafile: true,
569
- outfile: "out.js",
570
- platform: "node",
571
- sourcemap: false,
572
- write: false
573
- });
574
- const { text: code } = result.outputFiles[0] ?? {};
575
- const dependencies = isObject(result.metafile) ? Object.keys(result.metafile.inputs) : [];
576
- try {
577
- const realFileName = import_fs.realpathSync.native(file);
578
- if (!code) throw new Error("code is undefined");
579
- const script = new import_vm.Script(code, { filename: realFileName });
580
- const mod = { exports: {} };
581
- const require2 = (id) => id === realFileName ? mod.exports : require2(id);
582
- script.runInThisContext()(mod.exports, require2, mod);
583
- return { code, dependencies, mod };
584
- } catch {
585
- const mod = (0, import_node_eval.default)(code);
586
- return { code, dependencies, mod };
587
- }
588
- };
589
-
590
- // src/utils/object.ts
591
- init_cjs_shims();
592
- var getObject = (obj, path4) => {
593
- const keys = path4.split(".");
594
- return keys.reduce((obj2, key) => obj2[key] ?? {}, obj);
595
- };
596
-
597
- // src/utils/prettier.ts
598
- init_cjs_shims();
599
- var import_path = __toESM(require("path"));
600
- var import_prettier = require("prettier");
601
- var prettier = async (content, options) => {
602
- const prettierConfig = await (0, import_prettier.resolveConfig)(
603
- import_path.default.join(process.cwd(), ".prettierrc")
604
- );
605
- try {
606
- return (0, import_prettier.format)(content, {
607
- ...prettierConfig,
608
- parser: "typescript",
609
- ...options
610
- });
611
- } catch {
612
- return content;
613
- }
614
- };
615
-
616
- // src/command/tokens/create-theme-typings.ts
617
- init_cjs_shims();
618
-
619
- // src/command/tokens/config.ts
620
- init_cjs_shims();
621
- var config = [
622
- { key: "borders" },
623
- { key: "breakpoints" },
624
- { key: "colors" },
625
- { key: "fonts" },
626
- { key: "fontSizes" },
627
- { key: "fontWeights" },
628
- { key: "letterSpacings" },
629
- { key: "lineHeights" },
630
- { key: "radii" },
631
- { key: "shadows" },
632
- { key: "blurs" },
633
- { key: "sizes" },
634
- { key: "spaces", flatMap: (value) => [value, `-${value}`] },
635
- { key: "zIndices" },
636
- { key: "animations", omitScanKeys: ["keyframes"] },
637
- { key: "gradients" },
638
- { key: "transitions.property", replaceKey: "transitionProperty" },
639
- { key: "transitions.duration", replaceKey: "transitionDuration" },
640
- { key: "transitions.easing", replaceKey: "transitionEasing" }
641
- ];
642
-
643
- // src/command/tokens/create-theme-typings.ts
644
- var TONES = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
645
- var printComponent = (components) => `components: { ${Object.entries(components).map(
646
- ([key, unions]) => `${key.match(/^[a-zA-Z0-9\-_]+$/) ? key : `"${key}"`}: { ${print(
647
- unions
648
- )}}`
649
- ).join(`
650
- `)} }`;
651
- var print = (unions) => Object.entries(unions).sort(([a], [b]) => a.localeCompare(b)).map(
652
- ([key, union]) => `${key}: ${union.map((value) => `"${value}"`).concat(["(string & {})"]).join(" | ")};`
653
- ).join("\n");
654
- var extractComponents = ({ components = {} }) => Object.entries(components).reduce((obj, [key, { sizes, variants }]) => {
655
- if (sizes || variants) {
656
- obj[key] = {
657
- sizes: Object.keys(sizes ?? {}),
658
- variants: Object.keys(variants ?? {})
659
- };
660
- }
661
- return obj;
662
- }, {});
663
- var isTone = (value) => {
664
- if (!isObject(value)) return false;
665
- const keys = Object.keys(value);
666
- return TONES.every((key) => keys.includes(key.toString()));
667
- };
668
- var extractColorSchemes = (theme) => {
669
- const { colors, semantics } = theme;
670
- let colorSchemes = [];
671
- let colorSchemeColors = [];
672
- if (!isObject(colors)) return { colorSchemeColors, colorSchemes };
673
- Object.entries(colors).forEach(([key, value]) => {
674
- if (!isTone(value)) return;
675
- colorSchemes.push(key);
676
- });
677
- if (!isObject(semantics?.colorSchemes))
678
- return { colorSchemeColors, colorSchemes };
679
- Object.entries(semantics.colorSchemes).forEach(([key, value]) => {
680
- if (isTone(value)) {
681
- colorSchemes.push(key);
682
- colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
683
- } else {
684
- const hasColorScheme = isArray(value) ? value.every((key2) => Object.keys(colors).includes(String(key2))) : Object.keys(colors).includes(String(value));
685
- if (!hasColorScheme) return;
686
- colorSchemes.push(key);
687
- colorSchemeColors.push(...TONES.map((tone) => `${key}.${tone}`));
688
- }
689
- });
690
- return { colorSchemeColors, colorSchemes };
691
- };
692
- var extractThemeSchemes = (theme) => {
693
- const { themeSchemes } = theme;
694
- if (!isObject(themeSchemes)) return ["base"];
695
- return ["base", ...Object.keys(themeSchemes)];
696
- };
697
- var extractPaths = (target, maxDepth = 3, omitKeys = [], shouldProcess) => {
698
- if (!isObject(target) && !isArray(target) || !maxDepth) return [];
699
- return Object.entries(target).reduce((prev, [key, value]) => {
700
- if (isObject(value) && !Object.keys(value).some((key2) => omitKeys.includes(key2)) && (!shouldProcess || shouldProcess(value))) {
701
- extractPaths(value, maxDepth - 1, omitKeys, shouldProcess).forEach(
702
- (nestedKey) => prev.push(`${key}.${nestedKey}`)
703
- );
704
- } else {
705
- prev.push(key);
706
- }
707
- return prev;
708
- }, []);
709
- };
710
- var extractKeys = (obj, key) => {
711
- const property = getObject(obj, key);
712
- if (!isObject(property)) return [];
713
- return Object.keys(property);
714
- };
715
- var createThemeTypings = async (theme, { responsive = false }) => {
716
- let shouldProcess = void 0;
717
- if (responsive && isObject(theme.breakpoints)) {
718
- const keys = ["base", ...Object.keys(theme.breakpoints)];
719
- const isResponsive = (obj) => {
720
- const providedKeys = Object.keys(obj);
721
- if (!providedKeys.length) return false;
722
- if (!providedKeys.includes("base")) return false;
723
- return providedKeys.every((key) => keys.includes(key));
724
- };
725
- shouldProcess = (obj) => !isResponsive(obj);
726
- }
727
- const tokens = config.reduce(
728
- (prev, {
729
- key,
730
- flatMap = (value) => value,
731
- maxScanDepth,
732
- omitScanKeys,
733
- replaceKey
734
- }) => {
735
- const target = getObject(theme, key);
736
- prev[replaceKey ?? key] = [];
737
- if (isObject(target) || isArray(target)) {
738
- prev[replaceKey ?? key] = extractPaths(
739
- target,
740
- maxScanDepth,
741
- omitScanKeys,
742
- shouldProcess
743
- ).flatMap(flatMap);
744
- }
745
- if (isObject(theme.semantics)) {
746
- const target2 = getObject(theme.semantics, key);
747
- const semanticKeys = extractPaths(
748
- target2,
749
- maxScanDepth,
750
- omitScanKeys,
751
- shouldProcess
752
- ).flatMap(flatMap);
753
- prev[replaceKey ?? key]?.push(...semanticKeys);
754
- }
755
- return prev;
756
- },
757
- {}
758
- );
759
- const textStyles = extractKeys(theme, "styles.textStyles");
760
- const layerStyles = extractKeys(theme, "styles.layerStyles");
761
- const { colorSchemeColors, colorSchemes } = extractColorSchemes(theme);
762
- const themeSchemes = extractThemeSchemes(theme);
763
- const components = extractComponents(theme);
764
- tokens.colors = [...tokens.colors ?? [], ...colorSchemeColors];
765
- return prettier(
766
- [
767
- `import type { UITheme } from './ui-theme.types'`,
768
- ``,
769
- `export interface GeneratedTheme extends UITheme {`,
770
- print({
771
- ...tokens,
772
- colorSchemes,
773
- layerStyles,
774
- textStyles,
775
- themeSchemes
776
- }),
777
- printComponent(components),
778
- `}`
779
- ].join("\n")
780
- );
781
- };
782
-
783
- // src/command/tokens/resolve-output-path.ts
784
- init_cjs_shims();
785
- var import_glob = require("glob");
786
- var import_path2 = __toESM(require("path"));
787
- var themePath = [
788
- "node_modules",
789
- "@yamada-ui",
790
- "core",
791
- "dist",
792
- "generated-theme.types.d.ts"
793
- ];
794
- var resolveThemePath = async () => {
795
- const paths = [
796
- import_path2.default.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
797
- import_path2.default.join(...themePath),
798
- import_path2.default.posix.join("node_modules", ".pnpm", "@yamada-ui+core@*", ...themePath),
799
- import_path2.default.posix.join(...themePath)
800
- ];
801
- const triedPaths = await Promise.all(
802
- paths.map(async (possiblePath) => {
803
- const paths2 = await (0, import_glob.glob)(possiblePath);
804
- if (paths2.length) return paths2[0];
805
- return "";
806
- })
807
- );
808
- const resolvedPath = triedPaths.find(Boolean);
809
- if (!resolvedPath) return;
810
- return import_path2.default.resolve(process.cwd(), resolvedPath);
811
- };
812
- var resolveOutputPath = async (outPath) => {
813
- if (outPath) return import_path2.default.resolve(process.cwd(), outPath);
814
- const themePath2 = await resolveThemePath();
815
- if (!themePath2)
816
- throw new Error(
817
- "Could not find @yamada-ui/core in node_modules. Please provide `--out` parameter."
818
- );
819
- return themePath2;
820
- };
821
-
822
- // src/command/tokens/index.ts
823
- var generateThemeTypings = async ({
824
- config: config2,
825
- outFile,
826
- theme
827
- }) => {
828
- p.intro(source_default.magenta(`Generating Yamada UI theme typings`));
829
- const s = p.spinner();
830
- try {
831
- const start = process.hrtime.bigint();
832
- s.start(`Parsing the theme`);
833
- const generatedTheme = await createThemeTypings(theme, config2.theme ?? {});
834
- s.stop(`Parsed the theme`);
835
- s.start(`Resolving the output path`);
836
- const outPath = await resolveOutputPath(outFile);
837
- s.stop(`Resolved the output path`);
838
- s.start(`Writing file "${outPath}"`);
839
- await (0, import_promises.writeFile)(outPath, generatedTheme, "utf8");
840
- s.stop(`Wrote file`);
841
- p.note(outPath, "Output path");
842
- const end = process.hrtime.bigint();
843
- const duration = (Number(end - start) / 1e9).toFixed(2);
844
- p.outro(`${source_default.green(`Done`)} in ${source_default.dim(`${duration}s`)}
845
- `);
846
- } catch (e) {
847
- s.stop(`An error occurred`, 500);
848
- p.cancel(source_default.red(e instanceof Error ? e.message : "Message is missing"));
849
- }
850
- };
851
- var actionTokens = async (themePath2, { cwd = import_path3.default.resolve(), out: outFile, watch: watchFile }) => {
852
- const readFile = async () => {
853
- const filePath = import_path3.default.resolve(themePath2);
854
- const { dependencies: dependencies2, mod } = await getModule(filePath, cwd);
855
- const theme2 = mod?.default ?? mod?.theme ?? mod?.customTheme ?? mod?.defaultTheme ?? {};
856
- const config3 = mod?.config ?? mod?.customConfig ?? mod?.defaultConfig ?? {};
857
- return { config: config3, dependencies: dependencies2, theme: theme2 };
858
- };
859
- let file = await readFile();
860
- const { config: config2, dependencies, theme } = file;
861
- const buildFile = async () => {
862
- await generateThemeTypings({ config: config2, outFile, theme });
863
- if (watchFile) console.log("\n", "\u231B\uFE0F Watching for changes...");
864
- };
865
- if (watchFile) {
866
- const watchPath = typeof watchFile === "string" ? watchFile : dependencies;
867
- import_chokidar.default.watch(watchPath).on("ready", buildFile).on("change", async (filePath) => {
868
- console.log("\u{1F4E6} File changed", filePath);
869
- file = await readFile();
870
- return buildFile();
871
- });
872
- } else {
873
- await buildFile();
874
- }
875
- };
876
- // Annotate the CommonJS export names for ESM import in node:
877
- 0 && (module.exports = {
878
- actionTokens,
879
- themePath
880
- });