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

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 (80) hide show
  1. package/.generated/webpack/bin/compiler.js +5 -0
  2. package/.generated/webpack/bin/dev.server.js +115 -0
  3. package/.generated/webpack/bin/index.js +195 -0
  4. package/.generated/webpack/bin/prerender.js +88 -0
  5. package/.generated/webpack/bin/prod.server.js +356 -0
  6. package/.generated/webpack/config.typetest.js +15 -0
  7. package/.generated/webpack/eslint.config.js +41 -0
  8. package/.generated/webpack/index.js +4 -0
  9. package/.generated/webpack/loaders/ryunix-rsc-loader.js +104 -0
  10. package/.generated/webpack/loaders/ryunix-server-action-loader.js +77 -0
  11. package/.generated/webpack/plugins/remark-github-alerts.js +70 -0
  12. package/{webpack → .generated/webpack}/template/index.html +7 -0
  13. package/.generated/webpack/utils/ApiRouterPlugin.js +128 -0
  14. package/.generated/webpack/utils/apiHandler.js +154 -0
  15. package/.generated/webpack/utils/appRouterPlugin.js +813 -0
  16. package/.generated/webpack/utils/config.cjs +7 -0
  17. package/.generated/webpack/utils/config.js +192 -0
  18. package/.generated/webpack/utils/envExist.cjs +3 -0
  19. package/.generated/webpack/utils/envExist.js +10 -0
  20. package/.generated/webpack/utils/eslint-files.js +20 -0
  21. package/.generated/webpack/utils/index.js +172 -0
  22. package/.generated/webpack/utils/postcss-config.js +85 -0
  23. package/.generated/webpack/utils/routeMetadataFiles.js +137 -0
  24. package/.generated/webpack/utils/settingfile.cjs +8 -0
  25. package/.generated/webpack/utils/settingfile.js +41 -0
  26. package/.generated/webpack/utils/ssg.js +849 -0
  27. package/.generated/webpack/utils/ssgPlugin.js +504 -0
  28. package/.generated/webpack/utils/ssgStaticParams.js +120 -0
  29. package/.generated/webpack/utils/ssrDevHandler.js +138 -0
  30. package/.generated/webpack/utils/styleConfig.cjs +10 -0
  31. package/.generated/webpack/utils/styleConfig.js +66 -0
  32. package/.generated/webpack/utils/styleFonts.cjs +11 -0
  33. package/.generated/webpack/utils/styleFonts.js +128 -0
  34. package/.generated/webpack/webpack.config.js +918 -0
  35. package/package.json +13 -8
  36. package/webpack/config.d.ts +75 -0
  37. package/webpack/utils/config.cjs.d.ts +1 -0
  38. package/webpack/bin/compiler.js +0 -5
  39. package/webpack/bin/compiler.ts +0 -6
  40. package/webpack/bin/dev.server.js +0 -120
  41. package/webpack/bin/dev.server.ts +0 -151
  42. package/webpack/bin/index.js +0 -211
  43. package/webpack/bin/index.ts +0 -241
  44. package/webpack/bin/prerender.js +0 -53
  45. package/webpack/bin/prerender.ts +0 -62
  46. package/webpack/bin/prod.server.js +0 -343
  47. package/webpack/bin/prod.server.ts +0 -403
  48. package/webpack/config.typetest.js +0 -15
  49. package/webpack/config.typetest.ts +0 -17
  50. package/webpack/eslint.config.js +0 -39
  51. package/webpack/eslint.config.ts +0 -43
  52. package/webpack/index.js +0 -4
  53. package/webpack/index.ts +0 -6
  54. package/webpack/loaders/ryunix-rsc-loader.js +0 -112
  55. package/webpack/loaders/ryunix-rsc-loader.ts +0 -134
  56. package/webpack/loaders/ryunix-server-action-loader.js +0 -77
  57. package/webpack/loaders/ryunix-server-action-loader.ts +0 -86
  58. package/webpack/plugins/remark-github-alerts.js +0 -66
  59. package/webpack/plugins/remark-github-alerts.test.mjs +0 -73
  60. package/webpack/plugins/remark-github-alerts.ts +0 -90
  61. package/webpack/types/presets-shims.d.ts +0 -26
  62. package/webpack/utils/ApiRouterPlugin.js +0 -135
  63. package/webpack/utils/ApiRouterPlugin.ts +0 -160
  64. package/webpack/utils/apiHandler.js +0 -148
  65. package/webpack/utils/apiHandler.ts +0 -172
  66. package/webpack/utils/appRouterPlugin.js +0 -586
  67. package/webpack/utils/appRouterPlugin.ts +0 -656
  68. package/webpack/utils/config.cjs +0 -263
  69. package/webpack/utils/envExist.cjs +0 -14
  70. package/webpack/utils/index.js +0 -172
  71. package/webpack/utils/index.ts +0 -205
  72. package/webpack/utils/settingfile.cjs +0 -60
  73. package/webpack/utils/ssg.js +0 -798
  74. package/webpack/utils/ssg.ts +0 -882
  75. package/webpack/utils/ssgPlugin.js +0 -507
  76. package/webpack/utils/ssgPlugin.ts +0 -626
  77. package/webpack/utils/ssrDevHandler.js +0 -110
  78. package/webpack/utils/ssrDevHandler.ts +0 -125
  79. package/webpack/webpack.config.js +0 -877
  80. package/webpack/webpack.config.ts +0 -900
