bajo 0.1.0 → 0.2.1

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.
Files changed (75) hide show
  1. package/bajoBook/book/doc/.metadata.json +28 -0
  2. package/bajoBook/book/doc/How-to-Make-a-Paper-Boat-564x400@2x.jpg +0 -0
  3. package/bajoBook/book/doc/pages/guides/definition.md +7 -0
  4. package/bajoBook/book/doc/pages/guides/intro.md +3 -0
  5. package/bajoBook/book/doc/pages/guides/setup.md +22 -0
  6. package/bajoBook/book/reference/.metadata.json +152 -0
  7. package/bajoBook/book/reference/concept-leadership-business-with-paper-boats.jpg +0 -0
  8. package/bajoBook/book/reference/pages/configuration/configuration-file.md +52 -0
  9. package/bajoBook/book/reference/pages/helper/break-ns-path.md +24 -0
  10. package/bajoBook/book/reference/pages/helper/build-collections.md +19 -0
  11. package/bajoBook/book/reference/pages/helper/call-helper-or-handler.md +35 -0
  12. package/bajoBook/book/reference/pages/helper/current-loc.md +28 -0
  13. package/bajoBook/book/reference/pages/helper/dayjs.md +13 -0
  14. package/bajoBook/book/reference/pages/helper/defaults-deep.md +29 -0
  15. package/bajoBook/book/reference/pages/helper/dump.md +32 -0
  16. package/bajoBook/book/reference/pages/helper/each-plugins.md +24 -0
  17. package/bajoBook/book/reference/pages/helper/envs.md +11 -0
  18. package/bajoBook/book/reference/pages/helper/error.md +29 -0
  19. package/bajoBook/book/reference/pages/helper/fatal.md +18 -0
  20. package/bajoBook/book/reference/pages/helper/freeze.md +13 -0
  21. package/bajoBook/book/reference/pages/helper/generate-id.md +36 -0
  22. package/bajoBook/book/reference/pages/helper/get-config.md +27 -0
  23. package/bajoBook/book/reference/pages/helper/get-global-module-dir.md +13 -0
  24. package/bajoBook/book/reference/pages/helper/get-helper.md +13 -0
  25. package/bajoBook/book/reference/pages/helper/get-item-by-name.md +13 -0
  26. package/bajoBook/book/reference/pages/helper/get-key-by-value.md +13 -0
  27. package/bajoBook/book/reference/pages/helper/get-module-dir.md +13 -0
  28. package/bajoBook/book/reference/pages/helper/get-plugin-data-dir.md +13 -0
  29. package/bajoBook/book/reference/pages/helper/get-plugin-name.md +13 -0
  30. package/bajoBook/book/reference/pages/helper/get-plugin.md +13 -0
  31. package/bajoBook/book/reference/pages/helper/import-module.md +13 -0
  32. package/bajoBook/book/reference/pages/helper/import-pkg.md +13 -0
  33. package/bajoBook/book/reference/pages/helper/is-empty-dir.md +13 -0
  34. package/bajoBook/book/reference/pages/helper/is-log-in-range.md +13 -0
  35. package/bajoBook/book/reference/pages/helper/is-set.md +13 -0
  36. package/bajoBook/book/reference/pages/helper/is-valid-app.md +13 -0
  37. package/bajoBook/book/reference/pages/helper/is-valid-plugin.md +13 -0
  38. package/bajoBook/book/reference/pages/helper/log-levels.md +13 -0
  39. package/bajoBook/book/reference/pages/helper/log.md +13 -0
  40. package/bajoBook/book/reference/pages/helper/paginate.md +13 -0
  41. package/bajoBook/book/reference/pages/helper/pascal-case.md +13 -0
  42. package/bajoBook/book/reference/pages/helper/print.md +13 -0
  43. package/bajoBook/book/reference/pages/helper/read-config.md +13 -0
  44. package/bajoBook/book/reference/pages/helper/read-json.md +13 -0
  45. package/bajoBook/book/reference/pages/helper/resolve-path.md +13 -0
  46. package/bajoBook/book/reference/pages/helper/resolve-tpl-path.md +13 -0
  47. package/bajoBook/book/reference/pages/helper/run-hook.md +13 -0
  48. package/bajoBook/book/reference/pages/helper/save-as-download.md +13 -0
  49. package/bajoBook/book/reference/pages/helper/titleize.md +13 -0
  50. package/bajoBook/book/reference/pages/helper/white-space.md +13 -0
  51. package/boot/attach-helper.js +8 -0
  52. package/boot/build-config.js +8 -3
  53. package/boot/exit-handler.js +3 -1
  54. package/boot/helper/break-ns-path.js +17 -0
  55. package/boot/helper/build-collections.js +17 -23
  56. package/boot/helper/each-plugins.js +59 -49
  57. package/boot/helper/error.js +22 -2
  58. package/boot/helper/generate-id.js +4 -3
  59. package/boot/helper/get-config.js +3 -2
  60. package/boot/helper/get-global-module-dir.js +2 -2
  61. package/boot/helper/get-helper.js +2 -1
  62. package/boot/helper/get-module-dir.js +23 -11
  63. package/boot/helper/get-module-dir.js__ +50 -0
  64. package/boot/helper/get-plugin-data-dir.js +12 -0
  65. package/boot/helper/get-plugin.js +9 -2
  66. package/boot/helper/paginate.js +26 -0
  67. package/boot/helper/print.js +12 -2
  68. package/boot/helper/resolve-tpl-path.js +5 -11
  69. package/boot/helper/save-as-download.js +2 -3
  70. package/boot/helper/titleize.js +14 -0
  71. package/boot/lib/build-helper.js +1 -2
  72. package/boot/plugins/build-config.js +11 -4
  73. package/boot/plugins/collect-hooks.js +10 -9
  74. package/package.json +1 -1
  75. package/boot/helper/index.js +0 -36
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function getKeyByValue()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function getModuleDir()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function getPluginDataDir()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function getPluginName()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function getPlugin()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: async function importModule()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: async function importPkg()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: async function isEmptyDir()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function isLogInRange()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function isSet()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function isValidApp()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function isValidPlugin()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: object logLevels
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: object log
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function paginate()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function pascalCase()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: object print
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: async function readConfig()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function readJson()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function resolvePath()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function resolveTplPath()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: async function runHook()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: async function saveAsDownload()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: function titleize()
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: array whiteSpace
3
+ ---
4
+
5
+ ###### Parameters:
6
+
7
+ | Name | Type | Default Value | Description |
8
+ | ---- | ---- | ------------- | ----------- |
9
+
10
+ ###### Returns:
11
+
12
+
13
+ #### Example
@@ -18,9 +18,17 @@ export default async function () {
18
18
  }
