How to use the @sanity/util/lib/lazyRequire 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 / core / src / actions / deploy / deployAction.js View on Github external
output.print('To deploy your Sanity Studio to our hosted Sanity.Studio service,')
    output.print('you will need one. Please enter the part you want to use.')

    studioHostname = await prompt.single({
      type: 'input',
      filter: inp => inp.replace(/\.sanity\.studio$/i, ''),
      message: 'Studio hostname (.sanity.studio):',
      validate: name => validateHostname(name, client)
    })
  }

  // Always build the project, unless --no-build is passed
  const shouldBuild = flags.build
  if (shouldBuild) {
    const overrides = {project: {basePath: undefined}}
    const buildStaticAssets = lazyRequire(require.resolve('../build/buildStaticAssets'))
    const buildArgs = [args.argsWithoutOptions[0]].filter(Boolean)
    await buildStaticAssets({extOptions: flags, argsWithoutOptions: buildArgs, overrides}, context)
  }

  // Ensure that the directory exists, is a directory and seems to have valid content
  spinner = output.spinner('Verifying local content').start()
  try {
    await checkDir(sourceDir)
    spinner.succeed()
  } catch (err) {
    spinner.fail()
    throw err
  }

  // Now create a tarball of the given directory
  const parentDir = path.dirname(sourceDir)
github sanity-io / sanity / packages / @sanity / core / src / commands / deploy / deployCommand.js View on Github external
const helpText = `
Options
  --source-maps Enable source maps for built bundles (increases size of bundle)
  --no-minify Skip minifying built JavaScript (speeds up build, increases size of bundle)
  --no-build Don't build the studio prior to deploy, instead deploying the version currently in \`dist/\`

Examples
  sanity deploy
  sanity deploy --no-minify --source-maps
`

export default {
  name: 'deploy',
  signature: '[SOURCE_DIR] [--no-build]  [--source-maps] [--no-minify]',
  description: 'Deploys a statically built Sanity studio',
  action: lazyRequire(require.resolve('../../actions/deploy/deployAction')),
  helpText
}
github sanity-io / sanity / packages / @sanity / core / src / commands / build / buildCommand.js View on Github external
const helpText = `
Options
  --source-maps Enable source maps for built bundles (increases size of bundle)
  --no-minify Skip minifying built JavaScript (speeds up build, increases size of bundle)
  -y, --yes Use unattended mode, accepting defaults and using only flags for choices

Examples
  sanity build
  sanity build --no-minify --source-maps
`

export default {
  name: 'build',
  signature: '[OUTPUT_DIR]',
  description: 'Builds the current Sanity configuration to a static bundle',
  action: lazyRequire(require.resolve('../../actions/build/buildStaticAssets')),
  helpText
}
github sanity-io / sanity / packages / @sanity / core / src / commands / exec / execCommand.js View on Github external
Examples
  # Run the script at some/script.js in Sanity context
  sanity exec some/script.js

  # Run the script at migrations/fullname.js and configure \`part:@sanity/base/client\`
  # to include the current users token
  sanity exec migrations/fullname.js --with-user-token
`

export default {
  name: 'exec',
  signature: 'SCRIPT',
  description: 'Runs a script in Sanity context',
  helpText,
  action: lazyRequire(require.resolve('../../actions/exec/execScript'))
}
github sanity-io / sanity / packages / @sanity / core / src / commands / graphql / deleteGraphQLAPICommand.js View on Github external
import lazyRequire from '@sanity/util/lib/lazyRequire'

export default {
  name: 'undeploy',
  group: 'graphql',
  description: 'Remove a deployed GraphQL API',
  action: lazyRequire(require.resolve('../../actions/graphql/deleteApiAction'))
}
github sanity-io / sanity / packages / @sanity / core / src / commands / graphql / deployGraphQLAPICommand.js View on Github external
--dataset  Deploy API for the given dataset
  --playground Deploy a GraphQL playground for easily testing queries (public)
  --no-playground Skip playground prompt (do not deploy a playground)

Examples
  sanity graphql deploy
  sanity graphql deploy --playground
  sanity graphql deploy --dataset staging --no-playground
`

export default {
  name: 'deploy',
  signature: '',
  group: 'graphql',
  description: 'Deploy a GraphQL API from the current Sanity schema',
  action: lazyRequire(require.resolve('../../actions/graphql/deployApiAction')),
  helpText
}
github sanity-io / sanity / packages / @sanity / core / src / commands / start / startCommand.js View on Github external
Changing the hostname or port number might require a new CORS-entry to be added.

Options
  --port  TCP port to start server on. [default: 3333]
  --host  The local network interface at which to listen. [default: "127.0.0.1"]

Examples
  sanity start --host=0.0.0.0
  sanity start --port=1942
`

export default {
  name: 'start',
  signature: '[--port ] [--host ]',
  description: 'Starts a web server for the Content Studio',
  action: lazyRequire(require.resolve('../../actions/start/startAction')),
  helpText
}