1 |
|
2 | 'use strict'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const glob = require('glob')
|
9 | const pify = require('pify')
|
10 |
|
11 | const values = require('./values.js')
|
12 |
|
13 | function listAPIs (
|
14 | cwd /* : string */
|
15 | ) /* : Promise<Array<string>> */ {
|
16 | return pify(glob)('./*/index.js', { cwd })
|
17 | .then((matches) => matches.map((match) => match.split('/')[1]))
|
18 | }
|
19 |
|
20 | function listRoutes (
|
21 | cwd /* : string */
|
22 | ) /* : Promise<Array<RouteConfiguration>> */ {
|
23 | return listAPIs(cwd)
|
24 | .then((apis) => apis.map((api) => ({
|
25 | route: `/${api}`,
|
26 | module: `./${api}/index.js`,
|
27 | timeout: values.DEFAULT_TIMEOUT_SECONDS
|
28 | })))
|
29 | }
|
30 |
|
31 | module.exports = {
|
32 | listAPIs,
|
33 | listRoutes
|
34 | }
|