gladvn 0.2.29 → 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 +72 -3
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -420,10 +420,17 @@ async function main() {
420
420
  }
421
421
 
422
422
  // 3. Configure Path Alias
423
- let tsconfigPath = path.join(process.cwd(), 'tsconfig.json');
424
- 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
+ }
425
432
 
426
- if (fs.existsSync(tsconfigPath)) {
433
+ if (tsconfigPath) {
427
434
  let content = fs.readFileSync(tsconfigPath, 'utf8');
428
435
  if (!content.includes('@gladvn/*')) {
429
436
  const pathsEmptyRegex = /"paths"\s*:\s*\{\s*\}/;
@@ -437,12 +444,74 @@ async function main() {
437
444
  content = content.replace(compilerOptionsEmptyRegex, `"compilerOptions": {\n "paths": {\n "@gladvn/*": ["./${userDest}/*"]\n }\n }`);
438
445
  } else if (content.match(/"compilerOptions"\s*:\s*\{/)) {
439
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 },`);
440
449
  }
441
450
  fs.writeFileSync(tsconfigPath, content);
442
451
  console.log(`\x1b[32m✔ Configured path alias @gladvn/* in ${path.basename(tsconfigPath)}\x1b[0m`);
443
452
  }
444
453
  }
445
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
+
446
515
  } // END OF INIT COMMAND
447
516
 
448
517
  // 3. Install dependencies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gladvn",
3
- "version": "0.2.29",
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.",