bajo 0.3.5 → 0.3.7

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,15 +1,18 @@
1
- import { isEmpty } from 'lodash-es'
1
+ import { isEmpty, find } from 'lodash-es'
2
2
 
3
- function breakNsPath (item = '') {
4
- const { error, getPlugin } = this.bajo.helper
3
+ function breakNsPath (item = '', defaultNs = 'bajo') {
4
+ const { error } = this.bajo.helper
5
5
  let [ns, ...path] = item.split(':')
6
6
  path = path.join(':')
7
7
  if (isEmpty(path)) {
8
8
  path = ns
9
- ns = null
9
+ ns = defaultNs
10
+ }
11
+ if (ns.length === 1) return [ns, path].join(':') // windows fs
12
+ if (!this[ns]) {
13
+ const ref = find(this.bajo.pluginRefs ?? [], { alias: ns })
14
+ if (ref) ns = ref.plugin
10
15
  }
11
- // if (path.startsWith('.')) throw error('Path \'%s\' must be an absolute path', path)
12
- if (!this[ns]) ns = (getPlugin(ns) || {}).name
13
16
  if (!this[ns]) throw error('Unknown plugin \'%s\' or plugin isn\'t loaded yet', ns)
14
17
  return [ns, path]
15
18
  }
@@ -1,7 +1,7 @@
1
1
  import { filter, isArray, each, pullAt, camelCase, has, find, set, get, cloneDeep } from 'lodash-es'
2
2
 
3
3
  async function buildCollections (options = {}) {
4
- const { getConfig, getPluginName, fatal, runHook, error } = this.bajo.helper
4
+ const { getConfig, getPluginName, fatal, runHook, error, join } = this.bajo.helper
5
5
  let { plugin, handler, dupChecks = [], container = 'connections', useDefaultName } = options
6
6
  useDefaultName = useDefaultName ?? true
7
7
  if (!plugin) plugin = getPluginName(4)
@@ -32,7 +32,7 @@ async function buildCollections (options = {}) {
32
32
  each(dupChecks, d => {
33
33
  const checker = set({}, d, c[d])
34
34
  const match = filter(data, checker)
35
- if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, dupChecks.join(', '))
35
+ if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, join(dupChecks))
36
36
  })
37
37
  })
38
38
  await runHook(`${plugin}:${camelCase(`after build ${container}`)}`)
@@ -1,8 +1,10 @@
1
1
  import { get } from 'lodash-es'
2
+ import breakNsPath from './break-ns-path.js'
2
3
 
