UNPKG

695 BJavaScriptView Raw
1/* @flow */
2'use strict'
3
4/* ::
5import type {RouteConfiguration} from '../types.js'
6*/
7
8const glob = require('glob')
9const pify = require('pify')
10
11const values = require('./values.js')
12
13function 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
20function 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
31module.exports = {
32 listAPIs,
33 listRoutes
34}