bajo 0.2.19 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,9 @@
1
1
  import fastGlob from 'fast-glob'
2
+ import path from 'path'
2
3
  import { camelCase, isFunction, isPlainObject, forOwn } from 'lodash-es'
3
4
  import resolvePath from '../helper/resolve-path.js'
4
5
  import importModule from '../helper/import-module.js'
6
+ import readJson from '../helper/read-json.js'
5
7
 
6
8
  function stackInfo (name, ...args) {
7
9
  const { log, callsites } = this.bajo.helper
@@ -32,13 +34,16 @@ const wrapAsyncFn = function (name, handler, bind) {
32
34
 
33
35
  export default async function (dir, pkg = 'bajo') {
34
36
  dir = resolvePath(dir)
35
- const files = await fastGlob([`!${dir}/**/_*.js`, `${dir}/**/*.js`])
37
+ const files = await fastGlob([`!${dir}/**/_*.{js,json}`, `${dir}/**/*.{js,json}`])
36
38
  const helper = {}
37
39
  for (const f of files) {
38
- const base = f.replace(dir, '').replace('.js', '')
40
+ const ext = path.extname()
41
+ const base = f.replace(dir, '').replace(ext, '')
39
42
  const name = camelCase(base)
40
43
  const fnName = pkg + '.' + name
41
- let mod = await importModule(f)
44
+ let mod
45
+ if (ext === '.json') mod = readJson(f)
46
+ else await importModule(f)
42
47
  if (isFunction(mod)) {
43
48
  if (mod.constructor.name === 'AsyncFunction') mod = wrapAsyncFn.call(this, fnName, mod, true)
44
49
  else mod = wrapFn.call(this, fnName, mod, true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {