bajo 1.1.1 → 1.1.3

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.
@@ -154,5 +154,7 @@
154
154
  "thankYou": "Thank you!",
155
155
  "adminArea": "Admin Area",
156
156
  "instanceCreatedOnConn%s%s": "Instance '%s' created on connection '%s'",
157
- "fileNotModuleHandler%s": "File '%s' is NOT a module handler"
157
+ "fileNotModuleHandler%s": "File '%s' is NOT a module handler",
158
+ "error%s": "Error: %s",
159
+ "invalid%s%s": "Invalid %s (%s)"
158
160
  }
package/bajo/intl/id.json CHANGED
@@ -154,5 +154,7 @@
154
154
  "thankYou": "Terima kasih!",
155
155
  "adminArea": "Area Admin",
156
156
  "instanceCreatedOnConn%s%s": "Instance '%s' telah dibuat pada koneksi '%s'",
157
- "fileNotModuleHandler%s": "Berkas '%s' BUKAN merupakan module handler"
157
+ "fileNotModuleHandler%s": "Berkas '%s' BUKAN merupakan module handler",
158
+ "error%s": "Kesalahan: %s",
159
+ "invalid%s%s": "%s tidak valid (%s)"
158
160
  }
@@ -42,8 +42,10 @@ export async function buildBaseConfig () {
42
42
  if (!get(this, 'dir.data')) set(this, 'dir.data', `${this.dir.base}/data`)
43
43
  this.dir.data = this.resolvePath(this.dir.data)
44
44
  if (!fs.existsSync(this.dir.data)) {
45
- this.log.warn('ddirNotExists%s', this.dir.data)
45
+ console.log('Data directory (%s) doesn\'t exist yet', this.dir.data)
46
+ process.exit(1)
46
47
  }
48
+ fs.ensureDirSync(`${this.dir.data}/config`)
47
49
  if (!this.dir.tmp) {
48
50
  this.dir.tmp = `${this.resolvePath(os.tmpdir())}/${this.name}`
49
51
  fs.ensureDirSync(this.dir.tmp)
@@ -19,8 +19,15 @@ async function buildPlugins () {
19
19
  this.pluginPkgs.push(this.mainNs)
20
20
  for (const pkg of this.pluginPkgs) {
21
21
  const ns = camelCase(pkg)
22
- const dir = ns === this.mainNs ? (`${this.dir.base}/${this.mainNs}`) : this.getModuleDir(pkg)
23
- if (ns !== this.mainNs && !fs.existsSync(`${dir}/plugin`)) throw new Error(`Package '${pkg}' isn't a valid Bajo package`)
22
+ let dir
23
+ if (ns === 'main') {
24
+ dir = `${this.dir.base}/${this.mainNs}`
25
+ fs.ensureDirSync(dir)
26
+ fs.ensureDirSync(`${dir}/plugin`)
27
+ } else {
28
+ dir = this.getModuleDir(pkg)
29
+ if (!fs.existsSync(`${dir}/plugin`)) throw new Error(`Package '${pkg}' isn't a valid Bajo package`)
30
+ }
24
31
  let plugin
25
32
  const factory = `${dir}/plugin/factory.js`
26
33
  if (fs.existsSync(factory)) {
@@ -28,7 +28,7 @@ const {
28
28
  isFunction, words, upperFirst, map, concat, uniq, forOwn, padStart,
29
29
  trim, filter, isEmpty, orderBy, pullAt, find, camelCase, isNumber,
30
30
  cloneDeep, isPlainObject, isArray, isString, set, omit, keys, indexOf,
31
- last, get, has, values, dropRight, mergeWith
31
+ last, get, has, values, dropRight, pick, mergeWith
32
32
  } = lodash
33
33
 
34
34
  class BajoCore extends Plugin {
@@ -163,14 +163,11 @@ class BajoCore extends Plugin {
163
163
  if (deleted.length > 0) pullAt(items, deleted)
164
164
 
165
165
  // check for duplicity
166
- for (const c of items) {
167
- for (const d of dupChecks) {
168
- if (isFunction(d)) await d.call(this.app[ns], c, items)
169
- else {
170
- const checker = set({}, d, c[d])
171
- const match = filter(items, checker)
172
- if (match.length > 1) this.app[ns].fatal('oneOrMoreSharedTheSame%s%s', container, this.join(dupChecks.filter(i => !isFunction(i))))
173
- }
166
+ if (dupChecks.length > 0) {
167
+ const checkers = []
168
+ for (const c of items) {
169
+ const checker = JSON.stringify(pick(c, dupChecks))
170
+ if (checkers.includes(checker)) this.app[ns].fatal('oneOrMoreSharedTheSame%s%s', container, this.join(dupChecks.filter(i => !isFunction(i))))
174
171
  }
175
172
  }
176
173
  await this.runHook(`${ns}:${camelCase('afterBuildCollection')}`, container)
@@ -570,32 +567,35 @@ class BajoCore extends Plugin {
570
567
  return dt.toDate()
571
568
  }
572
569
 
573
- parseObject = (input, { silent = true, parseValue = false, lang, ns } = {}) => {
570
+ parseObject = (input, options = {}) => {
571
+ const { silent = true, parseValue = false, lang, ns } = options
572
+ const translate = (item) => {
573
+ const scope = ns ? this.app[ns] : this
574
+ const [text, ...args] = item.split('|')
575
+ return scope.print.write(text, ...args, { lang })
576
+ }
574
577
  const statics = ['*']
575
578
  let obj = cloneDeep(input)
576
579
  const keys = Object.keys(obj)
577
- const me = this
578
580
  const mutated = []
579
581
  keys.forEach(k => {
580
- const v = obj[k]
581
- if (isPlainObject(v)) obj[k] = this.parseObject(v)
582
+ let v = obj[k]
583
+ if (isPlainObject(v)) obj[k] = this.parseObject(v, options)
582
584
  else if (isArray(v)) {
583
585
  v.forEach((i, idx) => {
584
- if (isPlainObject(i)) obj[k][idx] = this.parseObject(i)
586
+ if (isPlainObject(i)) obj[k][idx] = this.parseObject(i, options)
585
587
  else if (statics.includes(i)) obj[k][idx] = i
586
588
  else if (parseValue) obj[k][idx] = dotenvParseVariables(set({}, 'item', obj[k][idx]), { assignToProcessEnv: false }).item
587
589
  if (isArray(obj[k][idx])) obj[k][idx] = obj[k][idx].map(item => typeof item === 'string' ? item.trim() : item)
588
590
  })
589
591
  } else if (this.isSet(v)) {
592
+ if (isString(v) && v.startsWith('t:') && lang) v = translate(v.slice(2))
590
593
  try {
591
594
  if (statics.includes(v)) obj[k] = v
592
595
  else if (k.startsWith('t:') && isString(v)) {
593
596
  const newK = k.slice(2)
594
- if (lang) {
595
- const scope = ns ? me.app[ns] : me
596
- const [text, ...args] = v.split('|')
597
- obj[newK] = scope.print.write(text, ...args, { lang })
598
- } else obj[newK] = v
597
+ if (lang) obj[newK] = translate(v)
598
+ else obj[newK] = v
599
599
  mutated.push(k)
600
600
  } else if (parseValue) {
601
601
  obj[k] = dotenvParseVariables(set({}, 'item', v), { assignToProcessEnv: false }).item
@@ -3,6 +3,20 @@ import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
3
3
  import Log from './log.js'
4
4
  import Print from './print.js'
5
5
  import BajoError from './error.js'
6
+ import fastGlob from 'fast-glob'
7
+ import { sprintf } from 'sprintf-js'
8
+ import outmatch from 'outmatch'
9
+ import dayjs from '../lib/dayjs.js'
10
+ import fs from 'fs-extra'
11
+
12
+ const lib = {
13
+ _: lodash,
14
+ fs,
15
+ fastGlob,
16
+ sprintf,
17
+ outmatch,
18
+ dayjs
19
+ }
6
20
 
7
21
  const { get, isEmpty, cloneDeep, omit, isPlainObject, camelCase } = lodash
8
22
 
@@ -12,7 +26,7 @@ class Plugin {
12
26
  this.name = camelCase(pkgName)
13
27
  this.app = app
14
28
  this.config = {}
15
- this.lib = {}
29
+ this.lib = lib
16
30
  this.exitHandler = undefined
17
31
  }
18
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {