@unsetsoft/ryunix-presets 1.0.26-canary.4 → 1.0.26-canary.41

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.
Files changed (56) hide show
  1. package/README.es.md +126 -0
  2. package/README.md +133 -0
  3. package/package.json +55 -37
  4. package/webpack/bin/{compiler.mjs → compiler.js} +5 -6
  5. package/webpack/bin/compiler.ts +6 -0
  6. package/webpack/bin/dev.server.js +120 -0
  7. package/webpack/bin/dev.server.ts +151 -0
  8. package/webpack/bin/index.js +211 -0
  9. package/webpack/bin/index.ts +241 -0
  10. package/webpack/bin/prerender.js +53 -0
  11. package/webpack/bin/{prerender.mjs → prerender.ts} +62 -54
  12. package/webpack/bin/prod.server.js +343 -0
  13. package/webpack/bin/{prod.server.mjs → prod.server.ts} +403 -407
  14. package/webpack/config.d.ts +174 -85
  15. package/webpack/config.typetest.js +15 -0
  16. package/webpack/config.typetest.ts +17 -0
  17. package/webpack/{eslint.config.mjs → eslint.config.js} +39 -43
  18. package/webpack/eslint.config.ts +43 -0
  19. package/webpack/index.js +4 -6
  20. package/webpack/index.ts +6 -0
  21. package/webpack/loaders/ryunix-rsc-loader.js +112 -0
  22. package/webpack/loaders/ryunix-rsc-loader.ts +134 -0
  23. package/webpack/loaders/ryunix-server-action-loader.js +77 -0
  24. package/webpack/loaders/ryunix-server-action-loader.ts +86 -0
  25. package/webpack/plugins/remark-github-alerts.js +66 -0
  26. package/webpack/plugins/remark-github-alerts.test.mjs +73 -0
  27. package/webpack/plugins/remark-github-alerts.ts +90 -0
  28. package/webpack/template/index.html +20 -19
  29. package/webpack/types/presets-shims.d.ts +26 -0
  30. package/webpack/utils/{ApiRouterPlugin.mjs → ApiRouterPlugin.js} +135 -140
  31. package/webpack/utils/ApiRouterPlugin.ts +160 -0
  32. package/webpack/utils/apiHandler.js +148 -0
  33. package/webpack/utils/{apiHandler.mjs → apiHandler.ts} +172 -150
  34. package/webpack/utils/appRouterPlugin.js +586 -0
  35. package/webpack/utils/appRouterPlugin.ts +656 -0
  36. package/webpack/utils/config.cjs +263 -173
  37. package/webpack/utils/config.cjs.d.ts +34 -0
  38. package/webpack/utils/envExist.cjs +14 -14
  39. package/webpack/utils/index.js +172 -0
  40. package/webpack/utils/{index.mjs → index.ts} +205 -205
  41. package/webpack/utils/settingfile.cjs +60 -33
  42. package/webpack/utils/ssg.js +798 -0
  43. package/webpack/utils/ssg.ts +882 -0
  44. package/webpack/utils/{ssgPlugin.mjs → ssgPlugin.js} +507 -602
  45. package/webpack/utils/ssgPlugin.ts +626 -0
  46. package/webpack/utils/ssrDevHandler.js +110 -0
  47. package/webpack/utils/ssrDevHandler.ts +125 -0
  48. package/webpack/webpack.config.js +877 -0
  49. package/webpack/webpack.config.ts +900 -0
  50. package/rspack/index.js +0 -92
  51. package/vite/index.js +0 -18
  52. package/webpack/bin/dev.server.mjs +0 -115
  53. package/webpack/bin/index.mjs +0 -184
  54. package/webpack/utils/appRouterPlugin.mjs +0 -486
  55. package/webpack/utils/ssg.mjs +0 -371
  56. package/webpack/webpack.config.mjs +0 -376
