lerna: complete refactor!

This commit is contained in:
41666 2019-04-03 07:12:01 -05:00
parent 51dd8bd6b1
commit e1bd5747b3
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF
12 changed files with 83 additions and 71 deletions

View file

@ -1,15 +1,14 @@
// @flow
import logger from '../logger'
import glob from 'glob'
import type { Router, AppContext } from '../Roleypoly'
import path from 'path'
import logger from '../logger'
const log = logger(__filename)
const PROD = process.env.NODE_ENV === 'production'
export default async (router: Router, ctx: AppContext, { forceClear = false }: { forceClear: boolean } = {}) => {
const apis = glob.sync(`./api/**/!(index).js`)
const apis = glob.sync(`${__dirname}/**/!(index).js`).map(v => v.replace(__dirname, '.'))
log.debug('found apis', apis)
for (let a of apis) {
@ -19,12 +18,11 @@ export default async (router: Router, ctx: AppContext, { forceClear = false }: {
}
log.debug(`mounting ${a}`)
try {
const pathname = a.replace('api/', '')
if (forceClear) {
delete require.cache[require.resolve(pathname)]
delete require.cache[require.resolve(a)]
}
// $FlowFixMe this isn't an important error. potentially dangerous, but irrelevant.
require(pathname).default(router, ctx)
require(a).default(router, ctx)
} catch (e) {
log.error(`couldn't mount ${a}`, e)
}