@srcroot/ui 0.0.34 → 0.0.35

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 +76 -77
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@ import { Command } from "commander";
5
5
  import chalk3 from "chalk";
6
6
 
7
7
  // src/cli/services/project-initializer.ts
8
- import fs2 from "fs-extra";
9
- import path2 from "path";
8
+ import fs3 from "fs-extra";
9
+ import path3 from "path";
10
10
  import ora from "ora";
11
11
  import prompts from "prompts";
12
12
  import { fileURLToPath as fileURLToPath2 } from "url";
@@ -144,20 +144,21 @@ export default config
144
144
  `;
145
145
 
146
146
  // src/cli/utils/get-package-manager.ts
147
- function getPackageManager() {
147
+ import fs2 from "fs";
148
+ import path2 from "path";
149
+ function getPackageManager(cwd) {
148
150
  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";
151
+ if (userAgent) {
152
+ if (userAgent.startsWith("yarn")) return "yarn";
153
+ if (userAgent.startsWith("pnpm")) return "pnpm";
154
+ if (userAgent.startsWith("bun")) return "bun";
155
+ if (userAgent.startsWith("npm")) return "npm";
160
156
  }
157
+ const dir = cwd || process.cwd();
158
+ if (fs2.existsSync(path2.join(dir, "bun.lockb"))) return "bun";
159
+ if (fs2.existsSync(path2.join(dir, "pnpm-lock.yaml"))) return "pnpm";
160
+ if (fs2.existsSync(path2.join(dir, "yarn.lock"))) return "yarn";
161
+ if (fs2.existsSync(path2.join(dir, "package-lock.json"))) return "npm";
161
162
  return "npm";
162
163
  }
163
164
 
@@ -179,7 +180,7 @@ var logger = {
179
180
  };
180
181
 
181
182
  // src/cli/services/project-initializer.ts
182
- var __dirname3 = path2.dirname(fileURLToPath2(import.meta.url));
183
+ var __dirname3 = path3.dirname(fileURLToPath2(import.meta.url));
183
184
  var ProjectInitializer = class {
184
185
  options;
185
186
  config = {};
@@ -198,13 +199,13 @@ var ProjectInitializer = class {
198
199
  this.printSuccess();
199
200
  }
200
201
  async validateEnvironment() {
201
- const cwd = path2.resolve(this.options.cwd);
202
- const packageJsonPath = path2.join(cwd, "package.json");
203
- if (!fs2.existsSync(packageJsonPath)) {
202
+ const cwd = path3.resolve(this.options.cwd);
203
+ const packageJsonPath = path3.join(cwd, "package.json");
204
+ if (!fs3.existsSync(packageJsonPath)) {
204
205
  logger.error("Error: No package.json found. Please run this in a project directory.");
205
206
  process.exit(1);
206
207
  }
207
- const pkg = await fs2.readJson(packageJsonPath);
208
+ const pkg = await fs3.readJson(packageJsonPath);
208
209
  const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
209
210
  if (!allDeps["react"]) {
210
211
  logger.error("Error: React not found in dependencies. Please initialize this in a React project.");
@@ -212,33 +213,33 @@ var ProjectInitializer = class {
212
213
  }
213
214
  }
214
215
  async detectConfiguration() {
215
- const cwd = path2.resolve(this.options.cwd);
216
- const packageManager = getPackageManager();
216
+ const cwd = path3.resolve(this.options.cwd);
217
+ const packageManager = getPackageManager(cwd);
217
218
  const installCmd = packageManager === "npm" ? "install" : "add";
218
- const pkg = await fs2.readJson(path2.join(cwd, "package.json"));
219
+ const pkg = await fs3.readJson(path3.join(cwd, "package.json"));
219
220
  const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
220
221
  const tailwindVersion = allDeps["tailwindcss"] || "";
221
222
  const isTailwind4 = tailwindVersion.includes("^4") || tailwindVersion.startsWith("4") || allDeps["@tailwindcss/postcss"];
222
- const hasSrc = fs2.existsSync(path2.join(cwd, "src"));
223
- const srcPath = hasSrc ? path2.join(cwd, "src") : cwd;
224
- const appPath = path2.join(srcPath, "app");
225
- const pagesPath = path2.join(srcPath, "pages");
226
- const hasAppDir = fs2.existsSync(appPath);
227
- const hasPagesDir = fs2.existsSync(pagesPath);
228
- const libDir = path2.join(srcPath, "lib");
229
- const componentsDir = path2.join(srcPath, "components", "ui");
223
+ const hasSrc = fs3.existsSync(path3.join(cwd, "src"));
224
+ const srcPath = hasSrc ? path3.join(cwd, "src") : cwd;
225
+ const appPath = path3.join(srcPath, "app");
226
+ const pagesPath = path3.join(srcPath, "pages");
227
+ const hasAppDir = fs3.existsSync(appPath);
228
+ const hasPagesDir = fs3.existsSync(pagesPath);
229
+ const libDir = path3.join(srcPath, "lib");
230
+ const componentsDir = path3.join(srcPath, "components", "ui");
230
231
  let globalsPath = "";
231
232
  if (hasAppDir) {
232
- if (fs2.existsSync(path2.join(appPath, "globals.css"))) globalsPath = path2.join(appPath, "globals.css");
233
- else if (fs2.existsSync(path2.join(appPath, "global.css"))) globalsPath = path2.join(appPath, "global.css");
234
- else globalsPath = path2.join(appPath, "globals.css");
233
+ if (fs3.existsSync(path3.join(appPath, "globals.css"))) globalsPath = path3.join(appPath, "globals.css");
234
+ else if (fs3.existsSync(path3.join(appPath, "global.css"))) globalsPath = path3.join(appPath, "global.css");
235
+ else globalsPath = path3.join(appPath, "globals.css");
235
236
  } else if (hasPagesDir) {
236
- const stylesPath = path2.join(srcPath, "styles");
237
- if (fs2.existsSync(path2.join(stylesPath, "globals.css"))) globalsPath = path2.join(stylesPath, "globals.css");
238
- else if (fs2.existsSync(path2.join(stylesPath, "global.css"))) globalsPath = path2.join(stylesPath, "global.css");
239
- else globalsPath = path2.join(stylesPath, "globals.css");
237
+ const stylesPath = path3.join(srcPath, "styles");
238
+ if (fs3.existsSync(path3.join(stylesPath, "globals.css"))) globalsPath = path3.join(stylesPath, "globals.css");
239
+ else if (fs3.existsSync(path3.join(stylesPath, "global.css"))) globalsPath = path3.join(stylesPath, "global.css");
240
+ else globalsPath = path3.join(stylesPath, "globals.css");
240
241
  } else {
241
- globalsPath = path2.join(srcPath, "globals.css");
242
+ globalsPath = path3.join(srcPath, "globals.css");
242
243
  }
243
244
  this.config = {
244
245
  cwd,
@@ -266,7 +267,7 @@ var ProjectInitializer = class {
266
267
  return;
267
268
  }
268
269
  const themeChoices = availableThemes.map((theme) => ({
269
- title: `${theme.name} - ${theme.description}`,
270
+ title: theme.name,
270
271
  value: theme.file.replace(".css", "")
271
272
  }));
272
273
  const themeResponse = await prompts({
@@ -286,13 +287,13 @@ var ProjectInitializer = class {
286
287
  const spinner = ora("Creating project structure...").start();
287
288
  const cfg = this.config;
288
289
  try {
289
- await fs2.ensureDir(cfg.libDir);
290
- await fs2.ensureDir(cfg.componentsDir);
291
- const utilsPath = path2.join(cfg.libDir, "utils.ts");
292
- const registryUtilsPath = path2.resolve(__dirname3, "..", "src", "registry", "lib", "utils.ts");
290
+ await fs3.ensureDir(cfg.libDir);
291
+ await fs3.ensureDir(cfg.componentsDir);
292
+ const utilsPath = path3.join(cfg.libDir, "utils.ts");
293
+ const registryUtilsPath = path3.resolve(__dirname3, "..", "src", "registry", "lib", "utils.ts");
293
294
  let utilsContent = "";
294
- if (fs2.existsSync(registryUtilsPath)) {
295
- utilsContent = await fs2.readFile(registryUtilsPath, "utf-8");
295
+ if (fs3.existsSync(registryUtilsPath)) {
296
+ utilsContent = await fs3.readFile(registryUtilsPath, "utf-8");
296
297
  } else {
297
298
  utilsContent = `import { type ClassValue, clsx } from "clsx"
