Skip to content

Commit bbc3ed1

Browse files
authored
Merge pull request #1 from StatelessStudio/github-v2.1.0
GitHub v2.1.0
2 parents 6d4fb2a + 8a87f36 commit bbc3ed1

8 files changed

Lines changed: 554 additions & 498 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# typescript-template
22

3+
## [2.1.0]
4+
5+
### Additions
6+
- [TSTEMPLATE-33] Add teardown function for graceful shutdown
7+
8+
### Fixes
9+
310
## [2.0.1]
411

512
### Fixes

package-lock.json

Lines changed: 515 additions & 465 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "typescript-template",
33
"version": "1.0.0",
4-
"ts-project-version": "2.0.1",
4+
"ts-project-version": "2.1.0",
55
"description": "typescript-template",
66
"scripts": {
77
"start": "npm run dev",
@@ -25,9 +25,9 @@
2525
"admin:example": "ts-node script/example"
2626
},
2727
"dependencies": {
28-
"ts-appconfig": "^1.0.0",
29-
"ts-async-bootstrap": "^2.0.0",
30-
"ts-error-handler": "^1.0.0",
28+
"ts-appconfig": "^1.2.0",
29+
"ts-async-bootstrap": "^2.1.0",
30+
"ts-error-handler": "^1.0.2",
3131
"ts-tiny-log": "^1.0.2"
3232
},
3333
"devDependencies": {

src/bootstrap.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,19 @@
22
* This file bootstraps your application by running the register function
33
* and setting up error handling.
44
*/
5-
import {
6-
bootstrap as _bootstrap,
7-
BootstrapFunction,
8-
BootstrapOptions
9-
} from 'ts-async-bootstrap';
5+
import { Bootstrap as _Bootstrap, RunFunction } from 'ts-async-bootstrap';
106

117
import { errorHandler } from './error-handler';
12-
import { register } from './register';
8+
import { register, teardown } from './register';
139

14-
/**
15-
* Default bootstrapping options
16-
*/
17-
export const defaultBootstrapOptions: Partial<BootstrapOptions> = {
18-
register: register,
19-
errorHandler: errorHandler,
20-
shouldExitOnError: true,
21-
};
10+
export class App extends _Bootstrap {
11+
onError = errorHandler;
12+
register = register;
13+
teardown = teardown;
14+
}
2215

23-
/**
24-
* Bootstrap a function
25-
*/
26-
export function bootstrap(
27-
run: BootstrapFunction,
28-
options?: Partial<BootstrapOptions>
29-
): void {
30-
_bootstrap({
31-
...defaultBootstrapOptions,
32-
...options,
33-
run: run
34-
});
16+
export const app = new App();
17+
18+
export function bootstrap(run: RunFunction) {
19+
app.boot(run);
3520
}

src/error-handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { setupErrorHandling } from 'ts-error-handler';
2+
import { app } from './bootstrap';
23
import { log } from './log';
34

45
/**
@@ -8,6 +9,8 @@ import { log } from './log';
89
*/
910
export function errorHandler(error: Error): void {
1011
log.fatal(error);
12+
13+
app.exit();
1114
}
1215

1316
// Setup error handling

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ bootstrap(main);
1212
/**
1313
* Documentation - Exported modules will appear in documentation
1414
*/
15-
export { bootstrap } from './bootstrap';
15+
export { App, app, bootstrap } from './bootstrap';
1616
export { Environment } from './environment';
1717
export { errorHandler } from './error-handler';

src/register.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
1+
import { log } from './log';
22

33
/**
44
* Initialize & register your app's services here
55
*/
66
export async function register(): Promise<void> {
7+
log.info('Booting...');
8+
79
// TODO: Register services here
810
}
11+
12+
/**
13+
* Teardown services here
14+
*/
15+
export async function teardown(): Promise<void> {
16+
log.info('Tearing down...');
17+
18+
// TODO: Teardown services here
19+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"target": "es6",
1313
"types": ["node"],
1414
"typeRoots": ["node_modules/@types", "./"],
15-
"lib": ["es2017"]
15+
"lib": ["es2020"]
1616
},
1717
"exclude": [
1818
"./dist/"

0 commit comments

Comments
 (0)