dmgLicense.js 2.35 KB
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.addLicenseToDmg = addLicenseToDmg;

function _builderUtil() {
  const data = require("builder-util");

  _builderUtil = function () {
    return data;
  };

  return data;
}

function _jsYaml() {
  const data = require("js-yaml");

  _jsYaml = function () {
    return data;
  };

  return data;
}

function _license() {
  const data = require("app-builder-lib/out/util/license");

  _license = function () {
    return data;
  };

  return data;
}

function _fsExtra() {
  const data = require("fs-extra");

  _fsExtra = function () {
    return data;
  };

  return data;
}

function _licenseButtons() {
  const data = require("./licenseButtons");

  _licenseButtons = function () {
    return data;
  };

  return data;
}

function _dmgLicense() {
  const data = require("dmg-license");

  _dmgLicense = function () {
    return data;
  };

  return data;
}

async function addLicenseToDmg(packager, dmgPath) {
  const licenseFiles = await (0, _license().getLicenseFiles)(packager);

  if (licenseFiles.length === 0) {
    return null;
  }

  const licenseButtonFiles = await (0, _licenseButtons().getLicenseButtonsFile)(packager);
  packager.debugLogger.add("dmg.licenseFiles", licenseFiles);
  packager.debugLogger.add("dmg.licenseButtons", licenseButtonFiles);
  const jsonFile = {
    "$schema": "https://github.com/argv-minus-one/dmg-license/raw/master/schema.json",
    // defaultLang: '',
    body: [],
    labels: []
  };

  for (const file of licenseFiles) {
    jsonFile.body.push({
      file: file.file,
      lang: file.langWithRegion.replace('_', '-')
    });
  }

  for (const button of licenseButtonFiles) {
    const filepath = button.file;
    const label = filepath.endsWith(".yml") ? (0, _jsYaml().load)(await (0, _fsExtra().readFile)(filepath, "utf-8")) : await (0, _fsExtra().readJson)(filepath);

    if (label.description) {
      // to support original button file format
      label.message = label.description;
      delete label.description;
    }

    jsonFile.labels.push(Object.assign({
      lang: button.langWithRegion.replace('_', '-')
    }, label));
  }

  await (0, _dmgLicense().dmgLicenseFromJSON)(dmgPath, jsonFile, {
    onNonFatalError: _builderUtil().log.warn.bind(_builderUtil().log)
  });
  return jsonFile;
} 
// __ts-babel@6.0.4
//# sourceMappingURL=dmgLicense.js.map