responsive-system 1.7.1 → 1.7.3

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.1",
3
+ "version": "1.7.3",
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 fs from 'fs'
14
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'
15
15
  import path from 'path'
16
16
  import { execSync } from 'child_process'
17
17
  import { fileURLToPath } from 'url'
@@ -50,14 +50,14 @@ console.log(` Directorio: ${projectRoot}`)
50
50
  console.log('')
51
51
 
52
52
  // Verificar si package.json existe
53
- if (!fs.existsSync(packageJsonPath)) {
53
+ if (!existsSync(packageJsonPath)) {
54
54
  console.log('⚠️ No se encontró package.json, saltando configuración')
55
55
  process.exit(0)
56
56
  }
57
57
 
58
58
  let packageJson
59
59
  try {
60
- packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
60
+ packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
61
61
  } catch (error) {
62
62
  console.error('❌ Error al leer package.json:', error.message)
63
63
  process.exit(1)
@@ -126,18 +126,18 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
126
126
  const sourcePath = path.join(__dirname, '..', relativePath)
127
127
  const destPath = path.join(projectRoot, targetPath)
128
128
 
129
- if (!fs.existsSync(sourcePath)) {
129
+ if (!existsSync(sourcePath)) {
130
130
  console.error(` ❌ No se encontró: ${relativePath}`)
131
131
  return false
132
132
  }
133
133
 
134
134
  // Crear directorio destino si no existe
135
135
  const destDir = path.dirname(destPath)
136
- if (!fs.existsSync(destDir)) {
137
- fs.mkdirSync(destDir, { recursive: true })
136
+ if (!existsSync(destDir)) {
137
+ mkdirSync(destDir, { recursive: true })
138
138
  }
139
139
 
140
- let content = fs.readFileSync(sourcePath, 'utf8')
140
+ let content = readFileSync(sourcePath, 'utf8')
141
141
 
142
142
  // Si es un componente, reemplazar importaciones relativas por importaciones del paquete
143
143
  if (isComponent) {
@@ -158,7 +158,7 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
158
158
  )
159
159
  }
160
160
 
161
- fs.writeFileSync(destPath, content)
161
+ writeFileSync(destPath, content)
162
162
  return true
163
163
  }
164
164
 
@@ -167,8 +167,8 @@ function generateLayoutComponents(selectedLayout) {
167
167
  const componentsDir = path.join(projectRoot, 'src', 'components', 'layout')
168
168
 
169
169
  // Crear directorio si no existe
170
- if (!fs.existsSync(componentsDir)) {
171
- fs.mkdirSync(componentsDir, { recursive: true })
170
+ if (!existsSync(componentsDir)) {
171
+ mkdirSync(componentsDir, { recursive: true })
172
172
  }
173
173
 
174
174
  const componentsToGenerate = {
@@ -224,7 +224,7 @@ const Navigation = () => {
224
224
 
225
225
  export default Navigation
226
226
  `
227
- fs.writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
227
+ writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
228
228
  console.log(' ✅ Navigation.tsx')
229
229
  }
230
230
 
@@ -246,7 +246,7 @@ export default Navigation
246
246
 
247
247
  export default Footer
248
248
  `
249
- fs.writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
249
+ writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
250
250
  console.log(' ✅ Footer.tsx')
251
251
  }
252
252
 
@@ -359,13 +359,13 @@ const Sidebar = ({ showLogo = true }: SidebarProps) => {
359
359
 
360
360
  export default Sidebar
361
361
  `
362
- fs.writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
362
+ writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
363
363
  console.log(' ✅ Sidebar.tsx')
364
364
  }
365
365
 
366
366
  // Crear index.ts para exportar los componentes
367
367
  const indexContent = components.map(c => `export { default as ${c} } from './${c}'`).join('\n')
368
- fs.writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
368
+ writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
369
369
  console.log(' ✅ index.ts')
370
370
  }
371
371
 
@@ -375,22 +375,22 @@ function copyUseResponsiveHook() {
375
375
 
376
376
  // Crear directorio hooks
377
377
  const hooksDir = path.join(projectRoot, 'src', 'hooks')
378
- if (!fs.existsSync(hooksDir)) {
379
- fs.mkdirSync(hooksDir, { recursive: true })
378
+ if (!existsSync(hooksDir)) {
379
+ mkdirSync(hooksDir, { recursive: true })
380
380
  }
381
381
 
382
382
  // Copiar tipos
383
383
  const typesDir = path.join(projectRoot, 'src', 'types')
384
- if (!fs.existsSync(typesDir)) {
385
- fs.mkdirSync(typesDir, { recursive: true })
384
+ if (!existsSync(typesDir)) {
385
+ mkdirSync(typesDir, { recursive: true })
386
386
  }
387
387
  copyFileFromPackage('src/types/responsive.ts', 'src/types/responsive.ts')
388
388
  console.log(' ✅ types/responsive.ts')
389
389
 
390
390
  // Copiar constantes
391
391
  const constantsDir = path.join(projectRoot, 'src', 'constants')
392
- if (!fs.existsSync(constantsDir)) {
393
- fs.mkdirSync(constantsDir, { recursive: true })
392
+ if (!existsSync(constantsDir)) {
393
+ mkdirSync(constantsDir, { recursive: true })
394
394
  }
395
395
  copyFileFromPackage('src/constants/breakpoints.ts', 'src/constants/breakpoints.ts')
396
396
  console.log(' ✅ constants/breakpoints.ts')
@@ -404,7 +404,7 @@ function copyUseResponsiveHook() {
404
404
  export type { ResponsiveState, Breakpoint, Orientation } from '../types/responsive'
405
405
  export { DEFAULT_BREAKPOINTS, getCurrentBreakpoint, getBreakpointIndex, getBreakpointValue } from '../constants/breakpoints'
406
406
  `
407
- fs.writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
407
+ writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
408
408
  console.log(' ✅ hooks/index.ts')
409
409
  }
410
410
 
@@ -469,7 +469,7 @@ if (!packageJson.type) {
469
469
  if (needsUpdate) {
470
470
  console.log('')
471
471
  console.log('📝 Actualizando package.json...')
472
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
472
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
473
473
  console.log('✅ package.json actualizado')
474
474
  console.log('')
475
475
  console.log('⚠️ Ejecuta "npm install" para instalar las dependencias')
@@ -480,10 +480,12 @@ if (needsUpdate) {
480
480
  // Verificar si el proyecto ya está configurado
481
481
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
482
482
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
483
- const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsDir) && fs.existsSync(path.join(projectRoot, 'vite.config.ts'))
483
+ const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) && existsSync(path.join(projectRoot, 'vite.config.ts'))
484
484
 
485
- // Si el proyecto está vacío, crear estructura base
486
- if (isProjectEmpty) {
485
+ // Función async para manejar la configuración del proyecto
486
+ (async () => {
487
+ // Si el proyecto está vacío, crear estructura base
488
+ if (isProjectEmpty) {
487
489
  // Si ya está configurado, preguntar si quiere sobrescribir
488
490
  if (isAlreadyConfigured) {
489
491
  console.log('')
@@ -529,8 +531,8 @@ if (isProjectEmpty) {
529
531
  const dirs = ['src', 'src/components', 'src/components/layout', 'src/pages', 'src/hooks', 'src/types', 'src/constants', 'public']
530
532
  dirs.forEach(dir => {
531
533
  const dirPath = path.join(projectRoot, dir)
532
- if (!fs.existsSync(dirPath)) {
533
- fs.mkdirSync(dirPath, { recursive: true })
534
+ if (!existsSync(dirPath)) {
535
+ mkdirSync(dirPath, { recursive: true })
534
536
  }
535
537
  })
536
538
 
@@ -544,7 +546,7 @@ if (isProjectEmpty) {
544
546
 
545
547
  // Crear vite.config.ts
546
548
  const viteConfigPath = path.join(projectRoot, 'vite.config.ts')
547
- if (!fs.existsSync(viteConfigPath)) {
549
+ if (!existsSync(viteConfigPath)) {
548
550
  const viteConfig = `import { defineConfig } from 'vite'
549
551
  import react from '@vitejs/plugin-react'
550
552
 
@@ -552,13 +554,13 @@ export default defineConfig({
552
554
  plugins: [react()],
553
555
  })
554
556
  `
555
- fs.writeFileSync(viteConfigPath, viteConfig)
557
+ writeFileSync(viteConfigPath, viteConfig)
556
558
  console.log(' ✅ Creado: vite.config.ts')
557
559
  }
558
560
 
559
561
  // Crear tailwind.config.js
560
562
  const tailwindConfigPath = path.join(projectRoot, 'tailwind.config.js')
561
- if (!fs.existsSync(tailwindConfigPath)) {
563
+ if (!existsSync(tailwindConfigPath)) {
562
564
  const tailwindConfig = `import responsiveScalePlugin from 'responsive-system/plugin'
563
565
 
564
566
  export default {
@@ -594,13 +596,13 @@ export default {
594
596
  ],
595
597
  }
596
598
  `
597
- fs.writeFileSync(tailwindConfigPath, tailwindConfig)
599
+ writeFileSync(tailwindConfigPath, tailwindConfig)
598
600
  console.log(' ✅ Creado: tailwind.config.js')
599
601
  }
600
602
 
601
603
  // Crear postcss.config.js
602
604
  const postcssConfigPath = path.join(projectRoot, 'postcss.config.js')
603
- if (!fs.existsSync(postcssConfigPath)) {
605
+ if (!existsSync(postcssConfigPath)) {
604
606
  const postcssConfig = `export default {
605
607
  plugins: {
606
608
  '@tailwindcss/postcss': {},
@@ -608,13 +610,13 @@ export default {
608
610
  },
609
611
  }
610
612
  `
611
- fs.writeFileSync(postcssConfigPath, postcssConfig)
613
+ writeFileSync(postcssConfigPath, postcssConfig)
612
614
  console.log(' ✅ Creado: postcss.config.js')
613
615
  }
614
616
 
615
617
  // Crear tsconfig.json
616
618
  const tsconfigPath = path.join(projectRoot, 'tsconfig.json')
617
- if (!fs.existsSync(tsconfigPath)) {
619
+ if (!existsSync(tsconfigPath)) {
618
620
  const tsconfig = `{
619
621
  "compilerOptions": {
620
622
  "target": "ES2020",
@@ -637,13 +639,13 @@ export default {
637
639
  "references": [{ "path": "./tsconfig.node.json" }]
638
640
  }
639
641
  `
640
- fs.writeFileSync(tsconfigPath, tsconfig)
642
+ writeFileSync(tsconfigPath, tsconfig)
641
643
  console.log(' ✅ Creado: tsconfig.json')
642
644
  }
643
645
 
644
646
  // Crear tsconfig.node.json
645
647
  const tsconfigNodePath = path.join(projectRoot, 'tsconfig.node.json')
646
- if (!fs.existsSync(tsconfigNodePath)) {
648
+ if (!existsSync(tsconfigNodePath)) {
647
649
  const tsconfigNode = `{
648
650
  "compilerOptions": {
649
651
  "composite": true,
@@ -655,13 +657,13 @@ export default {
655
657
  "include": ["vite.config.ts"]
656
658
  }
657
659
  `
658
- fs.writeFileSync(tsconfigNodePath, tsconfigNode)
660
+ writeFileSync(tsconfigNodePath, tsconfigNode)
659
661
  console.log(' ✅ Creado: tsconfig.node.json')
660
662
  }
661
663
 
662
664
  // Crear index.html
663
665
  const indexHtmlPath = path.join(projectRoot, 'index.html')
664
- if (!fs.existsSync(indexHtmlPath)) {
666
+ if (!existsSync(indexHtmlPath)) {
665
667
  const indexHtml = `<!doctype html>
666
668
  <html lang="es">
667
669
  <head>
@@ -676,14 +678,14 @@ export default {
676
678
  </body>
677
679
  </html>
678
680
  `
679
- fs.writeFileSync(indexHtmlPath, indexHtml)
681
+ writeFileSync(indexHtmlPath, indexHtml)
680
682
  console.log(' ✅ Creado: index.html')
681
683
  }
682
684
 
683
685
  // Crear layout local según el seleccionado
684
686
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
685
- if (!fs.existsSync(layoutsDir)) {
686
- fs.mkdirSync(layoutsDir, { recursive: true })
687
+ if (!existsSync(layoutsDir)) {
688
+ mkdirSync(layoutsDir, { recursive: true })
687
689
  }
688
690
 
689
691
  // Generar layout local que use los componentes locales
@@ -798,12 +800,12 @@ export default MinimalLayout
798
800
  }
799
801
 
800
802
  const layoutPath = path.join(layoutsDir, `${selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1)}Layout.tsx`)
801
- fs.writeFileSync(layoutPath, layoutContent)
803
+ writeFileSync(layoutPath, layoutContent)
802
804
  console.log(` ✅ Creado: src/layouts/${path.basename(layoutPath)}`)
803
805
 
804
806
  // Crear src/main.tsx que use el layout local
805
807
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
806
- if (!fs.existsSync(mainTsxPath)) {
808
+ if (!existsSync(mainTsxPath)) {
807
809
  const layoutName = selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1) + 'Layout'
808
810
  const mainTsx = `import React from 'react'
809
811
  import ReactDOM from 'react-dom/client'
@@ -822,22 +824,22 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
822
824
  </React.StrictMode>,
823
825
  )
824
826
  `
825
- fs.writeFileSync(mainTsxPath, mainTsx)
827
+ writeFileSync(mainTsxPath, mainTsx)
826
828
  console.log(' ✅ Creado: src/main.tsx')
827
829
  }
828
830
 
829
831
  // Crear src/index.css
830
832
  const indexCssPath = path.join(projectRoot, 'src', 'index.css')
831
- if (!fs.existsSync(indexCssPath)) {
833
+ if (!existsSync(indexCssPath)) {
832
834
  const indexCss = `@import "tailwindcss";
833
835
  `
834
- fs.writeFileSync(indexCssPath, indexCss)
836
+ writeFileSync(indexCssPath, indexCss)
835
837
  console.log(' ✅ Creado: src/index.css')
836
838
  }
837
839
 
838
840
  // Crear src/pages/HomePage.tsx con página de ejemplo simple
839
841
  const homePagePath = path.join(projectRoot, 'src', 'pages', 'HomePage.tsx')
840
- if (!fs.existsSync(homePagePath)) {
842
+ if (!existsSync(homePagePath)) {
841
843
  const homePage = `import { useResponsiveLayout } from 'responsive-system'
842
844
  import { useResponsive } from '../hooks'
843
845
 
@@ -917,13 +919,13 @@ function HomePage() {
917
919
 
918
920
  export default HomePage
919
921
  `
920
- fs.writeFileSync(homePagePath, homePage)
922
+ writeFileSync(homePagePath, homePage)
921
923
  console.log(' ✅ Creado: src/pages/HomePage.tsx (página de ejemplo simple)')
922
924
  }
923
925
 
924
926
  // Crear src/App.tsx que importa la página
925
927
  const appTsxPath = path.join(projectRoot, 'src', 'App.tsx')
926
- if (!fs.existsSync(appTsxPath)) {
928
+ if (!existsSync(appTsxPath)) {
927
929
  const appTsx = `import HomePage from './pages/HomePage'
928
930
 
929
931
  function App() {
@@ -932,7 +934,7 @@ function App() {
932
934
 
933
935
  export default App
934
936
  `
935
- fs.writeFileSync(appTsxPath, appTsx)
937
+ writeFileSync(appTsxPath, appTsx)
936
938
  console.log(' ✅ Creado: src/App.tsx')
937
939
  }
938
940
 
@@ -950,7 +952,7 @@ export default App
950
952
  packageJson.scripts.preview = 'vite preview'
951
953
  }
952
954
 
953
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
955
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
954
956
  console.log(' ✅ Actualizado: package.json con scripts')
955
957
 
956
958
  console.log('')
@@ -967,10 +969,14 @@ export default App
967
969
  console.log('')
968
970
  console.log('💡 Para cambiar el layout: npx responsive-system-setup')
969
971
  console.log('')
970
- } else {
971
- console.log('✅ Proyecto ya inicializado')
972
- }
972
+ } else {
973
+ console.log('✅ Proyecto ya inicializado')
974
+ }
973
975
 
974
- console.log('')
975
- console.log('✅ Configuración completada')
976
- console.log('')
976
+ console.log('')
977
+ console.log('✅ Configuración completada')
978
+ console.log('')
979
+ })().catch((error) => {
980
+ console.error('❌ Error durante la configuración:', error)
981
+ process.exit(1)
982
+ })