Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'read-config-file' 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.
return (args: any) => {
checkIsOutdated()
loadEnv(path.join(process.cwd(), "electron-builder.env"))
.then(() => task(args))
.catch(error => {
process.exitCode = 1
// https://github.com/electron-userland/electron-builder/issues/2940
process.on("exit", () => process.exitCode = 1)
if (error instanceof InvalidConfigurationError) {
log.error(null, error.message)
}
else if (!(error instanceof ExecError) || !error.alreadyLogged) {
log.error({stackTrace: error.stack}, error.message)
}
})
}
}
if (env == null) {
env = {}
}
const projectDir = (env.configuration || {}).projectDir || process.cwd()
const packageMetadata = getPackageMetadata(projectDir)
const electronWebpackConfig = await getElectronWebpackConfiguration({
packageMetadata,
projectDir,
})
if (env.configuration != null) {
deepAssign(electronWebpackConfig, env.configuration)
}
await validateConfig(electronWebpackConfig, schemeDataPromise, message => {
return `${message}
How to fix:
1. Open https://webpack.electron.build/configuration
2. Search the option name on the page.
* Not found? The option was deprecated or not exists (check spelling).
* Found? Check that the option in the appropriate place. e.g. "sourceDirectory" only in the "main" or "renderer", not in the root.
`
})
return new WebpackConfigurator(type, env, electronWebpackConfig, await packageMetadata.value)
}
}
}
}
if (env == null) {
env = {}
}
const projectDir = (env.configuration || {}).projectDir || process.cwd()
const packageMetadata = getPackageMetadata(projectDir)
const electronWebpackConfig = await getElectronWebpackConfiguration({
packageMetadata,
projectDir,
})
if (env.configuration != null) {
deepAssign(electronWebpackConfig, env.configuration)
}
await validateConfig(electronWebpackConfig, schemeDataPromise, message => {
return `${message}
How to fix:
1. Open https://webpack.electron.build/configuration
2. Search the option name on the page.
* Not found? The option was deprecated or not exists (check spelling).
* Found? Check that the option in the appropriate place. e.g. "sourceDirectory" only in the "main" or "renderer", not in the root.
`
})
return new WebpackConfigurator(type, env, electronWebpackConfig, await packageMetadata.value)
}
export async function getElectronWebpackConfiguration(context: ConfigurationRequest): Promise {
const result = await getConfig({
packageKey: "electronWebpack",
configFilename: "electron-webpack",
projectDir: context.projectDir,
packageMetadata: context.packageMetadata
})
const configuration: ElectronWebpackConfiguration = result == null || result.result == null ? {} : result.result
if (configuration.staticSourceDirectory == null) {
configuration.staticSourceDirectory = "static"
}
if (configuration.commonDistDirectory == null) {
configuration.commonDistDirectory = "dist"
}
if (configuration.commonSourceDirectory == null) {
configuration.commonSourceDirectory = getDefaultRelativeSystemDependentCommonSource()
}
configuration.commonDistDirectory = path.resolve(context.projectDir, configuration.commonDistDirectory)
async function computeTitle(configurator: WebpackConfigurator): Promise {
const titleFromOptions = configurator.electronWebpackConfiguration.title
if (titleFromOptions == null || titleFromOptions === false) {
return null
}
if (titleFromOptions !== true) {
return titleFromOptions
}
let title: string | null | undefined = (configurator.metadata as any).productName
if (title == null) {
const electronBuilderConfig = await getConfig({
packageKey: "build",
configFilename: "electron-builder",
projectDir: configurator.projectDir,
packageMetadata: new Lazy(() => Promise.resolve(configurator.metadata))
})
if (electronBuilderConfig != null) {
title = electronBuilderConfig.result.productName
}
}
if (title == null) {
title = configurator.metadata.name
}
return title
}
export async function getConfig(projectDir: string,
configPath: string | null,
configFromOptions: Configuration | null | undefined,
packageMetadata: Lazy<{ [key: string]: any } | null> = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))): Promise {
const configRequest: ReadConfigRequest = {packageKey: "build", configFilename: "electron-builder", projectDir, packageMetadata}
const configAndEffectiveFile = await _getConfig(configRequest, configPath)
const config = configAndEffectiveFile == null ? {} : configAndEffectiveFile.result
if (configFromOptions != null) {
mergePublish(config, configFromOptions)
}
if (configAndEffectiveFile != null) {
log.info({file: configAndEffectiveFile.configFile == null ? 'package.json ("build" field)' : configAndEffectiveFile.configFile}, "loaded configuration")
}
if (config.extends == null && config.extends !== null) {
const metadata = await packageMetadata.value || {}
const devDependencies = metadata.devDependencies
const dependencies = metadata.dependencies
if ((dependencies != null && "react-scripts" in dependencies) || (devDependencies != null && "react-scripts" in devDependencies)) {
config.extends = "react-cra"
}
packageMetadata: Lazy<{ [key: string]: any } | null> = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))): Promise {
const configRequest: ReadConfigRequest = {packageKey: "build", configFilename: "electron-builder", projectDir, packageMetadata}
const packageMetadata = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))
const config = await getConfig(projectDir, null, null, packageMetadata)
export async function getElectronVersion(projectDir: string, config?: Configuration, projectMetadata: MetadataValue = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))): Promise {
if (config == null) {
file = require.resolve(file)
}
catch (ignore) {
file = require.resolve("electron-webpack/electron-builder.yml")
}
config.extends = `file:${file}`
}
}
let parentConfig: Configuration | null
if (config.extends === "react-cra") {
parentConfig = await reactCra(projectDir)
log.info({preset: config.extends}, "loaded parent configuration")
}
else if (config.extends != null) {
const parentConfigAndEffectiveFile = await loadParentConfig(configRequest, config.extends)
log.info({file: parentConfigAndEffectiveFile.configFile}, "loaded parent configuration")
parentConfig = parentConfigAndEffectiveFile.result
}
else {
parentConfig = null
}
return doMergeConfigs(config, parentConfig)
}