package/README.es.md ADDED
@@ -0,0 +1,126 @@
1
+ <!-- markdownlint-disable MD033 MD041 MD013 -->
2
+
3
+ > **Language / Idioma:** [English](./README.md) · [Español](./README.es.md)
4
+
5
+ <p align="center">
6
+ <img src="https://raw.githubusercontent.com/UnSetSoft/Ryunixjs/canary/assets/logo.png" width="200" height="200" alt="RyunixJS Logo" />
7
+ </p>
8
+
9
+ <h1 align="center">@unsetsoft/ryunix-presets</h1>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@unsetsoft/ryunix-presets">
13
+ <img src="https://img.shields.io/npm/v/@unsetsoft/ryunix-presets.svg?style=flat-square" alt="versión npm" />
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@unsetsoft/ryunix-presets/v/canary">
16
+ <img src="https://img.shields.io/npm/v/@unsetsoft/ryunix-presets/canary.svg?style=flat-square&label=canary" alt="versión canary" />
17
+ </a>
18
+ </p>
19
+
20
+ ## <!-- markdownlint-enable MD013 -->
21
+
22
+ ## 🛠️ La columna vertebral del tooling
23
+
24
+ `@unsetsoft/ryunix-presets` es el paquete central que gestiona el sistema de build de
25
+ RyunixJS. Abstrae la complejidad de Webpack, Babel y loaders especializados, ofreciendo
26
+ una experiencia de desarrollo unificada y optimizada.
27
+
28
+ ### Capacidades principales
29
+
30
+ - **Configuración Webpack unificada**: compilación dual para entornos SSR y navegador.
31
+
32
+ - **RSC y Server Actions**: loaders nativos para Server Components y Actions al estilo
33
+
34
+ React.
35
+
36
+ - **Loaders avanzados**: soporte preconfigurado para MDX, SASS, PostCSS y assets
37
+
38
+ optimizados.
39
+
40
+ - **Motor SSG**: plugins integrados para generación de sitios estáticos y
41
+
42
+ prerenderizado.
43
+
44
+ ## 🚀 Instalación
45
+
46
+ ```bash
47
+ npm install @unsetsoft/ryunix-presets
48
+ ```
49
+
50
+ ## ⚙️ Configuración (`ryunix.config.js`)
51
+
52
+ Los proyectos RyunixJS se configuran con un archivo `ryunix.config.js` (o `.cjs`) en la
53
+
54
+ raíz.
55
+
56
+ ### Opciones principales
57
+
58
+ | Opción | Tipo | Por defecto | Descripción |
59
+ | :--------- | :---------------- | :---------- | :-------------------------------------------------- |
60
+ | `ssr` | `boolean` | `true` | Habilita Server-Side Rendering. |
61
+ | `mdx` | `boolean` | `false` | Habilita soporte MDX nativo. |
62
+ | `rootDir` | `string` | `"src"` | Directorio del código fuente. |
63
+ | `buildDir` | `string` | `".ryunix"` | Directorio de salida del build. |
64
+ | `port` | `number` | `3000` | Puerto del servidor de desarrollo. |
65
+ | `favicon` | `string\|boolean` | `true` | Ruta del favicon o booleano para el predeterminado. |
66
+ | `debug` | `boolean` | `false` | Registro detallado para depuración. |
67
+
68
+ ### Servidor y seguridad
69
+
70
+ - **`server.csp`**: `boolean` — activa Content Security Policy.
71
+ - **`server.cors`**: configura CORS en el servidor de desarrollo (`enabled`, `origin`,
72
+
73
+ `methods`, etc.).
74
+
75
+ ### Personalización avanzada de Webpack
76
+
77
+ Puedes extender la configuración de Webpack con la clave `webpack`:
78
+
79
+ ```javascript
80
+ module.exports = {
81
+ webpack: {
82
+ resolve: {
83
+ alias: {
84
+ '@components': 'src/components',
85
+ },
86
+ },
87
+ plugins: [
88
+ /* Plugins personalizados */
89
+ ],
90
+ module: {
91
+ rules: [
92
+ /* Reglas personalizadas */
93
+ ],
94
+ },
95
+ },
96
+ }
97
+ ```
98
+
99
+ ### Configuración del linter
100
+
101
+ Controla el comportamiento de ESLint en desarrollo:
102
+
103
+ ```javascript
104
+ module.exports = {
105
+ eslint: {
106
+ files: ['src/**/*.ryx'],
107
+ rules: {
108
+ 'no-console': 'warn',
109
+ },
110
+ },
111
+ }
112
+ ```
113
+
114
+ ## 🏗️ Pipelines de build
115
+
116
+ El paquete presets gestiona tres pipelines principales:
117
+
118
+ 1. **Pipeline cliente**: compila assets para el navegador con code splitting y HMR.
119
+
120
+ 2. **Pipeline servidor**: compila lógica de servidor y renderizadores SSG para Node.js.
121
+
122
+ 3. **SSG / prerender**: lógica unificada para generar HTML estático en la fase de build.
123
+
124
+ ## 📄 Licencia
125
+
126
+ RyunixJS tiene [licencia MIT](../../LICENSE).
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ <!-- markdownlint-disable MD033 MD041 MD013 -->
2
+
3
+ > **Language / Idioma:** [English](./README.md) · [Español](./README.es.md)
4
+
5
+ <p align="center">
6
+ <img src="https://raw.githubusercontent.com/UnSetSoft/Ryunixjs/canary/assets/logo.png" width="200" height="200" alt="RyunixJS Logo" />
7
+ </p>
8
+
9
+ <h1 align="center">@unsetsoft/ryunix-presets</h1>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@unsetsoft/ryunix-presets">
13
+ <img src="https://img.shields.io/npm/v/@unsetsoft/ryunix-presets.svg?style=flat-square" alt="npm version" />
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@unsetsoft/ryunix-presets/v/canary">
16
+ <img src="https://img.shields.io/npm/v/@unsetsoft/ryunix-presets/canary.svg?style=flat-square&label=canary" alt="canary version" />
17
+ </a>
18
+ </p>
19
+
20
+ ## <!-- markdownlint-enable MD013 -->
21
+
22
+ ## 🛠️ The Tooling Backbone
23
+
24
+ `@unsetsoft/ryunix-presets` is the central package managing the build system of
25
+ RyunixJS. It abstracts the complexity of Webpack, Babel, and specialized
26
+ loaders, providing a unified and optimized development experience.
27
+
28
+ ### Key Capabilities
29
+
30
+ - **Unified Webpack Config**: Handles dual compilation for SSR and Browser
31
+
32
+ environments.
33
+
34
+ - **RSC & Server Actions**: Includes native loaders for React-like Server
35
+
36
+ Components and Actions.
37
+
38
+ - **Advanced Loaders**: Pre-configured support for MDX, SASS, PostCSS, and
39
+
40
+ optimized assets.
41
+
42
+ - **SSG Engine**: Integrated plugins for static site generation and
43
+
44
+ prerendering.
45
+
46
+ ## 🚀 Installation
47
+
48
+ ```bash
49
+ npm install @unsetsoft/ryunix-presets
50
+ ```
51
+
52
+ ## ⚙️ Configuration (`ryunix.config.js`)
53
+
54
+ RyunixJS projects are configured via a `ryunix.config.js` (or `.cjs`) file at
55
+ the root.
56
+
57
+ ### Core Options
58
+
59
+ | Option | Type | Default | Description |
60
+ | :--------- | :---------------- | :---------- | :-------------------------------------------- |
61
+ | `ssr` | `boolean` | `true` | Enables Server-Side Rendering. |
62
+ | `mdx` | `boolean` | `false` | Enables native MDX support. |
63
+ | `rootDir` | `string` | `"src"` | The directory containing your source code. |
64
+ | `buildDir` | `string` | `".ryunix"` | The output directory for builds. |
65
+ | `port` | `number` | `3000` | Dev server port. |
66
+ | `favicon` | `string\|boolean` | `true` | Path to favicon or boolean to enable default. |
67
+ | `debug` | `boolean` | `false` | Enable verbose logging for debugging. |
68
+
69
+ ### Server & Security
70
+
71
+ - **`server.csp`**: `boolean` - Enable Content Security Policy.
72
+ - **`server.cors`**: Configure CORS for the dev server (`enabled`, `origin`,
73
+
74
+ `methods`, etc.).
75
+
76
+ ### Advanced Webpack Customization
77
+
78
+ You can extend the underlying Webpack configuration via the `webpack` key:
79
+
80
+ ```javascript
81
+ module.exports = {
82
+ webpack: {
83
+ resolve: {
84
+ alias: {
85
+ '@components': 'src/components',
86
+ },
87
+ },
88
+ plugins: [
89
+ /* Custom Webpack Plugins */
90
+ ],
91
+ module: {
92
+ rules: [
93
+ /* Custom Rules */
94
+ ],
95
+ },
96
+ },
97
+ }
98
+ ```
99
+
100
+ ### Linter Configuration
101
+
102
+ Control how ESLint behaves during development:
103
+
104
+ ```javascript
105
+ module.exports = {
106
+ eslint: {
107
+ files: ['src/**/*.ryx'],
108
+ rules: {
109
+ 'no-console': 'warn',
110
+ },
111
+ },
112
+ }
113
+ ```
114
+
115
+ ## 🏗️ Build Pipelines
116
+
117
+ The presets package manages three main pipelines:
118
+
119
+ 1. **Client Pipeline**: Compiles assets for the browser with code splitting and
120
+
121
+ HMR.
122
+
123
+ 2. **Server Pipeline**: Compiles server-side logic and SSG renderers for Node.js
124
+
125
+ environments.
126
+
127
+ 3. **SSG/Prerender**: Unified logic to generate static HTML during the build
128
+
129
+ phase.
130
+
131
+ ## 📄 License
132
+
133
+ RyunixJS is [MIT Licensed](../../LICENSE).
package/package.json CHANGED
@@ -1,83 +1,101 @@
1
1
  {
2
2
  "name": "@unsetsoft/ryunix-presets",
3
3
  "description": "Package with presets for different development environments.",
4
- "version": "1.0.26-canary.4",
4
+ "version": "1.0.26-canary.41",
5
5
  "author": "Neyunse",
6
6
  "type": "module",
7
- "repository": "https://github.com/UnSetSoft/Ryunixjs",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/UnSetSoft/Ryunixjs.git",
10
+ "directory": "packages/ryunix-presets"
11
+ },
8
12
  "license": "MIT",
