Skip to content

Commit 385b41a

Browse files
committed
convert hooks to async, added new console option called exit to determine if process.exit() should be called automatically at the end of the command
1 parent 947e957 commit 385b41a

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

lib/core/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ let config = {
5151
console: {
5252
use: true,
5353
quiet: false,
54+
exit: false,
5455
},
5556

5657
views: {

lib/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default new class {
9797
logger.info('hooks missing or invalid');
9898
}
9999

100-
hooks?.before_startup?.();
100+
await hooks?.before_startup?.();
101101

102102
/**
103103
* initialize database connection and models
@@ -128,6 +128,12 @@ export default new class {
128128
} else {
129129
logger.error(`no script called ${command} found`);
130130
}
131+
132+
await hooks?.before_shutdown?.();
133+
134+
if (config.console.exit) {
135+
process.exit(0);
136+
}
131137
} else {
132138
/**
133139
* initiate the express module
@@ -137,7 +143,7 @@ export default new class {
137143
await init_express();
138144
}
139145

140-
hooks?.after_startup?.();
146+
await hooks?.after_startup?.();
141147
} catch (err) {
142148
logger.error('exa uncaught exception:');
143149
handle_fatal_logging(err);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@exajs/core",
33
"type": "module",
44
"author": "Brian Seymour <@realtux>",
5-
"version": "0.0.26",
5+
"version": "0.0.27",
66
"description": "modern opinionated node.js framework",
77
"license": "MIT",
88
"homepage": "https://github.com/realtux/exa",

var/template/config/hooks.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
export default new class {
22

33
// runs before starting any modules but after configuration was loaded
4-
before_startup() {
4+
async before_startup() {
55

66
}
77

88
// runs after all modules have finished starting up
9-
after_startup() {
9+
async after_startup() {
10+
11+
}
12+
13+
// runs before a console command terminates
14+
async before_shutdown() {
1015

1116
}
1217

0 commit comments

Comments
 (0)