@srcroot/ui 0.0.32 → 0.0.34

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