responsive-system 1.7.2 → 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 +1 -1
- package/scripts/postinstall.js +49 -49
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'
|
|
@@ -50,14 +50,14 @@ console.log(` Directorio: ${projectRoot}`)
|
|
|
50
50
|
console.log('')
|
|
51
51
|
|
|
52
52
|
// Verificar si package.json existe
|
|
53
|
-
if (!
|
|
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(
|
|
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 (!
|
|
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 (!
|
|
137
|
-
|
|
136
|
+
if (!existsSync(destDir)) {
|
|
137
|
+
mkdirSync(destDir, { recursive: true })
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
let content =
|
|
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
|
-
|
|
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 (!
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (!
|
|
379
|
-
|
|
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 (!
|
|
385
|
-
|
|
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 (!
|
|
393
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,7 +480,7 @@ 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 =
|
|
483
|
+
const isAlreadyConfigured = existsSync(mainTsxPath) && existsSync(layoutsDir) && existsSync(path.join(projectRoot, 'vite.config.ts'))
|
|
484
484
|
|
|
485
485
|
// Función async para manejar la configuración del proyecto
|
|
486
486
|
(async () => {
|
|
@@ -531,8 +531,8 @@ const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsD
|
|
|
531
531
|
const dirs = ['src', 'src/components', 'src/components/layout', 'src/pages', 'src/hooks', 'src/types', 'src/constants', 'public']
|
|
532
532
|
dirs.forEach(dir => {
|
|
533
533
|
const dirPath = path.join(projectRoot, dir)
|
|
534
|
-
if (!
|
|
535
|
-
|
|
534
|
+
if (!existsSync(dirPath)) {
|
|
535
|
+
mkdirSync(dirPath, { recursive: true })
|
|
536
536
|
}
|
|
537
537
|
})
|
|
538
538
|
|
|
@@ -546,7 +546,7 @@ const isAlreadyConfigured = fs.existsSync(mainTsxPath) && fs.existsSync(layoutsD
|
|
|
546
546
|
|
|
547
547
|
// Crear vite.config.ts
|
|
548
548
|
const viteConfigPath = path.join(projectRoot, 'vite.config.ts')
|
|
549
|
-
if (!
|
|
549
|
+
if (!existsSync(viteConfigPath)) {
|
|
550
550
|
const viteConfig = `import { defineConfig } from 'vite'
|
|
551
551
|
import react from '@vitejs/plugin-react'
|
|
552
552
|
|
|
@@ -554,13 +554,13 @@ export default defineConfig({
|
|
|
554
554
|
plugins: [react()],
|
|
555
555
|
})
|
|
556
556
|
`
|
|
557
|
-
|
|
557
|
+
writeFileSync(viteConfigPath, viteConfig)
|
|
558
558
|
console.log(' ✅ Creado: vite.config.ts')
|
|
559
559
|
}
|
|
560
560
|
|
|
561
561
|
// Crear tailwind.config.js
|
|
562
562
|
const tailwindConfigPath = path.join(projectRoot, 'tailwind.config.js')
|
|
563
|
-
if (!
|
|
563
|
+
if (!existsSync(tailwindConfigPath)) {
|
|
564
564
|
const tailwindConfig = `import responsiveScalePlugin from 'responsive-system/plugin'
|
|
565
565
|
|
|
566
566
|
export default {
|
|
@@ -596,13 +596,13 @@ export default {
|
|
|
596
596
|
],
|
|
597
597
|
}
|
|
598
598
|
`
|
|
599
|
-
|
|
599
|
+
writeFileSync(tailwindConfigPath, tailwindConfig)
|
|
600
600
|
console.log(' ✅ Creado: tailwind.config.js')
|
|
601
601
|
}
|
|
602
602
|
|
|
603
603
|
// Crear postcss.config.js
|
|
604
604
|
const postcssConfigPath = path.join(projectRoot, 'postcss.config.js')
|
|
605
|
-
if (!
|
|
605
|
+
if (!existsSync(postcssConfigPath)) {
|
|
606
606
|
const postcssConfig = `export default {
|
|
607
607
|
plugins: {
|
|
608
608
|
'@tailwindcss/postcss': {},
|
|
@@ -610,13 +610,13 @@ export default {
|
|
|
610
610
|
},
|
|
611
611
|
}
|
|
612
612
|
`
|
|
613
|
-
|
|
613
|
+
writeFileSync(postcssConfigPath, postcssConfig)
|
|
614
614
|
console.log(' ✅ Creado: postcss.config.js')
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
// Crear tsconfig.json
|
|
618
618
|
const tsconfigPath = path.join(projectRoot, 'tsconfig.json')
|
|
619
|
-
if (!
|
|
619
|
+
if (!existsSync(tsconfigPath)) {
|
|
620
620
|
const tsconfig = `{
|
|
621
621
|
"compilerOptions": {
|
|
622
622
|
"target": "ES2020",
|
|
@@ -639,13 +639,13 @@ export default {
|
|
|
639
639
|
"references": [{ "path": "./tsconfig.node.json" }]
|
|
640
640
|
}
|
|
641
641
|
`
|
|
642
|
-
|
|
642
|
+
writeFileSync(tsconfigPath, tsconfig)
|
|
643
643
|
console.log(' ✅ Creado: tsconfig.json')
|
|
644
644
|
}
|
|
645
645
|
|
|
646
646
|
// Crear tsconfig.node.json
|
|
647
647
|
const tsconfigNodePath = path.join(projectRoot, 'tsconfig.node.json')
|
|
648
|
-
if (!
|
|
648
|
+
if (!existsSync(tsconfigNodePath)) {
|
|
649
649
|
const tsconfigNode = `{
|
|
650
650
|
"compilerOptions": {
|
|
651
651
|
"composite": true,
|
|
@@ -657,13 +657,13 @@ export default {
|
|
|
657
657
|
"include": ["vite.config.ts"]
|
|
658
658
|
}
|
|
659
659
|
`
|
|
660
|
-
|
|
660
|
+
writeFileSync(tsconfigNodePath, tsconfigNode)
|
|
661
661
|
console.log(' ✅ Creado: tsconfig.node.json')
|
|
662
662
|
}
|
|
663
663
|
|
|
664
664
|
// Crear index.html
|
|
665
665
|
const indexHtmlPath = path.join(projectRoot, 'index.html')
|
|
666
|
-
if (!
|
|
666
|
+
if (!existsSync(indexHtmlPath)) {
|
|
667
667
|
const indexHtml = `<!doctype html>
|
|
668
668
|
<html lang="es">
|
|
669
669
|
<head>
|
|
@@ -678,14 +678,14 @@ export default {
|
|
|
678
678
|
</body>
|
|
679
679
|
</html>
|
|
680
680
|
`
|
|
681
|
-
|
|
681
|
+
writeFileSync(indexHtmlPath, indexHtml)
|
|
682
682
|
console.log(' ✅ Creado: index.html')
|
|
683
683
|
}
|
|
684
684
|
|
|
685
685
|
// Crear layout local según el seleccionado
|
|
686
686
|
const layoutsDir = path.join(projectRoot, 'src', 'layouts')
|
|
687
|
-
if (!
|
|
688
|
-
|
|
687
|
+
if (!existsSync(layoutsDir)) {
|
|
688
|
+
mkdirSync(layoutsDir, { recursive: true })
|
|
689
689
|
}
|
|
690
690
|
|
|
691
691
|
// Generar layout local que use los componentes locales
|
|
@@ -800,12 +800,12 @@ export default MinimalLayout
|
|
|
800
800
|
}
|
|
801
801
|
|
|
802
802
|
const layoutPath = path.join(layoutsDir, `${selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1)}Layout.tsx`)
|
|
803
|
-
|
|
803
|
+
writeFileSync(layoutPath, layoutContent)
|
|
804
804
|
console.log(` ✅ Creado: src/layouts/${path.basename(layoutPath)}`)
|
|
805
805
|
|
|
806
806
|
// Crear src/main.tsx que use el layout local
|
|
807
807
|
const mainTsxPath = path.join(projectRoot, 'src', 'main.tsx')
|
|
808
|
-
if (!
|
|
808
|
+
if (!existsSync(mainTsxPath)) {
|
|
809
809
|
const layoutName = selectedLayout.charAt(0).toUpperCase() + selectedLayout.slice(1) + 'Layout'
|
|
810
810
|
const mainTsx = `import React from 'react'
|
|
811
811
|
import ReactDOM from 'react-dom/client'
|
|
@@ -824,22 +824,22 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
|
824
824
|
</React.StrictMode>,
|
|
825
825
|
)
|
|
826
826
|
`
|
|
827
|
-
|
|
827
|
+
writeFileSync(mainTsxPath, mainTsx)
|
|
828
828
|
console.log(' ✅ Creado: src/main.tsx')
|
|
829
829
|
}
|
|
830
830
|
|
|
831
831
|
// Crear src/index.css
|
|
832
832
|
const indexCssPath = path.join(projectRoot, 'src', 'index.css')
|
|
833
|
-
if (!
|
|
833
|
+
if (!existsSync(indexCssPath)) {
|
|
834
834
|
const indexCss = `@import "tailwindcss";
|
|
835
835
|
`
|
|
836
|
-
|
|
836
|
+
writeFileSync(indexCssPath, indexCss)
|
|
837
837
|
console.log(' ✅ Creado: src/index.css')
|
|
838
838
|
}
|
|
839
839
|
|
|
840
840
|
// Crear src/pages/HomePage.tsx con página de ejemplo simple
|
|
841
841
|
const homePagePath = path.join(projectRoot, 'src', 'pages', 'HomePage.tsx')
|
|
842
|
-
if (!
|
|
842
|
+
if (!existsSync(homePagePath)) {
|
|
843
843
|
const homePage = `import { useResponsiveLayout } from 'responsive-system'
|
|
844
844
|
import { useResponsive } from '../hooks'
|
|
845
845
|
|
|
@@ -919,13 +919,13 @@ function HomePage() {
|
|
|
919
919
|
|
|
920
920
|
export default HomePage
|
|
921
921
|
`
|
|
922
|
-
|
|
922
|
+
writeFileSync(homePagePath, homePage)
|
|
923
923
|
console.log(' ✅ Creado: src/pages/HomePage.tsx (página de ejemplo simple)')
|
|
924
924
|
}
|
|
925
925
|
|
|
926
926
|
// Crear src/App.tsx que importa la página
|
|
927
927
|
const appTsxPath = path.join(projectRoot, 'src', 'App.tsx')
|
|
928
|
-
if (!
|
|
928
|
+
if (!existsSync(appTsxPath)) {
|
|
929
929
|
const appTsx = `import HomePage from './pages/HomePage'
|
|
930
930
|
|
|
931
931
|
function App() {
|
|
@@ -934,7 +934,7 @@ function App() {
|
|
|
934
934
|
|
|
935
935
|
export default App
|
|
936
936
|
`
|
|
937
|
-
|
|
937
|
+
writeFileSync(appTsxPath, appTsx)
|
|
938
938
|
console.log(' ✅ Creado: src/App.tsx')
|
|
939
939
|
}
|
|
940
940
|
|
|
@@ -952,7 +952,7 @@ export default App
|
|
|
952
952
|
packageJson.scripts.preview = 'vite preview'
|
|
953
953
|
}
|
|
954
954
|
|
|
955
|
-
|
|
955
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
956
956
|
console.log(' ✅ Actualizado: package.json con scripts')
|
|
957
957
|
|
|
958
958
|
console.log('')
|