9
13
  "keywords": [
10
14
  "ryunixjs"
11
15
  ],
12
16
  "files": [
13
- "vite/",
14
- "rspack/",
15
17
  "webpack/"
16
18
  ],
17
19
  "peerDependencies": {
18
- "@unsetsoft/ryunixjs": "^1.2.4-canary.x || ^1.2.4"
20
+ "@unsetsoft/ryunixjs": "^1.2.5-canary.0 || ^1.2.4"
19
21
  },
20
22
  "publishConfig": {
21
- "registry": "https://registry.npmjs.org"
23
+ "registry": "https://registry.npmjs.org",
24
+ "access": "public",
25
+ "provenance": true
22
26
  },
23
27
  "exports": {
24
- "./vite": "./vite/index.js",
25
- "./rspack": "./rspack/index.js",
26
- "./webpack": "./webpack/index.js"
28
+ ".": {
29
+ "types": "./webpack/config.d.ts"
30
+ },
31
+ "./webpack": {
32
+ "types": "./webpack/config.d.ts",
33
+ "import": "./webpack/index.js",
34
+ "default": "./webpack/index.js"
35
+ }
27
36
  },
28
37
  "types": "./webpack/config.d.ts",
29
38
  "bin": {
30
- "ryunix": "./webpack/bin/index.mjs"
39
+ "ryunix": "./webpack/bin/index.js"
31
40
  },