19
19
  this.bajo.helper.log = logger.call(this)
20
20
  this.bajo.helper.dayjs = dayjs
21
+ this.bajo.helper.setImmediate = function () {
22
+ return new Promise((resolve) => {
23
+ setImmediate(() => resolve())
24
+ })
25
+ }
21
26
  this.bajo.helper.freeze(this.bajo.helper, true)
22
27
  // last cleanup
23
28
  if (!fs.existsSync(this.bajo.config.dir.data)) {
24
29
  this.bajo.helper.log.warn('Data directory \'%s\' is not set yet!', this.bajo.config.dir.data)
25
30
  }
31
+ if (this.bajo.config.env === 'dev') {
32
+ this.dump = this.bajo.helper.dump
33
+ }
26
34
  }
@@ -14,9 +14,10 @@ import defaultsDeep from './helper/defaults-deep.js'
14
14
  import parseArgsArgv from './lib/parse-args-argv.js'
15
15
  import parseEnv from './lib/parse-env.js'
16
16
  import error from './helper/error.js'
17
+ import currentLoc from './helper/current-loc.js'
17
18
 
18
19
  const configFilePick = ['log', 'plugins', 'env', 'run']
19
- const configFileOmit = ['tool', 'spawn', 'cwd']
20
+ const configFileOmit = ['tool', 'spawn', 'cwd', 'name', 'alias']
20
21
 
