responsive-system 1.7.6 → 1.7.8

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.6",
3
+ "version": "1.7.8",
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'
@@ -21,22 +21,8 @@ const __filename = fileURLToPath(import.meta.url)
21
21
  const __dirname = path.dirname(__filename)
22
22
 
23
23
  // Obtener el directorio del proyecto consumidor
24
- // Cuando npm ejecuta postinstall, process.cwd() debería ser el proyecto consumidor
25
- // Pero si estamos en node_modules, necesitamos subir hasta el proyecto raíz
26
- let projectRoot = process.cwd()
27
- // Si process.cwd() está en node_modules, subir hasta encontrar el proyecto raíz
28
- if (projectRoot.includes('node_modules')) {
29
- // Subir hasta encontrar un directorio que no sea node_modules
30
- let currentDir = projectRoot
31
- while (currentDir !== path.dirname(currentDir)) {
32
- const parentDir = path.dirname(currentDir)
33
- if (!parentDir.includes('node_modules') || parentDir.endsWith('node_modules')) {
34
- projectRoot = parentDir
35
- break
36
- }
37
- currentDir = parentDir
38
- }
39
- }
24
+ // Cuando npm ejecuta postinstall, process.cwd() ya apunta al proyecto consumidor
25
+ const projectRoot = process.cwd()
40
26
  const packageJsonPath = path.join(projectRoot, 'package.json')
41
27
 
42
28
  // Detectar si se ejecuta como postinstall o manualmente
@@ -60,20 +46,25 @@ if (isCI && isPostinstall) {
60
46
  process.exit(0)
61
47
  }
62
48
 
49
+ // Si NO es postinstall y NO es manual, no hacer nada (evitar ejecución accidental)
50
+ if (!isPostinstall && !isManual) {
51
+ process.exit(0)
52
+ }
53
+
63
54
  console.log('')
64
55
  console.log('📦 responsive-system: Iniciando configuración...')
65
56
  console.log(` Directorio: ${projectRoot}`)
66
57
  console.log('')
67
58
 
68
59
  // Verificar si package.json existe