32
41
  "engines": {
33
42
  "node": "^20 || ^22 || ^24"
34
43
  },
35
44
  "dependencies": {
36
- "@babel/cli": "7.28.3",
45
+ "@babel/cli": "7.28.6",
37
46
  "@babel/core": "7.28.5",
38
47
  "@babel/plugin-transform-react-jsx": "7.27.1",
39
48
  "@babel/preset-env": "7.28.5",
40
49
  "@babel/preset-react": "7.28.5",
41
50
  "@eslint/eslintrc": "3.3.3",
42
51
  "@eslint/js": "9.39.2",
43
- "@rollup/plugin-terser": "0.4.4",
52
+ "@mdx-js/loader": "3.1.1",
53
+ "@mdx-js/rollup": "3.1.1",
54
+ "@remark-embedder/core": "3.0.3",
55
+ "@remark-embedder/transformer-oembed": "5.0.1",
56
+ "@rollup/plugin-terser": "1.0.0",
44
57
  "@swc/core": "1.15.5",
58
+ "@vitejs/plugin-react-swc": "4.3.0",
45
59
  "babel-loader": "10.0.0",
60
+ "boxen": "8.0.1",
46
61
  "chalk": "5.6.2",
47
- "copy-webpack-plugin": "13.0.1",
62
+ "copy-webpack-plugin": "14.0.0",
48
63
  "css-loader": "7.1.2",
49
- "css-minimizer-webpack-plugin": "7.0.4",
50
- "sass": "1.97.0",
51
- "sass-loader": "16.0.6",
64
+ "css-minimizer-webpack-plugin": "8.0.0",
52
65
  "dotenv-webpack": "8.1.1",
53
66
  "eslint": "9.39.2",
54
- "eslint-plugin-react": "^7.37.5",
67
+ "eslint-plugin-mdx": "3.6.2",
68
+ "eslint-plugin-react": "7.37.5",
55
69
  "eslint-webpack-plugin": "5.0.2",
56
- "file-loader": "6.2.0",
57
- "glob": "13.0.0",
58
- "globals": "16.5.0",
70
+ "glob": "13.0.6",
71
+ "globals": "17.4.0",
59
72
  "html-loader": "5.1.0",
60
73
  "html-webpack-plugin": "5.6.5",
61
- "lodash": "4.17.21",
62
- "mini-css-extract-plugin": "2.9.4",
63
- "rollup": "4.53.5",
74
+ "jiti": "2.6.1",
75
+ "mini-css-extract-plugin": "2.10.1",
76
+ "postcss": "8.5.8",
77
+ "postcss-loader": "8.2.1",
78
+ "rehype-highlight": "7.0.2",
79
+ "remark-frontmatter": "5.0.0",
80
+ "remark-gfm": "4.0.1",
81
+ "remark-mdx-frontmatter": "5.2.0",
82
+ "rollup": "4.59.0",
83
+ "sass": "1.97.0",
84
+ "sass-loader": "16.0.7",
64
85
  "style-loader": "4.0.0",
86
+ "swc-loader": "0.2.7",
65
87
  "terminal-log": "1.0.1",
66
- "terser-webpack-plugin": "5.3.16",
67
- "url-loader": "4.1.1",
68
- "webpack": "5.104.0",
88
+ "terser-webpack-plugin": "5.4.0",
89
+ "thread-loader": "4.0.4",
90
+ "vite": "8.0.0",
91
+ "webpack": "5.105.4",
69
92
  "webpack-cli": "6.0.1",
70
93
  "webpack-dev-server": "5.2.2",
71
- "thread-loader": "4.0.4",
72
- "yargs": "18.0.0",
73
- "@mdx-js/loader": "3.1.1",
74
- "@mdx-js/rollup": "3.1.1",
75
- "eslint-plugin-mdx": "3.6.2",
76
- "remark-gfm": "4.0.1",
77
- "rehype-highlight": "7.0.2",
78
- "remark-frontmatter": "5.0.0",
79
- "remark-mdx-frontmatter": "5.2.0",
80
- "@remark-embedder/core": "3.0.3",
81
- "@remark-embedder/transformer-oembed": "5.0.1"
94
+ "yargs": "18.0.0"
95
+ },
96
+ "scripts": {
97
+ "typecheck": "tsc --noEmit -p tsconfig.json",
98
+ "build": "tsc -p tsconfig.emit.json && prettier -w \"webpack/**/*.js\"",
99
+ "test": "node --test webpack/plugins/remark-github-alerts.test.mjs"
82
100
  }
