Skip to content

Commit 8a38806

Browse files
committed
refactor: extract createEndpoints() function
1 parent 2586d20 commit 8a38806

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/cli.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ const fs = require('fs');
66
const endpointsFile = 'endpoints.yaml';
77
const resultFile = 'app.js';
88

9-
console.log('Read', endpointsFile);
10-
11-
try {
12-
13-
const content = fs.readFileSync(endpointsFile, 'utf8');
14-
const config = yaml.safeLoad(content);
15-
//console.debug(config);
9+
const createEndpoints = (config) => {
1610
console.log('Generate', resultFile);
1711
for (let endpoint of config) {
1812
console.log('GET', endpoint.path, '=>', endpoint.get);
@@ -32,6 +26,16 @@ try {
3226
})\n`.replace(/^ /gm, '');
3327

3428
fs.writeFileSync(resultFile, resultedCode);
29+
};
30+
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);
3539

3640
} catch (ex) {
3741
console.error('Failed to parse', endpointsFile);

0 commit comments

Comments
 (0)