1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.serializeString = exports.computeBackground = exports.detach = exports.attachAndExecute = exports.getDmgVendorPath = exports.getDmgTemplatePath = exports.DmgTarget = void 0;
|
4 | const promise_1 = require("builder-util/out/promise");
|
5 | const path = require("path");
|
6 | const hdiuil_1 = require("./hdiuil");
|
7 | var dmg_1 = require("./dmg");
|
8 | Object.defineProperty(exports, "DmgTarget", { enumerable: true, get: function () { return dmg_1.DmgTarget; } });
|
9 | const root = path.join(__dirname, "..");
|
10 | function getDmgTemplatePath() {
|
11 | return path.join(root, "templates");
|
12 | }
|
13 | exports.getDmgTemplatePath = getDmgTemplatePath;
|
14 | function getDmgVendorPath() {
|
15 | return path.join(root, "vendor");
|
16 | }
|
17 | exports.getDmgVendorPath = getDmgVendorPath;
|
18 | async function attachAndExecute(dmgPath, readWrite, task) {
|
19 |
|
20 | const args = ["attach", "-noverify", "-noautoopen"];
|
21 | if (readWrite) {
|
22 | args.push("-readwrite");
|
23 | }
|
24 | args.push(dmgPath);
|
25 | const attachResult = await (0, hdiuil_1.hdiUtil)(args);
|
26 | const deviceResult = attachResult == null ? null : /^(\/dev\/\w+)/.exec(attachResult);
|
27 | const device = deviceResult == null || deviceResult.length !== 2 ? null : deviceResult[1];
|
28 | if (device == null) {
|
29 | throw new Error(`Cannot mount: ${attachResult}`);
|
30 | }
|
31 | return await (0, promise_1.executeFinally)(task(), () => detach(device));
|
32 | }
|
33 | exports.attachAndExecute = attachAndExecute;
|
34 | async function detach(name) {
|
35 | return (0, hdiuil_1.hdiUtil)(["detach", "-quiet", name]);
|
36 | }
|
37 | exports.detach = detach;
|
38 | async function computeBackground(packager) {
|
39 | const resourceList = await packager.resourceList;
|
40 | if (resourceList.includes("background.tiff")) {
|
41 | return path.join(packager.buildResourcesDir, "background.tiff");
|
42 | }
|
43 | else if (resourceList.includes("background.png")) {
|
44 | return path.join(packager.buildResourcesDir, "background.png");
|
45 | }
|
46 | else {
|
47 | return path.join(getDmgTemplatePath(), "background.tiff");
|
48 | }
|
49 | }
|
50 | exports.computeBackground = computeBackground;
|
51 |
|
52 | function serializeString(data) {
|
53 | return (' $"' +
|
54 | data
|
55 | .match(/.{1,32}/g)
|
56 | .map(it => it.match(/.{1,4}/g).join(" "))
|
57 | .join('"\n $"') +
|
58 | '"');
|
59 | }
|
60 | exports.serializeString = serializeString;
|
61 |
|
\ | No newline at end of file |