298
299
  import { twMerge } from "tailwind-merge"
@@ -303,15 +304,15 @@ export function cn(...inputs: ClassValue[]) {
303
304
  `;
304
305
  spinner.warn(`Could not find registry/utils.ts, using fallback content.`);
305
306
  }
306
- await fs2.writeFile(utilsPath, utilsContent);
307
- spinner.succeed(`Created ${path2.relative(cfg.cwd, utilsPath)}`);
307
+ await fs3.writeFile(utilsPath, utilsContent);
308
+ spinner.succeed(`Created ${path3.relative(cfg.cwd, utilsPath)}`);
308
309
  spinner.start(`Setting up ${cfg.selectedTheme} theme...`);
309
- const stylesDir = path2.dirname(cfg.globalsPath);
310
- await fs2.ensureDir(stylesDir);
310
+ const stylesDir = path3.dirname(cfg.globalsPath);
311
+ await fs3.ensureDir(stylesDir);
311
312
  try {
312
313
  const cssContent = await this.themeService.getThemeCss(cfg.selectedTheme, cfg.isTailwind4);
313
- await fs2.writeFile(cfg.globalsPath, cssContent);
314
- spinner.succeed(`Updated ${path2.relative(cfg.cwd, cfg.globalsPath)} with ${cfg.selectedTheme} theme (${cfg.isTailwind4 ? "Tailwind 4" : "Tailwind 3"})`);
314
+ await fs3.writeFile(cfg.globalsPath, cssContent);
315
+ spinner.succeed(`Updated ${path3.relative(cfg.cwd, cfg.globalsPath)} with ${cfg.selectedTheme} theme (${cfg.isTailwind4 ? "Tailwind 4" : "Tailwind 3"})`);
315
316
  } catch (error) {
316
317
  spinner.fail(`Failed to load theme: ${cfg.selectedTheme}`);
317
318
  console.error(error);
@@ -319,11 +320,9 @@ export function cn(...inputs: ClassValue[]) {
319
320
  }
320
321
  if (!cfg.isTailwind4) {
321
322
  spinner.start("Setting up Tailwind config...");
322
- const tailwindConfigPath = path2.join(cfg.cwd, "tailwind.config.ts");
323
- await fs2.writeFile(tailwindConfigPath, TAILWIND_CONFIG);
323
+ const tailwindConfigPath = path3.join(cfg.cwd, "tailwind.config.ts");
324
+ await fs3.writeFile(tailwindConfigPath, TAILWIND_CONFIG);
324
325
  spinner.succeed(`Created tailwind.config.ts`);
325
- } else {
326
- spinner.info(`Tailwind 4 detected - skipping tailwind.config.ts`);
327
326
  }
328
327
  } catch (error) {
329
328
  spinner.fail("Failed to initialize project");
@@ -374,8 +373,8 @@ async function init(options) {
374
373
  }
375
374
 
376
375
  // src/cli/commands/add.ts
377
- import fs3 from "fs-extra";
378
- import path3 from "path";
376
+ import fs4 from "fs-extra";
377
+ import path4 from "path";
379
378
  import ora2 from "ora";
380
379
  import prompts2 from "prompts";
381
380
  import { fileURLToPath as fileURLToPath3 } from "url";
@@ -760,9 +759,9 @@ var REGISTRY = {
760
759
  };
761
760
 
762
761
  // src/cli/commands/add.ts
763
- var __dirname4 = path3.dirname(fileURLToPath3(import.meta.url));
762
+ var __dirname4 = path4.dirname(fileURLToPath3(import.meta.url));
764
763
  async function add(components, options) {
765
- const cwd = path3.resolve(options.cwd);
764
+ const cwd = path4.resolve(options.cwd);
766
765
  if (options.all) {
767
766
  components = Object.keys(REGISTRY);
768
767
  }
@@ -825,16 +824,16 @@ async function add(components, options) {
825
824
  }
826
825
  console.log();
827
826
  const spinner = ora2("Adding components...").start();
828
- const hasSrc = fs3.existsSync(path3.join(cwd, "src"));
829
- const srcPath = hasSrc ? path3.join(cwd, "src") : cwd;
830
- const componentsDir = path3.join(srcPath, "components", "ui");
827
+ const hasSrc = fs4.existsSync(path4.join(cwd, "src"));
828
+ const srcPath = hasSrc ? path4.join(cwd, "src") : cwd;
829
+ const componentsDir = path4.join(srcPath, "components", "ui");
831
830
  try {
832
- await fs3.ensureDir(componentsDir);
831
+ await fs4.ensureDir(componentsDir);
833
832
  for (const name of componentsToAdd) {
834
833
  const comp = REGISTRY[name];
835
- const fileName = path3.basename(comp.file);
836
- const targetPath = path3.join(componentsDir, fileName);
837
- if (fs3.existsSync(targetPath) && !options.overwrite) {
834
+ const fileName = path4.basename(comp.file);
835
+ const targetPath = path4.join(componentsDir, fileName);
836
+ if (fs4.existsSync(targetPath) && !options.overwrite) {
838
837
  spinner.stop();
839
838
  const { overwrite } = await prompts2({
840
839
  type: "confirm",
@@ -849,13 +848,13 @@ async function add(components, options) {
849
848
  }
850
849
  spinner.start("Adding components...");
851
850
  }
852
- const registryPath = path3.resolve(__dirname4, "..", "src", "registry", comp.file);
853
- if (!fs3.existsSync(registryPath)) {
851
+ const registryPath = path4.resolve(__dirname4, "..", "src", "registry", comp.file);
852
+ if (!fs4.existsSync(registryPath)) {
854
853
  spinner.warn(`Registry file not found for ${name}: ${registryPath}`);
855
854
  continue;
856
855
  }
857
- const content = await fs3.readFile(registryPath, "utf-8");
858
- await fs3.writeFile(targetPath, content);
856
+ const content = await fs4.readFile(registryPath, "utf-8");
857
+ await fs4.writeFile(targetPath, content);
859
858
  if (componentsToAdd.length > 10) {
860
859
  spinner.text = `Adding ${fileName}...`;
861
860
  } else {
@@ -905,19 +904,19 @@ async function list() {
905
904
  }
906
905
 
907
906
  // src/cli/utils/get-package-info.ts
908
- import path4 from "path";
909
- import fs4 from "fs-extra";
907
+ import path5 from "path";
908
+ import fs5 from "fs-extra";
910
909
  import { fileURLToPath as fileURLToPath4 } from "url";
911
910
  function getPackageInfo() {
912
911
  const __filename2 = fileURLToPath4(import.meta.url);
913
- const __dirname5 = path4.dirname(__filename2);
912
+ const __dirname5 = path5.dirname(__filename2);
914
913
  const pathsToCheck = [
915
- path4.resolve(__dirname5, "..", "package.json"),
916
- path4.resolve(__dirname5, "..", "..", "..", "package.json")
914
+ path5.resolve(__dirname5, "..", "package.json"),
915
+ path5.resolve(__dirname5, "..", "..", "..", "package.json")
917
916
  ];
918
917
  for (const pkgPath of pathsToCheck) {
919
- if (fs4.existsSync(pkgPath)) {
920
- return fs4.readJSONSync(pkgPath);
918
+ if (fs5.existsSync(pkgPath)) {
919
+ return fs5.readJSONSync(pkgPath);
921
920
  }
922
921
  }
923
922
  return { version: "0.0.0" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srcroot/ui",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "A UI library with polymorphic, accessible React components",
5
5
  "type": "module",
6
6
  "bin": {