@@ -0,0 +1,5 @@
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,115 @@
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.js';
5
+ import envPath from '../utils/envExist.js';
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.js';
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
+ }
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
+ const findAvailablePort = async (port) => {
31
+ let isPortInUse = await checkPortInUse(port);
32
+ while (isPortInUse) {
33
+ logger.warn(chalk.yellow(`Port ${port} is in use, trying port ${port + 1}...`));
34
+ port += 1;
35
+ isPortInUse = await checkPortInUse(port);
36
+ }
37
+ return port;
38
+ };
39
+ const StartServer = async (cliSettings) => {
40
+ const cacheDir = resolveApp(process.cwd(), `${defaultSettings.buildDir}/cache`);
41
+ const mode = cliSettings.production || defaultSettings.webpack.production ? true : false;
42
+ if (!mode) {
43
+ cleanCacheDir(cacheDir);
44
+ }
45
+ const configs = webpackConfig;
46
+ const clientConfig = Array.isArray(configs)
47
+ ? configs.find((c) => c.name === 'client') || configs[0]
48
+ : configs;
49
+ if (Array.isArray(configs)) {
50
+ configs.forEach((c) => {
51
+ c.mode = mode ? 'production' : 'development';
52
+ });
53
+ }
54
+ else {
55
+ configs.mode = mode ? 'production' : 'development';
56
+ }
57
+ const compiler = Array.isArray(configs)
58
+ ? Webpack(configs)
59
+ : Webpack(configs);
60
+ const clientDevServer = clientConfig.devServer;
61
+ let port = Number(clientDevServer?.port) || 3000;
62
+ // Encontrar un puerto disponible
63
+ port = await findAvailablePort(port);
64
+ // Modificamos el puerto en la configuración
65
+ if (clientDevServer) {
66
+ clientDevServer.port = port;
67
+ }
68
+ const devServerOptions = { ...(clientDevServer || {}), ...cliSettings };
69
+ const server = new WebpackDevServer(devServerOptions, compiler);
70
+ const devMode = Boolean(!mode);
71
+ const startServer = async () => {
72
+ try {
73
+ await server.start(); // Iniciar el servidor con el nuevo puerto
74
+ const url = `http://localhost:${port}`;
75
+ const cfgStatus = configFileExist()
76
+ ? chalk.green('✔ Loaded')
77
+ : chalk.red('✘ Not found');
78
+ const envStatus = envPath()
79
+ ? chalk.green('✔ Loaded')
80
+ : chalk.yellow('✘ Not found');
81
+ const modeLabel = mode
82
+ ? chalk.bold(chalk.magenta('production'))
83
+ : chalk.bold(chalk.cyan('development'));
84
+ const { version } = await getPackageVersion();
85
+ const content = [
86
+ `${chalk.bold(chalk.cyanBright('<Ryunix/>'))} ${chalk.gray(`v${version}`)}`,
87
+ '',
88
+ `${chalk.white('Ready at:')} ${chalk.underline(chalk.cyan(url))}`,
89
+ `${chalk.white('Config:')} ${cfgStatus}`,
90
+ `${chalk.white('Env:')} ${envStatus}`,
91
+ `${chalk.white('Mode:')} ${modeLabel}`,
92
+ ];
93
+ if (devMode) {
94
+ content.push('');
95
+ content.push(`${chalk.yellow('⚠️')} ${chalk.yellow('Development mode active')}`);
96
+ content.push(chalk.gray('Build for production to optimize performance'));
97
+ }
98
+ console.log(boxen(content.join('\n'), {
99
+ padding: 1,
100
+ margin: 1,
101
+ borderStyle: 'round',
102
+ borderColor: 'cyan',
103
+ title: chalk.bold('Dev Server'),
104
+ titleAlignment: 'center',
105
+ minimumWidth: 50,
106
+ }));
107
+ }
108
+ catch (err) {
109
+ const message = err instanceof Error ? err.message : String(err);
110
+ logger.error(`[error] ${message}`);
111
+ }
112
+ };
113
+ await startServer();
114
+ };
115
+ export { StartServer as StartDevServer };
@@ -0,0 +1,195 @@
1
+ #! /usr/bin/env node
2
+ import yargs from 'yargs';
3
+ const hideBin = (argv) => argv.slice(2);
4
+ import { StartDevServer } from './dev.server.js';
5
+ import { compiler } from './compiler.js';
6
+ import logger from 'terminal-log';
7
+ import chalk from 'chalk';
8
+ import boxen from 'boxen';
9
+ import defaultSettings from '../utils/config.js';
10
+ import Prerender from './prerender.js';
11
+ import { resolveApp, getPackageVersion } from '../utils/index.js';
12
+ import { ESLint } from 'eslint';
13
+ import eslintConfig from '../eslint.config.js';
14
+ import fs from 'fs';
15
+ import { fileURLToPath } from 'url';
16
+ import { dirname, join } from 'path';
17
+ import server from './prod.server.js';
18
+ import config from '../utils/config.js';
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = dirname(__filename);
21
+ const lint = {
22
+ command: 'lint',
23
+ describe: 'Lint code',
24
+ builder: {
25
+ fix: {
26
+ alias: 'f',
27
+ type: 'boolean',
28
+ default: false,
29
+ describe: 'Automatically fix problems',
30
+ },
31
+ },
32
+ handler: async (arg) => {
33
+ const classicConfig = eslintConfig[0];
34
+ const fix = arg.fix;
35
+ const eslint = new ESLint({
36
+ cwd: process.cwd(),
37
+ overrideConfigFile: true,
38
+ overrideConfig: classicConfig,
39
+ fix,
40
+ });
41
+ const results = await eslint.lintFiles(defaultSettings.eslint.files);
42
+ await ESLint.outputFixes(results);
43
+ const formatter = await eslint.loadFormatter('stylish');
44
+ const report = formatter.format(results);
45
+ console.log(report);
46
+ },
47
+ };
48
+ const dev = {
49
+ command: 'dev',
50
+ describe: 'Run server for developer mode.',
51
+ handler: async (arg) => {
52
+ process.env.RYUNIX_MODE = 'development';
53
+ const open = Boolean(arg.browser) || false;
54
+ const settings = {
55
+ open,
56
+ };
57
+ // add message to say the server is starting with chalk
58
+ console.log(chalk.cyan('Starting development server, please wait...'));
59
+ console.log(`${chalk.cyan('○')} Compiler: ${chalk.bold(config.compiler.toUpperCase())}`);
60
+ try {
61
+ await StartDevServer(settings);
62
+ }
63
+ catch (error) {
64
+ logger.error(chalk.red('Error starting development server:'), error);
65
+ process.exit(1);
66
+ }
67
+ },
68
+ };
69
+ const prod = {
70
+ command: 'start',
71
+ describe: 'Run server for production mode. Requiere .ryunix/static',
72
+ handler: async (_arg) => {
73
+ process.env.RYUNIX_MODE = 'production';
74
+ if (!fs.existsSync(join(process.cwd(), config.buildDir, 'static'))) {
75
+ logger.error('You need build first!');
76
+ return;
77
+ }
78
+ const { version } = await getPackageVersion();
79
+ server.listen(config.port, () => {
80
+ const content = [
81
+ `${chalk.bold(chalk.cyanBright('<Ryunix/>'))} ${chalk.gray(`v${version}`)}`,
82
+ '',
83
+ `${chalk.white('Ready at:')} ${chalk.underline(chalk.cyan(`http://localhost:${config.port}/`))}`,
84
+ `${chalk.white('Mode:')} ${chalk.bold(chalk.magenta('production'))}`,
85
+ ];
86
+ console.log(boxen(content.join('\n'), {
87
+ padding: 1,
88
+ margin: 1,
89
+ borderStyle: 'round',
90
+ borderColor: 'magenta',
91
+ title: chalk.bold('Production Server'),
92
+ titleAlignment: 'center',
93
+ minimumWidth: 50,
94
+ }));
95
+ });
96
+ },
97
+ };
98
+ const build = {
99
+ command: 'build',
100
+ describe: 'Run builder',
101
+ handler: async (_arg) => {
102
+ process.env.RYUNIX_MODE = 'production';
103
+ // ── Clean build output before each production build ───────────────────
104
+ // Clears static/ and server/ (except server/api/) but keeps cache/ intact.
105
+ const buildRoot = resolveApp(process.cwd(), defaultSettings.buildDir);
106
+ const clean = (dir) => {
107
+ if (fs.existsSync(dir)) {
108
+ fs.rmSync(dir, { recursive: true, force: true });
109
+ }
110
+ };
111
+ clean(join(buildRoot, 'static'));
112
+ clean(join(buildRoot, 'server', 'app'));
113
+ clean(join(buildRoot, 'server', 'app-router-server.bundle.js'));
114
+ // Note: server/api/ is cleaned by ApiRouterPlugin on its own (incremental recompile)
115
+ console.log(`${chalk.cyan('○')} Compiling using ${chalk.bold(config.compiler.toUpperCase())}...`);
116
+ const buildStart = Date.now();
117
+ compiler.run(async (err, stats) => {
118
+ if (err || !stats || stats.hasErrors()) {
119
+ logger.error(chalk.red('✘ Error during compilation:'));
120
+ if (err) {
121
+ logger.error(err);
122
+ }
123
+ else {
124
+ // MultiStats or Stats — toString works on both
125
+ const output = stats.toString('errors-only');
126
+ const lines = output.split('\n').filter(Boolean);
127
+ lines.forEach((line) => logger.error(line));
128
+ }
129
+ compiler.close(() => process.exit(1));
130
+ return;
131
+ }
132
+ // ── Build time ─────────────────────────────────────────────────────────
133
+ const buildTimeMs = Date.now() - buildStart;
134
+ const minutes = Math.floor(buildTimeMs / 60000);
135
+ const seconds = ((buildTimeMs % 60000) / 1000).toFixed(1);
136
+ const formattedTime = minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`;
137
+ // ── SSG Prerender ──────────────────────────────────────────────────────
138
+ if (defaultSettings.webpack.production) {
139
+ await Prerender(defaultSettings.buildDir);
140
+ }
141
+ // ── API Routes log ─────────────────────────────────────────────────────
142
+ const apiOutputDir = join(buildRoot, 'server', 'api');
143
+ if (fs.existsSync(apiOutputDir)) {
144
+ const collectRoutes = (dir, base = '') => {
145
+ const routes = [];
146
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
147
+ const fullPath = join(dir, entry.name);
148
+ if (entry.isDirectory()) {
149
+ routes.push(...collectRoutes(fullPath, `${base}/${entry.name}`));
150
+ }
151
+ else if (/^(route|router|endpoint)\.(mjs|js)$/.test(entry.name)) {
152
+ routes.push(base || '/');
153
+ }
154
+ }
155
+ return routes;
156
+ };
157
+ const apiRoutes = collectRoutes(apiOutputDir);
158
+ if (apiRoutes.length > 0) {
159
+ console.log(`${chalk.cyan('○')} API routes (${chalk.bold(apiRoutes.length)}):`);
160
+ apiRoutes.forEach((r) => console.log(` ${chalk.green('✔')} ${chalk.gray(`/api${r}`)}`));
161
+ console.log('');
162
+ }
163
+ }
164
+ logger.info(`${chalk.green('✔')} ${chalk.bold('Compilation successful! 🎉')}`);
165
+ logger.info(`${chalk.gray('Done in')} ${chalk.bold(formattedTime)}`);
166
+ compiler.close((closeErr) => {
167
+ if (closeErr) {
168
+ logger.error(chalk.red('Error closing the compiler:'), closeErr);
169
+ }
170
+ process.exit(0);
171
+ });
172
+ });
173
+ },
174
+ };
175
+ const extractHTML = {
176
+ command: 'customHtml',
177
+ describe: 'Extract HTML for customization',
178
+ handler: async (_arg) => {
179
+ const runPath = process.cwd();
180
+ fs.copyFile(join(__dirname, '..', 'template/index.html'), join(runPath, 'public/index.html'), (err) => {
181
+ if (err) {
182
+ console.error('Error extracting HTML: ', err.message);
183
+ return;
184
+ }
185
+ console.log('File extracted successfully. Now you can enable the template with legacy.template inside ryunix.config.js');
186
+ });
187
+ },
188
+ };
189
+ yargs(hideBin(process.argv))
190
+ .command(dev)
191
+ .command(build)
192
+ .command(prod)
193
+ .command(lint)
194
+ .command(extractHTML)
195
+ .parse();
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Automatic Prerender - reads routes from manifest
3
+ */
4
+ import { buildSSG } from '../utils/ssg.js';
5
+ import { configFileExist } from '../utils/settingfile.js';
6
+ import defaultSettings from '../utils/config.js';
7
+ import { resolveApp } from '../utils/index.js';
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ const loadResolvedSSGRoutes = async (buildDirectory) => {
11
+ const serverBundleCandidates = [
12
+ path.join(buildDirectory, 'server', 'app-router-server.bundle.js'),
13
+ path.join(buildDirectory, 'server', 'app-router-server.bundle.mjs'),
14
+ ];
15
+ const serverBundlePath = serverBundleCandidates.find((candidate) => fs.existsSync(candidate));
16
+ if (!serverBundlePath)
17
+ return null;
18
+ try {
19
+ const serverModule = await import(`file://${serverBundlePath}?update=${Date.now()}`);
20
+ if (typeof serverModule.resolveSSGPaths === 'function') {
21
+ return await serverModule.resolveSSGPaths();
22
+ }
23
+ }
24
+ catch (error) {
25
+ const message = error instanceof Error ? error.message : String(error);
26
+ console.warn('[SSG] Could not resolve dynamic routes from server bundle:', message);
27
+ }
28
+ return null;
29
+ };
30
+ const normalizeManifestRoutes = (routes) => routes
31
+ .filter((route) => route && route.path && !route.path.includes(':'))
32
+ .map((route) => ({
33
+ path: route.path,
34
+ meta: route.meta || {},
35
+ }));
36
+ const Prerender = async (directory) => {
37
+ const buildDirectory = resolveApp(process.cwd(), directory);
38
+ if (!configFileExist()) {
39
+ console.error('❌ No configuration file found.');
40
+ process.exit(1);
41
+ }
42
+ const manifestPath = path.join(process.cwd(), directory, 'cache/ssg', 'routes.json');
43
+ let routes = [];
44
+ if (fs.existsSync(manifestPath)) {
45
+ try {
46
+ routes = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
47
+ }
48
+ catch (error) {
49
+ console.error('[SSG] Error reading routes manifest:', error);
50
+ }
51
+ }
52
+ const resolvedRoutes = await loadResolvedSSGRoutes(buildDirectory);
53
+ if (resolvedRoutes) {
54
+ routes = resolvedRoutes;
55
+ if (defaultSettings.debug) {
56
+ console.log(`[SSG] Resolved ${routes.length} routes via generateStaticParams`);
57
+ }
58
+ }
59
+ else {
60
+ routes = normalizeManifestRoutes(routes);
61
+ }
62
+ const metaExist = routes.some((route) => route.meta);
63
+ if (metaExist &&
64
+ Object.keys(defaultSettings.legacy?.seo?.meta || {}).length > 0) {
65
+ console.error('[Ryunix Error] You are mixing static and dynamic meta tags; you can only use one of the two. Remove legacy.seo.meta from ryunix.config.js.');
66
+ process.exit(1);
67
+ }
68
+ if (routes.length === 0) {
69
+ const legacyRoutes = defaultSettings.legacy?.ssg?.prerender || [];
70
+ routes = legacyRoutes.map((route) => typeof route === 'string' ? { path: route, meta: {} } : route);
71
+ if (routes.length > 0) {
72
+ console.log(`[SSG] Using ${routes.length} routes from config`);
73
+ }
74
+ }
75
+ if (routes.length === 0) {
76
+ console.log('[SSG] No routes to prerender, skipping SSG generation.');
77
+ return;
78
+ }
79
+ try {
80
+ await buildSSG(routes, defaultSettings, buildDirectory, defaultSettings.debug);
81
+ }
82
+ catch (error) {
83
+ console.error(error instanceof Error ? error.message : error);
84
+ process.exit(1);
85
+ }
86
+ console.log('✅ SSG build complete');
87
+ };
88
+ export default Prerender;