@@ -6,6 +6,19 @@ const fs = require('fs');
66const endpointsFile = 'endpoints.yaml' ;
77const resultFile = 'app.js' ;
88
9+ const loadConfig = ( endpointsFile ) => {
10+ console . log ( 'Read' , endpointsFile ) ;
11+ try {
12+ const content = fs . readFileSync ( endpointsFile , 'utf8' ) ;
13+ const config = yaml . safeLoad ( content ) ;
14+ //console.debug(config);
15+ return config ;
16+ } catch ( ex ) {
17+ console . error ( `Failed to parse ${ endpointsFile } : ${ ex . message } ` ) ;
18+ throw ex ;
19+ }
20+ } ;
21+
922const createEndpoints = ( config ) => {
1023 console . log ( 'Generate' , resultFile ) ;
1124 for ( let endpoint of config ) {
@@ -28,15 +41,5 @@ const createEndpoints = (config) => {
2841 fs . writeFileSync ( resultFile , resultedCode ) ;
2942} ;
3043
31- console . log ( 'Read' , endpointsFile ) ;
32-
33- try {
34-
35- const content = fs . readFileSync ( endpointsFile , 'utf8' ) ;
36- const config = yaml . safeLoad ( content ) ;
37- //console.debug(config);
38- createEndpoints ( config ) ;
39-
40- } catch ( ex ) {
41- console . error ( 'Failed to parse' , endpointsFile ) ;
42- }
44+ const config = loadConfig ( endpointsFile ) ;
45+ createEndpoints ( config ) ;
0 commit comments