Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'gatsby-cli' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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.
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.
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)
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
}
}
}
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)
})
}
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)
})
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
}
}
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())
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())
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);