Commit ad8455e5 authored by Florian Pagnoux's avatar Florian Pagnoux
Browse files

Split parameter loading from route generating

parent bbba2de9
...@@ -4,6 +4,8 @@ const fs = require('fs') ...@@ -4,6 +4,8 @@ const fs = require('fs')
const yaml = require('js-yaml'); const yaml = require('js-yaml');
const map = require('lodash.map') const map = require('lodash.map')
const flatten = require('lodash.flatten') const flatten = require('lodash.flatten')
const fromPairs = require('lodash.frompairs')
const resolver = require('./resolver') const resolver = require('./resolver')
...@@ -12,12 +14,18 @@ async function loadSectionFile(file) { ...@@ -12,12 +14,18 @@ async function loadSectionFile(file) {
const textContent = fs.readFileSync(`./tables/${file}`, 'utf8') const textContent = fs.readFileSync(`./tables/${file}`, 'utf8')
const yamlContent = yaml.safeLoad(textContent) const yamlContent = yaml.safeLoad(textContent)
const resolvedDesc = await resolver.resolveSection(yamlContent) const resolvedDesc = await resolver.resolveSection(yamlContent)
return extractRoutes(resolvedDesc, `/${fileName}`) return [fileName, resolvedDesc]
} }
async function loadRoutes() { async function loadParametersTree() {
const sectionsFiles = fs.readdirSync('./tables') const sectionsFiles = fs.readdirSync('./tables')
const routes = await Promise.all(sectionsFiles.map(loadSectionFile)) const resolvedFiles = await Promise.all(sectionsFiles.map(loadSectionFile))
return fromPairs(resolvedFiles)
}
async function loadRoutes() {
const parametersTree = await loadParametersTree()
const routes = map(parametersTree, ((content, fileName) => extractRoutes(content, `/${fileName}`)))
return flatten(routes) return flatten(routes)
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment