miolo 2.0.0-beta.13 → 2.0.0-beta.15
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/bin/dev.mjs +29 -13
- package/dist/cli/miolo.cli.umd.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.js +1 -1
- package/dist/server/miolo.server.node.mjs +76 -3
- package/package.json +1 -1
- package/src/server/index.mjs +2 -0
- package/src/server/middleware/vite/watcher.mjs +14 -13
- package/src/server/server-cron.mjs +39 -0
- package/src/server/server.mjs +3 -0
package/bin/dev.mjs
CHANGED
|
@@ -5,13 +5,24 @@ let serverProcess = null
|
|
|
5
5
|
// let retryCount = 0
|
|
6
6
|
// const maxRetries = 5
|
|
7
7
|
|
|
8
|
+
function _isProcessRunning(pid) {
|
|
9
|
+
try {
|
|
10
|
+
process.kill(pid, 0) // Sending a signal 0 does nothing but checks if the process exists
|
|
11
|
+
return true
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return false
|
|
14
|
+
}
|
|
15
|
+
}
|
|
8
16
|
|
|
9
17
|
async function startDevServerProcess({ appName, entry }) {
|
|
10
18
|
const serverPath = path.join(process.cwd(), entry)
|
|
11
19
|
serverProcess = fork(serverPath)
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
console.log(`[${appName}][dev] Server process started with pid ${serverProcess.pid} from ${process.pid}`)
|
|
22
|
+
|
|
23
|
+
serverProcess.on('exit', (code, args) => {
|
|
24
|
+
console.log(`[${appName}][dev] Server process exited with code ${code} - ${args}`)
|
|
25
|
+
serverProcess = null
|
|
15
26
|
// Puedes implementar lógica de reintento aquí si es necesario
|
|
16
27
|
// if (code !== 0 && retryCount < maxRetries) {
|
|
17
28
|
// retryCount++
|
|
@@ -26,15 +37,23 @@ async function startDevServerProcess({ appName, entry }) {
|
|
|
26
37
|
})
|
|
27
38
|
|
|
28
39
|
serverProcess.on('message', (message) => {
|
|
29
|
-
if (message === '
|
|
40
|
+
if (message === 'miolo_restart') {
|
|
30
41
|
console.log(`[${appName}][dev] Received restart signal. Restarting server...`)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
|
|
43
|
+
const pidToKill = serverProcess ? serverProcess.pid : null
|
|
44
|
+
if (pidToKill) {
|
|
45
|
+
console.log(`[${appName}][dev] Killing process with PID: ${pidToKill}`)
|
|
46
|
+
// Clean kill
|
|
47
|
+
process.kill(pidToKill, 'SIGTERM')
|
|
48
|
+
|
|
49
|
+
// Harder if still alive
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
if (_isProcessRunning(pidToKill)) {
|
|
52
|
+
process.kill(pidToKill, 'SIGKILL')
|
|
53
|
+
}
|
|
54
|
+
}, 2000)
|
|
55
|
+
}
|
|
56
|
+
|
|
38
57
|
startDevServerProcess({ appName, entry }) // Inicia un nuevo proceso
|
|
39
58
|
}
|
|
40
59
|
})
|
|
@@ -43,9 +62,6 @@ async function startDevServerProcess({ appName, entry }) {
|
|
|
43
62
|
|
|
44
63
|
export default async function({ appName, entry, serverName }) {
|
|
45
64
|
console.log(`[${appName}][dev] Running DEV server ${serverName} from entry ${entry}`)
|
|
46
|
-
// const srv_module = await import(path.join(process.cwd(), entry))
|
|
47
|
-
// const server = srv_module[serverName]
|
|
48
|
-
// await server()
|
|
49
65
|
await startDevServerProcess({ appName, entry })
|
|
50
66
|
}
|
|
51
67
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v2.0.0-beta.
|
|
2
|
+
* miolo v2.0.0-beta.15
|
|
3
3
|
*
|
|
4
4
|
* https://www.afialapis.com/os/miolo
|
|
5
5
|
*
|
|
@@ -8004,7 +8004,10 @@ function _miolo() {
|
|
|
8004
8004
|
return app.http.stop();
|
|
8005
8005
|
case 3:
|
|
8006
8006
|
app.cron.stop();
|
|
8007
|
-
|
|
8007
|
+
if (app != null && app.vite) {
|
|
8008
|
+
app.vite.close();
|
|
8009
|
+
}
|
|
8010
|
+
case 5:
|
|
8008
8011
|
case "end":
|
|
8009
8012
|
return _context2.stop();
|
|
8010
8013
|
}
|
|
@@ -8038,4 +8041,74 @@ function _miolo() {
|
|
|
8038
8041
|
return _miolo.apply(this, arguments);
|
|
8039
8042
|
}
|
|
8040
8043
|
|
|
8041
|
-
|
|
8044
|
+
function miolo_cron(_x) {
|
|
8045
|
+
return _miolo_cron.apply(this, arguments);
|
|
8046
|
+
}
|
|
8047
|
+
function _miolo_cron() {
|
|
8048
|
+
_miolo_cron = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(sconfig) {
|
|
8049
|
+
var app, config;
|
|
8050
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
8051
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
8052
|
+
case 0:
|
|
8053
|
+
app = {
|
|
8054
|
+
use: function use() {}
|
|
8055
|
+
}; // Init some pieces
|
|
8056
|
+
config = init_config(sconfig); // attach to app some custom miolo methods
|
|
8057
|
+
init_context_middleware(app, config);
|
|
8058
|
+
|
|
8059
|
+
// Init cron (will not start jobs yet)
|
|
8060
|
+
init_cron(app, config == null ? void 0 : config.cron);
|
|
8061
|
+
|
|
8062
|
+
// Util callbacks
|
|
8063
|
+
app.start = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
8064
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
8065
|
+
while (1) switch (_context.prev = _context.next) {
|
|
8066
|
+
case 0:
|
|
8067
|
+
_context.next = 2;
|
|
8068
|
+
return app.context.miolo.db.init_connection();
|
|
8069
|
+
case 2:
|
|
8070
|
+
app.cron.start();
|
|
8071
|
+
case 3:
|
|
8072
|
+
case "end":
|
|
8073
|
+
return _context.stop();
|
|
8074
|
+
}
|
|
8075
|
+
}, _callee);
|
|
8076
|
+
}));
|
|
8077
|
+
app.stop = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
8078
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
8079
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
8080
|
+
case 0:
|
|
8081
|
+
app.context.miolo.db.drop_connections();
|
|
8082
|
+
app.cron.stop();
|
|
8083
|
+
case 2:
|
|
8084
|
+
case "end":
|
|
8085
|
+
return _context2.stop();
|
|
8086
|
+
}
|
|
8087
|
+
}, _callee2);
|
|
8088
|
+
}));
|
|
8089
|
+
app.restart = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
8090
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
8091
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
8092
|
+
case 0:
|
|
8093
|
+
_context3.next = 2;
|
|
8094
|
+
return app.stop();
|
|
8095
|
+
case 2:
|
|
8096
|
+
_context3.next = 4;
|
|
8097
|
+
return app.start();
|
|
8098
|
+
case 4:
|
|
8099
|
+
case "end":
|
|
8100
|
+
return _context3.stop();
|
|
8101
|
+
}
|
|
8102
|
+
}, _callee3);
|
|
8103
|
+
}));
|
|
8104
|
+
return _context4.abrupt("return", app);
|
|
8105
|
+
case 8:
|
|
8106
|
+
case "end":
|
|
8107
|
+
return _context4.stop();
|
|
8108
|
+
}
|
|
8109
|
+
}, _callee4);
|
|
8110
|
+
}));
|
|
8111
|
+
return _miolo_cron.apply(this, arguments);
|
|
8112
|
+
}
|
|
8113
|
+
|
|
8114
|
+
export { miolo, miolo_cron, init_emailer_transporter as miolo_emailer, init_logger as miolo_logger, init_parser as miolo_parser };
|
package/package.json
CHANGED
package/src/server/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { miolo } from './server.mjs'
|
|
2
|
+
import { miolo_cron } from './server-cron.mjs'
|
|
2
3
|
import { init_emailer_transporter as miolo_emailer} from './engines/emailer/index.mjs'
|
|
3
4
|
import { init_logger as miolo_logger } from './engines/logger/index.mjs'
|
|
4
5
|
import { init_parser as miolo_parser } from './engines/parser/index.mjs'
|
|
@@ -8,6 +9,7 @@ import { getConnection as miolo_db_connection} from 'calustra/conn-postgres'
|
|
|
8
9
|
|
|
9
10
|
export {
|
|
10
11
|
miolo,
|
|
12
|
+
miolo_cron,
|
|
11
13
|
miolo_emailer,
|
|
12
14
|
miolo_logger,
|
|
13
15
|
miolo_parser,
|
|
@@ -14,27 +14,28 @@ export async function init_watcher_dev_server_middleware(app, watcherConfig, ssr
|
|
|
14
14
|
watcher = app.vite.watcher
|
|
15
15
|
|
|
16
16
|
// Extra dirs to watch
|
|
17
|
-
const serverDirsToWatch = watcherConfig?.dirs || [
|
|
18
|
-
path.resolve(process.cwd(), path.basename(ssrConfig.server))
|
|
19
|
-
]
|
|
17
|
+
const serverDirsToWatch = watcherConfig?.dirs || ['server', 'src/server']
|
|
20
18
|
|
|
21
19
|
// Listen to changes in the extra dirs
|
|
22
20
|
serverDirsToWatch.forEach((dir) => {
|
|
23
|
-
watcher.add(dir)
|
|
24
|
-
app.context.miolo.logger.info(`[watcher] Vite is now watching for changes in: ${dir}`)
|
|
21
|
+
watcher.add(path.resolve(process.cwd(), dir))
|
|
22
|
+
app.context.miolo.logger.info(`[watcher] Vite is now watching for changes also in: ${dir}`)
|
|
25
23
|
})
|
|
26
24
|
|
|
27
25
|
// Listen to changes in the extra dirs
|
|
28
|
-
watcher.on('change', (filePath) => {
|
|
26
|
+
watcher.on('change', async (filePath) => {
|
|
27
|
+
let isCustom = false
|
|
28
|
+
serverDirsToWatch.forEach((dir) => {
|
|
29
|
+
if (filePath.startsWith(path.resolve(process.cwd(), dir))) {
|
|
30
|
+
isCustom = true
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
if (!isCustom) return // Ignore changes outside the custom watched directories
|
|
29
34
|
app.context.miolo.logger.info(`[watcher] File changed: ${filePath}. Reloading server...`)
|
|
30
|
-
// Aquí puedes implementar la lógica para reiniciar tu servidor Koa
|
|
31
|
-
// Por ejemplo, podrías cerrar el servidor actual y crear uno nuevo,
|
|
32
|
-
// o usar alguna forma de recarga en caliente específica de Koa (si existe).
|
|
33
|
-
// Un reinicio completo del proceso de Node.js suele ser la forma más segura.
|
|
34
|
-
//process.exit(0) // Forzar la salida del proceso para que un gestor de procesos lo reinicie
|
|
35
|
-
process.send('restart') // Envía un mensaje al proceso padre para reiniciar
|
|
36
|
-
})
|
|
37
35
|
|
|
36
|
+
await app.stop()
|
|
37
|
+
process.send('miolo_restart') // Envía un mensaje al proceso padre para reiniciar
|
|
38
|
+
})
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
app.watcher= watcher
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { init_config } from './config/index.mjs'
|
|
2
|
+
import { init_context_middleware } from './middleware/context/index.mjs'
|
|
3
|
+
import { init_cron } from './engines/cron/index.mjs'
|
|
4
|
+
|
|
5
|
+
export async function miolo_cron(sconfig) {
|
|
6
|
+
|
|
7
|
+
const app = {
|
|
8
|
+
use: () => {},
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Init some pieces
|
|
12
|
+
const config = init_config(sconfig)
|
|
13
|
+
|
|
14
|
+
// attach to app some custom miolo methods
|
|
15
|
+
init_context_middleware(app, config)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// Init cron (will not start jobs yet)
|
|
19
|
+
init_cron(app, config?.cron)
|
|
20
|
+
|
|
21
|
+
// Util callbacks
|
|
22
|
+
app.start = async () => {
|
|
23
|
+
// Init and reset db connection
|
|
24
|
+
await app.context.miolo.db.init_connection()
|
|
25
|
+
app.cron.start()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
app.stop = async () => {
|
|
29
|
+
app.context.miolo.db.drop_connections()
|
|
30
|
+
app.cron.stop()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
app.restart = async () => {
|
|
34
|
+
await app.stop()
|
|
35
|
+
await app.start()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return app
|
|
39
|
+
}
|
package/src/server/server.mjs
CHANGED
|
@@ -119,6 +119,9 @@ async function miolo(sconfig, devInit= undefined, devRender= undefined) {
|
|
|
119
119
|
app.context.miolo.db.drop_connections()
|
|
120
120
|
await app.http.stop()
|
|
121
121
|
app.cron.stop()
|
|
122
|
+
if (app?.vite) {
|
|
123
|
+
app.vite.close()
|
|
124
|
+
}
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
app.restart = async () => {
|