How to use the @sanity/util/lib/addPluginToManifest 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 / actions / init-plugin / initPlugin.js View on Github external
async function bootstrapFromUrl(context, url) {
  const {output, prompt, yarn, workDir} = context

  debug('Bootstrapping from URL: %s', url)
  const {name, outputPath, inPluginsPath, dependencies} = await bootstrapFromTemplate(context, url)

  if (inPluginsPath) {
    const addIt = await prompt.single({
      type: 'confirm',
      message: 'Enable plugin in current Sanity installation?',
      default: true
    })

    if (addIt) {
      await addPluginToManifest(workDir, name.replace(/^sanity-plugin-/, ''))
    }
  }

  if (dependencies) {
    const dependencyString = JSON.stringify(dependencies, null, 2)
      .split('\n')
      .slice(1, -1)
      .join('\n')
      .replace(/"/g, '')

    output.print('\nThe following dependencies are required for this template:')
    output.print(`${dependencyString}\n`)
  }

  if (dependencies && inPluginsPath) {
    const addDeps = await prompt.single({
github sanity-io / sanity / packages / @sanity / core / src / commands / install / installCommand.js View on Github external
async function installPlugin(plugin, context) {
  const {output, workDir, yarn} = context
  const isNamespaced = plugin[0] === '@'
  let shortName = plugin
  let fullName = plugin

  if (!isNamespaced) {
    const isFullName = plugin.indexOf('sanity-plugin-') === 0
    shortName = isFullName ? plugin.substr(14) : plugin
    fullName = isFullName ? plugin : `sanity-plugin-${plugin}`
  }

  await yarn(['add', fullName], context)
  await addPluginToManifest(workDir, shortName)
  await copyConfiguration(workDir, fullName, shortName, output)

  output.print(`Plugin '${fullName}' installed`)
}