bajo 0.2.16 → 0.2.17

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.
@@ -27,6 +27,7 @@ async function _eachPlugins (handler, { key = 'name', glob, ns, useBajo } = {})
27
27
  }
28
28
  const files = await fastGlob(pattern, opts)
29
29
  for (const f of files) {
30
+ if (path.basename(f)[0] === '_') continue
30
31
  const resp = await handler.call(this, { plugin, pkg, cfg, alias, file: f, dir: base, dependencies })
31
32
  if (resp === false) break
32
33
  else if (resp === undefined) continue
@@ -42,7 +42,8 @@ function error (msg = 'Internal server error', ...args) {
42
42
  }
43
43
  if (!ns) ns = getPluginName.call(this, 3)
44
44
  const orgMsg = msg
45
- const message = print.__(msg, ...args, { ns })
45
+ args.push({ ns })
46
+ const message = print.__(msg, ...args)
46
47
  let err
47
48
  if (isPlainObject(payload) && payload.class) err = payload.class(message)
48
49
  else err = Error(message)
@@ -1,10 +1,11 @@
1
- import error from './error.js'
2
1
  import getPluginName from './get-plugin-name.js'
3
2
 
4
3
  function fatal (...args) {
4
+ const { error } = this.bajo.helper
5
5
  const ns = getPluginName.call(this, 3)
6
6
  args.push({ ns })
7
- const err = error(...args)
7
+ const [msg, ...params] = args
8
+ const err = error(msg, ...params)
8
9
  console.error(err)
9
10
  process.exit(1)
10
11
  }
@@ -3,15 +3,17 @@ import { isFunction, isPlainObject } from 'lodash-es'
3
3
  import error from './error.js'
4
4
  import fs from 'fs-extra'
5
5
 
6
- async function load (file, asDefaultImport = true) {
7
- const imported = await import(resolvePath(file, true))
6
+ async function load (file, asDefaultImport = true, noCache = false) {
7
+ file = resolvePath(file, true)
8
+ if (noCache) file += `?_=${Date.now()}`
9
+ const imported = await import(file)
8
10
  if (asDefaultImport) return imported.default
9
11
  return imported
10
12
  }
11
13
 
12
- async function importModule (file, { asDefaultImport, asHandler } = {}) {
14
+ async function importModule (file, { asDefaultImport, asHandler, noCache } = {}) {
13
15
  if (!fs.existsSync(file)) return
14
- let mod = await load(file, asDefaultImport)
16
+ let mod = await load(file, asDefaultImport, noCache)
15
17
  if (!asHandler) return mod
16
18
  if (isFunction(mod)) mod = { level: 999, handler: mod }
17
19
  if (!isPlainObject(mod)) throw error.call(this, 'File \'%s\' is NOT a handler module', file)
@@ -29,7 +29,7 @@ import fs from 'fs-extra'
29
29
 
30
30
  async function importPkg (...pkg) {
31
31
  const result = {}
32
- let opts = { returnDefault: true, thrownNotFound: false }
32
+ let opts = { returnDefault: true, thrownNotFound: false, noCache: false }
33
33
  if (isPlainObject(last(pkg))) {
34
34
  opts = defaultsDeep(pkg.pop(), opts)
35
35
  }
@@ -52,6 +52,7 @@ async function importPkg (...pkg) {
52
52
  if (fs.existsSync(`${mainFileOrg}/index.js`)) mainFile += '/index.js'
53
53
  else mainFile += '.js'
54
54
  }
55
+ if (opts.noCache) mainFile += `?_=${Date.now()}`
55
56
  let mod = await import(mainFile)
56
57
  if (opts.returnDefault && has(mod, 'default')) {
57
58
  mod = mod.default
@@ -1,4 +1,5 @@
1
- import { isPlainObject, isArray, isNumber } from 'lodash-es'
1
+ import { isPlainObject, isArray, isNumber, set } from 'lodash-es'
2
+ import dotenvParseVariables from 'dotenv-parse-variables'
2
3
  import ms from 'ms'
3
4
  import dayjs from '../lib/dayjs.js'
4
5
  import isSet from './is-set.js'
@@ -13,7 +14,7 @@ function parseDt (val) {
13
14
  return dt.toDate()
14
15
  }
15
16
 
16
- function parseObject (obj, silent = true) {
17
+ function parseObject (obj, silent = true, parseValue = false) {
17
18
  const keys = Object.keys(obj)
18
19
  keys.forEach(k => {
19
20
  const v = obj[k]
@@ -21,9 +22,11 @@ function parseObject (obj, silent = true) {
21
22
  else if (isArray(v)) {
22
23
  v.forEach((i, idx) => {
23
24
  if (isPlainObject(i)) obj[k][idx] = parseObject(i)
25
+ else if (parseValue) obj[k][idx] = dotenvParseVariables(set({}, 'item', obj[k][idx]), { assignToProcessEnv: false }).item
24
26
  })
25
27
  } else if (isSet(v)) {
26
28
  try {
29
+ if (parseValue) obj[k] = dotenvParseVariables(set({}, 'item', v), { assignToProcessEnv: false }).item
27
30
  if (k.slice(-3) === 'Dur') obj[k] = parseDur(v)
28
31
  if (k.slice(-2) === 'Dt') obj[k] = parseDt(v)
29
32
  } catch (err) {
@@ -0,0 +1,13 @@
1
+ import isSet from './is-set.js'
2
+
3
+ function pick (obj, items, excludeUnset) {
4
+ const result = {}
5
+ items.forEach(item => {
6
+ const [k, nk] = item.split(':')
7
+ if (excludeUnset && !isSet(obj[k])) return undefined
8
+ result[nk ?? k] = obj[k]
9
+ })
10
+ return result
11
+ }
12
+
13
+ export default pick
@@ -0,0 +1,6 @@
1
+ function round (val, scale = 0) {
2
+ scale = scale <= 0 ? 1 : 10 ** scale
3
+ return Math.round(val * scale) / scale
4
+ }
5
+
6
+ export default round
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {
@@ -40,9 +40,8 @@
40
40
  "lodash-es": "^4.17.21",
41
41
  "ms": "^2.1.3",
42
42
  "nanoid": "^4.0.2",
43
- "node-fetch": "^3.3.1",
44
43
  "omit-deep": "^0.3.0",
45
- "ora": "^6.3.1",
44
+ "ora": "^8.0.1",
46
45
  "outmatch": "^0.7.0",
47
46
  "proper-lockfile": "^4.1.2",
48
47
  "semver": "^7.5.1",