How to use the @sanity/util/lib/safeJson.loadJson function in @sanity/util

To help you get started, we’ve selected a few @sanity/util 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 sanity-io / sanity / packages / @sanity / cli / src / CommandRunner.js View on Github external
throw new Error(noSuchCommandText(commandOrGroup, subCommandName, this.commandGroups))
    }

    const command = commandInfo.command

    if (command.group && command.group !== 'default') {
      cmdArgs.argsWithoutOptions = args.argsWithoutOptions.slice(1)
    }

    const output = this.handlers.outputter
    const {prompt} = this.handlers.prompter

    const manifestPath = path.join(options.workDir, 'sanity.json')
    debug(`Reading "${manifestPath}"`)

    const baseManifest = await loadJson(manifestPath)
    const manifest = reduceConfig(baseManifest || {}, environment, {
      studioRootPath: options.workDir
    })
    const apiClient = clientWrapper(manifest, manifestPath)

    const context = {
      output,
      prompt,
      apiClient,
      yarn,
      chalk,
      ...options,
      commandRunner: this
    }

    if (command.isGroupRoot) {
github sanity-io / sanity / packages / @sanity / cli / src / actions / init-project / initProject.js View on Github external
async function doDatasetImport(options) {
  const {outputPath, coreCommands, template, datasetName, context} = options
  const manifestPath = path.join(outputPath, 'sanity.json')
  const baseManifest = await loadJson(manifestPath)
  const manifest = reduceConfig(baseManifest || {}, environment, {
    studioRootPath: outputPath
  })

  const importCmd = coreCommands.find(cmd => cmd.name === 'import' && cmd.group === 'dataset')
  return importCmd.action(
    {argsWithoutOptions: [template.datasetUrl, datasetName], extOptions: {}},
    Object.assign({}, context, {
      apiClient: clientWrapper(manifest, manifestPath),
      workDir: outputPath,
      fromInitCommand: true
    })
  )
}