File tree 3 files changed +45
-1
lines changed
3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ You can use it like on example below.
12
12
App will exit if there at least on step is failed.
13
13
Check all connections before starting server:
14
14
15
- You can create file for your services like ` startServices .ts`
15
+ You can create file for your services like ` service-startup .ts`
16
16
``` typescript
17
17
import colors from ' colors'
18
18
import starter from ' service-startup'
Original file line number Diff line number Diff line change 1
1
import stepsList , { StarterStep } from './stepsList'
2
2
import executeStep , { ExecuteStepConfig } from './executeStep'
3
+ import resolveUtils from './utils/resolveUtils'
3
4
4
5
export interface StarterConfig extends ExecuteStepConfig {
5
6
}
6
7
7
8
async function starter ( steps : StarterStep [ ] , config ?: StarterConfig ) {
9
+ const path = resolveUtils . resolvePathFromRoot ( 'service-startup' )
10
+ try {
11
+ require ( path )
12
+ } catch ( e ) {
13
+ // seems file is not created...
14
+ }
15
+
8
16
const date = new Date ( )
9
17
console . log ( `
10
18
********************************************************
Original file line number Diff line number Diff line change
1
+ import path from 'path'
2
+
3
+ function resolvePathFromRoot ( filePath : string ) : string {
4
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
+ // @ts -ignore not sure issue can happen. Waiting for crash first.
6
+ let rootPath = process . env . PWD as string // require.main?.path
7
+ return path . resolve ( rootPath , filePath )
8
+ }
9
+
10
+
11
+ function resolveMigration ( fileName : string ) {
12
+ const filePath = `./${ getMigrationPath ( fileName ) } `
13
+
14
+ const pathAbsolute = resolvePathFromRoot ( filePath )
15
+
16
+ return importFile ( pathAbsolute )
17
+ }
18
+
19
+ function importFile ( filePath :string ) {
20
+ // eslint-disable-next-line
21
+ const fnMigration = require ( filePath )
22
+
23
+ return fnMigration ?. default || fnMigration
24
+ }
25
+
26
+ function requireFromRoot ( filePath : string ) {
27
+ filePath = resolvePathFromRoot ( filePath )
28
+ return importFile ( filePath )
29
+ }
30
+
31
+ export default {
32
+ resolvePathFromRoot,
33
+ resolveMigration,
34
+ importFile,
35
+ requireFromRoot,
36
+ }
You can’t perform that action at this time.
0 commit comments