bajo 0.0.1 → 0.2.0

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 (160) hide show
  1. package/.jsdoc.conf.json +38 -0
  2. package/README.md +57 -3
  3. package/bajoBook/book/doc/.metadata.json +28 -0
  4. package/bajoBook/book/doc/How-to-Make-a-Paper-Boat-564x400@2x.jpg +0 -0
  5. package/bajoBook/book/doc/pages/guides/definition.md +7 -0
  6. package/bajoBook/book/doc/pages/guides/intro.md +3 -0
  7. package/bajoBook/book/doc/pages/guides/setup.md +22 -0
  8. package/bajoBook/book/reference/.metadata.json +152 -0
  9. package/bajoBook/book/reference/concept-leadership-business-with-paper-boats.jpg +0 -0
  10. package/bajoBook/book/reference/pages/configuration/configuration-file.md +52 -0
  11. package/bajoBook/book/reference/pages/helper/break-ns-path.md +24 -0
  12. package/bajoBook/book/reference/pages/helper/build-collections.md +19 -0
  13. package/bajoBook/book/reference/pages/helper/call-helper-or-handler.md +35 -0
  14. package/bajoBook/book/reference/pages/helper/current-loc.md +28 -0
  15. package/bajoBook/book/reference/pages/helper/dayjs.md +13 -0
  16. package/bajoBook/book/reference/pages/helper/defaults-deep.md +29 -0
  17. package/bajoBook/book/reference/pages/helper/dump.md +32 -0
  18. package/bajoBook/book/reference/pages/helper/each-plugins.md +24 -0
  19. package/bajoBook/book/reference/pages/helper/envs.md +11 -0
  20. package/bajoBook/book/reference/pages/helper/error.md +29 -0
  21. package/bajoBook/book/reference/pages/helper/fatal.md +18 -0
  22. package/bajoBook/book/reference/pages/helper/freeze.md +13 -0
  23. package/bajoBook/book/reference/pages/helper/generate-id.md +36 -0
  24. package/bajoBook/book/reference/pages/helper/get-config.md +27 -0
  25. package/bajoBook/book/reference/pages/helper/get-global-module-dir.md +13 -0
  26. package/bajoBook/book/reference/pages/helper/get-helper.md +13 -0
  27. package/bajoBook/book/reference/pages/helper/get-item-by-name.md +13 -0
  28. package/bajoBook/book/reference/pages/helper/get-key-by-value.md +13 -0
  29. package/bajoBook/book/reference/pages/helper/get-module-dir.md +13 -0
  30. package/bajoBook/book/reference/pages/helper/get-plugin-data-dir.md +13 -0
  31. package/bajoBook/book/reference/pages/helper/get-plugin-name.md +13 -0
  32. package/bajoBook/book/reference/pages/helper/get-plugin.md +13 -0
  33. package/bajoBook/book/reference/pages/helper/import-module.md +13 -0
  34. package/bajoBook/book/reference/pages/helper/import-pkg.md +13 -0
  35. package/bajoBook/book/reference/pages/helper/is-empty-dir.md +13 -0
  36. package/bajoBook/book/reference/pages/helper/is-log-in-range.md +13 -0
  37. package/bajoBook/book/reference/pages/helper/is-set.md +13 -0
  38. package/bajoBook/book/reference/pages/helper/is-valid-app.md +13 -0
  39. package/bajoBook/book/reference/pages/helper/is-valid-plugin.md +13 -0
  40. package/bajoBook/book/reference/pages/helper/log-levels.md +13 -0
  41. package/bajoBook/book/reference/pages/helper/log.md +13 -0
  42. package/bajoBook/book/reference/pages/helper/paginate.md +13 -0
  43. package/bajoBook/book/reference/pages/helper/pascal-case.md +13 -0
  44. package/bajoBook/book/reference/pages/helper/print.md +13 -0
  45. package/bajoBook/book/reference/pages/helper/read-config.md +13 -0
  46. package/bajoBook/book/reference/pages/helper/read-json.md +13 -0
  47. package/bajoBook/book/reference/pages/helper/resolve-path.md +13 -0
  48. package/bajoBook/book/reference/pages/helper/resolve-tpl-path.md +13 -0
  49. package/bajoBook/book/reference/pages/helper/run-hook.md +13 -0
  50. package/bajoBook/book/reference/pages/helper/save-as-download.md +13 -0
  51. package/bajoBook/book/reference/pages/helper/titleize.md +13 -0
  52. package/bajoBook/book/reference/pages/helper/white-space.md +13 -0
  53. package/boot/attach-helper.js +34 -0
  54. package/boot/boot-order.js +34 -0
  55. package/boot/build-config.js +99 -0
  56. package/boot/create-scope.js +36 -0
  57. package/boot/exit-handler.js +60 -0
  58. package/boot/helper/break-ns-path.js +17 -0
  59. package/boot/helper/build-collections.js +34 -0
  60. package/boot/helper/call-helper-or-handler.js +15 -0
  61. package/boot/helper/current-loc.js +11 -0
  62. package/boot/helper/defaults-deep.js +14 -0
  63. package/boot/helper/dump.js +10 -0
  64. package/boot/helper/each-plugins.js +104 -0
  65. package/boot/helper/envs.js +14 -0
  66. package/boot/helper/error.js +67 -0
  67. package/boot/helper/fatal.js +12 -0
  68. package/boot/helper/generate-id.js +20 -0
  69. package/boot/helper/get-config.js +19 -0
  70. package/boot/helper/get-global-module-dir.js +27 -0
  71. package/boot/helper/get-helper.js +12 -0
  72. package/boot/helper/get-item-by-name.js +26 -0
  73. package/boot/helper/get-key-by-value.js +5 -0
  74. package/boot/helper/get-module-dir.js +22 -0
  75. package/boot/helper/get-plugin-data-dir.js +12 -0
  76. package/boot/helper/get-plugin-name.js +39 -0
  77. package/boot/helper/get-plugin.js +14 -0
  78. package/boot/helper/import-module.js +25 -0
  79. package/boot/helper/import-pkg.js +67 -0
  80. package/boot/helper/is-empty-dir.js +9 -0
  81. package/boot/helper/is-log-in-range.js +10 -0
  82. package/boot/helper/is-set.js +5 -0
  83. package/boot/helper/is-valid-app.js +12 -0
  84. package/boot/helper/is-valid-plugin.js +12 -0
  85. package/boot/helper/log-levels.js +19 -0
  86. package/boot/helper/paginate.js +26 -0
  87. package/boot/helper/pascal-case.js +7 -0
  88. package/boot/helper/print.js +99 -0
  89. package/boot/helper/read-config.js +46 -0
  90. package/boot/helper/read-json.js +10 -0
  91. package/boot/helper/resolve-path.js +15 -0
  92. package/boot/helper/resolve-tpl-path.js +15 -0
  93. package/boot/helper/run-hook.js +46 -0
  94. package/boot/helper/save-as-download.js +17 -0
  95. package/boot/helper/titleize.js +14 -0
  96. package/boot/helper/white-space.js +3 -0
  97. package/boot/index.js +60 -0
  98. package/boot/lib/bora.js +97 -0
  99. package/boot/lib/build-helper.js +57 -0
  100. package/boot/lib/logger.js +75 -0
  101. package/boot/lib/omitted-plugin-keys.js +3 -0
  102. package/boot/lib/parse-args-argv.js +75 -0
  103. package/boot/lib/parse-env.js +36 -0
  104. package/boot/lib/shim.js +14 -0
  105. package/boot/plugins/attach-helper.js +20 -0
  106. package/boot/plugins/build-config.js +82 -0
  107. package/boot/plugins/check-clash.js +18 -0
  108. package/boot/plugins/check-dependency.js +37 -0
  109. package/boot/plugins/collect-config-handlers.js +25 -0
  110. package/boot/plugins/collect-exit-handlers.js +23 -0
  111. package/boot/plugins/collect-hooks.js +34 -0
  112. package/boot/plugins/extend-config.js +21 -0
  113. package/boot/plugins/index.js +28 -0
  114. package/boot/plugins/run.js +31 -0
  115. package/boot/run-tool.js +34 -0
  116. package/docs/boot_build-config.js.html +75 -0
  117. package/docs/boot_create-scope.js.html +25 -0
  118. package/docs/boot_index.js.html +43 -0
  119. package/docs/data/search.json +1 -0
  120. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  121. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  122. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  123. package/docs/helper_emit.js.html +18 -0
  124. package/docs/helper_envs.js.html +16 -0
  125. package/docs/helper_error.js.html +25 -0
  126. package/docs/helper_get-bajo.js.html +42 -0
  127. package/docs/helper_index.js.html +39 -0
  128. package/docs/helper_log-levels.js.html +20 -0
  129. package/docs/helper_set-hook.js.html +38 -0
  130. package/docs/helper_walk-bajos.js.html +51 -0
  131. package/docs/index.html +16 -0
  132. package/docs/module-boot.html +3 -0
  133. package/docs/module-boot_buildConfig.html +3 -0
  134. package/docs/module-boot_createScope.html +3 -0
  135. package/docs/module-helper.html +7 -0
  136. package/docs/module-helper_setHook.html +4 -0
  137. package/docs/module-helper_walkBajos.html +6 -0
  138. package/docs/scripts/core.js +655 -0
  139. package/docs/scripts/core.min.js +23 -0
  140. package/docs/scripts/resize.js +90 -0
  141. package/docs/scripts/search.js +265 -0
  142. package/docs/scripts/search.min.js +6 -0
  143. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  144. package/docs/scripts/third-party/fuse.js +9 -0
  145. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  146. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  147. package/docs/scripts/third-party/hljs-original.js +5171 -0
  148. package/docs/scripts/third-party/hljs.js +1 -0
  149. package/docs/scripts/third-party/popper.js +5 -0
  150. package/docs/scripts/third-party/tippy.js +1 -0
  151. package/docs/scripts/third-party/tocbot.js +672 -0
  152. package/docs/scripts/third-party/tocbot.min.js +1 -0
  153. package/docs/styles/clean-jsdoc-theme-base.css +975 -0
  154. package/docs/styles/clean-jsdoc-theme-dark.css +407 -0
  155. package/docs/styles/clean-jsdoc-theme-light.css +388 -0
  156. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  157. package/package.json +36 -4
  158. package/test/helper-error.js +25 -0
  159. package/test/helper-isSet.js +41 -0
  160. package/test/helper-pathResolve.js +28 -0
