How to use gatsby-cli - 10 common examples

To help you get started, we’ve selected a few gatsby-cli 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 gatsbyjs / gatsby / packages / gatsby / src / commands / develop.ts View on Github external
module.exports = async (program: IProgram) => {
  initTracer(program.openTracingConfigFile)
  report.pendingActivity({ id: `webpack-develop` })
  telemetry.trackCli(`DEVELOP_START`)
  telemetry.startBackgroundUpdate()

  const port =
    typeof program.port === `string` ? parseInt(program.port, 10) : program.port

  // In order to enable custom ssl, --cert-file --key-file and -https flags must all be
  // used together
  if ((program[`cert-file`] || program[`key-file`]) && !program.https) {
    report.panic(
      `for custom ssl --https, --cert-file, and --key-file must be used together`
    )
  }

  try {
    program.port = await detectPortInUseAndPrompt(port)
  } catch (e) {
    if (e.message === `USER_REJECTED`) {
      process.exit(0)
    }

    throw e
  }

  // Check if https is enabled, then create or get SSL cert.
  // Certs are named after `name` inside the project's package.json.
github gatsbyjs / gatsby / packages / gatsby / src / commands / develop.ts View on Github external
There was an error compiling the html.js component for the development server.

          See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html
        `,
        err
      )
    }
  }

  await createIndexHtml(indexHTMLActivity)

  indexHTMLActivity.end()

  // report.stateUpdate(`webpack`, `IN_PROGRESS`)

  const webpackActivity = report.activityTimer(`Building development bundle`, {
    id: `webpack-develop`,
  })
  webpackActivity.start()

  const devConfig = await webpackConfig(
    program,
    directory,
    `develop`,
    program.port,
    { parentSpan: webpackActivity.span }
  )

  const compiler = webpack(devConfig)

  /**
   * Set up the express app.
github gatsbyjs / gatsby / packages / gatsby / src / commands / develop.ts View on Github external
module.exports = async (program: IProgram) => {
  initTracer(program.openTracingConfigFile)
  report.pendingActivity({ id: `webpack-develop` })
  telemetry.trackCli(`DEVELOP_START`)
  telemetry.startBackgroundUpdate()

  const port =
    typeof program.port === `string` ? parseInt(program.port, 10) : program.port

  // In order to enable custom ssl, --cert-file --key-file and -https flags must all be
  // used together
  if ((program[`cert-file`] || program[`key-file`]) && !program.https) {
    report.panic(
      `for custom ssl --https, --cert-file, and --key-file must be used together`
    )
  }

  try {
    program.port = await detectPortInUseAndPrompt(port)
github gatsbyjs / gatsby / packages / gatsby / src / internal-plugins / query-runner / query-compiler.js View on Github external
reportError(message) {
    const queryErrorMessage = `${report.format.red(`GraphQL Error`)} ${message}`
    report.panicOnBuild(queryErrorMessage)
    if (process.env.gatsby_executing_command === `develop`) {
      websocketManager.emitError(overlayErrorID, queryErrorMessage)
      lastRunHadErrors = true
    }
  }
github gatsbyjs / gatsby / packages / gatsby / src / internal-plugins / query-runner / query-compiler.js View on Github external
}

      if (query.isStaticQuery) {
        query.jsonName =
          `sq--` +
          _.kebabCase(
            `${path.relative(store.getState().program.directory, filePath)}`
          )
      }

      if (
        query.isHook &&
        process.env.NODE_ENV === `production` &&
        typeof require(`react`).useContext !== `function`
      ) {
        report.panicOnBuild(
          `You're likely using a version of React that doesn't support Hooks\n` +
            `Please update React and ReactDOM to 16.8.0 or later to use the useStaticQuery hook.`
        )
      }

      compiledNodes.set(filePath, query)
    })
github gatsbyjs / gatsby / packages / gatsby / src / query / query-compiler.js View on Github external
}

      if (query.isStaticQuery) {
        query.id =
          `sq--` +
          _.kebabCase(
            `${path.relative(store.getState().program.directory, filePath)}`
          )
      }

      if (
        query.isHook &&
        process.env.NODE_ENV === `production` &&
        typeof require(`react`).useContext !== `function`
      ) {
        report.panicOnBuild(
          `You're likely using a version of React that doesn't support Hooks\n` +
            `Please update React and ReactDOM to 16.8.0 or later to use the useStaticQuery hook.`
        )
      }

      compiledNodes.set(filePath, query)
    })
github gatsbyjs / gatsby / packages / gatsby / src / query / query-compiler.js View on Github external
reportError(message) {
    const queryErrorMessage = `${report.format.red(`GraphQL Error`)} ${message}`
    report.panicOnBuild(queryErrorMessage)
    if (process.env.gatsby_executing_command === `develop`) {
      websocketManager.emitError(overlayErrorID, queryErrorMessage)
      lastRunHadErrors = true
    }
  }
github gatsbyjs / gatsby / packages / gatsby / src / commands / develop.ts View on Github external
const refresh = async (req: express.Request) => {
    let activity = report.activityTimer(`createSchemaCustomization`, {})
    activity.start()
    await createSchemaCustomization({
      refresh: true,
    })
    activity.end()
    activity = report.activityTimer(`Refreshing source data`, {})
    activity.start()
    await sourceNodes({
      webhookBody: req.body,
    })
    activity.end()
  }
  app.use(REFRESH_ENDPOINT, express.json())
github gatsbyjs / gatsby / packages / gatsby / src / commands / develop.ts View on Github external
const refresh = async (req: express.Request) => {
    let activity = report.activityTimer(`createSchemaCustomization`, {})
    activity.start()
    await createSchemaCustomization({
      refresh: true,
    })
    activity.end()
    activity = report.activityTimer(`Refreshing source data`, {})
    activity.start()
    await sourceNodes({
      webhookBody: req.body,
    })
    activity.end()
  }
  app.use(REFRESH_ENDPOINT, express.json())
github algolia / gatsby-plugin-algolia / gatsby-node.js View on Github external
exports.onPostBuild = async function(
  { graphql },
  { appId, apiKey, queries, indexName: mainIndexName, chunkSize = 1000 }
) {
  const activity = report.activityTimer(`index to Algolia`);
  activity.start();
  const client = algoliasearch(appId, apiKey);

  setStatus(activity, `${queries.length} queries to index`);

  const jobs = queries.map(async function doQuery(
    { indexName = mainIndexName, query, transformer = identity, settings },
    i
  ) {
    if (!query) {
      report.panic(
        `failed to index to Algolia. You did not give "query" to this query`
      );
    }
    const index = client.initIndex(indexName);
    const mainIndexExists = await indexExists(index);