How to use the builder-util.deepAssign function in builder-util

To help you get started, we’ve selected a few builder-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 electron-userland / electron-builder / packages / app-builder-lib / src / util / config.ts View on Github external
function mergePublish(config: Configuration, configFromOptions: Configuration) {
  // if config from disk doesn't have publish (or object), no need to handle, it will be simply merged by deepAssign
  const publish = Array.isArray(config.publish) ? configFromOptions.publish : null
  if (publish != null) {
    delete (configFromOptions as any).publish
  }

  deepAssign(config, configFromOptions)

  if (publish == null) {
    return
  }

  const listOnDisk = config.publish as Array
  if (listOnDisk.length === 0) {
    config.publish = publish
  }
  else {
    // apply to first
    Object.assign(listOnDisk[0], publish)
  }
}
github electron-userland / electron-builder / packages / app-builder-lib / src / packager.ts View on Github external
log.debug({config: getSafeEffectiveConfig(configuration)}, "effective config")
    }

    this._appDir = await computeDefaultAppDirectory(projectDir, configuration.directories!!.app)
    this.isTwoPackageJsonProjectLayoutUsed = this._appDir !== projectDir

    const appPackageFile = this.isTwoPackageJsonProjectLayoutUsed ? path.join(this.appDir, "package.json") : devPackageFile

    // tslint:disable:prefer-conditional-expression
    if (this.devMetadata != null && !this.isTwoPackageJsonProjectLayoutUsed) {
      this._metadata = this.devMetadata
    }
    else {
      this._metadata = await this.readProjectMetadataIfTwoPackageStructureOrPrepacked(appPackageFile)
    }
    deepAssign(this.metadata, configuration.extraMetadata)

    if (this.isTwoPackageJsonProjectLayoutUsed) {
      log.debug({devPackageFile, appPackageFile}, "two package.json structure is used")
    }
    checkMetadata(this.metadata, this.devMetadata, appPackageFile, devPackageFile)

    return await this._build(configuration, this._metadata, this._devMetadata)
  }
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / MsiTarget.ts View on Github external
const ASSISTED_UI_FILE_NAME = "WixUI_Assisted.wxs"

const projectTemplate = new Lazy<(data: any) => string>(async () => {
  const template = (await readFile(path.join(getTemplatePath("msi"), "template.xml"), "utf8"))
    .replace(/{{/g, "<%")
    .replace(/}}/g, "%>")
    .replace(/\${([^}]+)}/g, "<%=$1%>")
  return ejs.compile(template)
})

// WiX doesn't support Mono, so, dontnet462 is required to be installed for wine (preinstalled in our bundled wine)
export default class MsiTarget extends Target {
  private readonly vm = process.platform === "win32" ? new VmManager() : new WineVmManager()

  readonly options: MsiOptions = deepAssign(this.packager.platformSpecificBuildOptions, this.packager.config.msi)

  constructor(private readonly packager: WinPackager, readonly outDir: string) {
    super("msi")
  }

