@@ -13,6 +13,32 @@ import { log, success, warn } from '../lib/logger';
13
13
14
14
const getDirPath = dir => path . resolve ( process . cwd ( ) , dir ) ;
15
15
16
+ const startGateway = ( {
17
+ mock,
18
+ gateway,
19
+ dataSourcePaths,
20
+ loadedDataSources,
21
+ } ) => {
22
+ // If a custom gateway was specified, set the env vars and start it.
23
+ if ( gateway ) {
24
+ // Define GrAMPS env vars.
25
+ process . env . GRAMPS_MODE = mock ? 'mock' : 'live' ;
26
+ process . env . GRAMPS_DATA_SOURCES = dataSourcePaths . length
27
+ ? dataSourcePaths . join ( ',' )
28
+ : '' ;
29
+
30
+ // Start the user-specified gateway.
31
+ spawn ( 'node' , [ gateway ] , { stdio : 'inherit' } ) ;
32
+ return ;
33
+ }
34
+
35
+ // If we get here, fire up the default gateway for development.
36
+ startDefaultGateway ( {
37
+ dataSources : loadedDataSources ,
38
+ enableMockData : mock ,
39
+ } ) ;
40
+ } ;
41
+
16
42
export const command = 'dev' ;
17
43
export const description = 'run a GraphQL gateway for local development' ;
18
44
@@ -70,23 +96,11 @@ export const handler = async ({
70
96
loadedDataSources = loadDataSources ( dataSourcePaths ) ;
71
97
}
72
98
73
- // If a custom gateway was specified, set the env vars and start it.
74
- if ( gateway ) {
75
- // Define GrAMPS env vars.
76
- process . env . GRAMPS_MODE = mock ? 'mock' : 'live' ;
77
- process . env . GRAMPS_DATA_SOURCES = dataSourcePaths . length
78
- ? dataSourcePaths . join ( ',' )
79
- : '' ;
80
-
81
- // Start the user-specified gateway.
82
- spawn ( 'node' , [ gateway ] , { stdio : 'inherit' } ) ;
83
- return ;
84
- }
85
-
86
- // If we get here, fire up the default gateway for development.
87
- startDefaultGateway ( {
88
- dataSources : loadedDataSources ,
89
- enableMockData : mock ,
99
+ startGateway ( {
100
+ mock,
101
+ gateway,
102
+ dataSourcePaths,
103
+ loadedDataSources,
90
104
} ) ;
91
105
} ;
92
106
0 commit comments