bajo-extra 0.2.4 → 0.2.6

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.
@@ -19,7 +19,8 @@ async function fetchAndSave ({ source = {}, converter, coll, current = {}, optio
19
19
  try {
20
20
  await recordCreate(coll, r)
21
21
  if (current.coll && current.query) {
22
- const recs = await recordFind(current.coll, current.query)
22
+ const query = await current.query.call(this, r)
23
+ const recs = await recordFind(current.coll, { query })
23
24
  const rc = current.converter ? await current.converter.call(this, r, options) : r
24
25
  if (recs.length > 0) {
25
26
  const id = recs[0].id
@@ -7,14 +7,20 @@ function makeProgress (spinner) {
7
7
  }
8
8
  }
9
9
 
10
- async function exportTo (path, args) {
10
+ async function exportTo ({ path, args, returnEarly }) {
11
11
  const { importPkg, print, dayjs, getConfig, importModule } = this.bajo.helper
12
12
  const { isEmpty, map } = await importPkg('lodash-es')
13
13
  const [input, select] = await importPkg('bajo-cli:@inquirer/input',
14
14
  'bajo-cli:@inquirer/select')
15
- if (!this.bajoDb) print.fatal('Bajo DB isn\'t loaded')
15
+ if (!this.bajoDb) {
16
+ print.fail('Bajo DB isn\'t loaded', { exit: !returnEarly })
17
+ if (returnEarly) return
18
+ }
16
19
  const schemas = map(this.bajoDb.schemas, 'name')
17
- if (isEmpty(schemas)) print.fatal('No schema found!')
20
+ if (isEmpty(schemas)) {
21
+ print.fail('No schema found!', { exit: !returnEarly })
22
+ if (returnEarly) return
23
+ }
18
24
  let [coll, dest, query] = args
19
25
  if (isEmpty(coll)) {
20
26
  coll = await select({
@@ -47,7 +53,7 @@ async function exportTo (path, args) {
47
53
  spinner.succeed('%d records successfully exported to \'%s\'', result.count, Path.resolve(result.file))
48
54
  } catch (err) {
49
55
  console.log(err)
50
- spinner.fatal('Error: %s', err.message)
56
+ spinner.fail('Error: %s', err.message, { exit: !returnEarly })
51
57
  }
52
58
  }
53
59
 
@@ -6,14 +6,20 @@ function makeProgress (spinner) {
6
6
  }
7
7
  }
8
8
 
9
- async function importFrom (path, args) {
9
+ async function importFrom ({ path, args, returnEarly }) {
10
10
  const { importPkg, print, importModule, getConfig } = this.bajo.helper
11
11
  const { isEmpty, map } = await importPkg('lodash-es')
12
12
  const [input, select, confirm] = await importPkg('bajo-cli:@inquirer/input',
13
13
  'bajo-cli:@inquirer/select', 'bajo-cli:@inquirer/confirm')
14
- if (!this.bajoDb) print.fatal('Bajo DB isn\'t loaded')
14
+ if (!this.bajoDb) {
15
+ print.fail('Bajo DB isn\'t loaded', { exit: !returnEarly })
16
+ if (returnEarly) return
17
+ }
15
18
  const schemas = map(this.bajoDb.schemas, 'name')
16
- if (isEmpty(schemas)) print.fatal('No schema found!')
19
+ if (isEmpty(schemas)) {
20
+ print.fail('No schema found!', { exit: !returnEarly })
21
+ if (returnEarly) return
22
+ }
17
23
  let [dest, coll] = args
18
24
  if (isEmpty(dest)) {
19
25
  dest = await input({
@@ -31,7 +37,10 @@ async function importFrom (path, args) {
31
37
  message: print.__('You\'re about to replace ALL records with the new ones. Are you really sure?'),
32
38
  default: false
33
39
  })
34
- if (!answer) print.fatal('Aborted!')
40
+ if (!answer) {
41
+ print.fail('Aborted!', { exit: !returnEarly })
42
+ if (returnEarly) return
43
+ }
35
44
  const spinner = print.bora('Importing...').start()
36
45
  const progressFn = makeProgress.call(this, spinner)
37
46
  const cfg = getConfig('bajoDb', { full: true })
@@ -43,7 +52,7 @@ async function importFrom (path, args) {
43
52
  const result = await this.bajoExtra.helper.importFrom(dest, coll, { batch, progressFn })
44
53
  spinner.succeed('%d records successfully imported from \'%s\'', result.count, Path.resolve(result.file))
45
54
  } catch (err) {
46
- spinner.fatal('Error: %s', err.message)
55
+ spinner.fail('Error: %s', err.message, { exit: !returnEarly })
47
56
  }
48
57
  }
49
58
 
package/bajoCli/tool.js CHANGED
@@ -1,8 +1,8 @@
1
- async function tool ({ path, args = [] }) {
1
+ async function tool ({ path, args = [], returnEarly }) {
2
2
  const { currentLoc } = this.bajo.helper
3
3
  const { runToolMethod } = this.bajoCli.helper
4
4
  const options = { demonize: ['shell'] }
5
- await runToolMethod({ path, args, dir: `${currentLoc(import.meta).dir}/tool`, options })
5
+ await runToolMethod({ path, args, dir: `${currentLoc(import.meta).dir}/tool`, options, returnEarly })
6
6
  }
7
7
 
8
8
  export default tool
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo-extra",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Extra package for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {