bajo 0.2.12 → 0.2.13

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.
@@ -0,0 +1,17 @@
1
+ import path from 'path'
2
+ import { isString, isFunction, keys, camelCase, kebabCase, snakeCase } from 'lodash-es'
3
+ import pascalCase from './pascal-case.js'
4
+ const converter = { camelCase, kebabCase, snakeCase, pascalCase }
5
+
6
+ function buildName (file, options = {}) {
7
+ if (isString(options)) options = { base: options }
8
+ if (!options.base) options.base = path.dirname(file)
9
+ if (!keys(converter).includes(options.converter)) options.converter = 'camelCase'
10
+ let name = file.replace(options.base, '')
11
+ name = name.slice(0, name.indexOf(path.extname(name)))
12
+ if (isFunction(options.converter)) name = options.converter.call(this, name)
13
+ else name = converter[options.converter](name)
14
+ return name
15
+ }
16
+
17
+ export default buildName
@@ -80,6 +80,7 @@ async function _eachPlugins (handler, { key = 'name', glob, ns, useBajo } = {})
80
80
 
81
81
  async function eachPlugins (handler, options = {}) {
82
82
  const { getConfig, getPluginName } = this.bajo.helper
83
+ if (typeof options === 'string') options = { glob: options }
83
84
  let { key = 'name', glob, ns, extend, extendHandler, useBajo } = options
84
85
  if (!extendHandler) extendHandler = handler
85
86
  ns = ns ?? getPluginName(4)
@@ -3,7 +3,7 @@ import error from './error.js'
3
3
  import breakNsPath from './break-ns-path.js'
4
4
 
5
5
  function getHelper (name = '', thrown = true) {
6
- const [plugin, method] = breakNsPath(name)
6
+ const [plugin, method] = breakNsPath.call(this, name)
7
7
  const helper = get(this, `${plugin}.helper.${method}`)
8
8
  if (helper) return helper
9
9
  if (thrown) throw error.call(this, 'Can\'t find helper named \'%s\'', name)
@@ -90,7 +90,7 @@ const print = {
90
90
  if (opts.type === 'bora') bora.call(this, ns, opts).fatal(msg, ...params)
91
91
  else console.error(format.call(this, ns, msg, ...params))
92
92
  }
93
- process.exit(0)
93
+ process.exit(1)
94
94
  },
95
95
  bora: function (...args) {
96
96
  let ns = getPluginName.call(this, 2)
package/boot/run-tool.js CHANGED
@@ -4,14 +4,14 @@ const tools = []
4
4
  async function runTool () {
5
5
  const { getConfig, log, eachPlugins, importPkg, importModule, print } = this.bajo.helper
6
6
  const config = getConfig()
7
- if (!config.tool) return
8
- log.debug('Run tool')
9
- print.info('Sidetool is running...')
10
-
11
7
  await eachPlugins(async function checkCli ({ file, plugin, alias }) {
12
8
  tools.push({ ns: plugin, file, nsAlias: alias })
13
9
  }, { glob: 'tool.js', ns: 'bajoCli' })
14
- if (tools.length === 0) print.fatal('No tool loaded. Aborted!')
10
+ this.bajo.tools = tools
11
+ if (!config.tool) return
12
+ log.debug('Run tool')
13
+ print.info('Sidetool is running...')
14
+ if (tools.length === 0) print.fatal('No tool found. Aborted!')
15
15
  let name = config.tool
16
16
  let toc = false
17
17
  if (!isString(config.tool)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {