responsive-system 1.7.7 → 1.7.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "responsive-system",
3
- "version": "1.7.7",
3
+ "version": "1.7.9",
4
4
  "description": "Sistema de layout responsivo con auto-scaling para Tailwind CSS",
5
5
  "type": "module",
6
6
  "main": "./dist/responsive-system.cjs",
@@ -11,7 +11,7 @@
11
11
  * - Configura App.tsx con el layout seleccionado
12
12
  */
13
13
 
14
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'
14
+ import * as fs from 'fs'
15
15
  import path from 'path'
16
16
  import { execSync } from 'child_process'
17
17
  import { fileURLToPath } from 'url'
@@ -57,14 +57,14 @@ console.log(` Directorio: ${projectRoot}`)
57
57
  console.log('')
58
58
 
59
59
  // Verificar si package.json existe
60
- if (!existsSync(packageJsonPath)) {
60
+ if (!fs.existsSync(packageJsonPath)) {
61
61
  console.log('⚠️ No se encontró package.json, saltando configuración')
62
62
  process.exit(0)
63
63
  }
64
64
 
65
65
  let packageJson
66
66
  try {
67
- packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
67
+ packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
68
68
  } catch (error) {
69
69
  console.error('❌ Error al leer package.json:', error.message)
70
70
  process.exit(1)
@@ -133,18 +133,18 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
133
133
  const sourcePath = path.join(__dirname, '..', relativePath)
134
134
  const destPath = path.join(projectRoot, targetPath)
135
135
 
136
- if (!existsSync(sourcePath)) {
136
+ if (!fs.existsSync(sourcePath)) {
137
137
  console.error(` ❌ No se encontró: ${relativePath}`)
138
138
  return false
139
139
  }
140
140
 
141
141
  // Crear directorio destino si no existe
142
142
  const destDir = path.dirname(destPath)
143
- if (!existsSync(destDir)) {
144
- mkdirSync(destDir, { recursive: true })
143
+ if (!fs.existsSync(destDir)) {
144
+ fs.mkdirSync(destDir, { recursive: true })
145
145
  }
146
146
 
147
- let content = readFileSync(sourcePath, 'utf8')
147
+ let content = fs.readFileSync(sourcePath, 'utf8')
148
148
 
149
149
  // Si es un componente, reemplazar importaciones relativas por importaciones del paquete
150
150
  if (isComponent) {
@@ -165,7 +165,7 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
165
165
  )
166
166
  }
167
167
 
168
- writeFileSync(destPath, content)
168
+ fs.writeFileSync(destPath, content)
169
169
  return true
170
170
  }
171
171
 
@@ -174,8 +174,8 @@ function generateLayoutComponents(selectedLayout) {
174
174
  const componentsDir = path.join(projectRoot, 'src', 'components', 'layout')
175
175
 
176
176
  // Crear directorio si no existe
177
- if (!existsSync(componentsDir)) {
178
- mkdirSync(componentsDir, { recursive: true })
177
+ if (!fs.existsSync(componentsDir)) {
178
+ fs.mkdirSync(componentsDir, { recursive: true })
179
179
  }
180
180
 
181
181
  const componentsToGenerate = {
@@ -231,7 +231,7 @@ const Navigation = () => {
231
231
 
232
232
  export default Navigation
233
233
  `
234
- writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
234
+ fs.writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
235
235
  console.log(' ✅ Navigation.tsx')
236
236
  }
237
237
 
@@ -253,7 +253,7 @@ export default Navigation
253
253
 
254
254
  export default Footer
255
255
  `
256
- writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
256
+ fs.writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
257
257
  console.log(' ✅ Footer.tsx')
258
258
  }
259
259
 
@@ -366,13 +366,13 @@ const Sidebar = ({ showLogo = true }: SidebarProps) => {
366
366
 
367
367
  export default Sidebar
368
368
  `
369
- writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
369
+ fs.writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
370
370
  console.log(' ✅ Sidebar.tsx')
371
371
  }
372
372
 
373
373
  // Crear index.ts para exportar los componentes
374
374
  const indexContent = components.map(c => `export { default as ${c} } from './${c}'`).join('\n')
375
- writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
375
+ fs.writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
376
376
  console.log(' ✅ index.ts')
377
377
  }
378
378
 
@@ -382,22 +382,22 @@ function copyUseResponsiveHook() {
382
382
 
383
383
  // Crear directorio hooks
384
384
  const hooksDir = path.join(projectRoot, 'src', 'hooks')
385
- if (!existsSync(hooksDir)) {
386
- mkdirSync(hooksDir, { recursive: true })
385
+ if (!fs.existsSync(hooksDir)) {
386
+ fs.mkdirSync(hooksDir, { recursive: true })
387
387
  }
388
388
 
389
389
  // Copiar tipos
390
390
  const typesDir = path.join(projectRoot, 'src', 'types')
391
- if (!existsSync(typesDir)) {
392
- mkdirSync(typesDir, { recursive: true })
391
+ if (!fs.existsSync(typesDir)) {
392
+ fs.mkdirSync(typesDir, { recursive: true })
393
393
  }
394
394
  copyFileFromPackage('src/types/responsive.ts', 'src/types/responsive.ts')
395
395
  console.log(' ✅ types/responsive.ts')
396
396
 
397
397
  // Copiar constantes
398
398
  const constantsDir = path.join(projectRoot, 'src', 'constants')
399
- if (!existsSync(constantsDir)) {
400
- mkdirSync(constantsDir, { recursive: true })
399
+ if (!fs.existsSync(constantsDir)) {
400
+ fs.mkdirSync(constantsDir, { recursive: true })
401
401
  }
402
402
  copyFileFromPackage('src/constants/breakpoints.ts', 'src/constants/breakpoints.ts')
403
403
  console.log(' ✅ constants/breakpoints.ts')
@@ -411,7 +411,7 @@ function copyUseResponsiveHook() {
411
411
  export type { ResponsiveState, Breakpoint, Orientation } from '../types/responsive'
412
412
  export { DEFAULT_BREAKPOINTS, getCurrentBreakpoint, getBreakpointIndex, getBreakpointValue } from '../constants/breakpoints'
413
413
  `
414
- writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
414
+ fs.writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
415
415
  console.log(' ✅ hooks/index.ts')
416
416
  }
417
417
 
@@ -476,7 +476,7 @@ if (!packageJson.type) {
476
476
  if (needsUpdate) {
477
477
  console.log('')
478
478
  console.log('📝 Actualizando package.json...')
479
- writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
479
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
480
480
  console.log('✅ package.json actualizado')
481
481
  console.log('')
482
482
  console.log('⚠️ Ejecuta "npm install" para instalar las dependencias')
@@ -484,17 +484,31 @@ if (needsUpdate) {
484
484
  console.log('✅ Todas las dependencias ya están en package.json')
485
485
  }
486
486
 
487
- // Verificar si el proyecto ya está configurado
487
+ // Verificar si el proyecto ya está configurado (antes de la función async)
488
488
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
489
489
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
490
- const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) && existsSync(path.join(projectRoot, 'vite.config.ts'))
490
+ const viteConfigPath = path.join(projectRoot, 'vite.config.ts')
491
+
492
+ // Función helper para verificar si existe un archivo/directorio
493
+ const fileExists = (filePath) => {
494
+ try {
495
+ return typeof fs.existsSync === 'function' && fs.existsSync(filePath)
496
+ } catch (e) {
497
+ return false
498
+ }
499
+ }
500
+
501
+ const isAlreadyConfigured = fileExists(mainTsxPath) &&
502
+ fileExists(layoutsDir) &&
503
+ fileExists(viteConfigPath)
491
504
 
492
505
  // Función async para manejar la configuración del proyecto
493
506
  (async () => {
507
+
494
508
  // Si el proyecto está vacío, crear estructura base
495
509
  if (isProjectEmpty) {
496
- // Si ya está configurado, preguntar si quiere sobrescribir
497
- if (isAlreadyConfigured) {
510
+ // Si ya está configurado, preguntar si quiere sobrescribir
511
+ if (isAlreadyConfigured) {
498
512
  console.log('')
499
513
  console.log('⚠️ El proyecto ya está configurado')
500
514
 
@@ -538,8 +552,8 @@ const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) &&
538
552
  const dirs = ['src', 'src/components', 'src/components/layout', 'src/pages', 'src/hooks', 'src/types', 'src/constants', 'public']
539
553
  dirs.forEach(dir => {
540
554
  const dirPath = path.join(projectRoot, dir)
541
- if (!existsSync(dirPath)) {
542
- mkdirSync(dirPath, { recursive: true })
555
+ if (!fs.existsSync(dirPath)) {
556
+ fs.mkdirSync(dirPath, { recursive: true })
543
557
  }
544
558
  })
545
559
 
@@ -553,7 +567,7 @@ const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) &&
553
567
 
554
568
  // Crear vite.config.ts
555
569
  const viteConfigPath = path.join(projectRoot, 'vite.config.ts')
556
- if (!existsSync(viteConfigPath)) {
570
+ if (!fs.existsSync(viteConfigPath)) {
557
571
  const viteConfig = `import { defineConfig } from 'vite'
558
572
  import react from '@vitejs/plugin-react'
559
573
 
@@ -561,13 +575,13 @@ export default defineConfig({
561
575
  plugins: [react()],
562
576
  })
563
577
  `
564
- writeFileSync(viteConfigPath, viteConfig)
578
+ fs.writeFileSync(viteConfigPath, viteConfig)
565
579
  console.log(' ✅ Creado: vite.config.ts')
566
580
  }
567
581
 
568
582
  // Crear tailwind.config.js
569
583
  const tailwindConfigPath = path.join(projectRoot, 'tailwind.config.js')
570
- if (!existsSync(tailwindConfigPath)) {
584
+ if (!fs.existsSync(tailwindConfigPath)) {
571
585
  const tailwindConfig = `import responsiveScalePlugin from 'responsive-system/plugin'
572
586
 
573
587
  export default {
@@ -603,13 +617,13 @@ export default {
603
617
  ],
604
618
  }
605
619
  `
606
- writeFileSync(tailwindConfigPath, tailwindConfig)
620
+ fs.writeFileSync(tailwindConfigPath, tailwindConfig)
607
621
  console.log(' ✅ Creado: tailwind.config.js')
608
622
  }
609
623
 
610
624
  // Crear postcss.config.js
611
625
  const postcssConfigPath = path.join(projectRoot, 'postcss.config.js')
612
- if (!existsSync(postcssConfigPath)) {
626
+ if (!fs.existsSync(postcssConfigPath)) {
613
627
  const postcssConfig = `export default {
614
628
  plugins: {
615
629
  '@tailwindcss/postcss': {},
@@ -617,13 +631,13 @@ export default {
617
631
  },
618
632
  }
619
633
  `
620
- writeFileSync(postcssConfigPath, postcssConfig)
634
+ fs.writeFileSync(postcssConfigPath, postcssConfig)
621
635
  console.log(' ✅ Creado: postcss.config.js')
622
636
  }
623
637
 
624
638
  // Crear tsconfig.json
625
639
  const tsconfigPath = path.join(projectRoot, 'tsconfig.json')
626
- if (!existsSync(tsconfigPath)) {
640
+ if (!fs.existsSync(tsconfigPath)) {
627
641
  const tsconfig = `{
628
642
  "compilerOptions": {
629
643
  "target": "ES2020",
@@ -646,13 +660,13 @@ export default {
646
660
  "references": [{ "path": "./tsconfig.node.json" }]
647
661
  }
648
662
  `
649
- writeFileSync(tsconfigPath, tsconfig)
663
+ fs.writeFileSync(tsconfigPath, tsconfig)
650
664
  console.log(' ✅ Creado: tsconfig.json')
651
665
  }
652
666
 
653
667
  // Crear tsconfig.node.json
654
668
  const tsconfigNodePath = path.join(projectRoot, 'tsconfig.node.json')
655
- if (!existsSync(tsconfigNodePath)) {
669
+ if (!fs.existsSync(tsconfigNodePath)) {
656
670
  const tsconfigNode = `{
657
671
  "compilerOptions": {
658
672
  "composite": true,
@@ -664,13 +678,13 @@ export default {
664
678
  "include": ["vite.config.ts"]
665
679
  }
666
680
  `
667
- writeFileSync(tsconfigNodePath, tsconfigNode)
681
+ fs.writeFileSync(tsconfigNodePath, tsconfigNode)
668
682
  console.log(' ✅ Creado: tsconfig.node.json')
669
683
  }
670
684
 
671
685
  // Crear index.html
672
686
  const indexHtmlPath = path.join(projectRoot, 'index.html')
673
- if (!existsSync(indexHtmlPath)) {
687
+ if (!fs.existsSync(indexHtmlPath)) {
674
688
  const indexHtml = `<!doctype html>
675
689
  <html lang="es">
676
690
  <head>
@@ -685,14 +699,14 @@ export default {
685
699
  </body>
686
700
  </html>
687
701
  `
688
- writeFileSync(indexHtmlPath, indexHtml)
702
+ fs.writeFileSync(indexHtmlPath, indexHtml)
689
703
  console.log(' ✅ Creado: index.html')
690
704
  }
691
705
 
692
706
  // Crear layout local según el seleccionado
693
707
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
694
- if (!existsSync(layoutsDir)) {
695
- mkdirSync(layoutsDir, { recursive: true })
708
+ if (!fs.existsSync(layoutsDir)) {
709
+ fs.mkdirSync(layoutsDir, { recursive: true })
696
710
  }
697
711
 
698
712
  // Generar layout local que use los componentes locales
@@ -807,12 +821,12 @@ export default MinimalLayout
807
821
  }
808
822
 
809
823
  const layoutPath = path.join(layoutsDir, `${selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1)}Layout.tsx`)
810
- writeFileSync(layoutPath, layoutContent)
824
+ fs.writeFileSync(layoutPath, layoutContent)
811
825
  console.log(` ✅ Creado: src/layouts/${path.basename(layoutPath)}`)
812
826
 
813
827
  // Crear src/main.tsx que use el layout local
814
828
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
815
- if (!existsSync(mainTsxPath)) {
829
+ if (!fs.existsSync(mainTsxPath)) {
816
830
  const layoutName = selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1) + 'Layout'
817
831
  const mainTsx = `import React from 'react'
818
832
  import ReactDOM from 'react-dom/client'
@@ -831,22 +845,22 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
831
845
  </React.StrictMode>,
832
846
  )
833
847
  `
834
- writeFileSync(mainTsxPath, mainTsx)
848
+ fs.writeFileSync(mainTsxPath, mainTsx)
835
849
  console.log(' ✅ Creado: src/main.tsx')
836
850
  }
837
851
 
838
852
  // Crear src/index.css
839
853
  const indexCssPath = path.join(projectRoot, 'src', 'index.css')
840
- if (!existsSync(indexCssPath)) {
854
+ if (!fs.existsSync(indexCssPath)) {
841
855
  const indexCss = `@import "tailwindcss";
842
856
  `
843
- writeFileSync(indexCssPath, indexCss)
857
+ fs.writeFileSync(indexCssPath, indexCss)
844
858
  console.log(' ✅ Creado: src/index.css')
845
859
  }
846
860
 
847
861
  // Crear src/pages/HomePage.tsx con página de ejemplo simple
848
862
  const homePagePath = path.join(projectRoot, 'src', 'pages', 'HomePage.tsx')
849
- if (!existsSync(homePagePath)) {
863
+ if (!fs.existsSync(homePagePath)) {
850
864
  const homePage = `import { useResponsiveLayout } from 'responsive-system'
851
865
  import { useResponsive } from '../hooks'
852
866
 
@@ -926,13 +940,13 @@ function HomePage() {
926
940
 
927
941
  export default HomePage
928
942
  `
929
- writeFileSync(homePagePath, homePage)
943
+ fs.writeFileSync(homePagePath, homePage)
930
944
  console.log(' ✅ Creado: src/pages/HomePage.tsx (página de ejemplo simple)')
931
945
  }
932
946
 
933
947
  // Crear src/App.tsx que importa la página
934
948
  const appTsxPath = path.join(projectRoot, 'src', 'App.tsx')
935
- if (!existsSync(appTsxPath)) {
949
+ if (!fs.existsSync(appTsxPath)) {
936
950
  const appTsx = `import HomePage from './pages/HomePage'
937
951
 
938
952
  function App() {
@@ -941,7 +955,7 @@ function App() {
941
955
 
942
956
  export default App
943
957
  `
944
- writeFileSync(appTsxPath, appTsx)
958
+ fs.writeFileSync(appTsxPath, appTsx)
945
959
  console.log(' ✅ Creado: src/App.tsx')
946
960
  }
947
961
 
@@ -959,7 +973,7 @@ export default App
959
973
  packageJson.scripts.preview = 'vite preview'
960
974
  }
961
975
 
962
- writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
976
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
963
977
  console.log(' ✅ Actualizado: package.json con scripts')
964
978
 
965
979
  console.log('')