How to use the @vue/cli-shared-utils.get function in @vue/cli-shared-utils

To help you get started, we’ve selected a few @vue/cli-shared-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KuangPF / vue-cli-analysis / packages / @vue / cli / lib / config.js View on Github external
/*exports.get = function (target, path) {
    const fields = path.split('.')
    let obj = target
    const l = fields.length
    for (let i = 0; i < l - 1; i++) {
      const key = fields[i]
      if (!obj[key]) {
        return undefined
      }
      obj = obj[key]
    }
    return obj[fields[l - 1]]
  }*/
  if (options.get) { // 获取 .vuerc 中某个指定的配置,vue config -g presets 可以获取预设的值
    const value = get(config, options.get)
    if (options.json) {
      console.log(JSON.stringify({
        value
      }))
    } else {
      console.log(value)
    }
  }

  if (options.delete) { // 删除 .vuerc 中某个指定的配置
    unset(config, options.delete)
    await fs.writeFile(file, JSON.stringify(config, null, 2), 'utf-8')
    if (options.json) {
      console.log(JSON.stringify({
        deleted: options.delete
      }))
github vuejs / vue-cli / packages / @vue / cli / lib / config.js View on Github external
const config = await fs.readJson(file)

  if (!options.delete && !options.get && !options.edit && !options.set) {
    if (options.json) {
      console.log(JSON.stringify({
        resolvedPath: file,
        content: config
      }))
    } else {
      console.log('Resolved path: ' + file + '\n', JSON.stringify(config, null, 2))
    }
  }

  if (options.get) {
    // eslint-disable-next-line no-shadow
    const value = get(config, options.get)
    if (options.json) {
      console.log(JSON.stringify({
        value
      }))
    } else {
      console.log(value)
    }
  }

  if (options.delete) {
    unset(config, options.delete)
    await fs.writeFile(file, JSON.stringify(config, null, 2), 'utf-8')
    if (options.json) {
      console.log(JSON.stringify({
        deleted: options.delete
      }))
github vuejs / vue-cli / packages / @vue / cli-service / lib / commands / inspect.js View on Github external
res = config.module.rules.map(r => {
          const name = r.__ruleNames ? r.__ruleNames[0] : 'Nameless Rule (*)'

          hasUnnamedRule = hasUnnamedRule || !r.__ruleNames

          return name
        })
      } else if (args.plugins) {
        res = config.plugins.map(p => p.__pluginName || p.constructor.name)
      } else if (paths.length > 1) {
        res = {}
        paths.forEach(path => {
          res[path] = get(config, path)
        })
      } else if (paths.length === 1) {
        res = get(config, paths[0])
      } else {
        res = config
      }

      const output = toString(res, { verbose })
      console.log(highlight(output, { language: 'js' }))

      // Log explanation for Nameless Rules
      if (hasUnnamedRule) {
        console.log(`--- ${chalk.green('Footnotes')} ---`)
        console.log(`*: ${chalk.green(
          'Nameless Rules'
        )} were added through the ${chalk.green(
          'configureWebpack()'
        )} API (possibly by a plugin) instead of ${chalk.green(
          'chainWebpack()'
github KuangPF / vue-cli-analysis / packages / @vue / cli-service / lib / commands / inspect.js View on Github external
let res
    if (args.rule) {
      res = config.module.rules.find(r => r.__ruleNames[0] === args.rule)
    } else if (args.plugin) {
      res = config.plugins.find(p => p.__pluginName === args.plugin)
    } else if (args.rules) {
      res = config.module.rules.map(r => r.__ruleNames[0])
    } else if (args.plugins) {
      res = config.plugins.map(p => p.__pluginName || p.constructor.name)
    } else if (paths.length > 1) {
      res = {}
      paths.forEach(path => {
        res[path] = get(config, path)
      })
    } else if (paths.length === 1) {
      res = get(config, paths[0])
    } else {
      res = config
    }
    // 根据参数 verbose 判断是否需要显示函数定义的内容,如果为 true,则用 function () { /* omitted long function */ } 代替函数的内容
    const output = toString(res, { verbose })
    console.log(output)
  })
}
github KuangPF / vue-cli-analysis / packages / @vue / cli-service / lib / commands / inspect.js View on Github external
paths.forEach(path => {
        res[path] = get(config, path)
      })
    } else if (paths.length === 1) {
github vuejs / vue-cli / packages / @vue / cli-ui / apollo-server / connectors / configurations.js View on Github external
getAnswer: async (id, mapper) => {
            const prompt = prompts.findOne(id)
            if (prompt) {
              const defaultValue = await prompts.getDefaultValue(prompt)
              if (defaultValue !== prompt.rawValue) {
                let value = get(answers, prompt.id)
                if (mapper) {
                  value = mapper(value)
                }
                return value
              }
            }
          }
        }