@srcroot/ui 0.0.32 → 0.0.33
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 +74 -45
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
-
import
|
|
5
|
+
import chalk3 from "chalk";
|
|
6
6
|
|
|
7
7
|
// src/cli/services/project-initializer.ts
|
|
8
8
|
import fs2 from "fs-extra";
|
|
9
9
|
import path2 from "path";
|
|
10
|
-
import chalk from "chalk";
|
|
11
10
|
import ora from "ora";
|
|
12
11
|
import prompts from "prompts";
|
|
13
12
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -143,6 +142,41 @@ const config: Config = {
|
|
|
143
142
|
export default config
|
|
144
143
|
`;
|
|
145
144
|
|
|
145
|
+
// src/cli/utils/get-package-manager.ts
|
|
146
|
+
function getPackageManager() {
|
|
147
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
148
|
+
if (!userAgent) {
|
|
149
|
+
return "npm";
|
|
150
|
+
}
|
|
151
|
+
if (userAgent.startsWith("yarn")) {
|
|
152
|
+
return "yarn";
|
|
153
|
+
}
|
|
154
|
+
if (userAgent.startsWith("pnpm")) {
|
|
155
|
+
return "pnpm";
|
|
156
|
+
}
|
|
157
|
+
if (userAgent.startsWith("bun")) {
|
|
158
|
+
return "bun";
|
|
159
|
+
}
|
|
160
|
+
return "npm";
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/cli/utils/logger.ts
|
|
164
|
+
import chalk from "chalk";
|
|
165
|
+
var logger = {
|
|
166
|
+
error(...args) {
|
|
167
|
+
console.log(chalk.red(...args));
|
|
168
|
+
},
|
|
169
|
+
warn(...args) {
|
|
170
|
+
console.log(chalk.yellow(...args));
|
|
171
|
+
},
|
|
172
|
+
info(...args) {
|
|
173
|
+
console.log(chalk.cyan(...args));
|
|
174
|
+
},
|
|
175
|
+
success(...args) {
|
|
176
|
+
console.log(chalk.green(...args));
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
146
180
|
// src/cli/services/project-initializer.ts
|
|
147
181
|
var __dirname3 = path2.dirname(fileURLToPath2(import.meta.url));
|
|
148
182
|
var ProjectInitializer = class {
|
|
@@ -154,7 +188,7 @@ var ProjectInitializer = class {
|
|
|
154
188
|
this.themeService = new ThemeService();
|
|
155
189
|
}
|
|
156
190
|
async run() {
|
|
157
|
-
|
|
191
|
+
logger.info("\n\u{1F680} Initializing @srcroot/ui...\n");
|
|
158
192
|
await this.validateEnvironment();
|
|
159
193
|
await this.detectConfiguration();
|
|
160
194
|
await this.promptUser();
|
|
@@ -165,24 +199,20 @@ var ProjectInitializer = class {
|
|
|
165
199
|
const cwd = path2.resolve(this.options.cwd);
|
|
166
200
|
const packageJsonPath = path2.join(cwd, "package.json");
|
|
167
201
|
if (!fs2.existsSync(packageJsonPath)) {
|
|
168
|
-
|
|
202
|
+
logger.error("Error: No package.json found. Please run this in a project directory.");
|
|
169
203
|
process.exit(1);
|
|
170
204
|
}
|
|
171
205
|
const pkg = await fs2.readJson(packageJsonPath);
|
|
172
206
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
173
207
|
if (!allDeps["react"]) {
|
|
174
|
-
|
|
208
|
+
logger.error("Error: React not found in dependencies. Please initialize this in a React project.");
|
|
175
209
|
process.exit(1);
|
|
176
210
|
}
|
|
177
211
|
}
|
|
178
212
|
async detectConfiguration() {
|
|
179
213
|
const cwd = path2.resolve(this.options.cwd);
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
const isPnpm = userAgent.includes("pnpm");
|
|
183
|
-
const isBun = userAgent.includes("bun");
|
|
184
|
-
const packageManager = isPnpm ? "pnpm" : isYarn ? "yarn" : isBun ? "bun" : "npm";
|
|
185
|
-
const installCmd = isPnpm ? "add" : isYarn ? "add" : isBun ? "add" : "install";
|
|
214
|
+
const packageManager = getPackageManager();
|
|
215
|
+
const installCmd = packageManager === "npm" ? "install" : "add";
|
|
186
216
|
const pkg = await fs2.readJson(path2.join(cwd, "package.json"));
|
|
187
217
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
188
218
|
const tailwindVersion = allDeps["tailwindcss"] || "";
|
|
@@ -229,12 +259,12 @@ var ProjectInitializer = class {
|
|
|
229
259
|
if (!this.options.yes && !this.options.theme) {
|
|
230
260
|
const availableThemes = this.themeService.getAvailableThemes();
|
|
231
261
|
if (availableThemes.length === 0) {
|
|
232
|
-
|
|
262
|
+
logger.warn("Warning: No themes found in registry. Using default.");
|
|
233
263
|
this.config.selectedTheme = selectedTheme;
|
|
234
264
|
return;
|
|
235
265
|
}
|
|
236
266
|
const themeChoices = availableThemes.map((theme) => ({
|
|
237
|
-
title: `${theme.name} - ${
|
|
267
|
+
title: `${theme.name} - ${theme.description}`,
|
|
238
268
|
value: theme.file.replace(".css", "")
|
|
239
269
|
}));
|
|
240
270
|
const themeResponse = await prompts({
|
|
@@ -272,14 +302,14 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
272
302
|
spinner.warn(`Could not find registry/utils.ts, using fallback content.`);
|
|
273
303
|
}
|
|
274
304
|
await fs2.writeFile(utilsPath, utilsContent);
|
|
275
|
-
spinner.succeed(`Created ${
|
|
276
|
-
spinner.start(`Setting up ${
|
|
305
|
+
spinner.succeed(`Created ${path2.relative(cfg.cwd, utilsPath)}`);
|
|
306
|
+
spinner.start(`Setting up ${cfg.selectedTheme} theme...`);
|
|
277
307
|
const stylesDir = path2.dirname(cfg.globalsPath);
|
|
278
308
|
await fs2.ensureDir(stylesDir);
|
|
279
309
|
try {
|
|
280
310
|
const cssContent = await this.themeService.getThemeCss(cfg.selectedTheme, cfg.isTailwind4);
|
|
281
311
|
await fs2.writeFile(cfg.globalsPath, cssContent);
|
|
282
|
-
spinner.succeed(`Updated ${
|
|
312
|
+
spinner.succeed(`Updated ${path2.relative(cfg.cwd, cfg.globalsPath)} with ${cfg.selectedTheme} theme (${cfg.isTailwind4 ? "Tailwind 4" : "Tailwind 3"})`);
|
|
283
313
|
} catch (error) {
|
|
284
314
|
spinner.fail(`Failed to load theme: ${cfg.selectedTheme}`);
|
|
285
315
|
console.error(error);
|
|
@@ -289,9 +319,9 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
289
319
|
spinner.start("Setting up Tailwind config...");
|
|
290
320
|
const tailwindConfigPath = path2.join(cfg.cwd, "tailwind.config.ts");
|
|
291
321
|
await fs2.writeFile(tailwindConfigPath, TAILWIND_CONFIG);
|
|
292
|
-
spinner.succeed(`Created
|
|
322
|
+
spinner.succeed(`Created tailwind.config.ts`);
|
|
293
323
|
} else {
|
|
294
|
-
spinner.info(`Tailwind 4 detected - skipping
|
|
324
|
+
spinner.info(`Tailwind 4 detected - skipping tailwind.config.ts`);
|
|
295
325
|
}
|
|
296
326
|
} catch (error) {
|
|
297
327
|
spinner.fail("Failed to initialize project");
|
|
@@ -301,9 +331,9 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
301
331
|
}
|
|
302
332
|
printSuccess() {
|
|
303
333
|
const cfg = this.config;
|
|
304
|
-
|
|
305
|
-
console.log(`Theme: ${
|
|
306
|
-
console.log(`Tailwind: ${
|
|
334
|
+
logger.success("\n\u2705 Project initialized successfully!\n");
|
|
335
|
+
console.log(`Theme: ${cfg.selectedTheme}`);
|
|
336
|
+
console.log(`Tailwind: ${cfg.isTailwind4 ? "v4" : "v3"}`);
|
|
307
337
|
const requiredDeps = [
|
|
308
338
|
"clsx",
|
|
309
339
|
"tailwind-merge",
|
|
@@ -313,12 +343,12 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
313
343
|
if (!cfg.isTailwind4) {
|
|
314
344
|
requiredDeps.push("tailwindcss-animate");
|
|
315
345
|
}
|
|
316
|
-
|
|
317
|
-
console.log(
|
|
346
|
+
logger.info("\n\u{1F4E6} Required dependencies:");
|
|
347
|
+
console.log(` ${cfg.packageManager} ${cfg.installCmd} ${requiredDeps.join(" ")}`);
|
|
318
348
|
console.log("\n\u2728 Next steps:");
|
|
319
|
-
console.log(
|
|
320
|
-
console.log(
|
|
321
|
-
console.log(
|
|
349
|
+
console.log(" 1. Install dependencies (command above)");
|
|
350
|
+
console.log(" 2. npx @srcroot/ui add button");
|
|
351
|
+
console.log(" 3. npx @srcroot/ui add --all");
|
|
322
352
|
console.log();
|
|
323
353
|
}
|
|
324
354
|
};
|
|
@@ -332,7 +362,6 @@ async function init(options) {
|
|
|
332
362
|
// src/cli/commands/add.ts
|
|
333
363
|
import fs3 from "fs-extra";
|
|
334
364
|
import path3 from "path";
|
|
335
|
-
import chalk2 from "chalk";
|
|
336
365
|
import ora2 from "ora";
|
|
337
366
|
import prompts2 from "prompts";
|
|
338
367
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
@@ -736,7 +765,7 @@ async function add(components, options) {
|
|
|
736
765
|
}))
|
|
737
766
|
});
|
|
738
767
|
if (!items || items.length === 0) {
|
|
739
|
-
|
|
768
|
+
logger.warn("No components selected.");
|
|
740
769
|
process.exit(0);
|
|
741
770
|
}
|
|
742
771
|
components = items;
|
|
@@ -751,8 +780,8 @@ async function add(components, options) {
|
|
|
751
780
|
}
|
|
752
781
|
}
|
|
753
782
|
if (invalidComponents.length > 0) {
|
|
754
|
-
|
|
755
|
-
console.log(
|
|
783
|
+
logger.error(`Unknown components: ${invalidComponents.join(", ")}`);
|
|
784
|
+
console.log("\nRun '@srcroot/ui list' to see available components.");
|
|
756
785
|
process.exit(1);
|
|
757
786
|
}
|
|
758
787
|
const toInstall = /* @__PURE__ */ new Set();
|
|
@@ -771,13 +800,13 @@ async function add(components, options) {
|
|
|
771
800
|
}
|
|
772
801
|
const componentsToAdd = Array.from(toInstall);
|
|
773
802
|
if (componentsToAdd.length > 10) {
|
|
774
|
-
|
|
803
|
+
logger.info(`
|
|
775
804
|
\u{1F4E6} Adding ${componentsToAdd.length} components...
|
|
776
|
-
`)
|
|
805
|
+
`);
|
|
777
806
|
} else {
|
|
778
|
-
|
|
807
|
+
logger.info("\n\u{1F4E6} Adding components:\n");
|
|
779
808
|
componentsToAdd.forEach((name) => {
|
|
780
|
-
console.log(
|
|
809
|
+
console.log(` - ${name}`);
|
|
781
810
|
});
|
|
782
811
|
}
|
|
783
812
|
console.log();
|
|
@@ -796,11 +825,11 @@ async function add(components, options) {
|
|
|
796
825
|
const { overwrite } = await prompts2({
|
|
797
826
|
type: "confirm",
|
|
798
827
|
name: "overwrite",
|
|
799
|
-
message: `${
|
|
828
|
+
message: `${fileName} already exists. Overwrite?`,
|
|
800
829
|
initial: false
|
|
801
830
|
});
|
|
802
831
|
if (!overwrite) {
|
|
803
|
-
spinner.info(`Skipped ${
|
|
832
|
+
spinner.info(`Skipped ${fileName}`);
|
|
804
833
|
spinner.start("Adding components...");
|
|
805
834
|
continue;
|
|
806
835
|
}
|
|
@@ -814,15 +843,15 @@ async function add(components, options) {
|
|
|
814
843
|
const content = await fs3.readFile(registryPath, "utf-8");
|
|
815
844
|
await fs3.writeFile(targetPath, content);
|
|
816
845
|
if (componentsToAdd.length > 10) {
|
|
817
|
-
spinner.text = `Adding ${
|
|
846
|
+
spinner.text = `Adding ${fileName}...`;
|
|
818
847
|
} else {
|
|
819
|
-
spinner.succeed(`Added ${
|
|
848
|
+
spinner.succeed(`Added ${fileName}`);
|
|
820
849
|
}
|
|
821
850
|
}
|
|
822
851
|
if (componentsToAdd.length > 10) {
|
|
823
852
|
spinner.succeed(`Added ${componentsToAdd.length} components`);
|
|
824
853
|
}
|
|
825
|
-
|
|
854
|
+
logger.success("\n\u2705 Components added successfully!\n");
|
|
826
855
|
} catch (error) {
|
|
827
856
|
spinner.fail("Failed to add components");
|
|
828
857
|
console.error(error);
|
|
@@ -831,9 +860,9 @@ async function add(components, options) {
|
|
|
831
860
|
}
|
|
832
861
|
|
|
833
862
|
// src/cli/commands/list.ts
|
|
834
|
-
import
|
|
863
|
+
import chalk2 from "chalk";
|
|
835
864
|
async function list() {
|
|
836
|
-
console.log(
|
|
865
|
+
console.log(chalk2.cyan("\n\u{1F4E6} Available components:\n"));
|
|
837
866
|
const categories = {
|
|
838
867
|
"Core": [],
|
|
839
868
|
"Typography": [],
|
|
@@ -851,14 +880,14 @@ async function list() {
|
|
|
851
880
|
}
|
|
852
881
|
for (const [category, components] of Object.entries(categories)) {
|
|
853
882
|
if (components.length === 0) continue;
|
|
854
|
-
console.log(
|
|
883
|
+
console.log(chalk2.bold.white(` ${category}`));
|
|
855
884
|
components.forEach((name) => {
|
|
856
885
|
const comp = REGISTRY[name];
|
|
857
|
-
console.log(
|
|
886
|
+
console.log(chalk2.dim(` - ${name}`) + chalk2.gray(` (${comp.description})`));
|
|
858
887
|
});
|
|
859
888
|
console.log();
|
|
860
889
|
}
|
|
861
|
-
console.log(
|
|
890
|
+
console.log(chalk2.dim("Usage: npx @srcroot/ui add <component>\n"));
|
|
862
891
|
}
|
|
863
892
|
|
|
864
893
|
// src/cli/utils/get-package-info.ts
|
|
@@ -894,7 +923,7 @@ async function main() {
|
|
|
894
923
|
program.command("add").description("Add components to your project").argument("[components...]", "Components to add").option("-y, --yes", "Skip confirmation prompts", false).option("-o, --overwrite", "Overwrite existing files", false).option("-a, --all", "Add all available components", false).option("--cwd <path>", "Working directory", process.cwd()).action(add);
|
|
895
924
|
program.command("list").description("List all available components").action(list);
|
|
896
925
|
if (process.argv.length < 3) {
|
|
897
|
-
console.log(
|
|
926
|
+
console.log(chalk3.cyan(`
|
|
898
927
|
@srcroot/ui v${packageInfo.version}
|
|
899
928
|
|
|
900
929
|
A UI library with polymorphic, accessible components.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@srcroot/ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "A UI library with polymorphic, accessible React components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -33,28 +33,29 @@
|
|
|
33
33
|
"@types/fs-extra": "^11.0.4",
|
|
34
34
|
"@types/node": "^22.10.1",
|
|
35
35
|
"@types/prompts": "^2.4.9",
|
|
36
|
-
"tsup": "^8.3.5",
|
|
37
|
-
"typescript": "^5.7.2",
|
|
38
|
-
"tailwindcss-animate": "^1.0.7",
|
|
39
36
|
"class-variance-authority": "^0.7.1",
|
|
40
37
|
"clsx": "^2.1.1",
|
|
41
38
|
"cmdk": "^1.0.0",
|
|
42
39
|
"react": "^18.0.0 || ^19.0.0",
|
|
43
40
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
41
|
+
"react-icons": "^5.5.0",
|
|
44
42
|
"tailwind-merge": "^3.4.0",
|
|
45
43
|
"tailwindcss": "^3.0.0 || ^4.0.0",
|
|
46
|
-
"
|
|
44
|
+
"tailwindcss-animate": "^1.0.7",
|
|
45
|
+
"tsup": "^8.3.5",
|
|
46
|
+
"type-fest": "^5.3.1",
|
|
47
|
+
"typescript": "^5.7.2"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"class-variance-authority": "^0.7.1",
|
|
50
51
|
"clsx": "^2.1.1",
|
|
51
52
|
"cmdk": "^1.0.0",
|
|
52
|
-
"react-icons": "^5.5.0",
|
|
53
53
|
"react": "^18.0.0 || ^19.0.0",
|
|
54
54
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
55
|
+
"react-icons": "^5.5.0",
|
|
55
56
|
"tailwind-merge": "^3.4.0",
|
|
56
|
-
"tailwindcss
|
|
57
|
-
"tailwindcss": "^
|
|
57
|
+
"tailwindcss": "^3.0.0 || ^4.0.0",
|
|
58
|
+
"tailwindcss-animate": "^1.0.7"
|
|
58
59
|
},
|
|
59
60
|
"peerDependenciesMeta": {
|
|
60
61
|
"cmdk": {
|