  async build(appOutDir: string, arch: Arch) {
    const packager = this.packager
    const artifactName = packager.expandArtifactBeautyNamePattern(this.options, "msi", arch)
    const artifactPath = path.join(this.outDir, artifactName)
    await packager.info.callArtifactBuildStarted({
      targetPresentableName: "MSI",
      file: artifactPath,
      arch,
    })

    const stageDir = await createStageDir(this, packager, arch)
github electron-userland / electron-builder / packages / electron-builder / src / builder.ts View on Github external
delete r.pd

  delete result.ia32
  delete result.x64
  delete result.armv7l
  delete result.arm64

  let config = result.config

  // config is array when combining dot-notation values with a config file value
  // https://github.com/electron-userland/electron-builder/issues/2016
  if (Array.isArray(config)) {
    const newConfig: Configuration = {}
    for (const configItem of config) {
      if (typeof configItem === "object") {
        deepAssign(newConfig, configItem)
      }
      else if (typeof configItem === "string") {
        newConfig.extends = configItem
      }
    }

    config = newConfig
    result.config = newConfig
  }

  // AJV cannot coerce "null" string to null if string is also allowed (because null string is a valid value)
  if (config != null && typeof config !== "string") {
    if (config.extraMetadata != null) {
      coerceTypes(config.extraMetadata)
    }
github electron-userland / electron-builder / packages / app-builder-lib / src / fileTransformer.ts View on Github external
async function modifyMainPackageJson(file: string, extraMetadata: any, isRemovePackageScripts: boolean) {
  const mainPackageData = JSON.parse(await readFile(file, "utf-8"))
  if (extraMetadata != null) {
    deepAssign(mainPackageData, extraMetadata)
  }

  // https://github.com/electron-userland/electron-builder/issues/1212
  const serializedDataIfChanged = cleanupPackageJson(mainPackageData, {
    isMain: true,
    isRemovePackageScripts,
  })
  if (serializedDataIfChanged != null) {
    return serializedDataIfChanged
  }
  else if (extraMetadata != null) {
    return JSON.stringify(mainPackageData, null, 2)
  }
  return null
}
github electron-userland / electron-builder / packages / app-builder-lib / src / macPackager.ts View on Github external
const hasMas = this.hasMasTarget(targets)
    const prepackaged = this.packagerOptions.prepackaged

    if (!hasMas || targets.length > 1) {
      const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged
      nonMasPromise = (prepackaged ? Promise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName as ElectronPlatformName, arch, this.platformSpecificBuildOptions, targets))
        .then(() => this.packageInDistributableFormat(appPath, Arch.x64, targets, taskManager))
    }

    for (const target of targets) {
      const targetName = target.name
      if (!(targetName === "mas" || targetName === "mas-dev")) {
        continue
      }

      const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, this.config.mas)
      if (targetName === "mas-dev") {
        deepAssign(masBuildOptions, this.config.masDev, {
          type: "development",
        })
      }

      const targetOutDir = path.join(outDir, targetName)
      if (prepackaged == null) {
        await this.doPack(outDir, targetOutDir, "mas", arch, masBuildOptions, [target])
        await this.sign(path.join(targetOutDir, `${this.appInfo.productFilename}.app`), targetOutDir, masBuildOptions)
      }
      else {
        await this.sign(prepackaged, targetOutDir, masBuildOptions)
      }
    }
github electron-userland / electron-builder / packages / app-builder-lib / src / targets / snap.ts View on Github external
command: "command.sh",
      plugs: plugNames,
      adapter: "none",
    }

    const snap: any = safeLoad(await readFile(path.join(getTemplatePath("snap"), "snapcraft.yaml"), "utf-8"))
    if (this.isUseTemplateApp) {
      delete appDescriptor.adapter
    }
    if (options.grade != null) {
      snap.grade = options.grade
    }
    if (options.confinement != null) {
      snap.confinement = options.confinement
    }
    deepAssign(snap, {
      name: snapName,
      version: appInfo.version,
      summary: options.summary || appInfo.productName,
      description: this.helper.getDescription(options),
      architectures: [toLinuxArchString(arch, "snap")],
      apps: {
        [snapName]: appDescriptor
      },
      parts: {
        app: {
          "stage-packages": stagePackages,
        }
      },
    })

    if (options.autoStart) {
github electron-userland / electron-builder / packages / app-builder-lib / src / util / config.ts View on Github external
export function doMergeConfigs(configuration: Configuration, parentConfiguration: Configuration | null) {
  normalizeFiles(configuration, "files")
  normalizeFiles(configuration, "extraFiles")
  normalizeFiles(configuration, "extraResources")

  if (parentConfiguration == null) {
    return deepAssign(getDefaultConfig(), configuration)
  }

  normalizeFiles(parentConfiguration, "files")
  normalizeFiles(parentConfiguration, "extraFiles")
  normalizeFiles(parentConfiguration, "extraResources")

  const result = deepAssign(getDefaultConfig(), parentConfiguration, configuration)
  mergeFiles(configuration, parentConfiguration, result, "files")
  return result
}
github electron-userland / electron-builder / packages / app-builder-lib / src / util / config.ts View on Github external
export function doMergeConfigs(configuration: Configuration, parentConfiguration: Configuration | null) {
  normalizeFiles(configuration, "files")
  normalizeFiles(configuration, "extraFiles")
  normalizeFiles(configuration, "extraResources")

  if (parentConfiguration == null) {
    return deepAssign(getDefaultConfig(), configuration)
  }

  normalizeFiles(parentConfiguration, "files")
  normalizeFiles(parentConfiguration, "extraFiles")
  normalizeFiles(parentConfiguration, "extraResources")

  const result = deepAssign(getDefaultConfig(), parentConfiguration, configuration)
  mergeFiles(configuration, parentConfiguration, result, "files")
  return result
}
github electron-userland / electron-builder / packages / app-builder-lib / src / macPackager.ts View on Github external
if (!hasMas || targets.length > 1) {
      const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged
      nonMasPromise = (prepackaged ? Promise.resolve() : this.doPack(outDir, path.dirname(appPath), this.platform.nodeName as ElectronPlatformName, arch, this.platformSpecificBuildOptions, targets))
        .then(() => this.packageInDistributableFormat(appPath, Arch.x64, targets, taskManager))
    }

    for (const target of targets) {
      const targetName = target.name
      if (!(targetName === "mas" || targetName === "mas-dev")) {
        continue
      }

      const masBuildOptions = deepAssign({}, this.platformSpecificBuildOptions, this.config.mas)
      if (targetName === "mas-dev") {
        deepAssign(masBuildOptions, this.config.masDev, {
          type: "development",
        })
      }

      const targetOutDir = path.join(outDir, targetName)
      if (prepackaged == null) {
        await this.doPack(outDir, targetOutDir, "mas", arch, masBuildOptions, [target])
        await this.sign(path.join(targetOutDir, `${this.appInfo.productFilename}.app`), targetOutDir, masBuildOptions)
      }
      else {
        await this.sign(prepackaged, targetOutDir, masBuildOptions)
      }
    }

    if (nonMasPromise != null) {
      await nonMasPromise