21
22
  const defConfig = {
22
23
  dir: {},
@@ -25,7 +26,7 @@ const defConfig = {
25
26
  report: [],
26
27
  tool: false
27
28
  },
28
- lang: Intl.DateTimeFormat().resolvedOptions().lang,
29
+ lang: Intl.DateTimeFormat().resolvedOptions().lang ?? 'en-US',
29
30
  plugins: ['app'],
30
31
  env: 'dev',
31
32
  tool: false,
@@ -59,8 +60,11 @@ async function buildConfig (cwd) {
59
60
  const { args, argv } = await parseArgsArgv()
60
61
  const env = parseEnv()
61
62
  const envArgv = defaultsDeep({}, env.root, argv.root)
63
+ envArgv.name = 'bajo'
64
+ envArgv.alias = 'bajo'
62
65
  // directories
63
66
  set(envArgv, 'dir.base', cwd)
67
+ set(envArgv, 'dir.pkg', resolvePath(currentLoc(import.meta).dir + '/..'))
64
68
  if (!get(envArgv, 'dir.data')) set(envArgv, 'dir.data', `${envArgv.dir.base}/data`)
65
69
  envArgv.dir.data = resolvePath(envArgv.dir.data)
66
70
  if (!envArgv.dir.tmp) {
@@ -81,7 +85,8 @@ async function buildConfig (cwd) {
81
85
  if (config.silent) config.log.level = 'silent'
82
86
  // sanitize plugins
83
87
  config.plugins = without(config.plugins, 'app')
84
- if (fs.existsSync(`${config.dir.base}/app/bajo`)) config.plugins.push('app')
88
+ // if (fs.existsSync(`${config.dir.base}/app/bajo`)) config.plugins.push('app')
89
+ config.plugins.push('app')
85
90
  config.plugins = filter(uniq(map(config.plugins, b => trim(b))), b => !isEmpty(b))
86
91
  if (config.tool) {
87
92
  if (!config.plugins.includes('bajo-cli')) throw error('Sidetool needs to have \'bajo-cli\' package loaded first')
@@ -4,7 +4,9 @@ async function exit (signal) {
4
4
  await eachPlugins(async function ({ plugin }) {
5
5
  const handler = this.bajo.exitHandler[plugin]
6
6
  if (!handler) return undefined
7
- await handler.call(this)
7
+ try {
8
+ await handler.call(this)
9
+ } catch (err) {}
8
10
  log.debug('Exited: %s', plugin)
9
11
  })
10
12
  log.debug('Program shutdown')
@@ -0,0 +1,17 @@
1
+ import { isEmpty } from 'lodash-es'
2
+
3
+ function breakNsPath (item = '') {
4
+ const { error, getPlugin } = this.bajo.helper
5
+ let [ns, ...path] = item.split(':')
6
+ path = path.join(':')
7
+ if (isEmpty(path)) {
8
+ path = ns
9
+ ns = null
10
+ }
11
+ // if (path.startsWith('.')) throw error('Path \'%s\' must be an absolute path', path)
12
+ if (!this[ns]) ns = (getPlugin(ns) || {}).name
13
+ if (!this[ns]) throw error('Unknown plugin \'%s\' or plugin isn\'t loaded yet', ns)
14
+ return [ns, path]
15
+ }
16
+
17
+ export default breakNsPath
@@ -1,40 +1,34 @@
1
1
  import { filter, isArray, each, pullAt, camelCase } from 'lodash-es'
2
2
 
3
- async function buildCollections ({ name, handler, dupChecks, container = 'connections' } = {}) {
3
+ async function buildCollections (options = {}) {
4
4
  const { getConfig, getPluginName, fatal, runHook } = this.bajo.helper
5
- if (!name) name = getPluginName(4)
6
- const options = getConfig(name, { full: true })
7
- if (!options[container]) return []
8
- if (!isArray(options[container])) options[container] = [options[container]]
9
- options[container] = options[container] ?? []
10
- await runHook(`${name}:${camelCase(`before build ${container}`)}`)
5
+ let { plugin, handler, dupChecks = [], container = 'connections' } = options
6
+ if (!plugin) plugin = getPluginName(4)
7
+ const cfg = getConfig(plugin, { full: true })
8
+ if (!cfg[container]) return []
9
+ if (!isArray(cfg[container])) cfg[container] = [cfg[container]]
10
+ cfg[container] = cfg[container] ?? []
11
+ await runHook(`${plugin}:${camelCase(`before build ${container}`)}`)
11
12
  const deleted = []
12
- for (const index in options[container]) {
13
- const item = options[container][index]
14
- const result = await handler.call(this, { item, index, options })
15
- if (result) options[container][index] = result
13
+ for (const index in cfg[container]) {
14
+ const item = cfg[container][index]
15
+ const result = await handler.call(this, { item, index, cfg })
16
+ if (result) cfg[container][index] = result
16
17
  else if (result === false) deleted.push(index)
17
18
  }
18
- if (deleted.length > 0) pullAt(options[container], deleted)
19
+ if (deleted.length > 0) pullAt(cfg[container], deleted)
19
20
 
20
21
  // check for duplicity
21
- each(options[container], c => {
22
+ each(cfg[container], c => {
22
23
  const checker = {}
23
24
  each(dupChecks, d => {
24
25
  checker[d] = c[d]
25
26
  })
26
- const match = filter(options[container], checker)
27
+ const match = filter(cfg[container], checker)
27
28
  if (match.length > 1) fatal('One or more %s shared the same \'%s\'', container, dupChecks.join(', '), { code: 'BAJOMQTT_CONNECTION_NOT_UNIQUE' })
28
29
  })
29
- /*
30
- each(dupChecks, item => {
31
- const items = map(options[container], item)
32
- const uItems = uniq(items)
33
- if (items.length !== uItems.length) fatal('One or more %s shared the same \'%s\'', container, item, { code: 'BAJOMQTT_CONNECTION_NOT_UNIQUE' })
34
- })
35
- */
36
- await runHook(`${name}:${camelCase(`after build ${container}`)}`)
37
- return options[container]
30
+ await runHook(`${plugin}:${camelCase(`after build ${container}`)}`)
31
+ return cfg[container]
38
32
  }
39
33
 
40
34
  export default buildCollections
@@ -1,8 +1,50 @@
1
- import { camelCase, isString, omit, isPlainObject, slice } from 'lodash-es'
1
+ import { camelCase, isString, omit, trim } from 'lodash-es'
2
2
  import fastGlob from 'fast-glob'
3
3
  import path from 'path'
4
4
  import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
5
5
 
6
+ async function _eachPlugins (handler, { key = 'name', glob, ns, useBajo } = {}) {
7
+ const { getConfig } = this.bajo.helper
8
+ const config = getConfig()
9
+ const result = {}
10
+ const plugins = [...config.plugins]
11
+ if (useBajo) plugins.unshift('bajo')
12
+ for (const pkg of plugins) {
13
+ const plugin = camelCase(pkg)
14
+ let cfg = getConfig(plugin, { full: true })
15
+ const { alias, dependencies } = cfg
16
+ const dir = cfg.dir.pkg
17
+ cfg = omit(cfg, omittedPluginKeys)
18
+ let r
19
+ if (glob) {
20
+ const base = `${dir}/${ns}`
21
+ let opts = isString(glob) ? { pattern: [glob] } : glob
22
+ let pattern = opts.pattern ?? []
23
+ if (isString(pattern)) pattern = [pattern]
24
+ opts = omit(opts, ['pattern'])
25
+ for (const i in pattern) {
26
+ pattern[i] = `${base}/${pattern[i]}`
27
+ }
28
+ const files = await fastGlob(pattern, opts)
29
+ for (const f of files) {
30
+ const resp = await handler.call(this, { plugin, pkg, cfg, alias, file: f, dir: base, dependencies })
31
+ if (resp === false) break
32
+ else if (resp === undefined) continue
33
+ else {
34
+ result[plugin] = result[plugin] ?? {}
35
+ result[plugin][f] = resp
36
+ }
37
+ }
38
+ } else {
39
+ r = await handler.call(this, { plugin, pkg, cfg, dir, alias, dependencies })
40
+ if (r === false) break
41
+ else if (r === undefined) continue
42
+ else result[plugin] = r
43
+ }
44
+ }
45
+ return result
46
+ }
47
+
6
48
  /**
7
49
  * @module helper/eachPlugins
8
50
  */
@@ -36,59 +78,27 @@ import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
36
78
  * })
37
79
  */
38
80
 
39
- async function eachPlugins (handler, { key = 'name', glob, ns } = {}) {
81
+ async function eachPlugins (handler, options = {}) {
40
82
  const { getConfig, getPluginName } = this.bajo.helper
41
- const config = getConfig()
42
- const result = {}
83
+ let { key = 'name', glob, ns, extend, extendHandler, useBajo } = options
84
+ if (!extendHandler) extendHandler = handler
43
85
  ns = ns ?? getPluginName(4)
44
- for (const pkg of config.plugins) {
45
- const plugin = camelCase(pkg)
46
- let cfg = getConfig(plugin, { full: true })
47
- const { alias, dir, dependencies } = cfg
48
- cfg = omit(cfg, omittedPluginKeys)
49
- let r
50
- if (glob) {
51
- const base = `${dir}/${ns}`
52
- let pattern
53
- let opts
54
- if (isPlainObject(glob) && glob.pattern) pattern = glob.pattern
55
- else {
56
- if (isString(glob)) pattern = [glob]
57
- for (const i in pattern) {
58
- pattern[i] = `${base}/${pattern[i]}`
59
- }
60
- }
61
- const files = await fastGlob(pattern, opts)
62
- for (const f of files) {
63
- const rel = f.replace(base, '')
64
- const b = path.basename(rel, path.extname(rel))
65
- const relDir = path.dirname(rel)
66
- const relDirBase = `${relDir}/${b}`
67
- const relName = slice(relDirBase.split('/'), 2).join('/')
68
- const fileInfo = {
69
- rel,
70
- relDir,
71
- relDirBase,
72
- base: b,
73
- name: camelCase(`${relName}`),
74
- nameWithPlugin: camelCase(`${plugin} ${relName}`)
75
- }
76
- const resp = await handler.call(this, { plugin, pkg, cfg, alias, file: f, dir: base, dependencies, fileInfo })
77
- if (resp === false) break
78
- else if (resp === undefined) continue
79
- else {
80
- result[plugin] = result[plugin] ?? {}
81
- result[plugin][f] = resp
82
- }
86
+ const result = await _eachPlugins.call(this, handler, { key, glob, ns, useBajo })
87
+ if (extend && isString(glob)) {
88
+ let nsExtend = ns
89
+ if (isString(extend)) nsExtend += '/' + trim(extend, '/')
90
+ const cfg = getConfig('app', { full: true })
91
+ const ext = `${cfg.dir.pkg}/${nsExtend}/extend/*`
92
+ const exts = await fastGlob(ext, { onlyDirectories: true })
93
+ for (const e of exts) {
94
+ const plugin = path.basename(e)
95
+ const files = await fastGlob(`${e}/${glob}`)
96
+ for (const file of files) {
97
+ await extendHandler.call(this, { file, plugin, dir: e })
83
98
  }
84
- } else {
85
- r = await handler.call(this, { plugin, pkg, cfg, dir, alias, dependencies })
86
- if (r === false) break
87
- else if (r === undefined) continue
88
- else result[plugin] = r
89
99
  }
90
100
  }
91
- return result
101
+ return result // TODO: merge with extender
92
102
  }
93
103
 
94
104
  export default eachPlugins