83
101
  }
@@ -1,6 +1,5 @@
1
- import webpack from 'webpack'
2
- import webpackConfig from '../webpack.config.mjs'
3
- webpackConfig.mode = 'production'
4
- const compiler = webpack(webpackConfig)
5
-
6
- export { compiler }
1
+ import webpack from 'webpack'
2
+ import webpackConfig from '../webpack.config.js'
3
+ webpackConfig.mode = 'production'
4
+ const compiler = webpack(webpackConfig)
5
+ export { compiler }
@@ -0,0 +1,6 @@
1
+ import webpack from 'webpack'
2
+ import webpackConfig from '../webpack.config.js'
3
+ ;(webpackConfig as webpack.Configuration).mode = 'production'
4
+ const compiler = webpack(webpackConfig as webpack.Configuration)
5
+
6
+ export { compiler }
@@ -0,0 +1,120 @@
1
+ import Webpack from 'webpack'
2
+ import WebpackDevServer from 'webpack-dev-server'
3
+ import webpackConfig from '../webpack.config.js'
4
+ import { configFileExist } from '../utils/settingfile.cjs'
5
+ import envPath from '../utils/envExist.cjs'
6
+ import { getPackageVersion, resolveApp, cleanCacheDir } from '../utils/index.js'
7
+ import logger from 'terminal-log'
8
+ import chalk from 'chalk'
9
+ import net from 'net' // Para verificar si el puerto está disponible
10
+ import boxen from 'boxen'
11
+ import defaultSettings from '../utils/config.cjs'
12
+ const checkPortInUse = (port) => {
13
+ return new Promise((resolve, reject) => {
14
+ const server = net.createServer()
15
+ server.once('error', (err) => {
16
+ if (err.code === 'EADDRINUSE') {
17
+ resolve(true) // Puerto en uso
18
+ } else {
19
+ reject(err)
20
+ }
21
+ })
22
+ server.once('listening', () => {
23
+ server.close()
24
+ resolve(false) // Puerto libre
25
+ })
26
+ server.listen(port)
27
+ })
28
+ }
29
+ const findAvailablePort = async (port) => {
30
+ let isPortInUse = await checkPortInUse(port)
31
+ while (isPortInUse) {
32
+ logger.warn(
33
+ chalk.yellow(`Port ${port} is in use, trying port ${port + 1}...`),
34
+ )
35
+ port += 1
36
+ isPortInUse = await checkPortInUse(port)
37
+ }
38
+ return port
39
+ }
40
+ const StartServer = async (cliSettings) => {
41
+ const cacheDir = resolveApp(
42
+ process.cwd(),
43
+ `${defaultSettings.buildDir}/cache`,
44
+ )
45
+ const mode =
46
+ cliSettings.production || defaultSettings.webpack.production ? true : false
47
+ if (!mode) {
48
+ cleanCacheDir(cacheDir)
49
+ }
50
+ const configs = webpackConfig
51
+ const clientConfig = Array.isArray(configs)
52
+ ? configs.find((c) => c.name === 'client') || configs[0]
53
+ : configs
54
+ if (Array.isArray(configs)) {
55
+ configs.forEach((c) => {
56
+ c.mode = mode ? 'production' : 'development'
57
+ })
58
+ } else {
59
+ configs.mode = mode ? 'production' : 'development'
60
+ }
61
+ const compiler = Array.isArray(configs) ? Webpack(configs) : Webpack(configs)
62
+ const clientDevServer = clientConfig.devServer
63
+ let port = clientDevServer?.port || 3000
64
+ // Encontrar un puerto disponible
65
+ port = await findAvailablePort(port)
66
+ // Modificamos el puerto en la configuración
67
+ if (clientDevServer) {
68
+ clientDevServer.port = port
69
+ }
70
+ const devServerOptions = { ...(clientDevServer || {}), ...cliSettings }
71
+ const server = new WebpackDevServer(devServerOptions, compiler)
72
+ const devMode = Boolean(!mode)
73
+ const { version } = await getPackageVersion()
74
+ const startServer = async () => {
75
+ try {
76
+ await server.start() // Iniciar el servidor con el nuevo puerto
77
+ const url = `http://localhost:${port}`
78
+ const cfgStatus = configFileExist()
79
+ ? chalk.green('✔ Loaded')
80
+ : chalk.red('✘ Not found')
81
+ const envStatus = envPath()
82
+ ? chalk.green('✔ Loaded')
83
+ : chalk.yellow('✘ Not found')
84
+ const modeLabel = mode
85
+ ? chalk.bold(chalk.magenta('production'))
86
+ : chalk.bold(chalk.cyan('development'))
87
+ const { version } = await getPackageVersion()
88
+ const content = [
89
+ `${chalk.bold(chalk.cyanBright('<Ryunix/>'))} ${chalk.gray(`v${version}`)}`,
90
+ '',
91
+ `${chalk.white('Ready at:')} ${chalk.underline(chalk.cyan(url))}`,
92
+ `${chalk.white('Config:')} ${cfgStatus}`,
93
+ `${chalk.white('Env:')} ${envStatus}`,
94
+ `${chalk.white('Mode:')} ${modeLabel}`,
95
+ ]
96
+ if (devMode) {
97
+ content.push('')
98
+ content.push(
99
+ `${chalk.yellow('⚠️')} ${chalk.yellow('Development mode active')}`,
100
+ )
101
+ content.push(chalk.gray('Build for production to optimize performance'))
102
+ }
103
+ console.log(
104
+ boxen(content.join('\n'), {
105
+ padding: 1,
106
+ margin: 1,
107
+ borderStyle: 'round',
108
+ borderColor: 'cyan',
109
+ title: chalk.bold('Dev Server'),
110
+ titleAlignment: 'center',
111
+ minimumWidth: 50,
112
+ }),
113
+ )
114
+ } catch (err) {
115
+ logger.error(`[error] ${err.message}`)
116
+ }
117
+ }
118
+ await startServer()
119
+ }
120
+ export { StartServer as StartDevServer }
@@ -0,0 +1,151 @@
1
+ import Webpack from 'webpack'
2
+ import WebpackDevServer from 'webpack-dev-server'
3
+ import webpackConfig from '../webpack.config.js'
4
+ import { configFileExist } from '../utils/settingfile.cjs'
5
+ import envPath from '../utils/envExist.cjs'
6
+ import { getPackageVersion, resolveApp, cleanCacheDir } from '../utils/index.js'
7
+ import logger from 'terminal-log'
8
+ import chalk from 'chalk'
9
+ import net from 'net' // Para verificar si el puerto está disponible
10
+ import boxen from 'boxen'
11
+ import defaultSettings from '../utils/config.cjs'
12
+
13
+ const checkPortInUse = (port) => {
14
+ return new Promise((resolve, reject) => {
15
+ const server = net.createServer()
16
+ server.once('error', (err: NodeJS.ErrnoException) => {
17
+ if (err.code === 'EADDRINUSE') {
18
+ resolve(true) // Puerto en uso
19
+ } else {
20
+ reject(err)
21
+ }
22
+ })
23
+ server.once('listening', () => {
24
+ server.close()
25
+ resolve(false) // Puerto libre
26
+ })
27
+ server.listen(port)
28
+ })
29
+ }
30
+
31
+ const findAvailablePort = async (port) => {
32
+ let isPortInUse = await checkPortInUse(port)
33
+ while (isPortInUse) {
34
+ logger.warn(
35
+ chalk.yellow(`Port ${port} is in use, trying port ${port + 1}...`),
36
+ )
37
+ port += 1
38
+ isPortInUse = await checkPortInUse(port)
39
+ }
40
+ return port
41
+ }
42
+
43
+ const StartServer = async (cliSettings) => {
44
+ const cacheDir = resolveApp(
45
+ process.cwd(),
46
+ `${defaultSettings.buildDir}/cache`,
47
+ )
48
+
49
+ const mode =
50
+ cliSettings.production || defaultSettings.webpack.production ? true : false
51
+
52
+ if (!mode) {
53
+ cleanCacheDir(cacheDir)
54
+ }
55
+
56
+ const configs = webpackConfig as
57
+ | Webpack.Configuration
58
+ | Webpack.Configuration[]
59
+ const clientConfig = Array.isArray(configs)
60
+ ? configs.find((c) => c.name === 'client') || configs[0]
61
+ : configs
62
+
63
+ if (Array.isArray(configs)) {
64
+ configs.forEach((c) => {
65
+ c.mode = mode ? 'production' : 'development'
66
+ })
67
+ } else {
68
+ configs.mode = mode ? 'production' : 'development'
69
+ }
70
+
71
+ const compiler = Array.isArray(configs)
72
+ ? Webpack(configs as Webpack.MultiConfiguration)
73
+ : Webpack(configs)
74
+ const clientDevServer = (
75
+ clientConfig as Webpack.Configuration & {
76
+ devServer?: WebpackDevServer.Configuration
77
+ }
78
+ ).devServer
79
+ let port = clientDevServer?.port || 3000
80
+
81
+ // Encontrar un puerto disponible
82
+ port = await findAvailablePort(port)
83
+
84
+ // Modificamos el puerto en la configuración
85
+ if (clientDevServer) {
86
+ clientDevServer.port = port
87
+ }
88
+ const devServerOptions = { ...(clientDevServer || {}), ...cliSettings }
89
+ const server = new WebpackDevServer(
90
+ devServerOptions as WebpackDevServer.Configuration,
91
+ compiler,
92
+ )
93
+
94
+ const devMode = Boolean(!mode)
95
+
96
+ const { version } = await getPackageVersion()
97
+
98
+ const startServer = async () => {
99
+ try {
100
+ await server.start() // Iniciar el servidor con el nuevo puerto
101
+
102
+ const url = `http://localhost:${port}`
103
+ const cfgStatus = configFileExist()
104
+ ? chalk.green('✔ Loaded')
105
+ : chalk.red('✘ Not found')
106
+ const envStatus = envPath()
107
+ ? chalk.green('✔ Loaded')
108
+ : chalk.yellow('✘ Not found')
109
+ const modeLabel = mode
110
+ ? chalk.bold(chalk.magenta('production'))
111
+ : chalk.bold(chalk.cyan('development'))
112
+
113
+ const { version } = await getPackageVersion()
114
+
115
+ const content = [
116
+ `${chalk.bold(chalk.cyanBright('<Ryunix/>'))} ${chalk.gray(`v${version}`)}`,
117
+ '',
118
+ `${chalk.white('Ready at:')} ${chalk.underline(chalk.cyan(url))}`,
119
+ `${chalk.white('Config:')} ${cfgStatus}`,
120
+ `${chalk.white('Env:')} ${envStatus}`,
121
+ `${chalk.white('Mode:')} ${modeLabel}`,
122
+ ]
123
+
124
+ if (devMode) {
125
+ content.push('')
126
+ content.push(
127
+ `${chalk.yellow('⚠️')} ${chalk.yellow('Development mode active')}`,
128
+ )
129
+ content.push(chalk.gray('Build for production to optimize performance'))
130
+ }
131
+
132
+ console.log(
133
+ boxen(content.join('\n'), {
134
+ padding: 1,
135
+ margin: 1,
136
+ borderStyle: 'round',
137
+ borderColor: 'cyan',
138
+ title: chalk.bold('Dev Server'),
139
+ titleAlignment: 'center',
140
+ minimumWidth: 50,
141
+ }),
142
+ )
143
+ } catch (err) {
144
+ logger.error(`[error] ${err.message}`)
145
+ }
146
+ }
147
+
148
+ await startServer()
149
+ }
150
+
151
+ export { StartServer as StartDevServer }