UNPKG

2.42 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.serializeString = exports.computeBackground = exports.detach = exports.attachAndExecute = exports.getDmgVendorPath = exports.getDmgTemplatePath = exports.DmgTarget = void 0;
4const promise_1 = require("builder-util/out/promise");
5const path = require("path");
6const hdiuil_1 = require("./hdiuil");
7var dmg_1 = require("./dmg");
8Object.defineProperty(exports, "DmgTarget", { enumerable: true, get: function () { return dmg_1.DmgTarget; } });
9const root = path.join(__dirname, "..");
10function getDmgTemplatePath() {
11 return path.join(root, "templates");
12}
13exports.getDmgTemplatePath = getDmgTemplatePath;
14function getDmgVendorPath() {
15 return path.join(root, "vendor");
16}
17exports.getDmgVendorPath = getDmgVendorPath;
18async function attachAndExecute(dmgPath, readWrite, task) {
19 //noinspection SpellCheckingInspection
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}
33exports.attachAndExecute = attachAndExecute;
34async function detach(name) {
35 return (0, hdiuil_1.hdiUtil)(["detach", "-quiet", name]);
36}
37exports.detach = detach;
38async 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}
50exports.computeBackground = computeBackground;
51/** @internal */
52function 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}
60exports.serializeString = serializeString;
61//# sourceMappingURL=dmgUtil.js.map
\No newline at end of file