responsive-system 1.7.4 → 1.7.6
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 +1 -1
- package/scripts/postinstall.js +66 -50
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - Configura App.tsx con el layout seleccionado
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import
|
|
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,7 +20,23 @@ import readline from 'readline'
|
|
|
20
20
|
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
40
|
const packageJsonPath = path.join(projectRoot, 'package.json')
|
|
25
41
|
|
|
26
42
|
// Detectar si se ejecuta como postinstall o manualmente
|
|
@@ -50,14 +66,14 @@ console.log(` Directorio: ${projectRoot}`)
|
|
|
50
66
|
console.log('')
|
|
51
67
|
|
|
52
68
|
// Verificar si package.json existe
|
|
53
|
-
if (!
|
|
69
|
+
if (!existsSync(packageJsonPath)) {
|
|
54
70
|
console.log('⚠️ No se encontró package.json, saltando configuración')
|
|
55
71
|
process.exit(0)
|
|
56
72
|
}
|
|
57
73
|
|
|
58
74
|
let packageJson
|
|
59
75
|
try {
|
|
60
|
-
packageJson = JSON.parse(
|
|
76
|
+
packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
|
61
77
|
} catch (error) {
|
|
62
78
|
console.error('❌ Error al leer package.json:', error.message)
|
|
63
79
|
process.exit(1)
|
|
@@ -126,18 +142,18 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
|
|
|
126
142
|
const sourcePath = path.join(__dirname, '..', relativePath)
|
|
127
143
|
const destPath = path.join(projectRoot, targetPath)
|
|
128
144
|
|
|
129
|
-
if (!
|
|
145
|
+
if (!existsSync(sourcePath)) {
|
|
130
146
|
console.error(` ❌ No se encontró: ${relativePath}`)
|
|
131
147
|
return false
|
|
132
148
|
}
|
|
133
149
|
|
|
134
150
|
// Crear directorio destino si no existe
|
|
135
151
|
const destDir = path.dirname(destPath)
|
|
136
|
-
if (!
|
|
137
|
-
|
|
152
|
+
if (!existsSync(destDir)) {
|
|
153
|
+
mkdirSync(destDir, { recursive: true })
|
|
138
154
|
}
|
|
139
155
|
|
|
140
|
-
let content =
|
|
156
|
+
let content = readFileSync(sourcePath, 'utf8')
|
|
141
157
|
|
|
142
158
|
// Si es un componente, reemplazar importaciones relativas por importaciones del paquete
|
|
143
159
|
if (isComponent) {
|
|
@@ -158,7 +174,7 @@ function copyFileFromPackage(relativePath, targetPath, isComponent = false) {
|
|
|
158
174
|
)
|
|
159
175
|
}
|
|
160
176
|
|
|
161
|
-
|
|
177
|
+
writeFileSync(destPath, content)
|
|
162
178
|
return true
|
|
163
179
|
}
|
|
164
180
|
|
|
@@ -167,8 +183,8 @@ function generateLayoutComponents(selectedLayout) {
|
|
|
167
183
|
const componentsDir = path.join(projectRoot, 'src', 'components', 'layout')
|
|
168
184
|
|
|
169
185
|
// Crear directorio si no existe
|
|
170
|
-
if (!
|
|
171
|
-
|
|
186
|
+
if (!existsSync(componentsDir)) {
|
|
187
|
+
mkdirSync(componentsDir, { recursive: true })
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
const componentsToGenerate = {
|
|
@@ -224,7 +240,7 @@ const Navigation = () => {
|
|
|
224
240
|
|
|
225
241
|
export default Navigation
|
|
226
242
|
`
|
|
227
|
-
|
|
243
|
+
writeFileSync(path.join(componentsDir, 'Navigation.tsx'), navigationContent)
|
|
228
244
|
console.log(' ✅ Navigation.tsx')
|
|
229
245
|
}
|
|
230
246
|
|
|
@@ -246,7 +262,7 @@ export default Navigation
|
|
|
246
262
|
|
|
247
263
|
export default Footer
|
|
248
264
|
`
|
|
249
|
-
|
|
265
|
+
writeFileSync(path.join(componentsDir, 'Footer.tsx'), footerContent)
|
|
250
266
|
console.log(' ✅ Footer.tsx')
|
|
251
267
|
}
|
|
252
268
|
|
|
@@ -359,13 +375,13 @@ const Sidebar = ({ showLogo = true }: SidebarProps) => {
|
|
|
359
375
|
|
|
360
376
|
export default Sidebar
|
|
361
377
|
`
|
|
362
|
-
|
|
378
|
+
writeFileSync(path.join(componentsDir, 'Sidebar.tsx'), sidebarContent)
|
|
363
379
|
console.log(' ✅ Sidebar.tsx')
|
|
364
380
|
}
|
|
365
381
|
|
|
366
382
|
// Crear index.ts para exportar los componentes
|
|
367
383
|
const indexContent = components.map(c => `export { default as ${c} } from './${c}'`).join('\n')
|
|
368
|
-
|
|
384
|
+
writeFileSync(path.join(componentsDir, 'index.ts'), indexContent)
|
|
369
385
|
console.log(' ✅ index.ts')
|
|
370
386
|
}
|
|
371
387
|
|
|
@@ -375,22 +391,22 @@ function copyUseResponsiveHook() {
|
|
|
375
391
|
|
|
376
392
|
// Crear directorio hooks
|
|
377
393
|
const hooksDir = path.join(projectRoot, 'src', 'hooks')
|
|
378
|
-
if (!
|
|
379
|
-
|
|
394
|
+
if (!existsSync(hooksDir)) {
|
|
395
|
+
mkdirSync(hooksDir, { recursive: true })
|
|
380
396
|
}
|
|
381
397
|
|
|
382
398
|
// Copiar tipos
|
|
383
399
|
const typesDir = path.join(projectRoot, 'src', 'types')
|
|
384
|
-
if (!
|
|
385
|
-
|
|
400
|
+
if (!existsSync(typesDir)) {
|
|
401
|
+
mkdirSync(typesDir, { recursive: true })
|
|
386
402
|
}
|
|
387
403
|
copyFileFromPackage('src/types/responsive.ts', 'src/types/responsive.ts')
|
|
388
404
|
console.log(' ✅ types/responsive.ts')
|
|
389
405
|
|
|
390
406
|
// Copiar constantes
|
|
391
407
|
const constantsDir = path.join(projectRoot, 'src', 'constants')
|
|
392
|
-
if (!
|
|
393
|
-
|
|
408
|
+
if (!existsSync(constantsDir)) {
|
|
409
|
+
mkdirSync(constantsDir, { recursive: true })
|
|
394
410
|
}
|
|
395
411
|
copyFileFromPackage('src/constants/breakpoints.ts', 'src/constants/breakpoints.ts')
|
|
396
412
|
console.log(' ✅ constants/breakpoints.ts')
|
|
@@ -404,7 +420,7 @@ function copyUseResponsiveHook() {
|
|
|
404
420
|
export type { ResponsiveState, Breakpoint, Orientation } from '../types/responsive'
|
|
405
421
|
export { DEFAULT_BREAKPOINTS, getCurrentBreakpoint, getBreakpointIndex, getBreakpointValue } from '../constants/breakpoints'
|
|
406
422
|
`
|
|
407
|
-
|
|
423
|
+
writeFileSync(path.join(hooksDir, 'index.ts'), indexContent)
|
|
408
424
|
console.log(' ✅ hooks/index.ts')
|
|
409
425
|
}
|
|
410
426
|
|
|
@@ -469,7 +485,7 @@ if (!packageJson.type) {
|
|
|
469
485
|
if (needsUpdate) {
|
|
470
486
|
console.log('')
|
|
471
487
|
console.log('📝 Actualizando package.json...')
|
|
472
|
-
|
|
488
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
473
489
|
console.log('✅ package.json actualizado')
|
|
474
490
|
console.log('')
|
|
475
491
|
console.log('⚠️ Ejecuta "npm install" para instalar las dependencias')
|
|
@@ -480,7 +496,7 @@ if (needsUpdate) {
|
|
|
480
496
|
// Verificar si el proyecto ya está configurado
|
|
481
497
|
const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
|
|
482
498
|
const layoutsDir = path.join(projectRoot, 'src', 'layouts')
|
|
483
|
-
const isAlreadyConfigured =
|
|
499
|
+
const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) && existsSync(path.join(projectRoot, 'vite.config.ts'))
|
|
484
500
|
|
|
485
501
|
// Función async para manejar la configuración del proyecto
|
|
486
502
|
(async () => {
|
|
@@ -531,8 +547,8 @@ const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsD
|
|
|
531
547
|
const dirs = ['src', 'src/components', 'src/components/layout', 'src/pages', 'src/hooks', 'src/types', 'src/constants', 'public']
|
|
532
548
|
dirs.forEach(dir => {
|
|
533
549
|
const dirPath = path.join(projectRoot, dir)
|
|
534
|
-
if (!
|
|
535
|
-
|
|
550
|
+
if (!existsSync(dirPath)) {
|
|
551
|
+
mkdirSync(dirPath, { recursive: true })
|
|
536
552
|
}
|
|
537
553
|
})
|
|
538
554
|
|
|
@@ -546,7 +562,7 @@ const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsD
|
|
|
546
562
|
|
|
547
563
|
// Crear vite.config.ts
|
|
548
564
|
const viteConfigPath = path.join(projectRoot, 'vite.config.ts')
|
|
549
|
-
if (!
|
|
565
|
+
if (!existsSync(viteConfigPath)) {
|
|
550
566
|
const viteConfig = `import { defineConfig } from 'vite'
|
|
551
567
|
import react from '@vitejs/plugin-react'
|
|
552
568
|
|
|
@@ -554,13 +570,13 @@ export default defineConfig({
|
|
|
554
570
|
plugins: [react()],
|
|
555
571
|
})
|
|
556
572
|
`
|
|
557
|
-
|
|
573
|
+
writeFileSync(viteConfigPath, viteConfig)
|
|
558
574
|
console.log(' ✅ Creado: vite.config.ts')
|
|
559
575
|
}
|
|
560
576
|
|
|
561
577
|
// Crear tailwind.config.js
|
|
562
578
|
const tailwindConfigPath = path.join(projectRoot, 'tailwind.config.js')
|
|
563
|
-
if (!
|
|
579
|
+
if (!existsSync(tailwindConfigPath)) {
|
|
564
580
|
const tailwindConfig = `import responsiveScalePlugin from 'responsive-system/plugin'
|
|
565
581
|
|
|
566
582
|
export default {
|
|
@@ -596,13 +612,13 @@ export default {
|
|
|
596
612
|
],
|
|
597
613
|
}
|
|
598
614
|
`
|
|
599
|
-
|
|
615
|
+
writeFileSync(tailwindConfigPath, tailwindConfig)
|
|
600
616
|
console.log(' ✅ Creado: tailwind.config.js')
|
|
601
617
|
}
|
|
602
618
|
|
|
603
619
|
// Crear postcss.config.js
|
|
604
620
|
const postcssConfigPath = path.join(projectRoot, 'postcss.config.js')
|
|
605
|
-
if (!
|
|
621
|
+
if (!existsSync(postcssConfigPath)) {
|
|
606
622
|
const postcssConfig = `export default {
|
|
607
623
|
plugins: {
|
|
608
624
|
'@tailwindcss/postcss': {},
|
|
@@ -610,13 +626,13 @@ export default {
|
|
|
610
626
|
},
|
|
611
627
|
}
|
|
612
628
|
`
|
|
613
|
-
|
|
629
|
+
writeFileSync(postcssConfigPath, postcssConfig)
|
|
614
630
|
console.log(' ✅ Creado: postcss.config.js')
|
|
615
631
|
}
|
|
616
632
|
|
|
617
633
|
// Crear tsconfig.json
|
|
618
634
|
const tsconfigPath = path.join(projectRoot, 'tsconfig.json')
|
|
619
|
-
if (!
|
|
635
|
+
if (!existsSync(tsconfigPath)) {
|
|
620
636
|
const tsconfig = `{
|
|
621
637
|
"compilerOptions": {
|
|
622
638
|
"target": "ES2020",
|
|
@@ -639,13 +655,13 @@ export default {
|
|
|
639
655
|
"references": [{ "path": "./tsconfig.node.json" }]
|
|
640
656
|
}
|
|
641
657
|
`
|
|
642
|
-
|
|
658
|
+
writeFileSync(tsconfigPath, tsconfig)
|
|
643
659
|
console.log(' ✅ Creado: tsconfig.json')
|
|
644
660
|
}
|
|
645
661
|
|
|
646
662
|
// Crear tsconfig.node.json
|
|
647
663
|
const tsconfigNodePath = path.join(projectRoot, 'tsconfig.node.json')
|
|
648
|
-
if (!
|
|
664
|
+
if (!existsSync(tsconfigNodePath)) {
|
|
649
665
|
const tsconfigNode = `{
|
|
650
666
|
"compilerOptions": {
|
|
651
667
|
"composite": true,
|
|
@@ -657,13 +673,13 @@ export default {
|
|
|
657
673
|
"include": ["vite.config.ts"]
|
|
658
674
|
}
|
|
659
675
|
`
|
|
660
|
-
|
|
676
|
+
writeFileSync(tsconfigNodePath, tsconfigNode)
|
|
661
677
|
console.log(' ✅ Creado: tsconfig.node.json')
|
|
662
678
|
}
|
|
663
679
|
|
|
664
680
|
// Crear index.html
|
|
665
681
|
const indexHtmlPath = path.join(projectRoot, 'index.html')
|
|
666
|
-
if (!
|
|
682
|
+
if (!existsSync(indexHtmlPath)) {
|
|
667
683
|
const indexHtml = `<!doctype html>
|
|
668
684
|
<html lang="es">
|
|
669
685
|
<head>
|
|
@@ -678,14 +694,14 @@ export default {
|
|
|
678
694
|
</body>
|
|
679
695
|
</html>
|
|
680
696
|
`
|
|
681
|
-
|
|
697
|
+
writeFileSync(indexHtmlPath, indexHtml)
|
|
682
698
|
console.log(' ✅ Creado: index.html')
|
|
683
699
|
}
|
|
684
700
|
|
|
685
701
|
// Crear layout local según el seleccionado
|
|
686
702
|
const layoutsDir = path.join(projectRoot, 'src', 'layouts')
|
|
687
|
-
if (!
|
|
688
|
-
|
|
703
|
+
if (!existsSync(layoutsDir)) {
|
|
704
|
+
mkdirSync(layoutsDir, { recursive: true })
|
|
689
705
|
}
|
|
690
706
|
|
|
691
707
|
// Generar layout local que use los componentes locales
|
|
@@ -800,12 +816,12 @@ export default MinimalLayout
|
|
|
800
816
|
}
|
|
801
817
|
|
|
802
818
|
const layoutPath = path.join(layoutsDir, `${selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1)}Layout.tsx`)
|
|
803
|
-
|
|
819
|
+
writeFileSync(layoutPath, layoutContent)
|
|
804
820
|
console.log(` ✅ Creado: src/layouts/${path.basename(layoutPath)}`)
|
|
805
821
|
|
|
806
822
|
// Crear src/main.tsx que use el layout local
|
|
807
823
|
const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
|
|
808
|
-
if (!
|
|
824
|
+
if (!existsSync(mainTsxPath)) {
|
|
809
825
|
const layoutName = selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1) + 'Layout'
|
|
810
826
|
const mainTsx = `import React from 'react'
|
|
811
827
|
import ReactDOM from 'react-dom/client'
|
|
@@ -824,22 +840,22 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
|
824
840
|
</React.StrictMode>,
|
|
825
841
|
)
|
|
826
842
|
`
|
|
827
|
-
|
|
843
|
+
writeFileSync(mainTsxPath, mainTsx)
|
|
828
844
|
console.log(' ✅ Creado: src/main.tsx')
|
|
829
845
|
}
|
|
830
846
|
|
|
831
847
|
// Crear src/index.css
|
|
832
848
|
const indexCssPath = path.join(projectRoot, 'src', 'index.css')
|
|
833
|
-
if (!
|
|
849
|
+
if (!existsSync(indexCssPath)) {
|
|
834
850
|
const indexCss = `@import "tailwindcss";
|
|
835
851
|
`
|
|
836
|
-
|
|
852
|
+
writeFileSync(indexCssPath, indexCss)
|
|
837
853
|
console.log(' ✅ Creado: src/index.css')
|
|
838
854
|
}
|
|
839
855
|
|
|
840
856
|
// Crear src/pages/HomePage.tsx con página de ejemplo simple
|
|
841
857
|
const homePagePath = path.join(projectRoot, 'src', 'pages', 'HomePage.tsx')
|
|
842
|
-
if (!
|
|
858
|
+
if (!existsSync(homePagePath)) {
|
|
843
859
|
const homePage = `import { useResponsiveLayout } from 'responsive-system'
|
|
844
860
|
import { useResponsive } from '../hooks'
|
|
845
861
|
|
|
@@ -919,13 +935,13 @@ function HomePage() {
|
|
|
919
935
|
|
|
920
936
|
export default HomePage
|
|
921
937
|
`
|
|
922
|
-
|
|
938
|
+
writeFileSync(homePagePath, homePage)
|
|
923
939
|
console.log(' ✅ Creado: src/pages/HomePage.tsx (página de ejemplo simple)')
|
|
924
940
|
}
|
|
925
941
|
|
|
926
942
|
// Crear src/App.tsx que importa la página
|
|
927
943
|
const appTsxPath = path.join(projectRoot, 'src', 'App.tsx')
|
|
928
|
-
if (!
|
|
944
|
+
if (!existsSync(appTsxPath)) {
|
|
929
945
|
const appTsx = `import HomePage from './pages/HomePage'
|
|
930
946
|
|
|
931
947
|
function App() {
|
|
@@ -934,7 +950,7 @@ function App() {
|
|
|
934
950
|
|
|
935
951
|
export default App
|
|
936
952
|
`
|
|
937
|
-
|
|
953
|
+
writeFileSync(appTsxPath, appTsx)
|
|
938
954
|
console.log(' ✅ Creado: src/App.tsx')
|
|
939
955
|
}
|
|
940
956
|
|
|
@@ -952,7 +968,7 @@ export default App
|
|
|
952
968
|
packageJson.scripts.preview = 'vite preview'
|
|
953
969
|
}
|
|
954
970
|
|
|
955
|
-
|
|
971
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
956
972
|
console.log(' ✅ Actualizado: package.json con scripts')
|
|
957
973
|
|
|
958
974
|
console.log('')
|