spooder 3.0.7 → 3.0.8
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/README.md +16 -3
- package/package.json +1 -1
- package/src/cli.ts +39 -21
package/README.md
CHANGED
|
@@ -71,13 +71,26 @@ When starting your server, `spooder` can automatically update the source code in
|
|
|
71
71
|
```json
|
|
72
72
|
{
|
|
73
73
|
"spooder": {
|
|
74
|
-
"update": "git pull
|
|
74
|
+
"update": "git pull"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
```
|
|
78
|
-
|
|
78
|
+
To execute multiple commands in sequence, provide an array rather than using the `&&` operator.
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"spooder": {
|
|
83
|
+
"update": [
|
|
84
|
+
"git pull",
|
|
85
|
+
"bun install"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If a command in the sequence fails, the remaining commands will not be executed. However, if the update fails, the server will still be started. This is preferred over entering a restart loop or failing to start the server at all.
|
|
92
|
+
|
|
93
|
+
As well as being executed when the server is first started, the `update` commands are also run when `spooder` automatically restarts the server after it exits.
|
|
81
94
|
|
|
82
95
|
You can utilize this to automatically update your server in response to a webhook or other event by simply exiting the process.
|
|
83
96
|
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -59,41 +59,59 @@ function log(message: string, ...args: unknown[]): void {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const config = await load_config();
|
|
62
|
-
const config_update_command = config.update as string ?? '';
|
|
63
62
|
const config_run_command = config.run as string ?? 'bun run index.ts';
|
|
64
63
|
const config_auto_restart_ms = config.autoRestart as number ?? 5000;
|
|
65
64
|
|
|
65
|
+
let config_update_commands = [] as string[];
|
|
66
|
+
if (config.update) {
|
|
67
|
+
if (typeof config.update === 'string')
|
|
68
|
+
config_update_commands = [config.update]
|
|
69
|
+
else if (Array.isArray(config.update))
|
|
70
|
+
config_update_commands = config.update;
|
|
71
|
+
}
|
|
72
|
+
|
|
66
73
|
async function start_server() {
|
|
67
74
|
log('start_server');
|
|
68
75
|
|
|
69
|
-
if (
|
|
70
|
-
log('running update
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
if (config_update_commands.length > 0) {
|
|
77
|
+
log('running %d update commands', config_update_commands.length);
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < config_update_commands.length; i++) {
|
|
80
|
+
const config_update_command = config_update_commands[i];
|
|
81
|
+
|
|
82
|
+
log('[%d] %s', i, config_update_command);
|
|
83
|
+
|
|
84
|
+
const update_proc = Bun.spawn(parse_command(config_update_command), {
|
|
85
|
+
cwd: process.cwd(),
|
|
86
|
+
stdout: 'inherit',
|
|
87
|
+
stderr: 'inherit'
|
|
88
|
+
});
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
await update_proc.exited;
|
|
91
|
+
|
|
92
|
+
log('[%d] exited with code %d', i, update_proc.exitCode);
|
|
93
|
+
|
|
94
|
+
if (update_proc.exitCode !== 0) {
|
|
95
|
+
log('aborting update due to non-zero exit code from [%d]', i);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
79
99
|
}
|
|
80
100
|
|
|
81
|
-
|
|
101
|
+
Bun.spawn(parse_command(config_run_command), {
|
|
82
102
|
cwd: process.cwd(),
|
|
83
103
|
stdout: 'inherit',
|
|
84
|
-
stderr: 'inherit'
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
log('server process started with pid %d', server_process.pid);
|
|
104
|
+
stderr: 'inherit',
|
|
88
105
|
|
|
89
|
-
|
|
90
|
-
|
|
106
|
+
onExit: (proc, exitCode, signal) => {
|
|
107
|
+
log('server exited with code %d', exitCode);
|
|
91
108
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
109
|
+
if (config_auto_restart_ms > -1) {
|
|
110
|
+
log('restarting server in %dms', config_auto_restart_ms);
|
|
111
|
+
setTimeout(start_server, config_auto_restart_ms);
|
|
112
|
+
}
|
|
95
113
|
}
|
|
96
114
|
});
|
|
97
115
|
}
|
|
98
116
|
|
|
99
|
-
start_server();
|
|
117
|
+
await start_server();
|