bajo 0.2.11 → 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/lib/bora.js CHANGED
@@ -29,7 +29,7 @@ class Bora {
29
29
  }
30
30
 
31
31
  setText (text, ...args) {
32
- const { dayjs, secToHms } = this.scope.bajo.helper
32
+ const { dayjs } = this.scope.bajo.helper
33
33
  if (isString(text)) {
34
34
  const i18n = get(this, 'scope.bajoI18N.instance')
35
35
  if (i18n) {
@@ -38,16 +38,22 @@ class Bora {
38
38
  } else text = sprintf(text, ...args)
39
39
  let opts = last(args)
40
40
  if (!isPlainObject(opts)) opts = {}
41
- const elapsed = dayjs().diff(this.startTime, 'second')
42
41
  const texts = []
43
42
  if (this.opts.showDatetime || opts.showDatetime) texts.push('[' + dayjs().toISOString() + ']')
44
- if (this.opts.showCounter || opts.showCounter) texts.push('[' + secToHms(elapsed) + ']')
43
+ if (this.opts.showCounter || opts.showCounter) texts.push('[' + this.getElapsed() + ']')
45
44
  texts.push(text)
46
45
  this.ora.text = texts.join(' ')
47
46
  }
48
47
  return this
49
48
  }
50
49
 
50
+ getElapsed (unit = 'hms') {
51
+ const { dayjs, secToHms } = this.scope.bajo.helper
52
+ const u = unit === 'hms' ? 'second' : unit
53
+ const elapsed = dayjs().diff(this.startTime, u)
54
+ return unit === 'hms' ? secToHms(elapsed) : elapsed
55
+ }
56
+
51
57
  start (text, ...args) {
52
58
  this.setText(text, ...args)
53
59
  this.ora.start()
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.11",
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": {