responsive-system 1.7.5 → 1.7.7

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.5",
3
+ "version": "1.7.7",
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 * as 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'
@@ -20,6 +20,8 @@ import readline from 'readline'
20
20
  const __filename = fileURLToPath(import.meta.url)
21
21
  const __dirname = path.dirname(__filename)
22
22
 
23
+ // Obtener el directorio del proyecto consumidor
24
+ // Cuando npm ejecuta postinstall, process.cwd() ya apunta al proyecto consumidor
23
25
  const projectRoot = process.cwd()
24
26
  const packageJsonPath = path.join(projectRoot, 'package.json')
25
27
 
@@ -44,20 +46,25 @@ if (isCI && isPostinstall) {
44
46
  process.exit(0)
45
47
  }
46
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
+
47
54
  console.log('')
48
55
  console.log('📦 responsive-system: Iniciando configuración...')
49
56
  console.log(` Directorio: ${projectRoot}`)
50
57
  console.log('')
51
58
 
52
59
  // Verificar si package.json existe
53
- if (!fs.existsSync(packageJsonPath)) {
60
+ if (!existsSync(packageJsonPath)) {
54
61
  console.log('⚠️ No se encontró package.json, saltando configuración')
55
62
  process.exit(0)
56
63
  }
57
64
 
58
65
  let packageJson
59
66
  try {
60
- packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
67
+ packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
61
68
  } catch (error) {
62
69
  console.error('❌ Error al leer package.json:', error.message)
63
70
  process.exit(1)
@@ -126,18 +133,18 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
126
133
  const sourcePath = path.join(__dirname, '..', relativePath)
127
134
  const destPath = path.join(projectRoot, targetPath)
128
135
 
129
- if (!fs.existsSync(sourcePath)) {
136
+ if (!existsSync(sourcePath)) {
130
137
  console.error(` ❌ No se encontró: ${relativePath}`)
131
138
  return false
132
139
  }
133
140
 
134
141
  // Crear directorio destino si no existe
135
142
  const destDir = path.dirname(destPath)
136
- if (!fs.existsSync(destDir)) {
137
- fs.mkdirSync(destDir, { recursive: true })
143
+ if (!existsSync(destDir)) {
144
+ mkdirSync(destDir, { recursive: true })
138
145
  }
139
146
 
140
- let content = fs.readFileSync(sourcePath, 'utf8')
147
+ let content = readFileSync(sourcePath, 'utf8')
141
148
 
142
149
  // Si es un componente, reemplazar importaciones relativas por importaciones del paquete
143
150
  if (isComponent) {
@@ -158,7 +165,7 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
158
165
  )
159
166
  }
160
167
 
161
- fs.writeFileSync(destPath, content)
168
+ writeFileSync(destPath, content)
162
169
  return true
163
170
  }
164
171
 
@@ -167,8 +174,8 @@ function generateLayoutComponents(selectedLayout) {
167
174
  const componentsDir = path.join(projectRoot, 'src', 'components', 'layout')
168
175
 
169
176
  // Crear directorio si no existe
170
- if (!fs.existsSync(componentsDir)) {
171
- fs.mkdirSync(componentsDir, { recursive: true })
177
+ if (!existsSync(componentsDir)) {
178
+ mkdirSync(componentsDir, { recursive: true })
172
179
  }
173
180
 
174
181
  const componentsToGenerate = {
@@ -224,7 +231,7 @@ const Navigation = () => {
224
231
 
225
232
  export default Navigation
226
233
  `
227
- fs.writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
234
+ writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
228
235
  console.log(' ✅ Navigation.tsx')
229
236
  }
230
237
 
@@ -246,7 +253,7 @@ export default Navigation
246
253
 
247
254
  export default Footer
248
255
  `
249
- fs.writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
256
+ writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
250
257
  console.log(' ✅ Footer.tsx')
251
258
  }
252
259
 
@@ -359,13 +366,13 @@ const Sidebar = ({ showLogo = true }: SidebarProps) => {
359
366
 
360
367
  export default Sidebar
361
368
  `
362
- fs.writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
369
+ writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
363
370
  console.log(' ✅ Sidebar.tsx')
364
371
  }
365
372
 
366
373
  // Crear index.ts para exportar los componentes
367
374
  const indexContent = components.map(c => `export { default as ${c} } from './${c}'`).join('\n')
368
- fs.writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
375
+ writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
369
376
  console.log(' ✅ index.ts')
370
377
  }
371
378
 
@@ -375,22 +382,22 @@ function copyUseResponsiveHook() {
375
382
 
376
383
  // Crear directorio hooks
377
384
  const hooksDir = path.join(projectRoot, 'src', 'hooks')
378
- if (!fs.existsSync(hooksDir)) {
379
- fs.mkdirSync(hooksDir, { recursive: true })
385
+ if (!existsSync(hooksDir)) {
386
+ mkdirSync(hooksDir, { recursive: true })
380
387
  }
381
388
 
382
389
  // Copiar tipos
383
390
  const typesDir = path.join(projectRoot, 'src', 'types')
384
- if (!fs.existsSync(typesDir)) {
385
- fs.mkdirSync(typesDir, { recursive: true })
391
+ if (!existsSync(typesDir)) {
392
+ mkdirSync(typesDir, { recursive: true })
386
393
  }
387
394
  copyFileFromPackage('src/types/responsive.ts', 'src/types/responsive.ts')
388
395
  console.log(' ✅ types/responsive.ts')
389
396
 
390
397
  // Copiar constantes
391
398
  const constantsDir = path.join(projectRoot, 'src', 'constants')
392
- if (!fs.existsSync(constantsDir)) {
393
- fs.mkdirSync(constantsDir, { recursive: true })
399
+ if (!existsSync(constantsDir)) {
400
+ mkdirSync(constantsDir, { recursive: true })
394
401
  }
395
402
  copyFileFromPackage('src/constants/breakpoints.ts', 'src/constants/breakpoints.ts')
396
403
  console.log(' ✅ constants/breakpoints.ts')
@@ -404,7 +411,7 @@ function copyUseResponsiveHook() {
404
411
  export type { ResponsiveState, Breakpoint, Orientation } from '../types/responsive'
405
412
  export { DEFAULT_BREAKPOINTS, getCurrentBreakpoint, getBreakpointIndex, getBreakpointValue } from '../constants/breakpoints'
406
413
  `
407
- fs.writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
414
+ writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
408
415
  console.log(' ✅ hooks/index.ts')
409
416
  }
410
417
 
@@ -469,7 +476,7 @@ if (!packageJson.type) {
469
476
  if (needsUpdate) {
470
477
  console.log('')
471
478
  console.log('📝 Actualizando package.json...')
472
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
479
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
473
480
  console.log('✅ package.json actualizado')
474
481
  console.log('')
475
482
  console.log('⚠️ Ejecuta "npm install" para instalar las dependencias')
@@ -480,7 +487,7 @@ if (needsUpdate) {
480
487
  // Verificar si el proyecto ya está configurado
481
488
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
482
489
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
483
- const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsDir) && fs.existsSync(path.join(projectRoot, 'vite.config.ts'))
490
+ const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) && existsSync(path.join(projectRoot, 'vite.config.ts'))
484
491
 
485
492
  // Función async para manejar la configuración del proyecto
486
493
  (async () => {
@@ -531,8 +538,8 @@ const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsD
531
538
  const dirs = ['src', 'src/components', 'src/components/layout', 'src/pages', 'src/hooks', 'src/types', 'src/constants', 'public']
532
539
  dirs.forEach(dir => {
533
540
  const dirPath = path.join(projectRoot, dir)
534
- if (!fs.existsSync(dirPath)) {
535
- fs.mkdirSync(dirPath, { recursive: true })
541
+ if (!existsSync(dirPath)) {
542
+ mkdirSync(dirPath, { recursive: true })
536
543
  }
537
544
  })
538
545
 
@@ -546,7 +553,7 @@ const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsD
546
553
 
547
554
  // Crear vite.config.ts
548
555
  const viteConfigPath = path.join(projectRoot, 'vite.config.ts')
549
- if (!fs.existsSync(viteConfigPath)) {
556
+ if (!existsSync(viteConfigPath)) {
550
557
  const viteConfig = `import { defineConfig } from 'vite'
551
558
  import react from '@vitejs/plugin-react'
552
559
 
@@ -554,13 +561,13 @@ export default defineConfig({
554
561
  plugins: [react()],
555
562
  })
556
563
  `
557
- fs.writeFileSync(viteConfigPath, viteConfig)
564
+ writeFileSync(viteConfigPath, viteConfig)
558
565
  console.log(' ✅ Creado: vite.config.ts')
559
566
  }
560
567
 
561
568
  // Crear tailwind.config.js
562
569
  const tailwindConfigPath = path.join(projectRoot, 'tailwind.config.js')
563
- if (!fs.existsSync(tailwindConfigPath)) {
570
+ if (!existsSync(tailwindConfigPath)) {
564
571
  const tailwindConfig = `import responsiveScalePlugin from 'responsive-system/plugin'
565
572
 
566
573
  export default {
@@ -596,13 +603,13 @@ export default {
596
603
  ],
597
604
  }
598
605
  `
599
- fs.writeFileSync(tailwindConfigPath, tailwindConfig)
606
+ writeFileSync(tailwindConfigPath, tailwindConfig)
600
607
  console.log(' ✅ Creado: tailwind.config.js')
601
608
  }
602
609
 
603
610
  // Crear postcss.config.js
604
611
  const postcssConfigPath = path.join(projectRoot, 'postcss.config.js')
605
- if (!fs.existsSync(postcssConfigPath)) {
612
+ if (!existsSync(postcssConfigPath)) {
606
613
  const postcssConfig = `export default {
607
614
  plugins: {
608
615
  '@tailwindcss/postcss': {},
@@ -610,13 +617,13 @@ export default {
610
617
  },
611
618
  }
612
619
  `
613
- fs.writeFileSync(postcssConfigPath, postcssConfig)
620
+ writeFileSync(postcssConfigPath, postcssConfig)
614
621
  console.log(' ✅ Creado: postcss.config.js')
615
622
  }
616
623
 
617
624
  // Crear tsconfig.json
618
625
  const tsconfigPath = path.join(projectRoot, 'tsconfig.json')
619
- if (!fs.existsSync(tsconfigPath)) {
626
+ if (!existsSync(tsconfigPath)) {
620
627
  const tsconfig = `{
621
628
  "compilerOptions": {
622
629
  "target": "ES2020",
@@ -639,13 +646,13 @@ export default {
639
646
  "references": [{ "path": "./tsconfig.node.json" }]
640
647
  }
641
648
  `
642
- fs.writeFileSync(tsconfigPath, tsconfig)
649
+ writeFileSync(tsconfigPath, tsconfig)
643
650
  console.log(' ✅ Creado: tsconfig.json')
644
651
  }
645
652
 
646
653
  // Crear tsconfig.node.json
647
654
  const tsconfigNodePath = path.join(projectRoot, 'tsconfig.node.json')
648
- if (!fs.existsSync(tsconfigNodePath)) {
655
+ if (!existsSync(tsconfigNodePath)) {
649
656
  const tsconfigNode = `{
650
657
  "compilerOptions": {
651
658
  "composite": true,
@@ -657,13 +664,13 @@ export default {
657
664
  "include": ["vite.config.ts"]
658
665
  }
659
666
  `
660
- fs.writeFileSync(tsconfigNodePath, tsconfigNode)
667
+ writeFileSync(tsconfigNodePath, tsconfigNode)
661
668
  console.log(' ✅ Creado: tsconfig.node.json')
662
669
  }
663
670
 
664
671
  // Crear index.html
665
672
  const indexHtmlPath = path.join(projectRoot, 'index.html')
666
- if (!fs.existsSync(indexHtmlPath)) {
673
+ if (!existsSync(indexHtmlPath)) {
667
674
  const indexHtml = `<!doctype html>
668
675
  <html lang="es">
669
676
  <head>
@@ -678,14 +685,14 @@ export default {
678
685
  </body>
679
686
  </html>
680
687
  `
681
- fs.writeFileSync(indexHtmlPath, indexHtml)
688
+ writeFileSync(indexHtmlPath, indexHtml)
682
689
  console.log(' ✅ Creado: index.html')
683
690
  }
684
691
 
685
692
  // Crear layout local según el seleccionado
686
693
  const layoutsDir = path.join(projectRoot, 'src', 'layouts')
687
- if (!fs.existsSync(layoutsDir)) {
688
- fs.mkdirSync(layoutsDir, { recursive: true })
694
+ if (!existsSync(layoutsDir)) {
695
+ mkdirSync(layoutsDir, { recursive: true })
689
696
  }
690
697
 
691
698
  // Generar layout local que use los componentes locales
@@ -800,12 +807,12 @@ export default MinimalLayout
800
807
  }
801
808
 
802
809
  const layoutPath = path.join(layoutsDir, `${selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1)}Layout.tsx`)
803
- fs.writeFileSync(layoutPath, layoutContent)
810
+ writeFileSync(layoutPath, layoutContent)
804
811
  console.log(` ✅ Creado: src/layouts/${path.basename(layoutPath)}`)
805
812
 
806
813
  // Crear src/main.tsx que use el layout local
807
814
  const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
808
- if (!fs.existsSync(mainTsxPath)) {
815
+ if (!existsSync(mainTsxPath)) {
809
816
  const layoutName = selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1) + 'Layout'
810
817
  const mainTsx = `import React from 'react'
811
818
  import ReactDOM from 'react-dom/client'
@@ -824,22 +831,22 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
824
831
  </React.StrictMode>,
825
832
  )
826
833
  `
827
- fs.writeFileSync(mainTsxPath, mainTsx)
834
+ writeFileSync(mainTsxPath, mainTsx)
828
835
  console.log(' ✅ Creado: src/main.tsx')
829
836
  }
830
837
 
831
838
  // Crear src/index.css
832
839
  const indexCssPath = path.join(projectRoot, 'src', 'index.css')
833
- if (!fs.existsSync(indexCssPath)) {
840
+ if (!existsSync(indexCssPath)) {
834
841
  const indexCss = `@import "tailwindcss";
835
842
  `
836
- fs.writeFileSync(indexCssPath, indexCss)
843
+ writeFileSync(indexCssPath, indexCss)
837
844
  console.log(' ✅ Creado: src/index.css')
838
845
  }
839
846
 
840
847
  // Crear src/pages/HomePage.tsx con página de ejemplo simple
841
848
  const homePagePath = path.join(projectRoot, 'src', 'pages', 'HomePage.tsx')
842
- if (!fs.existsSync(homePagePath)) {
849
+ if (!existsSync(homePagePath)) {
843
850
  const homePage = `import { useResponsiveLayout } from 'responsive-system'
844
851
  import { useResponsive } from '../hooks'
845
852
 
@@ -919,13 +926,13 @@ function HomePage() {
919
926
 
920
927
  export default HomePage
921
928
  `
922
- fs.writeFileSync(homePagePath, homePage)
929
+ writeFileSync(homePagePath, homePage)
923
930
  console.log(' ✅ Creado: src/pages/HomePage.tsx (página de ejemplo simple)')
924
931
  }
925
932
 
926
933
  // Crear src/App.tsx que importa la página
927
934
  const appTsxPath = path.join(projectRoot, 'src', 'App.tsx')
928
- if (!fs.existsSync(appTsxPath)) {
935
+ if (!existsSync(appTsxPath)) {
929
936
  const appTsx = `import HomePage from './pages/HomePage'
930
937
 
931
938
  function App() {
@@ -934,7 +941,7 @@ function App() {
934
941
 
935
942
  export default App
936
943
  `
937
- fs.writeFileSync(appTsxPath, appTsx)
944
+ writeFileSync(appTsxPath, appTsx)
938
945
  console.log(' ✅ Creado: src/App.tsx')
939
946
  }
940
947
 
@@ -952,7 +959,7 @@ export default App
952
959
  packageJson.scripts.preview = 'vite preview'
953
960
  }
954
961
 
955
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
962
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
956
963
  console.log(' ✅ Actualizado: package.json con scripts')
957
964
 
958
965
  console.log('')