bajo 1.0.2 → 1.0.4

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 (48) hide show
  1. package/boot/class/app.js +3 -1
  2. package/boot/class/bajo-core/helper/attach-method.js +2 -1
  3. package/boot/class/bajo-core/helper/boot-order.js +3 -1
  4. package/boot/class/bajo-core/helper/build-config.js +2 -1
  5. package/boot/class/bajo-core/helper/build-plugins.js +3 -1
  6. package/boot/class/bajo-core/helper/collect-config-handlers.js +2 -1
  7. package/boot/class/bajo-core/method/arrange-array.js +2 -1
  8. package/boot/class/bajo-core/method/break-ns-path-from-file.js +2 -1
  9. package/boot/class/bajo-core/method/break-ns-path.js +3 -1
  10. package/boot/class/bajo-core/method/build-collections.js +3 -1
  11. package/boot/class/bajo-core/method/call-handler.js +3 -1
  12. package/boot/class/bajo-core/method/defaults-deep.js +4 -1
  13. package/boot/class/bajo-core/method/each-plugins.js +3 -1
  14. package/boot/class/bajo-core/method/get-global-module-dir.js +5 -3
  15. package/boot/class/bajo-core/method/get-method.js +3 -1
  16. package/boot/class/bajo-core/method/get-plugin-file.js +3 -1
  17. package/boot/class/bajo-core/method/import-module.js +3 -1
  18. package/boot/class/bajo-core/method/import-pkg.js +3 -1
  19. package/boot/class/bajo-core/method/includes.js +1 -3
  20. package/boot/class/bajo-core/method/is-log-in-range.js +3 -1
  21. package/boot/class/bajo-core/method/join.js +3 -1
  22. package/boot/class/bajo-core/method/num-unit.js +3 -1
  23. package/boot/class/bajo-core/method/paginate.js +3 -1
  24. package/boot/class/bajo-core/method/parse-object.js +2 -1
  25. package/boot/class/bajo-core/method/pascal-case.js +3 -1
  26. package/boot/class/bajo-core/method/read-config.js +3 -1
  27. package/boot/class/bajo-core/method/read-json.js +3 -1
  28. package/boot/class/bajo-core/method/run-hook.js +3 -1
  29. package/boot/class/bajo-core/method/save-as-download.js +3 -1
  30. package/boot/class/bajo-core/method/sec-to-hms.js +2 -1
  31. package/boot/class/bajo-core/method/titleize.js +2 -1
  32. package/boot/class/bajo-core.js +2 -1
  33. package/boot/class/bajo-plugin/helper/build-config.js +3 -1
  34. package/boot/class/bajo-plugin/helper/check-clash.js +3 -1
  35. package/boot/class/bajo-plugin/helper/check-dependency.js +3 -1
  36. package/boot/class/bajo-plugin/helper/collect-hooks.js +3 -1
  37. package/boot/class/bajo-plugin/helper/run.js +2 -1
  38. package/boot/class/bajo-plugin.js +7 -4
  39. package/boot/class/error.js +2 -1
  40. package/boot/class/log.js +3 -1
  41. package/boot/class/plugin.js +3 -1
  42. package/boot/class/print.js +3 -1
  43. package/boot/lib/create-method.js +3 -1
  44. package/boot/lib/parse-args-argv.js +3 -1
  45. package/boot/lib/parse-env.js +3 -1
  46. package/boot/lib/translate.js +2 -1
  47. package/package.json +3 -2
  48. package/boot/lib/get-global-module-path.js +0 -189
package/boot/class/app.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import util from 'util'
2
- import { last } from 'lodash-es'
2
+ import lodash from 'lodash'
3
3
  import BajoCore from './bajo-core.js'
4
4
  import resolvePath from './bajo-core/method/resolve-path.js'
5
5
  import parseArgsArgv from '../lib/parse-args-argv.js'
@@ -13,6 +13,8 @@ import bootPlugins from './bajo-core/helper/boot-plugins.js'
13
13
  import exitHandler from './bajo-core/helper/exit-handler.js'
14
14
  import runAsApplet from './bajo-core/helper/run-as-applet.js'
15
15
 