@@ -0,0 +1,75 @@
1
+ import yargs from 'yargs'
2
+ import { Parser } from 'yargs/helpers'
3
+ import flat from 'flat'
4
+ import isSet from '../helper/is-set.js'
5
+ import dotenvParseVariables from 'dotenv-parse-variables'
6
+ import importModule from '../helper/import-module.js'
7
+ import { find, each, set, camelCase, forOwn } from 'lodash-es'
8
+ import fs from 'fs-extra'
9
+ import currentLoc from '../helper/current-loc.js'
10
+
11
+ const { unflatten } = flat
12
+
13
+ const parseItem = (data, delimiter) => {
14
+ return unflatten(data, {
15
+ delimiter,
16
+ safe: true,
17
+ overwrite: true,
18
+ })
19
+ }
20
+
21
+ const parseWithParser = async () => {
22
+ return Parser(process.argv.slice(2), {
23
+ configuration: {
24
+ 'camel-case-expansion': false
25
+ }
26
+ })
27
+ }
28
+
29
+ const parseWithYargs = async () => {
30
+ const parser = './app/bajo/argv-parser.js'
31
+ if (fs.existsSync(parser)) {
32
+ const mod = await importModule(parser)
33
+ return await mod(yargs)
34
+ }
35
+ const pkg = fs.readJSONSync(`${currentLoc(import.meta).dir}/../../package.json`)
36
+ let name = `node ${pkg.main}`
37
+ if (pkg.bin) name = path.basename(pkg.bin, '.js')
38
+ const cli = yargs(process.argv.slice(2))
39
+ .usage('Usage: $0 [args...]')
40
+ .scriptName(name)
41
+ .positional('args', {
42
+ describe: 'Optional one or more arguments'
43
+ })
44
+ .parserConfiguration({
45
+ 'camel-case-expansion': false
46
+ })
47
+ .version().alias('version', 'v')
48
+ .help().alias('help', 'h')
49
+ .alias('tool', 't')
50
+ if (pkg.homepage) cli.epilog(`For more information please visit ${pkg.homepage}`)
51
+ return cli.argv
52
+ }
53
+
54
+ async function parseArgsArgv ({ delimiter = '-', splitter = '--', useParser } = {}) {
55
+ if (!isSet(useParser)) useParser = find(process.argv, a => a.startsWith('--spawn'))
56
+ let argv = useParser ? await parseWithParser() : await parseWithYargs()
57
+ const args = argv._
58
+ delete argv._
59
+ delete argv.$0
60
+ argv = dotenvParseVariables(argv)
61
+
62
+ const all = { root: {} }
63
+ each(argv, (v, k) => {
64
+ const parts = k.split(splitter)
65
+ if (!parts[1]) all.root[parts[0]] = v
66
+ else set(all, `${camelCase(parts[0])}.${parts[1]}`, v)
67
+ })
68
+ const result = {}
69
+ forOwn(all, (v, k) => {
70
+ result[k] = parseItem(v, delimiter)
71
+ })
72
+ return { args, argv: result }
73
+ }
74
+
75
+ export default parseArgsArgv
@@ -0,0 +1,36 @@
1
+ import dotenvParseVariables from 'dotenv-parse-variables'
2
+ import flat from 'flat'
3
+ import dotEnv from 'dotenv'
4
+ import { each, set, camelCase, forOwn } from 'lodash-es'
5
+ const { unflatten } = flat
6
+
7
+ const parse = (data, delimiter) => {
8
+ return unflatten(data, {
9
+ delimiter,
10
+ safe: true,
11
+ overwrite: true,
12
+ transformKey: k => k.toLowerCase()
13
+ })
14
+ }
15
+
16
+ export default function ({ delimiter = '_', splitter = '__' } = {}) {
17
+ let env
18
+ try {
19
+ env = dotEnv.config()
20
+ if (env.error) throw env.error
21
+ } catch (err) {
22
+ env = { parsed: {} }
23
+ }
24
+ env = dotenvParseVariables(env.parsed, { assignToProcessEnv: false })
25
+ const all = { root: {} }
26
+ each(env, (v, k) => {
27
+ const parts = k.split(splitter)
28
+ if (!parts[1]) all.root[parts[0]] = v
29
+ else set(all, `${camelCase(parts[0])}.${parts[1]}`, v)
30
+ })
31
+ const result = {}
32
+ forOwn(all, (v, k) => {
33
+ result[k] = parse(v, delimiter)
34
+ })
35
+ return result
36
+ }
@@ -0,0 +1,14 @@
1
+ // taken from: https://vanillajstoolkit.com/polyfills/stringreplaceall/
2
+
3
+ function shim () {
4
+ if (!String.prototype.replaceAll) {
5
+ String.prototype.replaceAll = function(str, newStr){
6
+ if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
7
+ return this.replace(str, newStr)
8
+ }
9
+ return this.replace(new RegExp(str, 'g'), newStr)
10
+ }
11
+ }
12
+ }
13
+
14
+ export default shim
@@ -0,0 +1,20 @@
1
+ import buildHelper from '../lib/build-helper.js'
2
+ import { keys } from 'lodash-es'
3
+
4
+ async function runner (plugin, pkg) {
5
+ const { log, freeze } = this.bajo.helper
6
+ const dir = pkg === 'app' ? (this.bajo.config.dir.base + '/app') : this.bajo.helper.getModuleDir(pkg)
7
+ this[plugin].helper = await buildHelper.call(this, `${dir}/bajo/helper`, { pkg })
8
+ freeze(this[plugin].helper, true)
9
+ log.trace('Attach helper: %s (%d)', plugin, keys(this[plugin].helper).length)
10
+ }
11
+
12
+ async function attachHelper () {
13
+ const { log, eachPlugins } = this.bajo.helper
14
+ log.debug('Attach helpers')
15
+ await eachPlugins(async function ({ plugin, pkg }) {
16
+ await runner.call(this, plugin, pkg)
17
+ })
18
+ }
19
+
20
+ export default attachHelper
@@ -0,0 +1,82 @@
1
+ import { camelCase, pick, isString, omit, pull, each } from 'lodash-es'
2
+ import fs from 'fs-extra'
3
+ import lockfile from 'proper-lockfile'
4
+ import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
5
+ import titleize from '../helper/titleize.js'
6
+
7
+ export async function readAllConfigs (base, name) {
8
+ const { readConfig, getConfig } = this.bajo.helper
9
+ const config = getConfig()
10
+ let cfg = {}
11
+ try {
12
+ cfg = await readConfig(`${base}-${config.env}.*`)
13
+ } catch (err) {
14
+ if (['BAJO_CONFIG_NO_PARSER'].includes(err.code)) throw err
15
+ if (['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) {
16
+ try {
17
+ cfg = await readConfig(`${base}.*`)
18
+ } catch (err) {
19
+ if (!['BAJO_CONFIG_FILE_NOT_FOUND'].includes(err.code)) throw err
20
+ }
21
+ }
22
+ }
23
+ cfg.name = name
24
+ return cfg
25
+ }
26
+
27
+ async function runner (pkg, { singles, argv, env }) {
28
+ const { log, getConfig, getModuleDir, readConfig, error, readJson, defaultsDeep } = this.bajo.helper
29
+ const config = getConfig()
30
+ const name = camelCase(pkg)
31
+ log.trace('Read configuration: %s', name)
32
+ const dir = pkg === 'app' ? (config.dir.base + '/app') : getModuleDir(pkg)
33
+ if (pkg !== 'app' && !fs.existsSync(`${dir}/bajo`)) throw error('Package \'%s\' isn\'t a valid Bajo package', pkg, { code: 'BAJO_INVALID_PACKAGE' })
34
+ let cfg = await readAllConfigs.call(this, `${dir}/bajo/config`, name)
35
+ cfg.dir = {
36
+ pkg: dir,
37
+ data: `${config.dir.data}/plugins/${name}`
38
+ }
39
+ const pkgJson = await readJson(`${dir + (pkg === 'app' ? '/..' : '')}/package.json`)
40
+ cfg.pkg = pick(pkgJson,
41
+ ['name', 'version', 'description', 'author', 'license', 'homepage'])
42
+ if (cfg.name === 'app') {
43
+ cfg.alias = 'app'
44
+ cfg.title = 'Application'
45
+ } else if (!isString(cfg.alias)) cfg.alias = pkg.slice(0, 5) === 'bajo-' ? pkg.slice(5).toLowerCase() : pkg // fix. can't be overriden
46
+ cfg.title = cfg.title ?? titleize.call(this, cfg.alias)
47
+ // merge with config from datadir
48
+ try {
49
+ const altCfg = await readConfig(`${config.dir.data}/config/${cfg.name}.*`)
50
+ cfg = defaultsDeep({}, omit(altCfg, omittedPluginKeys), cfg)
51
+ } catch (err) {}
52
+ const envArgv = defaultsDeep({}, omit(env[cfg.name] ?? {}, omittedPluginKeys) ?? {}, omit(argv[cfg.name] ?? {}, omittedPluginKeys) ?? {})
53
+ cfg = defaultsDeep({}, envArgv ?? {}, cfg ?? {})
54
+ cfg.dependencies = cfg.dependencies ?? []
55
+ if (isString(cfg.dependencies)) cfg.dependencies = [cfg.dependencies]
56
+ if (cfg.single) {
57
+ const lockfileDir = `${config.dir.tmp}/lock`
58
+ const lockfilePath = `${lockfileDir}/${name}.lock`
59
+ fs.ensureDirSync(lockfileDir)
60
+ const file = `${dir}/package.json`
61
+ try {
62
+ await lockfile.lock(file, { lockfilePath })
63
+ } catch (err) {
64
+ singles.push(pkg)
65
+ }
66
+ }
67
+ if (!this[name]) this[name] = {}
68
+ this[name].config = cfg
69
+ }
70
+
71
+ async function buildConfig ({ singles, argv, env }) {
72
+ const { log, freeze } = this.bajo.helper
73
+ log.debug('Read configurations')
74
+ for (const pkg of this.bajo.config.plugins) {
75
+ await runner.call(this, pkg, { singles, argv, env })
76
+ }
77
+ pull(this.bajo.config.plugins, ...singles)
78
+ each(singles, s => delete this[camelCase(s)])
79
+ freeze(this.bajo.config)
80
+ }
81
+
82
+ export default buildConfig
@@ -0,0 +1,18 @@
1
+ import { find } from 'lodash-es'
2
+ import error from '../helper/error.js'
3
+
4
+ async function checkAlias () {
5
+ const { log, eachPlugins } = this.bajo.helper
6
+ log.debug('Checking alias & name clashes')
7
+ const refs = []
8
+ await eachPlugins(async function ({ plugin, pkg, alias }) {
9
+ let item = find(refs, { plugin })
10
+ if (item) throw error('Plugin name clash: \'%s (%s)\' with \'%s (%s)\'', plugin, pkg, item.plugin, item.pkg, { code: 'BAJO_NAME_CLASH' })
11
+ item = find(refs, { alias })
12
+ if (item) throw error('Plugin alias clash: \'%s (%s)\' with \'%s (%s)\'', alias, pkg, item.alias, item.pkg, { code: 'BAJO_ALIAS_CLASH' })
13
+ refs.push({ plugin, alias, pkg })
14
+ })
15
+ this.bajo.pluginRefs = refs
16
+ }
17
+
18
+ export default checkAlias
@@ -0,0 +1,37 @@
1
+ import { reduce, map, trim, keys, intersection, each, camelCase, get } from 'lodash-es'
2
+ import semver from 'semver'
3
+
4
+ async function runner ({ plugin, pkg, dependencies }) {
5
+ const { log, getConfig, error } = this.bajo.helper
6
+ log.trace('Checking dependencies: %s', plugin)
7
+ const config = getConfig()
8
+ const odep = reduce(dependencies, (o, k) => {
9
+ const item = map(k.split('@'), m => trim(m))
10
+ o[item[0]] = item[1]
11
+ return o
12
+ }, {})
13
+ const deps = keys(odep)
14
+ if (deps.length > 0) {
15
+ if (intersection(config.plugins, deps).length !== deps.length) {
16
+ throw error('Dependency for \'%s\' unfulfilled: %s', pkg, deps.join(', '), { code: 'BAJO_DEPENDENCY' })
17
+ }
18
+ each(deps, d => {
19
+ if (!odep[d]) return
20
+ const ver = get(this[camelCase(d)], 'config.pkg.version')
21
+ if (!ver) return
22
+ if (!semver.satisfies(ver, odep[d])) {
23
+ throw error('Semver check \'%s\' against \'%s\' failed', pkg, `${d}@${odep[d]}`, { code: 'BAJO_DEPENDENCY_SEMVER' })
24
+ }
25
+ })
26
+ }
27
+ }
28
+
29
+ async function checkDependency () {
30
+ const { log, eachPlugins } = this.bajo.helper
31
+ log.debug('Checking dependencies')
32
+ await eachPlugins(async function ({ plugin, pkg, dependencies }) {
33
+ await runner.call(this, { plugin, pkg, dependencies })
34
+ })
35
+ }
36
+
37
+ export default checkDependency
@@ -0,0 +1,25 @@
1
+ import { isFunction, isPlainObject, map } from 'lodash-es'
2
+ import fs from 'fs-extra'
3
+
4
+ async function collectConfigHandlers (pkg) {
5
+ const { getModuleDir, importModule, log } = this.bajo.helper
6
+ for (const pkg of this.bajo.config.plugins) {
7
+ let dir
8
+ try {
9
+ dir = getModuleDir(pkg)
10
+ } catch (err) {}
11
+ if (!dir) continue
12
+ const file = `${dir}/bajo/extend/read-config.js`
13
+ if (!fs.existsSync(file)) continue
14
+ try {
15
+ let mod = await importModule(file)
16
+ if (isFunction(mod)) mod = await mod.call(this)
17
+ if (isPlainObject(mod)) mod = [mod]
18
+ this.bajo.configHandlers.concat(mod)
19
+ } catch (err) {}
20
+ }
21
+ const exts = map(this.bajo.configHandlers, 'ext')
22
+ log.trace('Config handlers: %s', exts.join(', '))
23
+ }
24
+
25
+ export default collectConfigHandlers
@@ -0,0 +1,23 @@
1
+ import {} from 'lodash-es'
2
+ import fs from 'fs-extra'
3
+
4
+ async function collectExitHandlers () {
5
+ const { importModule, log, eachPlugins, getConfig, print } = this.bajo.helper
6
+ const config = getConfig()
7
+ if (!config.exitHandler) return
8
+ this.bajo.exitHandler = this.bajo.exitHandler ?? {}
9
+ const names = []
10
+ await eachPlugins(async function ({ plugin, dir }) {
11
+ const file = `${dir}/bajo/exit.js`
12
+ if (!fs.existsSync(file)) return undefined
13
+ try {
14
+ const mod = await importModule(file)
15
+ this.bajo.exitHandler[plugin] = mod
16
+ names.push(plugin)
17
+ } catch (err) {
18
+ }
19
+ })
20
+ log.trace('Exit handlers: %s', names.length === 0 ? print.__('none') : names.join(', '))
21
+ }
22
+
23
+ export default collectExitHandlers
@@ -0,0 +1,34 @@
1
+ import { map, camelCase, merge, forOwn, groupBy } from 'lodash-es'
2
+
3
+ async function collectHooks () {
4
+ const { eachPlugins, log, runHook, isLogInRange, importModule } = this.bajo.helper
5
+ this.bajo.hooks = this.bajo.hooks ?? []
6
+ log.debug('Collect hooks')
7
+ // collects
8
+ await eachPlugins(async function ({ plugin, dir, file }) {
9
+ const hookName = (file.slice(dir.length + 1) ?? '').split('/')[1]
10
+ let [ns, path] = hookName.replace('.js', '').split('@')
11
+ if (!path) {
12
+ path = ns
13
+ ns = plugin
14
+ }
15
+ path = camelCase(path)
16
+ ns = map(ns.split('.'), (n, i) => i === 1 ? n : camelCase(n)).join('.')
17
+ const mod = await importModule(file, { asHandler: true })
18
+ if (!mod) return undefined
19
+ merge(mod, { ns, path })
20
+ this.bajo.hooks.push(mod)
21
+ }, { glob: 'hook/**/*.js', insideBajo: true })
22
+ await runHook('bajo:afterCollectHooks')
23
+ // for log trace purpose only
24
+ if (!isLogInRange('trace')) return
25
+ const items = groupBy(this.bajo.hooks, 'ns')
26
+ forOwn(items, (v, k) => {
27
+ const hooks = groupBy(v, 'path')
28
+ forOwn(hooks, (v1, k1) => {
29
+ log.trace('Collect hook: %s:%s (%d)', k, k1, v1.length)
30
+ })
31
+ })
32
+ }
33
+
34
+ export default collectHooks
@@ -0,0 +1,21 @@
1
+ import { isArray, each, isPlainObject, has, merge, concat } from 'lodash-es'
2
+ import { readAllConfigs } from './build-config.js'
3
+
4
+ async function extendConfig () {
5
+ const { eachPlugins } = this.bajo.helper
6
+ await eachPlugins(async function (opts) {
7
+ if (!opts.cfg.mergeProps) return undefined
8
+ await eachPlugins(async function ({ dir, plugin }) {
9
+ const cfg = await readAllConfigs.call(this, `${dir}/${opts.plugin}/config`, opts.plugin)
10
+ each(opts.cfg.mergeProps, p => {
11
+ if (!has(cfg, p)) return undefined
12
+ if (isArray(opts.cfg[p])) this[opts.plugin].config[p] = concat(opts.cfg[p], cfg[p])
13
+ else if (isPlainObject(opts.cfg[p])) this[opts.plugin].config[p] = merge(opts.cfg[p], cfg[p])
14
+ else this[opts.plugin].config[p] = cfg[p]
15
+ })
16
+ })
17
+ delete this[opts.plugin].config.mergeProps
18
+ })
19
+ }
20
+
21
+ export default extendConfig
@@ -0,0 +1,28 @@
1
+ import buildConfig from './build-config.js'
2
+ import extendConfig from './extend-config.js'
3
+ import checkDependency from './check-dependency.js'
4
+ import checkClash from './check-clash.js'
5
+ import attachHelper from './attach-helper.js'
6
+ import collectHooks from './collect-hooks.js'
7
+ import run from './run.js'
8
+ import collectConfigHandlers from './collect-config-handlers.js'
9
+ import collectExitHandlers from './collect-exit-handlers.js'
10
+ import parseArgsArgv from '../lib/parse-args-argv.js'
11
+ import parseEnv from '../lib/parse-env.js'
12
+
13
+ async function bootBajos () {
14
+ const singles = []
15
+ const { argv } = await parseArgsArgv({ useParser: true }) ?? {}
16
+ const env = parseEnv() ?? {}
17
+ await collectConfigHandlers.call(this)
18
+ await buildConfig.call(this, { singles, argv, env })
19
+ await extendConfig.call(this)
20
+ await checkClash.call(this)
21
+ await checkDependency.call(this)
22
+ await attachHelper.call(this)
23
+ await collectHooks.call(this)
24
+ await run.call(this, { singles })
25
+ await collectExitHandlers.call(this)
26
+ }
27
+
28
+ export default bootBajos
@@ -0,0 +1,31 @@
1
+ import { get, camelCase, upperFirst, map } from 'lodash-es'
2
+ import fs from 'fs-extra'
3
+
4
+ async function run ({ singles }) {
5
+ const { runHook, log, eachPlugins, importModule, freeze, getConfig, print } = this.bajo.helper
6
+ const config = getConfig()
7
+ const methods = ['init']
8
+ if (!get(config, 'tool')) methods.push('start')
9
+ for (const f of methods) {
10
+ await runHook(`bajo:${camelCase(`before ${f} all plugins`)}`)
11
+ await eachPlugins(async function ({ plugin, dir }) {
12
+ const file = `${dir}/bajo/${f}.js`
13
+ if (fs.existsSync(file)) {
14
+ log.debug('%s: %s', print.__(upperFirst(f)), plugin)
15
+ await runHook(`bajo:${camelCase(`before ${f} ${plugin}`)}`)
16
+ const item = await importModule(file)
17
+ const params = f === 'start' ? ['all', true] : []
18
+ await item.call(this, ...params)
19
+ await runHook(`bajo:${camelCase(`after ${f} ${plugin}`)}`)
20
+ }
21
+ if (f === 'init') freeze(this[plugin].config)
22
+ })
23
+ await runHook(`bajo:${camelCase(`after ${f} all plugins`)}`)
24
+ }
25
+ log.debug('Loaded plugins: %s', map(config.plugins, b => camelCase(b)).join(', '))
26
+ if (singles.length > 0) {
27
+ log.warn('Unloaded \'single\' plugins: %s', map(singles, s => camelCase(s)).join(', '))
28
+ }
29
+ }
30
+
31
+ export default run
@@ -0,0 +1,34 @@
1
+ import { isString, map, find } from 'lodash-es'
2
+ const tools = []
3
+
4
+ async function runTool () {
5
+ const { getConfig, log, eachPlugins, importPkg, importModule, print } = this.bajo.helper
6
+ const config = getConfig()
7
+ if (!config.tool) return
8
+ log.debug('Run tool')
9
+ print.info('Sidetool is running...')
10
+
11
+ await eachPlugins(async function checkCli ({ file, plugin, alias }) {
12
+ tools.push({ ns: plugin, file, nsAlias: alias })
13
+ }, { glob: 'tool.js', ns: 'bajoCli' })
14
+ if (tools.length === 0) print.fatal('No tool loaded. Aborted!')
15
+ let name = config.tool
16
+ let toc = false
17
+ if (!isString(config.tool)) {
18
+ const select = await importPkg('bajo-cli:@inquirer/select')
19
+ name = await select({
20
+ message: print.__('Please select tool provider:'),
21
+ choices: map(tools, t => ({ value: t.ns }))
22
+ })
23
+ toc = true
24
+ }
25
+ const [ns, path, ...params] = name.split(':')
26
+ const tool = find(tools, t => (t.ns === ns || t.nsAlias === ns))
27
+ if (!tool) print.fatal('Sidetool \'%s\' not found. Aborted!', name)
28
+ const opts = { ns, toc, path, params, args: config.args }
29
+ const mod = await importModule(tool.file)
30
+ const handler = mod.handler ?? mod
31
+ await handler.call(this, opts)
32
+ }
33
+
34
+ export default runTool
@@ -0,0 +1,75 @@
1
+ <!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: boot/build-config.js</title><!--[if lt IE 9]>
2
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3
+ <![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="",baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body class="dark" data-theme="dark"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">boot_build-config.js</h1></header><article><pre class="prettyprint source lang-js"><code>/**
4
+ * @module boot/buildConfig
5
+ */
6
+
7
+ const fs = require('fs-extra')
8
+ const _ = require('lodash')
9
+ const pathResolve = require('../helper/path-resolve')
10
+ const readConfig = require('../helper/read-config')
11
+ const getKeyByValue = require('../helper/get-key-by-value')
12
+ const error = require('../helper/error')
13
+ const envs = require('../helper/envs')
14
+ const parseArgsArgv = require('../lib/parse-args-argv')
15
+ const parseEnv = require('../lib/parse-env')
16
+
17
+ /**
18
+ * Building configuration object. Read configurtion file from app data directory, program
19
+ * arguments and envoronment variables with following priority: ```Env > Args > Config file >
20
+ * defaults config```
21
+ *
22
+ * If data directory is provided and doesn't exist yet, it will be automatically created.
23
+ *
24
+ * Config file must be located in: ```&lt;data dir>/config/bajo.&lt;format>```, and support either
25
+ * ```.json``` or ```.js``` format. JS format must be a nodejs module that wrap an async
26
+ * function and return an object
27
+ *
28
+ * @instance
29
+ * @async
30
+ * @throws Will throw if data directory is not provided
31
+ *
32
+ * @returns {Object} config
33
+ */
34
+
35
+ async function buildConfig () {
36
+ const { args, argv } = parseArgsArgv()
37
+ const env = parseEnv()
38
+ let defConfig = {
39
+ dir: {},
40
+ log: {
41
+ level: 'info',
42
+ dateFormat: `UTC:yyyy-mm-dd'T'HH:MM:ss.l'Z'`,
43
+ report: ['sysreport', 'helper', 'hook'],
44
+ details: []
45
+ },
46
+ plugins: ['app'],
47
+ env: 'dev'
48
+ }
49
+ defConfig = _.defaultsDeep(env.root, argv.root, defConfig)
50
+ if (!defConfig.dir.data) throw error('No data directory provided', { code: 'BAJO_DATA_DIR_NOT_PROVIDED' })
51
+ defConfig.dir.data = pathResolve(defConfig.dir.data)
52
+ _.set(defConfig, 'dir.base', pathResolve(process.cwd()))
53
+ _.each(['tmp', 'lock'], k => {
54
+ if (!defConfig.dir[k]) defConfig.dir[k] = `${defConfig.dir.data}/${k}`
55
+ fs.ensureDirSync(defConfig.dir[k])
56
+ })
57
+ fs.ensureDirSync(defConfig.dir.data + '/config')
58
+ const resp = _.omit(await readConfig.call(this, `${defConfig.dir.data}/config/bajo.*`), ['dir'])
59
+ const config = _.defaultsDeep(resp, defConfig)
60
+ config.args = args
61
+ config.env = config.env.toLowerCase()
62
+ if (_.values(envs).includes(config.env)) config.env = getKeyByValue.handler(envs, config.env)
63
+ if (!_.keys(envs).includes(config.env)) config.env = 'dev'
64
+ process.env.NODE_ENV = envs[config.env]
65
+ if (_.isString(config.log.details)) config.log.details = _.map((argv.root['log-details'] || '').split(','), t => _.trim(t))
66
+ if (config.env === 'dev') config.log.level = 'debug'
67
+ if (config.verbose) config.log.level = 'trace'
68
+
69
+ if (!config.plugins.includes('app')) config.plugins.push('app')
70
+ config.plugins = _.filter(_.uniq(_.map(config.plugins, b => _.trim(b))), b => !_.isEmpty(b))
71
+ this.bajo.config = config
72
+ }
73
+
74
+ module.exports = buildConfig
75
+ </code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: boot/create-scope.js</title><!--[if lt IE 9]>
2
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3
+ <![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="",baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body class="dark" data-theme="dark"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">boot_create-scope.js</h1></header><article><pre class="prettyprint source lang-js"><code>/**
4
+ * @module boot/createScope
5
+ */
6
+
7
+ const { EventEmitter } = require('events')
8
+ const event = new EventEmitter()
9
+
10
+ const bajo = {
11
+ event
12
+ }
13
+
14
+ /**
15
+ * @instance
16
+ * @async
17
+ * @returns {Object} scope
18
+ */
19
+
20
+ function createScope () {
21
+ return { bajo }
22
+ }
23
+
24
+ module.exports = createScope
25
+ </code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo Framework</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="giIwooOtbeeq9fbiwZEz4"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-boot.html">boot</a></div><div class="sidebar-section-children"><a href="module-boot_buildConfig.html">boot/buildConfig</a></div><div class="sidebar-section-children"><a href="module-boot_createScope.html">boot/createScope</a></div><div class="sidebar-section-children"><a href="module-helper.html">helper</a></div><div class="sidebar-section-children"><a href="module-helper_runHook.html">helper/runHook</a></div><div class="sidebar-section-children"><a href="module-helper_eachPlugins.html">helper/eachPlugins</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>