dmgLicense.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.addLicenseToDmg = void 0;
  4. const builder_util_1 = require("builder-util");
  5. const js_yaml_1 = require("js-yaml");
  6. const license_1 = require("app-builder-lib/out/util/license");
  7. const fs_extra_1 = require("fs-extra");
  8. const licenseButtons_1 = require("./licenseButtons");
  9. const dmg_license_1 = require("dmg-license");
  10. async function addLicenseToDmg(packager, dmgPath) {
  11. const licenseFiles = await (0, license_1.getLicenseFiles)(packager);
  12. if (licenseFiles.length === 0) {
  13. return null;
  14. }
  15. const licenseButtonFiles = await (0, licenseButtons_1.getLicenseButtonsFile)(packager);
  16. packager.debugLogger.add("dmg.licenseFiles", licenseFiles);
  17. packager.debugLogger.add("dmg.licenseButtons", licenseButtonFiles);
  18. const jsonFile = {
  19. $schema: "https://github.com/argv-minus-one/dmg-license/raw/master/schema.json",
  20. // defaultLang: '',
  21. body: [],
  22. labels: [],
  23. };
  24. for (const file of licenseFiles) {
  25. jsonFile.body.push({
  26. file: file.file,
  27. lang: file.langWithRegion.replace("_", "-"),
  28. });
  29. }
  30. for (const button of licenseButtonFiles) {
  31. const filepath = button.file;
  32. const label = filepath.endsWith(".yml") ? (0, js_yaml_1.load)(await (0, fs_extra_1.readFile)(filepath, "utf-8")) : await (0, fs_extra_1.readJson)(filepath);
  33. if (label.description) {
  34. // to support original button file format
  35. label.message = label.description;
  36. delete label.description;
  37. }
  38. jsonFile.labels.push(Object.assign({
  39. lang: button.langWithRegion.replace("_", "-"),
  40. }, label));
  41. }
  42. await (0, dmg_license_1.dmgLicenseFromJSON)(dmgPath, jsonFile, {
  43. onNonFatalError: builder_util_1.log.warn.bind(builder_util_1.log),
  44. });
  45. return jsonFile;
  46. }
  47. exports.addLicenseToDmg = addLicenseToDmg;
  48. //# sourceMappingURL=dmgLicense.js.map