File tree 3 files changed +52
-5
lines changed
3 files changed +52
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import * as yargs from "yargs" ;
4
4
import tsw from "./index" ;
5
- import * as path from "path" ;
6
5
7
6
const { argv } = yargs
8
7
. alias ( "h" , "help" )
@@ -11,9 +10,15 @@ const { argv } = yargs
11
10
type : "boolean" ,
12
11
description : "Run with verbose logging" ,
13
12
default : false
13
+ } )
14
+ . option ( "config" , {
15
+ alias : "c" ,
16
+ type : "string" ,
17
+ description : "Config file path" ,
18
+ default : "tswconfig.json"
14
19
} ) ;
15
20
16
- const { _ } = argv ;
21
+ const { _, config } = argv ;
17
22
const [ main ] = _ ;
18
23
19
- tsw ( path . resolve ( process . cwd ( ) , main ) ) ;
24
+ tsw ( process . cwd ( ) , main , config ) ;
Original file line number Diff line number Diff line change
1
+ import * as path from "path" ;
1
2
import { consoleHack } from "./core/runtime/console.hack" ;
2
3
import { httpCreateServerHack } from "./core/runtime/create-server.hack" ;
3
4
import { dnsHack } from "./core/runtime/dns.hack" ;
4
5
import { requestHack } from "./core/runtime/capture/index" ;
6
+ import { eventBus } from "./core/bus" ;
7
+
8
+ const loadPlugins = async (
9
+ basePath : string ,
10
+ config : typeof global . tswConfig
11
+ ) : Promise < void > => {
12
+ // eslint-disable-next-line no-restricted-syntax
13
+ for ( const pluginPath of config . plugins ) {
14
+ if ( ! pluginPath . trim ( ) ) {
15
+ return ;
16
+ }
17
+
18
+ let absolutePath = "" ;
19
+ if ( path . isAbsolute ( pluginPath ) ) {
20
+ absolutePath = pluginPath ;
21
+ } else if ( pluginPath . startsWith ( "." ) ) {
22
+ absolutePath = path . resolve ( basePath , pluginPath ) ;
23
+ } else {
24
+ absolutePath = pluginPath ;
25
+ }
26
+
27
+ // eslint-disable-next-line no-await-in-loop
28
+ ( await import ( absolutePath ) ) ( eventBus , config ) ;
29
+ }
30
+ } ;
31
+
32
+ export default async (
33
+ basePath : string ,
34
+ mainPath : string ,
35
+ configPath : string
36
+ ) : Promise < void > => {
37
+ global . tswConfig = await import ( path . resolve ( basePath , configPath ) ) ;
5
38
6
- export default async ( absolutePath2Main : string ) : Promise < void > => {
7
39
httpCreateServerHack ( ) ;
8
40
dnsHack ( ) ;
9
41
consoleHack ( ) ;
10
42
requestHack ( ) ;
11
43
12
- await import ( absolutePath2Main ) ;
44
+ await loadPlugins ( basePath , global . tswConfig ) ;
45
+
46
+ await import ( path . resolve ( basePath , mainPath ) ) ;
13
47
} ;
Original file line number Diff line number Diff line change @@ -23,4 +23,12 @@ declare namespace NodeJS {
23
23
interface Domain {
24
24
currentContext ?: any ;
25
25
}
26
+
27
+ interface Global {
28
+ tswConfig : {
29
+ appid : string ;
30
+ appkey : string ;
31
+ plugins : string [ ] ;
32
+ } ;
33
+ }
26
34
}
You can’t perform that action at this time.
0 commit comments