gladvn 0.2.27 → 0.2.30

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/bin/cli.js +118 -26
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -16,7 +16,7 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
16
16
  console.log(`
17
17
  Usage:
18
18
  npx gladvn init [destination]
19
- npx gladvn add <component> [destination]
19
+ npx gladvn add <component | --all> [destination]
20
20
  npx gladvn add-block <block> [destination]
21
21
 
22
22
  Options:
@@ -254,29 +254,52 @@ async function main() {
254
254
  }
255
255
 
256
256
  if (command === "add") {
257
- console.log(`\x1b[36mAdding ${componentToAdd} to ${userDest}...\x1b[0m`);
258
- const compMatches = availableComponents.filter(c => c.endsWith(`/${componentToAdd}.tsx`) || c.endsWith(`/${componentToAdd}.ts`));
259
- if (compMatches.length === 0) {
260
- console.error(`\x1b[31m✖ Component "${componentToAdd}" not found.\x1b[0m`);
261
- process.exit(1);
262
- }
263
-
264
257
  if (!fs.existsSync(destPath)) {
265
258
  fs.mkdirSync(destPath, { recursive: true });
266
259
  }
267
- const comp = compMatches[0];
268
- const sourcePath = path.join(componentsDir, comp);
269
- const targetPath = path.join(destPath, 'components', comp);
270
- const targetDir = path.dirname(targetPath);
271
- if (!fs.existsSync(targetDir)) {
272
- fs.mkdirSync(targetDir, { recursive: true });
273
- }
274
- try {
275
- fs.cpSync(sourcePath, targetPath, { force: true });
276
- console.log(`\x1b[32m✔ Added ${comp}\x1b[0m`);
277
- } catch (err) {
278
- console.error(`\x1b[31m✖ Failed to add ${comp}: ${err.message}\x1b[0m`);
279
- hasErrors = true;
260
+
261
+ if (componentToAdd === "--all") {
262
+ console.log(`\x1b[36mAdding all components to ${userDest}...\x1b[0m`);
263
+ let addedCount = 0;
264
+ for (const comp of availableComponents) {
265
+ const sourcePath = path.join(componentsDir, comp);
266
+ const targetPath = path.join(destPath, 'components', comp);
267
+ const targetDir = path.dirname(targetPath);
268
+ if (!fs.existsSync(targetDir)) {
269
+ fs.mkdirSync(targetDir, { recursive: true });
270
+ }
271
+ try {
272
+ fs.cpSync(sourcePath, targetPath, { force: true });
273
+ console.log(`\x1b[32m✔ Added ${comp}\x1b[0m`);
274
+ addedCount++;
275
+ } catch (err) {
276
+ console.error(`\x1b[31m✖ Failed to add ${comp}: ${err.message}\x1b[0m`);
277
+ hasErrors = true;
278
+ }
279
+ }
280
+ console.log(`\x1b[32m✔ Successfully added ${addedCount} components!\x1b[0m`);
281
+ } else {
282
+ console.log(`\x1b[36mAdding ${componentToAdd} to ${userDest}...\x1b[0m`);
283
+ const compMatches = availableComponents.filter(c => c.endsWith(`/${componentToAdd}.tsx`) || c.endsWith(`/${componentToAdd}.ts`));
284
+ if (compMatches.length === 0) {
285
+ console.error(`\x1b[31m✖ Component "${componentToAdd}" not found.\x1b[0m`);
286
+ process.exit(1);
287
+ }
288
+
289
+ const comp = compMatches[0];
290
+ const sourcePath = path.join(componentsDir, comp);
291
+ const targetPath = path.join(destPath, 'components', comp);
292
+ const targetDir = path.dirname(targetPath);
293
+ if (!fs.existsSync(targetDir)) {
294
+ fs.mkdirSync(targetDir, { recursive: true });
295
+ }
296
+ try {
297
+ fs.cpSync(sourcePath, targetPath, { force: true });
298
+ console.log(`\x1b[32m✔ Added ${comp}\x1b[0m`);
299
+ } catch (err) {
300
+ console.error(`\x1b[31m✖ Failed to add ${comp}: ${err.message}\x1b[0m`);
301
+ hasErrors = true;
302
+ }
280
303
  }
281
304
  } else if (command === "add-block") {
282
305
  console.log(`\x1b[36mAdding block ${componentToAdd} to ${userDest}...\x1b[0m`);
@@ -362,7 +385,7 @@ async function main() {
362
385
 
363
386
  // Always copy core directories
364
387
 
365
- const coreDirs = ['hooks', 'lib', 'styles'];
388
+ const coreDirs = ['hooks', 'lib', 'styles', 'components', 'blocks'];
366
389
  for (const dir of coreDirs) {
367
390
  const sourcePath = path.join(srcDir, dir);
368
391
  const targetPath = path.join(destPath, dir);
@@ -375,7 +398,7 @@ async function main() {
375
398
  }
376
399
  }
377
400
  }
378
- console.log(`\x1b[32m✔ Copied core files (lib, hooks, styles)\x1b[0m`);
401
+ console.log(`\x1b[32m✔ Copied core files and all components (lib, hooks, styles, components, blocks)\x1b[0m`);
379
402
 
380
403
  // 2. Inject CSS
381
404
  if (cssFilePath && fs.existsSync(cssFilePath)) {
@@ -397,10 +420,17 @@ async function main() {
397
420
  }
398
421
 
399
422
  // 3. Configure Path Alias
400
- let tsconfigPath = path.join(process.cwd(), 'tsconfig.json');
401
- if (!fs.existsSync(tsconfigPath)) tsconfigPath = path.join(process.cwd(), 'jsconfig.json');
423
+ const tsconfigFiles = ['tsconfig.app.json', 'tsconfig.json', 'jsconfig.json'];
424
+ let tsconfigPath = null;
425
+ for (const file of tsconfigFiles) {
426
+ const p = path.join(process.cwd(), file);
427
+ if (fs.existsSync(p)) {
428
+ tsconfigPath = p;
429
+ break;
430
+ }
431
+ }
402
432
 
403
- if (fs.existsSync(tsconfigPath)) {
433
+ if (tsconfigPath) {
404
434
  let content = fs.readFileSync(tsconfigPath, 'utf8');
405
435
  if (!content.includes('@gladvn/*')) {
406
436
  const pathsEmptyRegex = /"paths"\s*:\s*\{\s*\}/;
@@ -414,12 +444,74 @@ async function main() {
414
444
  content = content.replace(compilerOptionsEmptyRegex, `"compilerOptions": {\n "paths": {\n "@gladvn/*": ["./${userDest}/*"]\n }\n }`);
415
445
  } else if (content.match(/"compilerOptions"\s*:\s*\{/)) {
416
446
  content = content.replace(/"compilerOptions"\s*:\s*\{/, `"compilerOptions": {\n "paths": {\n "@gladvn/*": ["./${userDest}/*"]\n },`);
447
+ } else if (!content.includes('"compilerOptions"')) {
448
+ content = content.replace(/\{/, `{\n "compilerOptions": {\n "paths": {\n "@gladvn/*": ["./${userDest}/*"]\n }\n },`);
417
449
  }
418
450
  fs.writeFileSync(tsconfigPath, content);
419
451
  console.log(`\x1b[32m✔ Configured path alias @gladvn/* in ${path.basename(tsconfigPath)}\x1b[0m`);
420
452
  }
421
453
  }
422
454
 
455
+ // 4. Configure Vite Alias
456
+ const viteConfigFiles = ['vite.config.ts', 'vite.config.js'];
457
+ let viteConfigPath = null;
458
+ for (const file of viteConfigFiles) {
459
+ const p = path.join(process.cwd(), file);
460
+ if (fs.existsSync(p)) {
461
+ viteConfigPath = p;
462
+ break;
463
+ }
464
+ }
465
+
466
+ if (viteConfigPath) {
467
+ let content = fs.readFileSync(viteConfigPath, 'utf8');
468
+ if (!content.includes('@gladvn')) {
469
+ if (!content.includes('import path from') && !content.includes('require("path")')) {
470
+ if (content.includes('import ')) {
471
+ const lastImportIndex = content.lastIndexOf('import ');
472
+ const endOfLine = content.indexOf('\n', lastImportIndex);
473
+ if (endOfLine !== -1) {
474
+ content = content.slice(0, endOfLine + 1) + 'import path from "path"\n' + content.slice(endOfLine + 1);
475
+ } else {
476
+ content = 'import path from "path"\n' + content;
477
+ }
478
+ } else {
479
+ content = 'import path from "path"\n' + content;
480
+ }
481
+ }
482
+
483
+ const resolveAlias = `\n resolve: {\n alias: {\n "@gladvn": path.resolve(__dirname, "./${userDest}"),\n },\n },`;
484
+
485
+ if (content.includes('resolve: {')) {
486
+ if (content.includes('alias: {')) {
487
+ content = content.replace(/alias:\s*\{/, `alias: {\n "@gladvn": path.resolve(__dirname, "./${userDest}"),`);
488
+ } else {
489
+ content = content.replace(/resolve:\s*\{/, `resolve: {\n alias: {\n "@gladvn": path.resolve(__dirname, "./${userDest}"),\n },`);
490
+ }
491
+ } else {
492
+ content = content.replace(/defineConfig\s*\(\s*\{/, `defineConfig({${resolveAlias}`);
493
+ }
494
+
495
+ fs.writeFileSync(viteConfigPath, content);
496
+ console.log(`\x1b[32m✔ Configured resolve.alias in ${path.basename(viteConfigPath)}\x1b[0m`);
497
+
498
+ if (viteConfigPath.endsWith('.ts')) {
499
+ try {
500
+ const userPkgPath = path.resolve(process.cwd(), 'package.json');
501
+ if (fs.existsSync(userPkgPath)) {
502
+ const userPkg = JSON.parse(fs.readFileSync(userPkgPath, 'utf8'));
503
+ if (!userPkg.devDependencies) userPkg.devDependencies = {};
504
+ if (!userPkg.devDependencies['@types/node'] && (!userPkg.dependencies || !userPkg.dependencies['@types/node'])) {
505
+ userPkg.devDependencies['@types/node'] = '^20.0.0';
506
+ fs.writeFileSync(userPkgPath, JSON.stringify(userPkg, null, 2));
507
+ console.log(`\x1b[32m✔ Added @types/node to devDependencies\x1b[0m`);
508
+ }
509
+ }
510
+ } catch (e) {}
511
+ }
512
+ }
513
+ }
514
+
423
515
  } // END OF INIT COMMAND
424
516
 
425
517
  // 3. Install dependencies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gladvn",
3
- "version": "0.2.27",
3
+ "version": "0.2.30",
4
4
  "type": "module",
5
5
  "packageManager": "pnpm@10.11.0",
6
6
  "description": "A CLI to scaffold beautiful, accessible React components into your project. Powered by Tailwind CSS v4 and Base UI.",