myoperator-ui 0.0.3 → 0.0.4
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/index.js +105 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11,22 +11,70 @@ import prompts from "prompts";
|
|
|
11
11
|
import ora from "ora";
|
|
12
12
|
|
|
13
13
|
// src/utils/registry.ts
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
function prefixTailwindClasses(content, prefix) {
|
|
15
|
+
if (!prefix) return content;
|
|
16
|
+
const patterns = [
|
|
17
|
+
// Layout & Display
|
|
18
|
+
/\b(flex|inline-flex|block|inline-block|grid|inline-grid|hidden|table|contents)\b/g,
|
|
19
|
+
// Flexbox & Grid
|
|
20
|
+
/\b(items-|justify-|gap-|flex-|grid-|col-|row-|place-|self-|order-)/g,
|
|
21
|
+
// Spacing
|
|
22
|
+
/\b([mp][trblxy]?-\d+|[mp][trblxy]?-\[)/g,
|
|
23
|
+
/\b(space-[xy]-)/g,
|
|
24
|
+
// Sizing
|
|
25
|
+
/\b([wh]-(full|screen|auto|min|max|fit|\d+|px|\[))/g,
|
|
26
|
+
/\b(min-[wh]-|max-[wh]-)/g,
|
|
27
|
+
// Typography
|
|
28
|
+
/\b(text-(?:xs|sm|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl|left|center|right|justify|wrap|nowrap|ellipsis|clip))\b/g,
|
|
29
|
+
/\b(font-(?:sans|serif|mono|thin|extralight|light|normal|medium|semibold|bold|extrabold|black))\b/g,
|
|
30
|
+
/\b(leading-|tracking-|whitespace-)/g,
|
|
31
|
+
// Colors (bg, text, border colors)
|
|
32
|
+
/\b(bg-|text-|border-|ring-|from-|via-|to-|fill-|stroke-)(?!\[)/g,
|
|
33
|
+
// Borders & Rings
|
|
34
|
+
/\b(border|rounded|ring|outline)(?:-|$)/g,
|
|
35
|
+
// Effects
|
|
36
|
+
/\b(shadow|opacity-|blur-|brightness-|contrast-|grayscale|invert|saturate|sepia)/g,
|
|
37
|
+
// Transitions & Animations
|
|
38
|
+
/\b(transition|duration-|ease-|delay-|animate-)/g,
|
|
39
|
+
// Transforms
|
|
40
|
+
/\b(scale-|rotate-|translate-|skew-|origin-|transform)/g,
|
|
41
|
+
// Interactivity
|
|
42
|
+
/\b(cursor-|pointer-events-|resize|select-|scroll-)/g,
|
|
43
|
+
// Pseudo-classes prefixes
|
|
44
|
+
/\b(hover:|focus:|active:|disabled:|focus-visible:|focus-within:|group-hover:|peer-)/g,
|
|
45
|
+
// Responsive prefixes
|
|
46
|
+
/\b(sm:|md:|lg:|xl:|2xl:)/g,
|
|
47
|
+
// Dark mode
|
|
48
|
+
/\b(dark:)/g,
|
|
49
|
+
// Other common utilities
|
|
50
|
+
/\b(overflow-|z-|relative|absolute|fixed|sticky|inset-|top-|right-|bottom-|left-)/g,
|
|
51
|
+
/\b(underline|line-through|no-underline|underline-offset-)/g,
|
|
52
|
+
/\b(sr-only|not-sr-only)\b/g
|
|
53
|
+
];
|
|
54
|
+
let result = content;
|
|
55
|
+
result = result.replace(
|
|
56
|
+
/(className=["'`{]|cn\(["'`])([^"'`}]+)(["'`}])/g,
|
|
57
|
+
(match, start, classes, end) => {
|
|
58
|
+
let prefixedClasses = classes;
|
|
59
|
+
prefixedClasses = prefixedClasses.replace(
|
|
60
|
+
/(?<=^|\s)([a-z])/g,
|
|
61
|
+
(m, char) => `${prefix}${char}`
|
|
62
|
+
);
|
|
63
|
+
prefixedClasses = prefixedClasses.replace(
|
|
64
|
+
/(?<=^|\s)-([a-z])/g,
|
|
65
|
+
(m, char) => `-${prefix}${char}`
|
|
66
|
+
);
|
|
67
|
+
prefixedClasses = prefixedClasses.replace(
|
|
68
|
+
new RegExp(`${prefix}(hover|focus|active|disabled|focus-visible|focus-within|group-hover|sm|md|lg|xl|2xl|dark):${prefix}`, "g"),
|
|
69
|
+
`${prefix}$1:`
|
|
70
|
+
);
|
|
71
|
+
return start + prefixedClasses + end;
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
async function getRegistry(prefix = "") {
|
|
77
|
+
const buttonContent = prefixTailwindClasses(`import * as React from "react"
|
|
30
78
|
import { Slot } from "@radix-ui/react-slot"
|
|
31
79
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
32
80
|
import { Loader2 } from "lucide-react"
|
|
@@ -114,7 +162,22 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
114
162
|
Button.displayName = "Button"
|
|
115
163
|
|
|
116
164
|
export { Button, buttonVariants }
|
|
117
|
-
|
|
165
|
+
`, prefix);
|
|
166
|
+
return {
|
|
167
|
+
button: {
|
|
168
|
+
name: "button",
|
|
169
|
+
description: "A customizable button component with variants, sizes, and icons",
|
|
170
|
+
dependencies: [
|
|
171
|
+
"@radix-ui/react-slot",
|
|
172
|
+
"class-variance-authority",
|
|
173
|
+
"clsx",
|
|
174
|
+
"tailwind-merge",
|
|
175
|
+
"lucide-react"
|
|
176
|
+
],
|
|
177
|
+
files: [
|
|
178
|
+
{
|
|
179
|
+
name: "button.tsx",
|
|
180
|
+
content: buttonContent
|
|
118
181
|
}
|
|
119
182
|
]
|
|
120
183
|
}
|
|
@@ -130,7 +193,9 @@ async function add(components, options) {
|
|
|
130
193
|
console.log(chalk.yellow(" Run `npx myoperator-ui init` first.\n"));
|
|
131
194
|
process.exit(1);
|
|
132
195
|
}
|
|
133
|
-
const
|
|
196
|
+
const config = await fs.readJson(configPath);
|
|
197
|
+
const prefix = config.tailwind?.prefix || "";
|
|
198
|
+
const registry = await getRegistry(prefix);
|
|
134
199
|
const availableComponents = Object.keys(registry);
|
|
135
200
|
if (!components || components.length === 0) {
|
|
136
201
|
const { selectedComponents } = await prompts({
|
|
@@ -158,7 +223,6 @@ async function add(components, options) {
|
|
|
158
223
|
`));
|
|
159
224
|
process.exit(1);
|
|
160
225
|
}
|
|
161
|
-
const config = await fs.readJson(configPath);
|
|
162
226
|
const componentsDir = path.join(cwd, options.path);
|
|
163
227
|
if (!options.yes) {
|
|
164
228
|
const { confirm } = await prompts({
|
|
@@ -359,9 +423,10 @@ var CSS_VARIABLES_V3 = `@tailwind base;
|
|
|
359
423
|
}
|
|
360
424
|
}
|
|
361
425
|
`;
|
|
362
|
-
var
|
|
426
|
+
var getTailwindConfig = (prefix) => `/** @type {import('tailwindcss').Config} */
|
|
363
427
|
export default {
|
|
364
428
|
darkMode: ["class"],
|
|
429
|
+
${prefix ? `prefix: "${prefix}",` : ""}
|
|
365
430
|
content: [
|
|
366
431
|
"./index.html",
|
|
367
432
|
"./src/**/*.{js,ts,jsx,tsx}",
|
|
@@ -441,7 +506,8 @@ var DEFAULT_CONFIG = {
|
|
|
441
506
|
config: "tailwind.config.js",
|
|
442
507
|
css: "src/index.css",
|
|
443
508
|
baseColor: "slate",
|
|
444
|
-
cssVariables: true
|
|
509
|
+
cssVariables: true,
|
|
510
|
+
prefix: ""
|
|
445
511
|
},
|
|
446
512
|
aliases: {
|
|
447
513
|
components: "@/components",
|
|
@@ -476,6 +542,18 @@ async function init() {
|
|
|
476
542
|
],
|
|
477
543
|
initial: 0
|
|
478
544
|
},
|
|
545
|
+
{
|
|
546
|
+
type: "confirm",
|
|
547
|
+
name: "usePrefix",
|
|
548
|
+
message: "Use a prefix for Tailwind classes? (recommended if using Bootstrap/other CSS frameworks)",
|
|
549
|
+
initial: false
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
type: (prev) => prev ? "text" : null,
|
|
553
|
+
name: "prefix",
|
|
554
|
+
message: "Enter prefix for Tailwind classes:",
|
|
555
|
+
initial: "tw-"
|
|
556
|
+
},
|
|
479
557
|
{
|
|
480
558
|
type: "text",
|
|
481
559
|
name: "componentsPath",
|
|
@@ -503,12 +581,14 @@ async function init() {
|
|
|
503
581
|
]);
|
|
504
582
|
const spinner = ora2("Initializing project...").start();
|
|
505
583
|
try {
|
|
584
|
+
const prefix = response.usePrefix ? response.prefix : "";
|
|
506
585
|
const config = {
|
|
507
586
|
...DEFAULT_CONFIG,
|
|
508
587
|
tailwind: {
|
|
509
588
|
...DEFAULT_CONFIG.tailwind,
|
|
510
|
-
config: response.tailwindConfig,
|
|
511
|
-
css: response.globalCss
|
|
589
|
+
config: response.tailwindConfig || "tailwind.config.js",
|
|
590
|
+
css: response.globalCss,
|
|
591
|
+
prefix
|
|
512
592
|
},
|
|
513
593
|
aliases: {
|
|
514
594
|
...DEFAULT_CONFIG.aliases,
|
|
@@ -560,7 +640,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
560
640
|
if (response.tailwindVersion === "v3" && response.tailwindConfig) {
|
|
561
641
|
const tailwindConfigPath = path2.join(cwd, response.tailwindConfig);
|
|
562
642
|
if (!await fs2.pathExists(tailwindConfigPath)) {
|
|
563
|
-
await fs2.writeFile(tailwindConfigPath,
|
|
643
|
+
await fs2.writeFile(tailwindConfigPath, getTailwindConfig(prefix));
|
|
564
644
|
tailwindUpdated = true;
|
|
565
645
|
} else {
|
|
566
646
|
const existingConfig = await fs2.readFile(tailwindConfigPath, "utf-8");
|
|
@@ -574,7 +654,7 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
574
654
|
});
|
|
575
655
|
spinner.start("Initializing project...");
|
|
576
656
|
if (updateTailwind) {
|
|
577
|
-
await fs2.writeFile(tailwindConfigPath,
|
|
657
|
+
await fs2.writeFile(tailwindConfigPath, getTailwindConfig(prefix));
|
|
578
658
|
tailwindUpdated = true;
|
|
579
659
|
}
|
|
580
660
|
}
|