3
4
  function getPluginFile (file) {
5
+ if (!get(this, 'bajo.helper')) return file
4
6
  if (file.includes(':')) {
5
- const [plugin, path] = file.split(':')
7
+ const [plugin, path] = breakNsPath.call(this, file)
6
8
  if (plugin !== 'file' && this && this[plugin] && plugin.length > 1) {
7
9
  const dir = get(this[plugin], 'config.dir.pkg')
8
10
  file = `${dir}${path}`
@@ -6,7 +6,7 @@ function getPlugin (name) {
6
6
  // alias?
7
7
  const ref = find(this.bajo.pluginRefs ?? [], { alias: name })
8
8
  if (!ref) throw error('\'%s\' is not loaded', name)
9
- name = ref.name
9
+ name = ref.plugin
10
10
  }
11
11
  return this[name]
12
12
  }
@@ -4,6 +4,7 @@ import getModuleDir from './get-module-dir.js'
4
4
  import resolvePath from './resolve-path.js'
5
5
  import readJson from './read-json.js'
6
6
  import defaultsDeep from './defaults-deep.js'
7
+ import breakNsPath from './break-ns-path.js'
7
8
  import path from 'path'
8
9
  import fs from 'fs-extra'
9
10
 
@@ -14,11 +15,7 @@ async function importPkg (...pkgs) {
14
15
  opts = defaultsDeep(pkgs.pop(), opts)
15
16
  }
16
17
  for (const pkg of pkgs) {
17
- let [plugin, name] = pkg.split(':').map(item => item.trim())
18
- if (!name) {
19
- name = plugin
20
- plugin = 'bajo'
21
- }
18
+ const [plugin, name] = breakNsPath.call(this, pkg)
22
19
  const dir = getModuleDir.call(this, name, plugin)
23
20
  const p = readJson(`${dir}/package.json`, opts.thrownNotFound)
24
21
  const mainFileOrg = dir + '/' + (p.main ?? get(p, 'exports.default', 'index.js'))
@@ -0,0 +1,11 @@
1
+ import { isPlainObject } from 'lodash-es'
2
+ import isSet from './is-set.js'
3
+
4
+ const join = (array, sep) => {
5
+ if (isSet(sep) && !isPlainObject(sep)) return array.join(sep)
6
+ const { separator = ', ', joiner = 'and' } = sep ?? {}
7
+ const last = (array.pop() ?? '').trim()
8
+ return array.map(a => (a + '').trim()).join(separator) + ` ${joiner} ${last}`
9
+ }
10
+
11
+ export default join
@@ -58,7 +58,6 @@ class Log {
58
58
  text = JSON.stringify(json)
59
59
  } else {
60
60
  text = `[${dayjs(dt).utc(true).format(this.format)}] ${upperFirst(level)}: ${msg}`
61
- // if (!isEmpty(data)) text += '\n ' + (pretty.render(data, prettyOpts).split('\n').join('\n '))
62
61
  if (!isEmpty(data)) text += '\n' + JSON.stringify(data)
63
62
  }
64
63
  console.log(text)
package/boot/lib/shim.js CHANGED
@@ -1,8 +1,7 @@
1
- // taken from: https://vanillajstoolkit.com/polyfills/stringreplaceall/
2
-
3
1
  function shim () {
2
+ // taken from: https://vanillajstoolkit.com/polyfills/stringreplaceall/
4
3
  if (!String.prototype.replaceAll) {
5
- String.prototype.replaceAll = function(str, newStr){
4
+ String.prototype.replaceAll = function(str, newStr) { // eslint-disable-line
6
5
  if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
7
6
  return this.replace(str, newStr)
8
7
  }
@@ -2,7 +2,7 @@ import { reduce, map, trim, keys, intersection, each, camelCase, get } from 'lod
2
2
  import semver from 'semver'
3
3
 
4
4
  async function runner ({ plugin, pkg, dependencies }) {
5
- const { log, getConfig, error } = this.bajo.helper
5
+ const { log, getConfig, error, join } = this.bajo.helper
6
6
  log.trace('Checking dependencies: %s', plugin)
7
7
  const config = getConfig()
8
8
  const odep = reduce(dependencies, (o, k) => {
@@ -13,7 +13,7 @@ async function runner ({ plugin, pkg, dependencies }) {
13
13
  const deps = keys(odep)
14
14
  if (deps.length > 0) {
15
15
  if (intersection(config.plugins, deps).length !== deps.length) {
16
- throw error('Dependency for \'%s\' unfulfilled: %s', pkg, deps.join(', '), { code: 'BAJO_DEPENDENCY' })
16
+ throw error('Dependency for \'%s\' unfulfilled: %s', pkg, join(deps), { code: 'BAJO_DEPENDENCY' })
17
17
  }
18
18
  each(deps, d => {
19
19
  if (!odep[d]) return
@@ -1,7 +1,7 @@
1
1
  import { isFunction, isPlainObject, map } from 'lodash-es'
2
2
 
3
3
  async function collectConfigHandlers (pkg) {
4
- const { getModuleDir, importModule, log } = this.bajo.helper
4
+ const { getModuleDir, importModule, log, join } = this.bajo.helper
5
5
  for (const pkg of this.bajo.config.plugins) {
6
6
  let dir
7
7
  try {
@@ -16,7 +16,7 @@ async function collectConfigHandlers (pkg) {
16
16
  this.bajo.configHandlers.concat(mod)
17
17
  }
18
18
  const exts = map(this.bajo.configHandlers, 'ext')
19
- log.trace('Config handlers: %s', exts.join(', '))
19
+ log.trace('Config handlers: %s', join(exts))
20
20
  }
21
21
 
22
22
  export default collectConfigHandlers
@@ -1,7 +1,7 @@
1
1
  import {} from 'lodash-es'
2
2
 
3
3
  async function collectExitHandlers () {
4
- const { importModule, log, eachPlugins, getConfig, print } = this.bajo.helper
4
+ const { importModule, log, eachPlugins, getConfig, print, join } = this.bajo.helper
5
5
  const config = getConfig()
6
6
  if (!config.exitHandler) return
7
7
  this.bajo.exitHandler = this.bajo.exitHandler ?? {}
@@ -12,7 +12,7 @@ async function collectExitHandlers () {
12
12
  this.bajo.exitHandler[plugin] = mod
13
13
  names.push(plugin)
14
14
  })
15
- log.trace('Exit handlers: %s', names.length === 0 ? print.__('none') : names.join(', '))
15
+ log.trace('Exit handlers: %s', names.length === 0 ? print.__('none') : join(names))
16
16
  }
17
17
 
18
18
  export default collectExitHandlers
@@ -1,7 +1,7 @@
1
1
  import { set, get, camelCase, upperFirst, map } from 'lodash-es'
2
2
 
3
3
  async function run () {
4
- const { runHook, log, eachPlugins, importModule, freeze, getConfig, print } = this.bajo.helper
4
+ const { runHook, log, eachPlugins, importModule, freeze, getConfig, print, join } = this.bajo.helper
5
5
  const config = getConfig()
6
6
  const methods = ['init']
7
7
  if (!get(config, 'tool')) methods.push('start')
@@ -20,7 +20,7 @@ async function run () {
20
20
  })
21
21
  await runHook(`bajo:${camelCase(`after ${f} all plugins`)}`)
22
22
  }
23
- log.debug('Loaded plugins: %s', map(config.plugins, b => camelCase(b)).join(', '))
23
+ log.debug('Loaded plugins: %s', join(map(config.plugins, b => camelCase(b))))
24
24
  }
25
25
 
26
26
  export default run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {