How to use read-config-file - 10 common examples

To help you get started, we’ve selected a few read-config-file 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 electron-userland / electron-builder / packages / electron-builder / src / cli / cli.ts View on Github external
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)
        }
      })
  }
}
github electron-userland / electron-webpack / packages / electron-webpack / src / main.ts View on Github external
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)
}
github electron-userland / electron-webpack / packages / electron-webpack / src / main.ts View on Github external
}
    }
  }

  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)
}
github electron-userland / electron-webpack / packages / electron-webpack / src / config.ts View on Github external
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)
github electron-userland / electron-webpack / packages / electron-webpack / src / targets / RendererTarget.ts View on Github external
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
}
github electron-userland / electron-builder / packages / app-builder-lib / src / util / config.ts View on Github external
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"
    }
github electron-userland / electron-builder / packages / app-builder-lib / src / util / config.ts View on Github external
                                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}
github electron-userland / electron-builder / packages / electron-builder / src / cli / install-app-deps.ts View on Github external
  const packageMetadata = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))
  const config = await getConfig(projectDir, null, null, packageMetadata)
github electron-userland / electron-builder / packages / app-builder-lib / src / electron / electronVersion.ts View on Github external
export async function getElectronVersion(projectDir: string, config?: Configuration, projectMetadata: MetadataValue = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))): Promise {
  if (config == null) {
github electron-userland / electron-builder / packages / app-builder-lib / src / util / config.ts View on Github external
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)
}

read-config-file

Read configuration file in various formats:

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis

Similar packages