gladvn 0.2.31 → 0.2.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/bin/cli.js +70 -10
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -456,23 +456,45 @@ async function main() {
|
|
|
456
456
|
|
|
457
457
|
if (tsconfigPath) {
|
|
458
458
|
let content = fs.readFileSync(tsconfigPath, 'utf8');
|
|
459
|
-
|
|
459
|
+
let modified = false;
|
|
460
|
+
|
|
461
|
+
// 3a. Ensure baseUrl is set (required for paths to work)
|
|
462
|
+
if (!content.includes('"baseUrl"')) {
|
|
463
|
+
if (content.match(/"compilerOptions"\s*:\s*\{/)) {
|
|
464
|
+
content = content.replace(/"compilerOptions"\s*:\s*\{/, `"compilerOptions": {\n "baseUrl": ".",`);
|
|
465
|
+
modified = true;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// 3b. Add path aliases: both @gladvn (barrel) and @gladvn/* (deep imports)
|
|
470
|
+
if (!content.includes('@gladvn')) {
|
|
471
|
+
const pathsBlock = `"paths": {\n "@gladvn": ["./${userDest}/index.ts"],\n "@gladvn/*": ["./${userDest}/*"]\n }`;
|
|
460
472
|
const pathsEmptyRegex = /"paths"\s*:\s*\{\s*\}/;
|
|
461
473
|
const compilerOptionsEmptyRegex = /"compilerOptions"\s*:\s*\{\s*\}/;
|
|
462
474
|
|
|
463
475
|
if (pathsEmptyRegex.test(content)) {
|
|
464
|
-
content = content.replace(pathsEmptyRegex,
|
|
476
|
+
content = content.replace(pathsEmptyRegex, pathsBlock);
|
|
465
477
|
} else if (content.match(/"paths"\s*:\s*\{/)) {
|
|
466
|
-
content = content.replace(/"paths"\s*:\s*\{/, `"paths": {\n "@gladvn/*": ["./${userDest}/*"],`);
|
|
478
|
+
content = content.replace(/"paths"\s*:\s*\{/, `"paths": {\n "@gladvn": ["./${userDest}/index.ts"],\n "@gladvn/*": ["./${userDest}/*"],`);
|
|
467
479
|
} else if (compilerOptionsEmptyRegex.test(content)) {
|
|
468
|
-
content = content.replace(compilerOptionsEmptyRegex, `"compilerOptions": {\n
|
|
480
|
+
content = content.replace(compilerOptionsEmptyRegex, `"compilerOptions": {\n ${pathsBlock}\n }`);
|
|
469
481
|
} else if (content.match(/"compilerOptions"\s*:\s*\{/)) {
|
|
470
|
-
content = content.replace(/"compilerOptions"\s*:\s*\{/, `"compilerOptions": {\n
|
|
482
|
+
content = content.replace(/"compilerOptions"\s*:\s*\{/, `"compilerOptions": {\n ${pathsBlock},`);
|
|
471
483
|
} else if (!content.includes('"compilerOptions"')) {
|
|
472
|
-
content = content.replace(/\{/, `{\n "compilerOptions": {\n
|
|
484
|
+
content = content.replace(/\{/, `{\n "compilerOptions": {\n ${pathsBlock}\n },`);
|
|
473
485
|
}
|
|
486
|
+
modified = true;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// 3c. Add destination folder to "include" so TS can see files outside src/
|
|
490
|
+
if (content.includes('"include"') && !content.includes(`"${userDest}"`)) {
|
|
491
|
+
content = content.replace(/"include"\s*:\s*\[/, `"include": [\n "${userDest}",`);
|
|
492
|
+
modified = true;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
if (modified) {
|
|
474
496
|
fs.writeFileSync(tsconfigPath, content);
|
|
475
|
-
console.log(`\x1b[32m✔ Configured path alias @gladvn
|
|
497
|
+
console.log(`\x1b[32m✔ Configured path alias @gladvn in ${path.basename(tsconfigPath)}\x1b[0m`);
|
|
476
498
|
}
|
|
477
499
|
}
|
|
478
500
|
|
|
@@ -489,6 +511,8 @@ async function main() {
|
|
|
489
511
|
|
|
490
512
|
if (viteConfigPath) {
|
|
491
513
|
let content = fs.readFileSync(viteConfigPath, 'utf8');
|
|
514
|
+
let modified = false;
|
|
515
|
+
|
|
492
516
|
if (!content.includes('@gladvn')) {
|
|
493
517
|
// Add `import path from "path"` if missing
|
|
494
518
|
if (!content.includes('import path from') && !content.includes('require("path")')) {
|
|
@@ -516,9 +540,35 @@ async function main() {
|
|
|
516
540
|
} else {
|
|
517
541
|
content = content.replace(/defineConfig\s*\(\s*\{/, `defineConfig({${resolveAlias}`);
|
|
518
542
|
}
|
|
543
|
+
modified = true;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (!content.includes('@tailwindcss/vite')) {
|
|
547
|
+
if (content.includes('import ')) {
|
|
548
|
+
const lastImportIndex = content.lastIndexOf('import ');
|
|
549
|
+
const endOfLine = content.indexOf('\n', lastImportIndex);
|
|
550
|
+
if (endOfLine !== -1) {
|
|
551
|
+
content = content.slice(0, endOfLine + 1) + 'import tailwindcss from "@tailwindcss/vite"\n' + content.slice(endOfLine + 1);
|
|
552
|
+
} else {
|
|
553
|
+
content = 'import tailwindcss from "@tailwindcss/vite"\n' + content;
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
content = 'import tailwindcss from "@tailwindcss/vite"\n' + content;
|
|
557
|
+
}
|
|
519
558
|
|
|
559
|
+
if (content.includes('plugins: [')) {
|
|
560
|
+
content = content.replace(/plugins:\s*\[/, `plugins: [\n tailwindcss(),`);
|
|
561
|
+
} else if (content.match(/plugins:\s*\[/)) {
|
|
562
|
+
content = content.replace(/plugins:\s*\[/, `plugins: [\n tailwindcss(),`);
|
|
563
|
+
} else if (content.includes('defineConfig({')) {
|
|
564
|
+
content = content.replace(/defineConfig\s*\(\s*\{/, `defineConfig({\n plugins: [tailwindcss()],`);
|
|
565
|
+
}
|
|
566
|
+
modified = true;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (modified) {
|
|
520
570
|
fs.writeFileSync(viteConfigPath, content);
|
|
521
|
-
console.log(`\x1b[32m✔ Configured resolve.alias in ${path.basename(viteConfigPath)}\x1b[0m`);
|
|
571
|
+
console.log(`\x1b[32m✔ Configured resolve.alias & tailwindcss plugin in ${path.basename(viteConfigPath)}\x1b[0m`);
|
|
522
572
|
}
|
|
523
573
|
}
|
|
524
574
|
|
|
@@ -530,15 +580,25 @@ async function main() {
|
|
|
530
580
|
|
|
531
581
|
// Check if we need @types/node (Vite + TypeScript)
|
|
532
582
|
const viteConfigExists = ['vite.config.ts', 'vite.config.mts'].some(f => fs.existsSync(path.join(process.cwd(), f)));
|
|
533
|
-
if (viteConfigExists) {
|
|
583
|
+
if (viteConfigExists || viteConfigPath) {
|
|
534
584
|
try {
|
|
535
585
|
const userPkgPath = path.resolve(process.cwd(), 'package.json');
|
|
536
586
|
if (fs.existsSync(userPkgPath)) {
|
|
537
587
|
const userPkg = JSON.parse(fs.readFileSync(userPkgPath, 'utf8'));
|
|
538
588
|
const allUserDeps = { ...userPkg.dependencies, ...userPkg.devDependencies };
|
|
539
|
-
if (!allUserDeps['@types/node']) {
|
|
589
|
+
if (viteConfigExists && !allUserDeps['@types/node']) {
|
|
540
590
|
extraDepsToInstall.push('@types/node@"^20.0.0"');
|
|
541
591
|
}
|
|
592
|
+
if (!allUserDeps['tailwindcss']) {
|
|
593
|
+
extraDepsToInstall.push('tailwindcss@"^4.0.0"');
|
|
594
|
+
}
|
|
595
|
+
if (!allUserDeps['@tailwindcss/vite']) {
|
|
596
|
+
extraDepsToInstall.push('@tailwindcss/vite@"^4.0.0"');
|
|
597
|
+
}
|
|
598
|
+
} else {
|
|
599
|
+
// If no package.json, just push them to be safe
|
|
600
|
+
extraDepsToInstall.push('tailwindcss@"^4.0.0"');
|
|
601
|
+
extraDepsToInstall.push('@tailwindcss/vite@"^4.0.0"');
|
|
542
602
|
}
|
|
543
603
|
} catch (e) {}
|
|
544
604
|
}
|
package/package.json
CHANGED