69
- if (!existsSync(packageJsonPath)) {
60
+ if (!fs.existsSync(packageJsonPath)) {
70
61
  console.log('⚠️ No se encontró package.json, saltando configuración')
71
62
  process.exit(0)
72
63
  }
73
64
 
74
65
  let packageJson
75
66
  try {
76
- packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
67
+ packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
77
68
  } catch (error) {
78
69
  console.error('❌ Error al leer package.json:', error.message)
79
70
  process.exit(1)
@@ -142,18 +133,18 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
142
133
  const sourcePath = path.join(__dirname, '..', relativePath)
143
134
  const destPath = path.join(projectRoot, targetPath)
144
135
 
145
- if (!existsSync(sourcePath)) {
136
+ if (!fs.existsSync(sourcePath)) {
146
137
  console.error(` ❌ No se encontró: ${relativePath}`)
147
138
  return false
148
139
  }
149
140
 
150
141
  // Crear directorio destino si no existe
151
142
  const destDir = path.dirname(destPath)
152
- if (!existsSync(destDir)) {
153
- mkdirSync(destDir, { recursive: true })
143
+ if (!fs.existsSync(destDir)) {
144
+ fs.mkdirSync(destDir, { recursive: true })
154
145
  }
155
146
 
156
- let content = readFileSync(sourcePath, 'utf8')
147
+ let content = fs.readFileSync(sourcePath, 'utf8')
157
148
 
158
149
  // Si es un componente, reemplazar importaciones relativas por importaciones del paquete
159
150
  if (isComponent) {
@@ -174,7 +165,7 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
174
165
  )
175
166
  }
176
167
 
177
- writeFileSync(destPath, content)
168
+ fs.writeFileSync(destPath, content)
178
169
  return true
179
170
  }
180
171
 
@@ -183,8 +174,8 @@ function generateLayoutComponents(selectedLayout) {
183
174
  const componentsDir = path.join(projectRoot, 'src', 'components', 'layout')
184
175
 
185
176
  // Crear directorio si no existe
186
- if (!existsSync(componentsDir)) {
187
- mkdirSync(componentsDir, { recursive: true })
177
+ if (!fs.existsSync(componentsDir)) {
178
+ fs.mkdirSync(componentsDir, { recursive: true })
188
179
  }
189
180
 
190
181
  const componentsToGenerate = {
@@ -240,7 +231,7 @@ const Navigation = () => {
240
231
 
241
232
  export default Navigation
242
233
  `
243
- writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
234
+ fs.writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
244
235
  console.log(' ✅ Navigation.tsx')
245
236
  }
246
237
 
@@ -262,7 +253,7 @@ export default Navigation
262
253
 
263
254
  export default Footer
264
255
  `
265
- writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
256
+ fs.writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
266
257
  console.log(' ✅ Footer.tsx')
267
258
  }
268
259
 
@@ -375,13 +366,13 @@ const Sidebar = ({ showLogo = true }: SidebarProps) => {
375
366
 
376
367
  export default Sidebar
377
368
  `
378
- writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
369
+ fs.writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
379
370
  console.log(' ✅ Sidebar.tsx')
380
371
  }
381
372
 
382
373
  // Crear index.ts para exportar los componentes
383
374
  const indexContent = components.map(c => `export { default as ${c} } from './${c}'`).join('\n')
384
- writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
375
+ fs.writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
385
376
  console.log(' ✅ index.ts')
386
377
  }
387
378
 
@@ -391,22 +382,22 @@ function copyUseResponsiveHook() {
391
382
 
392
383
  // Crear directorio hooks
393
384
  const hooksDir = path.join(projectRoot, 'src', 'hooks')
394
- if (!existsSync(hooksDir)) {
395
- mkdirSync(hooksDir, { recursive: true })
385
+ if (!fs.existsSync(hooksDir)) {
386
+ fs.mkdirSync(hooksDir, { recursive: true })
396
387
  }
397
388
 
398
389
  // Copiar tipos
399
390
  const typesDir = path.join(projectRoot, 'src', 'types')
400
- if (!existsSync(typesDir)) {
401
- mkdirSync(typesDir, { recursive: true })
391
+ if (!fs.existsSync(typesDir)) {
392
+ fs.mkdirSync(typesDir, { recursive: true })
402
393
  }
403
394
  copyFileFromPackage('src/types/responsive.ts', 'src/types/responsive.ts')
404
395
  console.log(' ✅ types/responsive.ts')
405
396
 
406
397
  // Copiar constantes
407
398
  const constantsDir = path.join(projectRoot, 'src', 'constants')
408
- if (!existsSync(constantsDir)) {
409
- mkdirSync(constantsDir, { recursive: true })
399
+ if (!fs.existsSync(constantsDir)) {
400
+ fs.mkdirSync(constantsDir, { recursive: true })
410
401
  }
411
402
  copyFileFromPackage('src/constants/breakpoints.ts', 'src/constants/breakpoints.ts')
412
403
  console.log(' ✅ constants/breakpoints.ts')
@@ -420,7 +411,7 @@ function copyUseResponsiveHook() {
420
411
  export type { ResponsiveState, Breakpoint, Orientation } from '../types/responsive'
421
412
  export { DEFAULT_BREAKPOINTS, getCurrentBreakpoint, getBreakpointIndex, getBreakpointValue } from '../constants/breakpoints'
422
413
  `
423
- writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
414
+ fs.writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
424
415
  console.log(' ✅ hooks/index.ts')
425
416
  }
426
417
 
@@ -485,7 +476,7 @@ if (!packageJson.type) {
485
476
  if (needsUpdate) {
486
477
  console.log('')
487
478
  console.log('📝 Actualizando package.json...')
488
- writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
479
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
489
480
  console.log('✅ package.json actualizado')
490
481
  console.log('')
491
482
  console.log('⚠️ Ejecuta "npm install" para instalar las dependencias')
@@ -496,7 +487,7 @@ if (needsUpdate) {
496
487
  // Verificar si el proyecto ya está configurado
497
488
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
498
489
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
499
- const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) && existsSync(path.join(projectRoot, 'vite.config.ts'))
490
+ const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsDir) && fs.existsSync(path.join(projectRoot, 'vite.config.ts'))
500
491
 
501
492
  // Función async para manejar la configuración del proyecto
502
493
  (async () => {
@@ -547,8 +538,8 @@ const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) &&
547
538
  const dirs = ['src', 'src/components', 'src/components/layout', 'src/pages', 'src/hooks', 'src/types', 'src/constants', 'public']
548
539
  dirs.forEach(dir => {
549
540
  const dirPath = path.join(projectRoot, dir)
550
- if (!existsSync(dirPath)) {
551
- mkdirSync(dirPath, { recursive: true })
541
+ if (!fs.existsSync(dirPath)) {
542
+ fs.mkdirSync(dirPath, { recursive: true })
552
543
  }
553
544
  })
554
545
 
@@ -562,7 +553,7 @@ const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) &&
562
553
 
563
554
  // Crear vite.config.ts
564
555
  const viteConfigPath = path.join(projectRoot, 'vite.config.ts')
565
- if (!existsSync(viteConfigPath)) {
556
+ if (!fs.existsSync(viteConfigPath)) {
566
557
  const viteConfig = `import { defineConfig } from 'vite'
567
558
  import react from '@vitejs/plugin-react'
568
559
 
@@ -570,13 +561,13 @@ export default defineConfig({
570
561
  plugins: [react()],
571
562
  })
572
563
  `
573
- writeFileSync(viteConfigPath, viteConfig)
564
+ fs.writeFileSync(viteConfigPath, viteConfig)
574
565
  console.log(' ✅ Creado: vite.config.ts')
575
566
  }
576
567
 
577
568
  // Crear tailwind.config.js
578
569
  const tailwindConfigPath = path.join(projectRoot, 'tailwind.config.js')
579
- if (!existsSync(tailwindConfigPath)) {
570
+ if (!fs.existsSync(tailwindConfigPath)) {
580
571
  const tailwindConfig = `import responsiveScalePlugin from 'responsive-system/plugin'
581
572
 
582
573
  export default {
@@ -612,13 +603,13 @@ export default {
612
603
  ],
613
604
  }
614
605
  `
615
- writeFileSync(tailwindConfigPath, tailwindConfig)
606
+ fs.writeFileSync(tailwindConfigPath, tailwindConfig)
616
607
  console.log(' ✅ Creado: tailwind.config.js')
617
608
  }
618
609
 
619
610
  // Crear postcss.config.js
620
611
  const postcssConfigPath = path.join(projectRoot, 'postcss.config.js')
621
- if (!existsSync(postcssConfigPath)) {
612
+ if (!fs.existsSync(postcssConfigPath)) {
622
613
  const postcssConfig = `export default {
623
614
  plugins: {
624
615
  '@tailwindcss/postcss': {},
@@ -626,13 +617,13 @@ export default {
626
617
  },
627
618
  }
628
619
  `
629
- writeFileSync(postcssConfigPath, postcssConfig)
620
+ fs.writeFileSync(postcssConfigPath, postcssConfig)
630
621
  console.log(' ✅ Creado: postcss.config.js')
631
622
  }
632
623
 
633
624
  // Crear tsconfig.json
634
625
  const tsconfigPath = path.join(projectRoot, 'tsconfig.json')
635
- if (!existsSync(tsconfigPath)) {
626
+ if (!fs.existsSync(tsconfigPath)) {
636
627
  const tsconfig = `{
637
628
  "compilerOptions": {
638
629
  "target": "ES2020",
@@ -655,13 +646,13 @@ export default {
655
646
  "references": [{ "path": "./tsconfig.node.json" }]
656
647
  }
657
648
  `
658
- writeFileSync(tsconfigPath, tsconfig)
649
+ fs.writeFileSync(tsconfigPath, tsconfig)
659
650
  console.log(' ✅ Creado: tsconfig.json')
660
651
  }
661
652
 
662
653
  // Crear tsconfig.node.json
663
654
  const tsconfigNodePath = path.join(projectRoot, 'tsconfig.node.json')
664
- if (!existsSync(tsconfigNodePath)) {
655
+ if (!fs.existsSync(tsconfigNodePath)) {
665
656
  const tsconfigNode = `{
666
657
  "compilerOptions": {
667
658
  "composite": true,
@@ -673,13 +664,13 @@ export default {
673
664
  "include": ["vite.config.ts"]
674
665
  }
675
666
  `
676
- writeFileSync(tsconfigNodePath, tsconfigNode)
667
+ fs.writeFileSync(tsconfigNodePath, tsconfigNode)
677
668
  console.log(' ✅ Creado: tsconfig.node.json')
678
669
  }
679
670
 
680
671
  // Crear index.html
681
672
  const indexHtmlPath = path.join(projectRoot, 'index.html')
682
- if (!existsSync(indexHtmlPath)) {
673
+ if (!fs.existsSync(indexHtmlPath)) {
683
674
  const indexHtml = `<!doctype html>
684
675
  <html lang="es">
685
676
  <head>
@@ -694,14 +685,14 @@ export default {
694
685
  </body>
695
686
  </html>
696
687
  `
697
- writeFileSync(indexHtmlPath, indexHtml)
688
+ fs.writeFileSync(indexHtmlPath, indexHtml)
698
689
  console.log(' ✅ Creado: index.html')
699
690
  }
700
691
 
701
692
  // Crear layout local según el seleccionado
702
693
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
703
- if (!existsSync(layoutsDir)) {
704
- mkdirSync(layoutsDir, { recursive: true })
694
+ if (!fs.existsSync(layoutsDir)) {
695
+ fs.mkdirSync(layoutsDir, { recursive: true })
705
696
  }
706
697
 
707
698
  // Generar layout local que use los componentes locales
@@ -816,12 +807,12 @@ export default MinimalLayout
816
807
  }
817
808
 
818
809
  const layoutPath = path.join(layoutsDir, `${selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1)}Layout.tsx`)
819
- writeFileSync(layoutPath, layoutContent)
810
+ fs.writeFileSync(layoutPath, layoutContent)
820
811
  console.log(` ✅ Creado: src/layouts/${path.basename(layoutPath)}`)
821
812
 
822
813
  // Crear src/main.tsx que use el layout local
823
814
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
824
- if (!existsSync(mainTsxPath)) {
815
+ if (!fs.existsSync(mainTsxPath)) {
825
816
  const layoutName = selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1) + 'Layout'
826
817
  const mainTsx = `import React from 'react'
827
818
  import ReactDOM from 'react-dom/client'
@@ -840,22 +831,22 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
840
831
  </React.StrictMode>,
841
832
  )
842
833
  `
843
- writeFileSync(mainTsxPath, mainTsx)
834
+ fs.writeFileSync(mainTsxPath, mainTsx)
844
835
  console.log(' ✅ Creado: src/main.tsx')
845
836
  }
846
837
 
847
838
  // Crear src/index.css
848
839
  const indexCssPath = path.join(projectRoot, 'src', 'index.css')
849
- if (!existsSync(indexCssPath)) {
840
+ if (!fs.existsSync(indexCssPath)) {
850
841
  const indexCss = `@import "tailwindcss";
851
842
  `
852
- writeFileSync(indexCssPath, indexCss)
843
+ fs.writeFileSync(indexCssPath, indexCss)
853
844
  console.log(' ✅ Creado: src/index.css')
854
845
  }
855
846
 
856
847
  // Crear src/pages/HomePage.tsx con página de ejemplo simple
857
848
  const homePagePath = path.join(projectRoot, 'src', 'pages', 'HomePage.tsx')
858
- if (!existsSync(homePagePath)) {
849
+ if (!fs.existsSync(homePagePath)) {
859
850
  const homePage = `import { useResponsiveLayout } from 'responsive-system'
860
851
  import { useResponsive } from '../hooks'
861
852
 
@@ -935,13 +926,13 @@ function HomePage() {
935
926
 
936
927
  export default HomePage
937
928
  `
938
- writeFileSync(homePagePath, homePage)
929
+ fs.writeFileSync(homePagePath, homePage)
939
930
  console.log(' ✅ Creado: src/pages/HomePage.tsx (página de ejemplo simple)')
940
931
  }
941
932
 
942
933
  // Crear src/App.tsx que importa la página
943
934
  const appTsxPath = path.join(projectRoot, 'src', 'App.tsx')
944
- if (!existsSync(appTsxPath)) {
935
+ if (!fs.existsSync(appTsxPath)) {
945
936
  const appTsx = `import HomePage from './pages/HomePage'
946
937
 
947
938
  function App() {
@@ -950,7 +941,7 @@ function App() {
950
941
 
951
942
  export default App
952
943
  `
953
- writeFileSync(appTsxPath, appTsx)
944
+ fs.writeFileSync(appTsxPath, appTsx)
954
945
  console.log(' ✅ Creado: src/App.tsx')
955
946
  }
956
947
 
@@ -968,7 +959,7 @@ export default App
968
959
  packageJson.scripts.preview = 'vite preview'
969
960
  }
970
961
 
971
- writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
962
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
972
963
  console.log(' ✅ Actualizado: package.json con scripts')
973
964
 
974
965
  console.log('')