16
+ const { last } = lodash
17
+
16
18
  class App {
17
19
  constructor (cwd) {
18
20
  if (!cwd) cwd = process.cwd()
@@ -5,6 +5,7 @@ import fs from 'fs-extra'
5
5
  import fastGlob from 'fast-glob'
6
6
  import { sprintf } from 'sprintf-js'
7
7
  import outmatch from 'outmatch'
8
+ import lodash from 'lodash'
8
9
 
9
10
  export default async function () {
10
11
  await createMethod.call(this, `${currentLoc(import.meta).dir}/../method`)
@@ -18,7 +19,7 @@ export default async function () {
18
19
  })
19
20
  }
20
21
  // commonly used libraries
21
- this.lib._ = await import('lodash-es')
22
+ this.lib._ = lodash
22
23
  this.lib.fs = fs
23
24
  this.lib.fastGlob = fastGlob
24
25
  this.lib.sprintf = sprintf
@@ -1,7 +1,9 @@
1
- import { reduce, map, isNaN, trim, forOwn, orderBy } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import fs from 'fs-extra'
3
3
  import getModuleDir from '../method/get-module-dir.js'
4
4
 
5
+ const { reduce, map, isNaN, trim, forOwn, orderBy } = lodash
6
+
5
7
  async function bootOrder () {
6
8
  this.log.debug('Setup boot order')
7
9
  const order = reduce(this.pluginPkgs, (o, k, i) => {
@@ -9,7 +9,8 @@ import omitDeep from 'omit-deep'
9
9
  import os from 'os'
10
10
  import fs from 'fs-extra'
11
11
 
12
- import { map, pick, values, keys, set, get } from 'lodash-es'
12
+ import lodash from 'lodash'
13
+ const { map, pick, values, keys, set, get } = lodash
13
14
 
14
15
  const omitted = ['spawn', 'cwd', 'name', 'alias', 'applet', 'a', 'plugins']
15
16
 
@@ -1,8 +1,10 @@
1
- import { isString, filter, map, trim, without, uniq, camelCase, isEmpty } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import fs from 'fs-extra'
3
3
  import getModuleDir from '../method/get-module-dir.js'
4
4
  import BajoPlugin from '../../bajo-plugin.js'
5
5
 
6
+ const { isString, filter, map, trim, without, uniq, camelCase, isEmpty } = lodash
7
+
6
8
  async function buildPlugins () {
7
9
  let pluginPkgs = this.config.plugins ?? []
8
10
  if (isString(pluginPkgs)) pluginPkgs = [pluginPkgs]
@@ -1,6 +1,7 @@
1
1
  import getModuleDir from '../method/get-module-dir.js'
2
2
  import importModule from '../method/import-module.js'
3
- import { isFunction, isPlainObject, camelCase } from 'lodash-es'
3
+ import lodash from 'lodash'
4
+ const { isFunction, isPlainObject, camelCase } = lodash
4
5
 
5
6
  async function collectConfigHandlers () {
6
7
  for (const pkg of this.pluginPkgs) {
@@ -1,4 +1,5 @@
1
- import { filter, trim } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+ const { filter, trim } = lodash
2
3
 
3
4
  function arrangeArray (inputs, trimItem = true) {
4
5
  const first = []
@@ -1,5 +1,6 @@
1
1
  import _path from 'path'
2
- import { map, camelCase } from 'lodash-es'
2
+ import lodash from 'lodash'
3
+ const { map, camelCase } = lodash
3
4
 
4
5
  function breakNsPathFromFile ({ file, dir, baseNs, suffix = '', getType } = {}) {
5
6
  let item = file.replace(dir + suffix, '')
@@ -1,6 +1,8 @@
1
- import { isEmpty } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import querystring from 'querystring'
3
3
 
4
+ const { isEmpty } = lodash
5
+
4
6
  function breakNsPath (item = '', defaultNs = 'bajo', checkNs = true) {
5
7
  let [ns, ...path] = item.split(':')
6
8
  let subNs
@@ -1,4 +1,6 @@
1
- import { filter, isArray, pullAt, camelCase, has, find, set, get, isFunction } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { filter, isArray, pullAt, camelCase, has, find, set, get, isFunction } = lodash
2
4
 
3
5
  async function buildCollections (options = {}) {
4
6
  const { runHook, join } = this.app.bajo
@@ -1,6 +1,8 @@
1
- import { isString, isFunction, isPlainObject, find } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import BajoPlugin from '../../bajo-plugin.js'
3
3
 
4
+ const { isString, isFunction, isPlainObject, find } = lodash
5
+
4
6
  async function callHandler (item, ...args) {
5
7
  let result
6
8
  let scope = this
@@ -1,4 +1,7 @@
1
- import { mergeWith, isArray } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { mergeWith, isArray } = lodash
4
+
2
5
  // based on https://github.com/nodeutils/defaults-deep/blob/master/lib/index.js
3
6
 
4
7
  const defaultsDeep = (...args) => {
@@ -1,7 +1,9 @@
1
- import { camelCase, isString, omit, cloneDeep } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import fastGlob from 'fast-glob'
3
3
  import path from 'path'
4
4
 
5
+ const { camelCase, isString, omit, cloneDeep } = lodash
6
+
5
7
  async function eachPlugins (handler, options = {}) {
6
8
  if (typeof options === 'string') options = { glob: options }
7
9
  const result = {}
@@ -1,12 +1,14 @@
1
- import getGlobalModulePath from '../../../lib/get-global-module-path.js'
1
+ import getGlobalPath from 'get-global-path'
2
2
  import resolvePath from './resolve-path.js'
3
- import { dropRight } from 'lodash-es'
3
+ import lodash from 'lodash'
4
4
  import fs from 'fs-extra'
5
5
 
6
+ const { dropRight } = lodash
7
+
6
8
  function getGlobalModuleDir (pkgName, silent = true) {
7
9
  let nodeModulesDir = process.env.BAJO_GLOBAL_MODULE_DIR
8
10
  if (!nodeModulesDir) {
9
- const npmPath = getGlobalModulePath('npm')
11
+ const npmPath = getGlobalPath('npm')
10
12
  if (!npmPath) {
11
13
  if (silent) return
12
14
  throw this.error('Can\'t locate npm global module directory', { code: 'BAJO_CANT_LOCATE_NPM_GLOBAL_DIR' })
@@ -1,4 +1,6 @@
1
- import { get, isFunction } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { get, isFunction } = lodash
2
4
 
3
5
  function getMethod (name = '', thrown = true) {
4
6
  const { ns, path } = this.breakNsPath(name)
@@ -1,6 +1,8 @@
1
1
  import breakNsPath from './break-ns-path.js'
2
2
  import currentLoc from '../../../lib/current-loc.js'
3
- import { trim } from 'lodash-es'
3
+ import lodash from 'lodash'
4
+
5
+ const { trim } = lodash
4
6
 
5
7
  function getPluginFile (file) {
6
8
  if (file[0] === '.') file = `${currentLoc(import.meta).dir}/${trim(file.slice(1), '/')}`
@@ -1,8 +1,10 @@
1
1
  import resolvePath from './resolve-path.js'
2
2
  import getPluginFile from './get-plugin-file.js'
3
- import { isFunction, isPlainObject } from 'lodash-es'
3
+ import lodash from 'lodash'
4
4
  import fs from 'fs-extra'
5
5
 
6
+ const { isFunction, isPlainObject } = lodash
7
+
6
8
  async function load (file, asDefaultImport = true, noCache = false) {
7
9
  file = resolvePath(file, true)
8
10
  if (noCache) file += `?_=${Date.now()}`
@@ -1,4 +1,4 @@
1
- import { isPlainObject, last, isEmpty, has, keys, values, get } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import os from 'os'
3
3
  import getModuleDir from './get-module-dir.js'
4
4
  import resolvePath from './resolve-path.js'
@@ -8,6 +8,8 @@ import breakNsPath from './break-ns-path.js'
8
8
  import path from 'path'
9
9
  import fs from 'fs-extra'
10
10
 
11
+ const { isPlainObject, last, isEmpty, has, keys, values, get } = lodash
12
+
11
13
  async function importPkg (...pkgs) {
12
14
  const result = {}
13
15
  const notFound = []
@@ -1,7 +1,5 @@
1
- import { isString } from 'lodash-es'
2
-
3
1
  function includes (matcher = [], array = []) {
4
- if (isString(matcher)) matcher = [matcher]
2
+ if (typeof matcher === 'string') matcher = [matcher]
5
3
  let found = false
6
4
  for (const m of matcher) {
7
5
  found = array.includes(m)
@@ -1,5 +1,7 @@
1
1
  import logLevels from './log-levels.js'
2
- import { keys, indexOf } from 'lodash-es'
2
+ import lodash from 'lodash'
3
+
4
+ const { keys, indexOf } = lodash
3
5
 
4
6
  function isLogInRange (level) {
5
7
  const levels = keys(logLevels)
@@ -1,6 +1,8 @@
1
- import { isPlainObject } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import isSet from './is-set.js'
3
3
 
4
+ const { isPlainObject } = lodash
5
+
4
6
  function join (array, sep) {
5
7
  const isI18n = this && this.app && this.app.bajoI18N
6
8
  if (array.length === 0) return isI18n ? this.app.bajoI18N.t('none') : 'none'
@@ -1,4 +1,6 @@
1
- import { isEmpty } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { isEmpty } = lodash
2
4
 
3
5
  function numUnit (value = '', defUnit = '') {
4
6
  const num = value.match(/\d+/g)
@@ -1,4 +1,6 @@
1
- import { isEmpty, isPlainObject, orderBy, forOwn } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { isEmpty, isPlainObject, orderBy, forOwn } = lodash
2
4
 
3
5
  function paginate (collection, { page = 1, limit = 25, sort } = {}) {
4
6
  const count = collection.length
@@ -1,10 +1,11 @@
1
- import { isPlainObject, isArray, isNumber, set, cloneDeep, isString, omit } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import dotenvParseVariables from 'dotenv-parse-variables'
3
3
  import ms from 'ms'
4
4
  import dayjs from '../../../lib/dayjs.js'
5
5
  import isSet from './is-set.js'
6
6
  import translate from '../../../lib/translate.js'
7
7
 
8
+ const { isPlainObject, isArray, isNumber, set, cloneDeep, isString, omit } = lodash
8
9
  const statics = ['*']
9
10
 
10
11
  function parseDur (val) {
@@ -1,4 +1,6 @@
1
- import { camelCase, upperFirst } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { camelCase, upperFirst } = lodash
2
4
 
3
5
  const pascalCase = (text) => {
4
6
  return upperFirst(camelCase(text))
@@ -3,9 +3,11 @@ import resolvePath from './resolve-path.js'
3
3
  import getPluginFile from './get-plugin-file.js'
4
4
  import readJson from './read-json.js'
5
5
  import parseObject from './parse-object.js'
6
- import { find, map, isEmpty } from 'lodash-es'
6
+ import lodash from 'lodash'
7
7
  import fg from 'fast-glob'
8
8
 
9
+ const { find, map, isEmpty } = lodash
10
+
9
11
  async function readConfig (file, { ns, pattern, globOptions = {}, ignoreError, defValue = {}, opts = {} } = {}) {
10
12
  if (!ns) ns = this.name
11
13
  file = resolvePath(getPluginFile.call(this, file))
@@ -1,7 +1,9 @@
1
1
  import fs from 'fs-extra'
2
- import { isEmpty } from 'lodash-es'
2
+ import lodash from 'lodash'
3
3
  import parseObject from './parse-object.js'
4
4
 
5
+ const { isEmpty } = lodash
6
+
5
7
  function readJson (file, thrownNotFound) {
6
8
  if (!fs.existsSync(file) && thrownNotFound) throw this.error('File \'%s\' not found', file)
7
9
  let resp = fs.readFileSync(file, 'utf8')
@@ -1,4 +1,6 @@
1
- import { filter, isEmpty, orderBy, pullAt } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { filter, isEmpty, orderBy, pullAt } = lodash
2
4
 
3
5
  async function runHook (hookName, ...args) {
4
6
  const [ns, path] = (hookName ?? '').split(':')
@@ -1,8 +1,10 @@
1
1
  import fs from 'fs-extra'
2
2
  import path from 'path'
3
- import { trim } from 'lodash-es'
3
+ import lodash from 'lodash'
4
4
  import increment from 'add-filename-increment'
5
5
 
6
+ const { trim } = lodash
7
+
6
8
  async function saveAsDownload (file, obj, printSaved = true) {
7
9
  const { print, getPluginDataDir } = this.app.bajo
8
10
  const plugin = this.name
@@ -1,4 +1,5 @@
1
- import { padStart } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+ const { padStart } = lodash
2
3
 
3
4
  // based on: https://stackoverflow.com/questions/1322732/convert-seconds-to-hh-mm-ss-with-javascript
4
5
 
@@ -1,6 +1,7 @@
1
- import { words, upperFirst, map, concat, uniq, forOwn } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import generateId from './generate-id.js'
3
3
 
4
+ const { words, upperFirst, map, concat, uniq, forOwn } = lodash
4
5
  const defIgnores = ['or', 'and', 'of', 'with']
5
6
 
6
7
  const titleize = (text, { ignores = [], replacement = {} } = {}) => {
@@ -3,7 +3,8 @@ import dayjs from '../lib/dayjs.js'
3
3
  import importModule from './bajo-core/method/import-module.js'
4
4
  import readJson from './bajo-core/method/read-json.js'
5
5
 
6
- import { isFunction } from 'lodash-es'
6
+ import lodash from 'lodash'
7
+ const { isFunction } = lodash
7
8
 
8
9
  async function defConfigHandler (file, opts) {
9
10
  let mod = await importModule(file)
@@ -1,4 +1,6 @@
1
- import { camelCase } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { camelCase } = lodash
2
4
 
3
5
  async function buildConfig () {
4
6
  this.bajo.log.debug('Read configurations')
@@ -1,4 +1,6 @@
1
- import { find } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { find } = lodash
2
4
 
3
5
  async function checkAlias () {
4
6
  const { eachPlugins } = this.bajo
@@ -1,6 +1,8 @@
1
- import { reduce, map, trim, keys, intersection, each, camelCase, get } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import semver from 'semver'
3
3
 
4
+ const { reduce, map, trim, keys, intersection, each, camelCase, get } = lodash
5
+
4
6
  async function runner ({ ns, pkgName }) {
5
7
  const { join } = this.app.bajo
6
8
  this.app.bajo.log.trace('- %s', ns)
@@ -1,4 +1,6 @@
1
- import { merge, forOwn, groupBy } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+
3
+ const { merge, forOwn, groupBy } = lodash
2
4
 
3
5
  async function collectHooks () {
4
6
  const { eachPlugins, runHook, isLogInRange, importModule, breakNsPathFromFile } = this.bajo
@@ -1,4 +1,5 @@
1
- import { camelCase, map } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+ const { camelCase, map } = lodash
2
3
 
3
4
  async function run () {
4
5
  const me = this
@@ -1,10 +1,12 @@
1
1
  import Plugin from './plugin.js'
2
- import { pick, isString, omit, camelCase } from 'lodash-es'
2
+ import lodash from 'lodash'
3
3
  import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
4
4
  import readAllConfigs from '../lib/read-all-configs.js'
5
5
  import titleize from './bajo-core/method/titleize.js'
6
6
  import fs from 'fs-extra'
7
7
 
8
+ const { pick, omit, camelCase, trim, without } = lodash
9
+
8
10
  class BajoPlugin extends Plugin {
9
11
  constructor (pkgName, app) {
10
12
  super(pkgName, app)
@@ -41,15 +43,16 @@ class BajoPlugin extends Plugin {
41
43
  const envArgv = defaultsDeep({}, omit(this.app.env[this.name] ?? {}, omittedPluginKeys) ?? {}, omit(this.app.argv[this.name] ?? {}, omittedPluginKeys) ?? {})
42
44
  cfg = defaultsDeep({}, envArgv ?? {}, cfg ?? {})
43
45
  this.title = this.title ?? cfg.title ?? titleize(this.alias)
44
- this.dependencies = cfg.dependencies ?? []
45
- if (isString(this.dependencies)) this.dependencies = [this.dependencies]
46
+
47
+ this.dependencies = []
48
+ const depFile = `${dir}/bajo/.dependencies`
49
+ if (fs.existsSync(depFile)) this.dependencies = without(fs.readFileSync(depFile, 'utf8').split('\n').map(item => trim(item)), '')
46
50
  this.config = omit(cfg, ['title', 'dependencies'])
47
51
  }
48
52
 
49
53
  async _onoff (item, text, ...args) {
50
54
  this.state[item] = false
51
55
  const { runHook, importModule } = this.app.bajo
52
- const { camelCase } = this.app.bajo.lib._
53
56
  const mod = await importModule(`${this.dir.pkg}/bajo/${item}.js`)
54
57
  if (mod) {
55
58
  this.log.trace(text)
@@ -1,4 +1,5 @@
1
- import { isPlainObject, each, isArray, get, isEmpty, merge } from 'lodash-es'
1
+ import lodash from 'lodash'
2
+ const { isPlainObject, each, isArray, get, isEmpty, merge } = lodash
2
3
 
3
4
  Error.stackTraceLimit = 15
4
5
 
package/boot/class/log.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import os from 'os'
2
- import { isEmpty, without, merge, upperFirst } from 'lodash-es'
2
+ import lodash from 'lodash'
3
3
  import levels from './bajo-core/method/log-levels.js'
4
4
  import isLogInRange from './bajo-core/method/is-log-in-range.js'
5
5
  import translate from '../lib/translate.js'
6
6
  import dayjs from 'dayjs'
7
7
 
8
+ const { isEmpty, without, merge, upperFirst } = lodash
9
+
8
10
  class Log {
9
11
  constructor (plugin) {
10
12
  this.plugin = plugin
@@ -1,9 +1,11 @@
1
- import { get, isEmpty, cloneDeep, omit, isPlainObject, camelCase } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  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
6
 
7
+ const { get, isEmpty, cloneDeep, omit, isPlainObject, camelCase } = lodash
8
+
7
9
  class Plugin {
8
10
  constructor (pkgName, app) {
9
11
  this.pkgName = pkgName
@@ -1,8 +1,10 @@
1
1
  import ora from 'ora'
2
- import { isPlainObject } from 'lodash-es'
2
+ import lodash from 'lodash'
3
3
  import defaultsDeep from './bajo-core/method/defaults-deep.js'
4
4
  import translate from '../lib/translate.js'
5
5
 
6
+ const { isPlainObject } = lodash
7
+
6
8
  class Print {
7
9
  constructor (plugin, opts = {}) {
8
10
  this.opts = opts
@@ -1,10 +1,12 @@
1
1
  import fastGlob from 'fast-glob'
2
2
  import path from 'path'
3
- import { camelCase, isFunction, isPlainObject, forOwn } from 'lodash-es'
3
+ import lodash from 'lodash'
4
4
  import resolvePath from '../class/bajo-core/method/resolve-path.js'
5
5
  import importModule from '../class/bajo-core/method/import-module.js'
6
6
  import readJson from '../class/bajo-core/method/read-json.js'
7
7
 
8
+ const { camelCase, isFunction, isPlainObject, forOwn } = lodash
9
+
8
10
  export default async function (dir, pkg = 'bajo') {
9
11
  dir = resolvePath(dir)
10
12
  const files = await fastGlob([`!${dir}/**/_*.{js,json}`, `${dir}/**/*.{js,json}`])
@@ -4,11 +4,13 @@ import { unflatten } from 'flat'
4
4
  import isSet from '../class/bajo-core/method/is-set.js'
5
5
  import dotenvParseVariables from 'dotenv-parse-variables'
6
6
  import importModule from '../class/bajo-core/method/import-module.js'
7
- import { find, each, set, camelCase, forOwn } from 'lodash-es'
7
+ import lodash from 'lodash'
8
8
  import fs from 'fs-extra'
9
9
  import path from 'path'
10
10
  import currentLoc from './current-loc.js'
11
11
 
12
+ const { find, each, set, camelCase, forOwn } = lodash
13
+
12
14
  const parseItem = (data, delimiter) => {
13
15
  return unflatten(data, {
14
16
  delimiter,
@@ -1,7 +1,9 @@
1
1
  import dotenvParseVariables from 'dotenv-parse-variables'
2
2
  import { unflatten } from 'flat'
3
3
  import dotEnv from 'dotenv'
4
- import { each, set, camelCase, forOwn } from 'lodash-es'
4
+ import lodash from 'lodash'
5
+
6
+ const { each, set, camelCase, forOwn } = lodash
5
7
 
6
8
  const parse = (data, delimiter) => {
7
9
  return unflatten(data, {
@@ -1,6 +1,7 @@
1
- import { get, isPlainObject } from 'lodash-es'
1
+ import lodash from 'lodash'
2
2
  import Sprintf from 'sprintf-js'
3
3
  const { sprintf } = Sprintf
4
+ const { get, isPlainObject } = lodash
4
5
 
5
6
  function translate (instance, text, ...args) {
6
7
  let ntext = text
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {
@@ -35,7 +35,8 @@
35
35
  "fast-glob": "^3.3.3",
36
36
  "flat": "^6.0.1",
37
37
  "fs-extra": "^11.2.0",
38
- "lodash-es": "^4.17.21",
38
+ "get-global-path": "^0.0.1",
39
+ "lodash": "^4.17.21",
39
40
  "ms": "^2.1.3",
40
41
  "nanoid": "^5.0.9",
41
42
  "omit-deep": "^0.3.0",
@@ -1,189 +0,0 @@
1
- // based on global-modules-path, patching it to work on Node LTS
2
- import { spawnSync } from 'child_process'
3
-
4
- import path from 'path'
5
- import fs from 'fs'
6
-
7
- const supportedPlatforms = [
8
- 'win32',
9
- 'linux',
10
- 'darwin'
11
- ]
12
-
13
- const nodeModulesDirName = 'node_modules'
14
-
15
- const getNpmExecutable = (platform) => {
16
- let npmExecutableName = 'npm'
17
- if (platform === 'win32') npmExecutableName += '.cmd'
18
- return npmExecutableName
19
- }
20
-
21
- const spawnSyncWrapper = (command, commandArgs) => {
22
- const result = spawnSync(command, commandArgs, { shell: true })
23
- if (!result) return null
24
- if (result.error) throw result.error
25
- if (result.stdout) return result.stdout.toString().trim()
26
- return null
27
- }
28
-
29
- const getNpmPrefix = (pathToNpm) => {
30
- try {
31
- const npmPrefixStdout = spawnSyncWrapper(pathToNpm, ['config', 'get', 'prefix'])
32
- return npmPrefixStdout && npmPrefixStdout.toString().trim()
33
- } catch (err) {
34
- console.error(err.message)
35
- }
36
-
37
- return null
38
- }
39
-
40
- const getPathFromNpmConfig = (platform, packageName) => {
41
- const pathToNpm = getNpmExecutable(platform)
42
- const npmConfigPrefix = getNpmPrefix(pathToNpm)
43
-
44
- if (npmConfigPrefix) {
45
- let nodeModulesPath = path.join(npmConfigPrefix, nodeModulesDirName)
46
-
47
- if (platform !== 'win32') {
48
- nodeModulesPath = path.join(npmConfigPrefix, 'lib', nodeModulesDirName)
49
- }
50
-
51
- const packagePath = path.join(nodeModulesPath, packageName)
52
- const verifiedPath = getVerifiedPath(packagePath, packageName)
53
-
54
- if (verifiedPath) {
55
- return verifiedPath
56
- }
57
- }
58
-
59
- return null
60
- }
61
-
62
- const getPathFromCmdContent = (packageName, pathToExecutable) => {
63
- if (fs.existsSync(pathToExecutable)) {
64
- const executableContent = fs.readFileSync(pathToExecutable).toString()
65
-
66
- let fullPath
67
-
68
- let windowsPathRegExp = /(%~dp0[\w\\.-]+node_modules).*?'/g
69
- let match = windowsPathRegExp.exec(executableContent)
70
-
71
- if (match && match[1]) {
72
- const realPath = path.normalize(match[1].replace('%~dp0', path.dirname(pathToExecutable)))
73
- fullPath = path.join(realPath, packageName)
74
- }
75
-
76
- if (!fullPath) {
77
- windowsPathRegExp = new RegExp(`(%~dp0[\\w\\\\.-]+?${packageName})(?:\\\\|')`, 'g')
78
- match = windowsPathRegExp.exec(executableContent)
79
- if (match && match[1]) fullPath = path.normalize(match[1].replace('%~dp0', path.dirname(pathToExecutable)))
80
- }
81
-
82
- if (fullPath) {
83
- const pathToPackage = getVerifiedPath(fullPath, packageName)
84
- if (pathToPackage) return pathToPackage
85
- }
86
- }
87
- }
88
-
89
- const getVerifiedPath = (suggestedPath, packageName) => {
90
- const pathToPackageJson = path.join(suggestedPath, 'package.json')
91
- if (fs.existsSync(suggestedPath) && fs.existsSync(pathToPackageJson)) {
92
- try {
93
- const packageJsonContent = JSON.parse(fs.readFileSync(pathToPackageJson))
94
- if (packageJsonContent.name === packageName) return suggestedPath
95
- } catch (err) {
96
- // do nothing
97
- }
98
- }
99
- }
100
-
101
- const getPathFromExecutableNameOnWindows = (packageName, executableName) => {
102
- try {
103
- const whereResult = (spawnSyncWrapper('where', [executableName]) || '').split('\n')
104
- for (const line of whereResult) {
105
- const pathToExecutable = line && line.trim()
106
-
107
- if (pathToExecutable) {
108
- const pathToLib = path.join(path.dirname(pathToExecutable), nodeModulesDirName, packageName)
109
- const verifiedPath = getVerifiedPath(pathToLib, packageName)
110
- if (verifiedPath) return verifiedPath
111
- const pathToExecutableFromContent = getPathFromCmdContent(packageName, pathToExecutable)
112
- if (pathToExecutableFromContent) return pathToExecutableFromContent
113
-
114
- const resolvedPath = getPathWhenExecutableIsAddedDirectlyToPath(packageName, pathToExecutable)
115
- if (resolvedPath) return resolvedPath
116
- }
117
- }
118
- } catch (err) {
119
- console.error(err.message)
120
- }
121
-
122
- return null
123
- }
124
-
125
- const getPathFromExecutableNameOnNonWindows = (packageName, executableName) => {
126
- try {
127
- const whichResult = spawnSyncWrapper('which', [executableName])
128
- const lsLResult = spawnSyncWrapper('ls', ['-l', whichResult])
129
-
130
- if (whichResult && lsLResult) {
131
- const regex = new RegExp(`${whichResult}\\s+->\\s+(.*?)$`)
132
- const match = lsLResult.match(regex)
133
-
134
- if (match && match[1]) {
135
- const pathToRealExecutable = fs.realpathSync(path.join(path.dirname(whichResult), match[1]))
136
- const packagePathMatch = pathToRealExecutable.match(new RegExp(`(.*?${path.join(nodeModulesDirName, packageName)}).*$`))
137
- if (packagePathMatch) {
138
- const verifiedPath = getVerifiedPath(packagePathMatch[1], packageName)
139
- if (verifiedPath) return verifiedPath
140
- }
141
- }
142
-
143
- return getPathWhenExecutableIsAddedDirectlyToPath(packageName, whichResult)
144
- }
145
- } catch (err) {
146
- console.error(err.message)
147
- }
148
-
149
- return null
150
- }
151
-
152
- const getPathWhenExecutableIsAddedDirectlyToPath = (packageName, executablePath) => {
153
- const pathToPackageJson = path.join(path.dirname(executablePath), '..', 'package.json')
154
- if (fs.existsSync(pathToPackageJson)) {
155
- const packageNameFromPackageJson = JSON.parse(fs.readFileSync(pathToPackageJson)).name
156
- if (packageNameFromPackageJson === packageName) return path.dirname(pathToPackageJson)
157
- }
158
-
159
- return null
160
- }
161
-
162
- const getPath = (packageName, executableName) => {
163
- const platform = process.platform
164
-
165
- if (supportedPlatforms.indexOf(platform) === -1) {
166
- throw new Error(`OS '${platform}' is not supported.'`)
167
- }
168
-
169
- let foundPath = null
170
-
171
- if (executableName) {
172
- foundPath = platform === 'win32' ?
173
- getPathFromExecutableNameOnWindows(packageName, executableName) :
174
- getPathFromExecutableNameOnNonWindows(packageName, executableName)
175
- }
176
-
177
- if (!foundPath) foundPath = getPathFromNpmConfig(platform, packageName)
178
- if (foundPath) {
179
- try {
180
- foundPath = fs.realpathSync(foundPath)
181
- } catch (err) {
182
- console.error(err.message)
183
- }
184
- }
185
-
186
- return foundPath
187
- }
188
-
189
- export default getPath