cnui-radix 0.0.1
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/README.md +0 -0
- package/dist/cli.js +382 -0
- package/dist/index.cjs +284 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +246 -0
- package/package.json +57 -0
- package/r/button.json +21 -0
- package/r/cnui-base.json +137 -0
- package/r/input.json +20 -0
- package/r/registry.json +172 -0
- package/r/utils.json +17 -0
- package/src/lib/cnui-preset.ts +347 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/globals.css +3 -0
package/README.md
ADDED
|
File without changes
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// cli/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
6
|
+
import { resolve as resolve5 } from "path";
|
|
7
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8
|
+
import { dirname as dirname4 } from "path";
|
|
9
|
+
|
|
10
|
+
// cli/commands/init.ts
|
|
11
|
+
import {
|
|
12
|
+
existsSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
writeFileSync,
|
|
15
|
+
mkdirSync,
|
|
16
|
+
copyFileSync
|
|
17
|
+
} from "fs";
|
|
18
|
+
import { resolve as resolve2, dirname as dirname2 } from "path";
|
|
19
|
+
import { execSync } from "child_process";
|
|
20
|
+
|
|
21
|
+
// cli/utils/paths.ts
|
|
22
|
+
import { fileURLToPath } from "url";
|
|
23
|
+
import { dirname, resolve } from "path";
|
|
24
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
var __dirname = dirname(__filename);
|
|
26
|
+
function getPackageRoot() {
|
|
27
|
+
return resolve(__dirname, "..");
|
|
28
|
+
}
|
|
29
|
+
function getRegistryDir() {
|
|
30
|
+
return resolve(getPackageRoot(), "r");
|
|
31
|
+
}
|
|
32
|
+
function getTemplateFile(name) {
|
|
33
|
+
return resolve(getPackageRoot(), "src", "lib", name);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// cli/utils/templates.ts
|
|
37
|
+
function getComponentsJsonTemplate(opts) {
|
|
38
|
+
return JSON.stringify(
|
|
39
|
+
{
|
|
40
|
+
$schema: "https://ui.shadcn.com/schema.json",
|
|
41
|
+
style: "new-york",
|
|
42
|
+
rsc: false,
|
|
43
|
+
tsx: true,
|
|
44
|
+
tailwind: {
|
|
45
|
+
config: opts.tailwindConfig,
|
|
46
|
+
css: opts.cssFile,
|
|
47
|
+
baseColor: "zinc",
|
|
48
|
+
cssVariables: true
|
|
49
|
+
},
|
|
50
|
+
aliases: {
|
|
51
|
+
components: "@/components",
|
|
52
|
+
utils: "@/lib/utils",
|
|
53
|
+
ui: "@/components/ui",
|
|
54
|
+
lib: "@/lib",
|
|
55
|
+
hooks: "@/hooks"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
null,
|
|
59
|
+
2
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function getTailwindConfigTemplate() {
|
|
63
|
+
return `import cnuiPreset from "./src/lib/cnui-preset";
|
|
64
|
+
|
|
65
|
+
/** @type {import('tailwindcss').Config} */
|
|
66
|
+
export default {
|
|
67
|
+
presets: [cnuiPreset],
|
|
68
|
+
content: ["./src/**/*.{ts,tsx}", "./index.html"],
|
|
69
|
+
};
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
function getGlobalsCssTemplate() {
|
|
73
|
+
return `@tailwind base;
|
|
74
|
+
@tailwind components;
|
|
75
|
+
@tailwind utilities;
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// cli/utils/logger.ts
|
|
80
|
+
var RESET = "\x1B[0m";
|
|
81
|
+
var GREEN = "\x1B[32m";
|
|
82
|
+
var YELLOW = "\x1B[33m";
|
|
83
|
+
var RED = "\x1B[31m";
|
|
84
|
+
var CYAN = "\x1B[36m";
|
|
85
|
+
var DIM = "\x1B[2m";
|
|
86
|
+
function success(msg) {
|
|
87
|
+
console.log(`${GREEN}\u2714${RESET} ${msg}`);
|
|
88
|
+
}
|
|
89
|
+
function warn(msg) {
|
|
90
|
+
console.log(`${YELLOW}\u26A0${RESET} ${msg}`);
|
|
91
|
+
}
|
|
92
|
+
function error(msg) {
|
|
93
|
+
console.error(`${RED}\u2716${RESET} ${msg}`);
|
|
94
|
+
}
|
|
95
|
+
function info(msg) {
|
|
96
|
+
console.log(`${CYAN}\u2139${RESET} ${msg}`);
|
|
97
|
+
}
|
|
98
|
+
function dim(msg) {
|
|
99
|
+
console.log(`${DIM}${msg}${RESET}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// cli/commands/init.ts
|
|
103
|
+
async function initCommand(options) {
|
|
104
|
+
const cwd = resolve2(options.cwd);
|
|
105
|
+
const force = options.force ?? false;
|
|
106
|
+
info(`\u521D\u59CB\u5316 cnui-radix \u9879\u76EE\u914D\u7F6E... (${cwd})`);
|
|
107
|
+
const hasSrc = existsSync(resolve2(cwd, "src"));
|
|
108
|
+
const hasTsconfig = existsSync(resolve2(cwd, "tsconfig.json"));
|
|
109
|
+
if (!hasSrc) {
|
|
110
|
+
mkdirSync(resolve2(cwd, "src"), { recursive: true });
|
|
111
|
+
dim(" \u521B\u5EFA src/ \u76EE\u5F55");
|
|
112
|
+
}
|
|
113
|
+
const componentsJsonPath = resolve2(cwd, "components.json");
|
|
114
|
+
if (existsSync(componentsJsonPath) && !force) {
|
|
115
|
+
warn("components.json \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7 (\u4F7F\u7528 --force \u8986\u76D6)");
|
|
116
|
+
} else {
|
|
117
|
+
const twConfigName = detectTailwindConfig(cwd);
|
|
118
|
+
const cssFile = "src/styles/globals.css";
|
|
119
|
+
writeFileSync(
|
|
120
|
+
componentsJsonPath,
|
|
121
|
+
getComponentsJsonTemplate({ tailwindConfig: twConfigName, cssFile })
|
|
122
|
+
);
|
|
123
|
+
success("\u521B\u5EFA components.json");
|
|
124
|
+
}
|
|
125
|
+
const presetDest = resolve2(cwd, "src/lib/cnui-preset.ts");
|
|
126
|
+
ensureDir(dirname2(presetDest));
|
|
127
|
+
if (existsSync(presetDest) && !force) {
|
|
128
|
+
warn("src/lib/cnui-preset.ts \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
129
|
+
} else {
|
|
130
|
+
copyFileSync(getTemplateFile("cnui-preset.ts"), presetDest);
|
|
131
|
+
success("\u521B\u5EFA src/lib/cnui-preset.ts (CNUI Tailwind Preset)");
|
|
132
|
+
}
|
|
133
|
+
const utilsDest = resolve2(cwd, "src/lib/utils.ts");
|
|
134
|
+
if (existsSync(utilsDest) && !force) {
|
|
135
|
+
warn("src/lib/utils.ts \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
136
|
+
} else {
|
|
137
|
+
copyFileSync(getTemplateFile("utils.ts"), utilsDest);
|
|
138
|
+
success("\u521B\u5EFA src/lib/utils.ts (cn \u5DE5\u5177\u51FD\u6570)");
|
|
139
|
+
}
|
|
140
|
+
const twConfigPath = resolve2(cwd, detectTailwindConfig(cwd));
|
|
141
|
+
if (existsSync(twConfigPath) && !force) {
|
|
142
|
+
const content = readFileSync(twConfigPath, "utf-8");
|
|
143
|
+
if (content.includes("cnui-preset")) {
|
|
144
|
+
warn(`${detectTailwindConfig(cwd)} \u5DF2\u5305\u542B cnui-preset\uFF0C\u8DF3\u8FC7`);
|
|
145
|
+
} else {
|
|
146
|
+
warn(
|
|
147
|
+
`${detectTailwindConfig(cwd)} \u5DF2\u5B58\u5728\u4F46\u672A\u914D\u7F6E cnui-preset\uFF0C\u8BF7\u624B\u52A8\u6DFB\u52A0:`
|
|
148
|
+
);
|
|
149
|
+
dim(' import cnuiPreset from "./src/lib/cnui-preset";');
|
|
150
|
+
dim(" // \u5728\u914D\u7F6E\u4E2D\u6DFB\u52A0: presets: [cnuiPreset]");
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
writeFileSync(twConfigPath, getTailwindConfigTemplate());
|
|
154
|
+
success(`\u521B\u5EFA ${detectTailwindConfig(cwd)}`);
|
|
155
|
+
}
|
|
156
|
+
const cssPath = resolve2(cwd, "src/styles/globals.css");
|
|
157
|
+
ensureDir(dirname2(cssPath));
|
|
158
|
+
if (existsSync(cssPath)) {
|
|
159
|
+
const content = readFileSync(cssPath, "utf-8");
|
|
160
|
+
if (!content.includes("@tailwind")) {
|
|
161
|
+
warn("src/styles/globals.css \u672A\u5305\u542B @tailwind \u6307\u4EE4\uFF0C\u8BF7\u624B\u52A8\u6DFB\u52A0");
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
writeFileSync(cssPath, getGlobalsCssTemplate());
|
|
165
|
+
success("\u521B\u5EFA src/styles/globals.css");
|
|
166
|
+
}
|
|
167
|
+
if (hasTsconfig) {
|
|
168
|
+
updateTsconfig(cwd, force);
|
|
169
|
+
} else {
|
|
170
|
+
warn("\u672A\u68C0\u6D4B\u5230 tsconfig.json\uFF0C\u8DF3\u8FC7\u8DEF\u5F84\u522B\u540D\u914D\u7F6E");
|
|
171
|
+
}
|
|
172
|
+
const pm = detectPackageManager(cwd);
|
|
173
|
+
info(`\u4F7F\u7528 ${pm} \u5B89\u88C5\u4F9D\u8D56...`);
|
|
174
|
+
try {
|
|
175
|
+
const installCmd = pm === "yarn" ? "yarn add clsx tailwind-merge" : `${pm} add clsx tailwind-merge`;
|
|
176
|
+
execSync(installCmd, { cwd, stdio: "pipe" });
|
|
177
|
+
success("\u5B89\u88C5 clsx, tailwind-merge");
|
|
178
|
+
} catch {
|
|
179
|
+
warn("\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u8FD0\u884C: " + pm + " add clsx tailwind-merge");
|
|
180
|
+
}
|
|
181
|
+
console.log("");
|
|
182
|
+
success("cnui-radix \u521D\u59CB\u5316\u5B8C\u6210!");
|
|
183
|
+
console.log("");
|
|
184
|
+
info("\u4E0B\u4E00\u6B65: \u6DFB\u52A0\u7EC4\u4EF6");
|
|
185
|
+
dim(" npx cnui-radix add button");
|
|
186
|
+
dim(" npx cnui-radix add input");
|
|
187
|
+
}
|
|
188
|
+
function detectTailwindConfig(cwd) {
|
|
189
|
+
for (const name of [
|
|
190
|
+
"tailwind.config.ts",
|
|
191
|
+
"tailwind.config.js",
|
|
192
|
+
"tailwind.config.mjs"
|
|
193
|
+
]) {
|
|
194
|
+
if (existsSync(resolve2(cwd, name))) return name;
|
|
195
|
+
}
|
|
196
|
+
return "tailwind.config.ts";
|
|
197
|
+
}
|
|
198
|
+
function detectPackageManager(cwd) {
|
|
199
|
+
if (existsSync(resolve2(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
200
|
+
if (existsSync(resolve2(cwd, "yarn.lock"))) return "yarn";
|
|
201
|
+
if (existsSync(resolve2(cwd, "bun.lockb"))) return "bun";
|
|
202
|
+
return "npm";
|
|
203
|
+
}
|
|
204
|
+
function ensureDir(dir) {
|
|
205
|
+
if (!existsSync(dir)) {
|
|
206
|
+
mkdirSync(dir, { recursive: true });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function updateTsconfig(cwd, force) {
|
|
210
|
+
const tsconfigPath = resolve2(cwd, "tsconfig.json");
|
|
211
|
+
try {
|
|
212
|
+
const content = readFileSync(tsconfigPath, "utf-8");
|
|
213
|
+
const tsconfig = JSON.parse(content);
|
|
214
|
+
let modified = false;
|
|
215
|
+
if (!tsconfig.compilerOptions) {
|
|
216
|
+
tsconfig.compilerOptions = {};
|
|
217
|
+
}
|
|
218
|
+
if (!tsconfig.compilerOptions.baseUrl) {
|
|
219
|
+
tsconfig.compilerOptions.baseUrl = ".";
|
|
220
|
+
modified = true;
|
|
221
|
+
}
|
|
222
|
+
if (!tsconfig.compilerOptions.paths) {
|
|
223
|
+
tsconfig.compilerOptions.paths = {};
|
|
224
|
+
}
|
|
225
|
+
if (!tsconfig.compilerOptions.paths["@/*"]) {
|
|
226
|
+
tsconfig.compilerOptions.paths["@/*"] = ["./src/*"];
|
|
227
|
+
modified = true;
|
|
228
|
+
}
|
|
229
|
+
if (modified) {
|
|
230
|
+
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + "\n");
|
|
231
|
+
success("\u66F4\u65B0 tsconfig.json (\u6DFB\u52A0 @/* \u8DEF\u5F84\u522B\u540D)");
|
|
232
|
+
} else {
|
|
233
|
+
dim(" tsconfig.json \u8DEF\u5F84\u522B\u540D\u5DF2\u914D\u7F6E\uFF0C\u8DF3\u8FC7");
|
|
234
|
+
}
|
|
235
|
+
} catch {
|
|
236
|
+
warn("tsconfig.json \u89E3\u6790\u5931\u8D25\uFF0C\u8DF3\u8FC7\u8DEF\u5F84\u522B\u540D\u914D\u7F6E");
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// cli/commands/add.ts
|
|
241
|
+
import {
|
|
242
|
+
existsSync as existsSync2,
|
|
243
|
+
writeFileSync as writeFileSync2,
|
|
244
|
+
mkdirSync as mkdirSync2
|
|
245
|
+
} from "fs";
|
|
246
|
+
import { resolve as resolve4, dirname as dirname3 } from "path";
|
|
247
|
+
import { execSync as execSync2 } from "child_process";
|
|
248
|
+
|
|
249
|
+
// cli/utils/registry.ts
|
|
250
|
+
import { readFileSync as readFileSync2, readdirSync } from "fs";
|
|
251
|
+
import { resolve as resolve3 } from "path";
|
|
252
|
+
function loadRegistryItem(name) {
|
|
253
|
+
const filePath = resolve3(getRegistryDir(), `${name}.json`);
|
|
254
|
+
const content = readFileSync2(filePath, "utf-8");
|
|
255
|
+
return JSON.parse(content);
|
|
256
|
+
}
|
|
257
|
+
function resolveAllDependencies(name) {
|
|
258
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
259
|
+
const visited = /* @__PURE__ */ new Set();
|
|
260
|
+
function walk(itemName) {
|
|
261
|
+
if (visited.has(itemName)) return;
|
|
262
|
+
visited.add(itemName);
|
|
263
|
+
const item = loadRegistryItem(itemName);
|
|
264
|
+
if (item.registryDependencies) {
|
|
265
|
+
for (const dep of item.registryDependencies) {
|
|
266
|
+
walk(dep);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
resolved.set(itemName, item);
|
|
270
|
+
}
|
|
271
|
+
walk(name);
|
|
272
|
+
return Array.from(resolved.values());
|
|
273
|
+
}
|
|
274
|
+
function listAvailableComponents() {
|
|
275
|
+
const dir = getRegistryDir();
|
|
276
|
+
const files = readdirSync(dir).filter(
|
|
277
|
+
(f) => f.endsWith(".json") && f !== "registry.json"
|
|
278
|
+
);
|
|
279
|
+
const items = [];
|
|
280
|
+
for (const file of files) {
|
|
281
|
+
const content = readFileSync2(resolve3(dir, file), "utf-8");
|
|
282
|
+
const item = JSON.parse(content);
|
|
283
|
+
if (item.type === "registry:ui") {
|
|
284
|
+
items.push(item);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return items;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// cli/commands/add.ts
|
|
291
|
+
async function addCommand(components, options) {
|
|
292
|
+
const cwd = resolve4(options.cwd);
|
|
293
|
+
if (!existsSync2(resolve4(cwd, "components.json"))) {
|
|
294
|
+
error("\u672A\u627E\u5230 components.json\uFF0C\u8BF7\u5148\u8FD0\u884C: npx cnui-radix init");
|
|
295
|
+
process.exit(1);
|
|
296
|
+
}
|
|
297
|
+
if (!components || components.length === 0) {
|
|
298
|
+
const available = listAvailableComponents();
|
|
299
|
+
info("\u53EF\u7528\u7EC4\u4EF6:");
|
|
300
|
+
console.log("");
|
|
301
|
+
for (const item of available) {
|
|
302
|
+
console.log(` ${item.name.padEnd(15)} ${item.description || ""}`);
|
|
303
|
+
}
|
|
304
|
+
console.log("");
|
|
305
|
+
dim("\u4F7F\u7528: npx cnui-radix add <component>");
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const allItems = /* @__PURE__ */ new Map();
|
|
309
|
+
for (const name of components) {
|
|
310
|
+
try {
|
|
311
|
+
const deps = resolveAllDependencies(name);
|
|
312
|
+
for (const item of deps) {
|
|
313
|
+
allItems.set(item.name, item);
|
|
314
|
+
}
|
|
315
|
+
} catch {
|
|
316
|
+
error(`\u672A\u627E\u5230\u7EC4\u4EF6: ${name}`);
|
|
317
|
+
const available = listAvailableComponents();
|
|
318
|
+
info(
|
|
319
|
+
"\u53EF\u7528\u7EC4\u4EF6: " + available.map((c) => c.name).join(", ")
|
|
320
|
+
);
|
|
321
|
+
process.exit(1);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const items = Array.from(allItems.values());
|
|
325
|
+
info(
|
|
326
|
+
`\u51C6\u5907\u5B89\u88C5: ${items.map((i) => i.name).join(", ")}`
|
|
327
|
+
);
|
|
328
|
+
const writtenFiles = [];
|
|
329
|
+
for (const item of items) {
|
|
330
|
+
if (!item.files || item.files.length === 0) continue;
|
|
331
|
+
for (const file of item.files) {
|
|
332
|
+
const targetPath = resolve4(cwd, file.path);
|
|
333
|
+
mkdirSync2(dirname3(targetPath), { recursive: true });
|
|
334
|
+
writeFileSync2(targetPath, file.content, "utf-8");
|
|
335
|
+
writtenFiles.push(file.path);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const allDeps = /* @__PURE__ */ new Set();
|
|
339
|
+
for (const item of items) {
|
|
340
|
+
if (item.dependencies) {
|
|
341
|
+
for (const dep of item.dependencies) {
|
|
342
|
+
allDeps.add(dep);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (allDeps.size > 0) {
|
|
347
|
+
const pm = detectPackageManager2(cwd);
|
|
348
|
+
const depsList = Array.from(allDeps);
|
|
349
|
+
const depsStr = depsList.join(" ");
|
|
350
|
+
info(`\u4F7F\u7528 ${pm} \u5B89\u88C5\u4F9D\u8D56...`);
|
|
351
|
+
try {
|
|
352
|
+
const installCmd = pm === "yarn" ? `yarn add ${depsStr}` : `${pm} add ${depsStr}`;
|
|
353
|
+
execSync2(installCmd, { cwd, stdio: "pipe" });
|
|
354
|
+
success(`\u5B89\u88C5 ${depsList.join(", ")}`);
|
|
355
|
+
} catch {
|
|
356
|
+
warn(`\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u8FD0\u884C: ${pm} add ${depsStr}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
console.log("");
|
|
360
|
+
success("\u7EC4\u4EF6\u5B89\u88C5\u5B8C\u6210!");
|
|
361
|
+
for (const file of writtenFiles) {
|
|
362
|
+
dim(` + ${file}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function detectPackageManager2(cwd) {
|
|
366
|
+
if (existsSync2(resolve4(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
367
|
+
if (existsSync2(resolve4(cwd, "yarn.lock"))) return "yarn";
|
|
368
|
+
if (existsSync2(resolve4(cwd, "bun.lockb"))) return "bun";
|
|
369
|
+
return "npm";
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// cli/index.ts
|
|
373
|
+
var __filename2 = fileURLToPath2(import.meta.url);
|
|
374
|
+
var __dirname2 = dirname4(__filename2);
|
|
375
|
+
var pkg = JSON.parse(
|
|
376
|
+
readFileSync3(resolve5(__dirname2, "..", "package.json"), "utf-8")
|
|
377
|
+
);
|
|
378
|
+
var program = new Command();
|
|
379
|
+
program.name("cnui-radix").description("CNUI Radix \u7EC4\u4EF6\u5E93 CLI - \u521D\u59CB\u5316\u9879\u76EE\u914D\u7F6E\u5E76\u5B89\u88C5\u7EC4\u4EF6").version(pkg.version);
|
|
380
|
+
program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE\uFF1A\u914D\u7F6E Tailwind\u3001\u8DEF\u5F84\u522B\u540D\u3001\u7EC4\u4EF6\u76EE\u5F55\u7B49").option("-f, --force", "\u8986\u76D6\u5DF2\u6709\u6587\u4EF6").option("--cwd <path>", "\u6307\u5B9A\u5DE5\u4F5C\u76EE\u5F55", process.cwd()).action(initCommand);
|
|
381
|
+
program.command("add").description("\u6DFB\u52A0\u7EC4\u4EF6\u5230\u9879\u76EE\u4E2D").argument("[components...]", "\u8981\u6DFB\u52A0\u7684\u7EC4\u4EF6\u540D\u79F0").option("--cwd <path>", "\u6307\u5B9A\u5DE5\u4F5C\u76EE\u5F55", process.cwd()).action(addCommand);
|
|
382
|
+
program.parse();
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
var index_exports = {};
|
|
61
|
+
__export(index_exports, {
|
|
62
|
+
Button: () => Button,
|
|
63
|
+
Input: () => Input,
|
|
64
|
+
buttonVariants: () => buttonVariants,
|
|
65
|
+
cn: () => cn,
|
|
66
|
+
inputVariants: () => inputVariants
|
|
67
|
+
});
|
|
68
|
+
module.exports = __toCommonJS(index_exports);
|
|
69
|
+
|
|
70
|
+
// src/components/ui/button.tsx
|
|
71
|
+
var React = __toESM(require("react"), 1);
|
|
72
|
+
var import_react_slot = require("@radix-ui/react-slot");
|
|
73
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
74
|
+
|
|
75
|
+
// src/lib/utils.ts
|
|
76
|
+
var import_clsx = require("clsx");
|
|
77
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
78
|
+
function cn(...inputs) {
|
|
79
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/components/ui/button.tsx
|
|
83
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
84
|
+
var buttonVariants = (0, import_class_variance_authority.cva)(
|
|
85
|
+
[
|
|
86
|
+
"inline-flex items-center justify-center gap-1 whitespace-nowrap",
|
|
87
|
+
"rounded border text-xs font-normal",
|
|
88
|
+
"transition-[box-shadow,border-color,background-color] duration-100",
|
|
89
|
+
"outline-none",
|
|
90
|
+
"disabled:pointer-events-none"
|
|
91
|
+
],
|
|
92
|
+
{
|
|
93
|
+
variants: {
|
|
94
|
+
variant: {
|
|
95
|
+
// normal 按钮:白底 + 灰色边框,hover 文字变主色
|
|
96
|
+
default: [
|
|
97
|
+
"border-solid bg-white border-line-dark text-foreground",
|
|
98
|
+
"hover:text-primary hover:shadow-[0_4px_10px_0_rgba(32,60,153,0.1)]",
|
|
99
|
+
"active:text-primary active:border-primary",
|
|
100
|
+
"disabled:bg-white disabled:border-line disabled:text-foreground-disabled"
|
|
101
|
+
],
|
|
102
|
+
// primary 按钮:主色背景 + 白色文字
|
|
103
|
+
primary: [
|
|
104
|
+
"border-solid bg-primary border-transparent text-white",
|
|
105
|
+
"hover:bg-primary-hover hover:shadow-[0_4px_10px_0_rgba(32,60,153,0.1)]",
|
|
106
|
+
"active:bg-primary-active",
|
|
107
|
+
"disabled:bg-secondary-light disabled:border-transparent disabled:text-foreground-disabled"
|
|
108
|
+
],
|
|
109
|
+
// secondary 按钮:白底 + 主色边框 + 主色文字
|
|
110
|
+
secondary: [
|
|
111
|
+
"border-solid bg-white border-primary text-primary",
|
|
112
|
+
"hover:border-primary-hover hover:text-primary-hover hover:shadow-[0_4px_10px_0_rgba(32,60,153,0.1)]",
|
|
113
|
+
"active:bg-fill-lighter active:border-primary-active active:text-primary-active",
|
|
114
|
+
"disabled:bg-fill-lighter disabled:border-line-dark disabled:text-foreground-disabled"
|
|
115
|
+
],
|
|
116
|
+
// ghost 按钮:透明底,hover 半透明背景
|
|
117
|
+
ghost: [
|
|
118
|
+
"border-solid bg-transparent border-transparent text-foreground",
|
|
119
|
+
"hover:bg-[rgba(126,147,217,0.3)]",
|
|
120
|
+
"active:bg-[rgba(126,147,217,0.3)]",
|
|
121
|
+
"disabled:bg-transparent disabled:border-[rgba(0,0,0,0.1)] disabled:text-[rgba(0,0,0,0.2)]"
|
|
122
|
+
],
|
|
123
|
+
// text 按钮:无边框无背景,纯文本
|
|
124
|
+
text: [
|
|
125
|
+
"border-0 bg-transparent shadow-none !p-0 !h-auto text-primary",
|
|
126
|
+
"hover:text-primary-hover hover:shadow-none",
|
|
127
|
+
"active:text-primary-hover",
|
|
128
|
+
"disabled:text-foreground-disabled"
|
|
129
|
+
],
|
|
130
|
+
// warning 按钮:error 色背景
|
|
131
|
+
warning: [
|
|
132
|
+
"border-solid bg-error border-transparent text-white",
|
|
133
|
+
"hover:bg-error-dark hover:shadow-[0_4px_10px_0_rgba(32,60,153,0.1)]",
|
|
134
|
+
"active:bg-error-heavy",
|
|
135
|
+
"disabled:bg-fill-lighter disabled:border-transparent disabled:text-foreground-disabled"
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
size: {
|
|
139
|
+
sm: "h-6 px-1.5 py-0.5 text-xs",
|
|
140
|
+
default: "h-8 px-3 py-1.5 text-xs",
|
|
141
|
+
lg: "h-10 px-3 py-[9px] text-sm"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
defaultVariants: {
|
|
145
|
+
variant: "default",
|
|
146
|
+
size: "default"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
var Button = React.forwardRef(
|
|
151
|
+
(_a, ref) => {
|
|
152
|
+
var _b = _a, {
|
|
153
|
+
className,
|
|
154
|
+
variant,
|
|
155
|
+
size,
|
|
156
|
+
asChild = false,
|
|
157
|
+
loading = false,
|
|
158
|
+
disabled,
|
|
159
|
+
children
|
|
160
|
+
} = _b, props = __objRest(_b, [
|
|
161
|
+
"className",
|
|
162
|
+
"variant",
|
|
163
|
+
"size",
|
|
164
|
+
"asChild",
|
|
165
|
+
"loading",
|
|
166
|
+
"disabled",
|
|
167
|
+
"children"
|
|
168
|
+
]);
|
|
169
|
+
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
171
|
+
Comp,
|
|
172
|
+
__spreadProps(__spreadValues({
|
|
173
|
+
className: cn(
|
|
174
|
+
buttonVariants({ variant, size }),
|
|
175
|
+
loading && "pointer-events-none",
|
|
176
|
+
className
|
|
177
|
+
),
|
|
178
|
+
ref,
|
|
179
|
+
disabled: disabled || loading
|
|
180
|
+
}, props), {
|
|
181
|
+
children: [
|
|
182
|
+
loading && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
183
|
+
"svg",
|
|
184
|
+
{
|
|
185
|
+
className: "animate-spin h-4 w-4",
|
|
186
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
187
|
+
fill: "none",
|
|
188
|
+
viewBox: "0 0 24 24",
|
|
189
|
+
children: [
|
|
190
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
191
|
+
"circle",
|
|
192
|
+
{
|
|
193
|
+
className: "opacity-25",
|
|
194
|
+
cx: "12",
|
|
195
|
+
cy: "12",
|
|
196
|
+
r: "10",
|
|
197
|
+
stroke: "currentColor",
|
|
198
|
+
strokeWidth: "4"
|
|
199
|
+
}
|
|
200
|
+
),
|
|
201
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
202
|
+
"path",
|
|
203
|
+
{
|
|
204
|
+
className: "opacity-75",
|
|
205
|
+
fill: "currentColor",
|
|
206
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
children
|
|
213
|
+
]
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
Button.displayName = "Button";
|
|
219
|
+
|
|
220
|
+
// src/components/ui/input.tsx
|
|
221
|
+
var React2 = __toESM(require("react"), 1);
|
|
222
|
+
var import_class_variance_authority2 = require("class-variance-authority");
|
|
223
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
224
|
+
var inputVariants = (0, import_class_variance_authority2.cva)(
|
|
225
|
+
[
|
|
226
|
+
"flex w-full rounded border bg-white text-xs text-foreground",
|
|
227
|
+
"border-line-dark",
|
|
228
|
+
"transition-[box-shadow,border-color,background-color] duration-100",
|
|
229
|
+
"placeholder:text-foreground-disabled",
|
|
230
|
+
"hover:border-line-darker",
|
|
231
|
+
"focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-[rgba(40,76,192,0.2)]",
|
|
232
|
+
"disabled:cursor-not-allowed disabled:bg-fill-lighter disabled:border-line-light disabled:text-foreground-disabled",
|
|
233
|
+
"disabled:placeholder:text-foreground-disabled",
|
|
234
|
+
"file:border-0 file:bg-transparent file:text-sm file:font-medium"
|
|
235
|
+
],
|
|
236
|
+
{
|
|
237
|
+
variants: {
|
|
238
|
+
inputSize: {
|
|
239
|
+
sm: "h-6 px-1.5 py-0.5 text-xs",
|
|
240
|
+
default: "h-8 px-2 py-1.5 text-xs",
|
|
241
|
+
lg: "h-10 px-2.5 py-[9px] text-sm leading-5"
|
|
242
|
+
},
|
|
243
|
+
state: {
|
|
244
|
+
default: "",
|
|
245
|
+
error: [
|
|
246
|
+
"border-[#ff695c]",
|
|
247
|
+
"hover:border-[#ff695c]",
|
|
248
|
+
"focus-visible:border-[#ff695c] focus-visible:ring-[rgba(255,105,92,0.2)]"
|
|
249
|
+
],
|
|
250
|
+
warning: [
|
|
251
|
+
"border-[#ffcd00]",
|
|
252
|
+
"hover:border-[#ffcd00]",
|
|
253
|
+
"focus-visible:border-[#ffcd00] focus-visible:ring-[rgba(255,205,0,0.2)]"
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
defaultVariants: {
|
|
258
|
+
inputSize: "default",
|
|
259
|
+
state: "default"
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
var Input = React2.forwardRef(
|
|
264
|
+
(_a, ref) => {
|
|
265
|
+
var _b = _a, { className, inputSize, state, type } = _b, props = __objRest(_b, ["className", "inputSize", "state", "type"]);
|
|
266
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
267
|
+
"input",
|
|
268
|
+
__spreadValues({
|
|
269
|
+
type,
|
|
270
|
+
className: cn(inputVariants({ inputSize, state }), className),
|
|
271
|
+
ref
|
|
272
|
+
}, props)
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
);
|
|
276
|
+
Input.displayName = "Input";
|
|
277
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
278
|
+
0 && (module.exports = {
|
|
279
|
+
Button,
|
|
280
|
+
Input,
|
|
281
|
+
buttonVariants,
|
|
282
|
+
cn,
|
|
283
|
+
inputVariants
|
|
284
|
+
});
|