1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.compute7zCompressArgs = compute7zCompressArgs;
|
7 | exports.archive = exports.tar = void 0;
|
8 |
|
9 | function _bluebirdLst() {
|
10 | const data = require("bluebird-lst");
|
11 |
|
12 | _bluebirdLst = function () {
|
13 | return data;
|
14 | };
|
15 |
|
16 | return data;
|
17 | }
|
18 |
|
19 | function _zipBin() {
|
20 | const data = require("7zip-bin");
|
21 |
|
22 | _zipBin = function () {
|
23 | return data;
|
24 | };
|
25 |
|
26 | return data;
|
27 | }
|
28 |
|
29 | function _builderUtil() {
|
30 | const data = require("builder-util");
|
31 |
|
32 | _builderUtil = function () {
|
33 | return data;
|
34 | };
|
35 |
|
36 | return data;
|
37 | }
|
38 |
|
39 | function _fs() {
|
40 | const data = require("builder-util/out/fs");
|
41 |
|
42 | _fs = function () {
|
43 | return data;
|
44 | };
|
45 |
|
46 | return data;
|
47 | }
|
48 |
|
49 | function _fsExtraP() {
|
50 | const data = require("fs-extra-p");
|
51 |
|
52 | _fsExtraP = function () {
|
53 | return data;
|
54 | };
|
55 |
|
56 | return data;
|
57 | }
|
58 |
|
59 | var path = _interopRequireWildcard(require("path"));
|
60 |
|
61 | function _tools() {
|
62 | const data = require("./tools");
|
63 |
|
64 | _tools = function () {
|
65 | return data;
|
66 | };
|
67 |
|
68 | return data;
|
69 | }
|
70 |
|
71 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
72 |
|
73 |
|
74 | let tar = (() => {
|
75 | var _ref = (0, _bluebirdLst().coroutine)(function* (compression, format, outFile, dirToArchive, isMacApp, tempDirManager) {
|
76 | const tarFile = yield tempDirManager.getTempFile({
|
77 | suffix: ".tar"
|
78 | });
|
79 | const tarArgs = (0, _builderUtil().debug7zArgs)("a");
|
80 | tarArgs.push(tarFile);
|
81 | tarArgs.push(path.basename(dirToArchive));
|
82 | yield Promise.all([(0, _builderUtil().exec)(_zipBin().path7za, tarArgs, {
|
83 | cwd: path.dirname(dirToArchive)
|
84 | }),
|
85 | (0, _fs().unlinkIfExists)(outFile)]);
|
86 |
|
87 | if (!isMacApp) {
|
88 | yield (0, _builderUtil().exec)(_zipBin().path7za, ["rn", tarFile, path.basename(dirToArchive), path.basename(outFile, `.${format}`)]);
|
89 | }
|
90 |
|
91 | if (format === "tar.lz") {
|
92 |
|
93 | let lzipPath = "lzip";
|
94 |
|
95 | if (process.platform === "darwin") {
|
96 | lzipPath = path.join((yield (0, _tools().getLinuxToolsPath)()), "bin", lzipPath);
|
97 | }
|
98 |
|
99 | yield (0, _builderUtil().exec)(lzipPath, [compression === "store" ? "-1" : "-9", "--keep"
|
100 |
|
101 | , tarFile]);
|
102 |
|
103 | yield (0, _fsExtraP().move)(`${tarFile}.lz`, outFile);
|
104 | return;
|
105 | }
|
106 |
|
107 | const args = compute7zCompressArgs(format === "tar.xz" ? "xz" : format === "tar.bz2" ? "bzip2" : "gzip", {
|
108 | isRegularFile: true,
|
109 | method: "DEFAULT",
|
110 | compression
|
111 | });
|
112 | args.push(outFile, tarFile);
|
113 | yield (0, _builderUtil().exec)(_zipBin().path7za, args, {
|
114 | cwd: path.dirname(dirToArchive)
|
115 | }, _builderUtil().debug7z.enabled);
|
116 | });
|
117 |
|
118 | return function tar(_x, _x2, _x3, _x4, _x5, _x6) {
|
119 | return _ref.apply(this, arguments);
|
120 | };
|
121 | })();
|
122 |
|
123 | exports.tar = tar;
|
124 |
|
125 | function compute7zCompressArgs(format, options = {}) {
|
126 | let storeOnly = options.compression === "store";
|
127 | const args = (0, _builderUtil().debug7zArgs)("a");
|
128 | let isLevelSet = false;
|
129 |
|
130 | if (process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL != null) {
|
131 | storeOnly = false;
|
132 | args.push(`-mx=${process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL}`);
|
133 | isLevelSet = true;
|
134 | }
|
135 |
|
136 | const isZip = format === "zip";
|
137 |
|
138 | if (!storeOnly) {
|
139 | if (isZip && options.compression === "maximum") {
|
140 |
|
141 | args.push("-mfb=258", "-mpass=15");
|
142 | }
|
143 |
|
144 | if (!isLevelSet) {
|
145 |
|
146 | args.push("-mx=" + (!isZip || options.compression === "maximum" ? "9" : "7"));
|
147 | }
|
148 | }
|
149 |
|
150 | if (options.dictSize != null) {
|
151 | args.push(`-md=${options.dictSize}m`);
|
152 | }
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | if (!options.isRegularFile) {
|
159 | args.push("-mtc=off");
|
160 | }
|
161 |
|
162 | if (format === "7z" || format.endsWith(".7z")) {
|
163 | if (options.solid === false) {
|
164 | args.push("-ms=off");
|
165 | }
|
166 |
|
167 | if (options.isArchiveHeaderCompressed === false) {
|
168 | args.push("-mhc=off");
|
169 | }
|
170 |
|
171 |
|
172 |
|
173 | args.push("-mtm=off", "-mta=off");
|
174 | }
|
175 |
|
176 | if (options.method != null) {
|
177 | if (options.method !== "DEFAULT") {
|
178 | args.push(`-mm=${options.method}`);
|
179 | }
|
180 | } else if (isZip || storeOnly) {
|
181 | args.push(`-mm=${storeOnly ? "Copy" : "Deflate"}`);
|
182 | }
|
183 |
|
184 | if (isZip) {
|
185 |
|
186 |
|
187 |
|
188 | args.push("-mcu");
|
189 | }
|
190 |
|
191 | return args;
|
192 | }
|
193 |
|
194 |
|
195 |
|
196 |
|
197 | let archive = (() => {
|
198 | var _ref2 = (0, _bluebirdLst().coroutine)(function* (format, outFile, dirToArchive, options = {}) {
|
199 | const args = compute7zCompressArgs(format, options);
|
200 |
|
201 | yield (0, _fs().unlinkIfExists)(outFile);
|
202 | args.push(outFile, options.listFile == null ? options.withoutDir ? "." : path.basename(dirToArchive) : `@${options.listFile}`);
|
203 |
|
204 | if (options.excluded != null) {
|
205 | for (const mask of options.excluded) {
|
206 | args.push(`-xr!${mask}`);
|
207 | }
|
208 | }
|
209 |
|
210 | try {
|
211 | yield (0, _builderUtil().exec)(_zipBin().path7za, args, {
|
212 | cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive)
|
213 | }, _builderUtil().debug7z.enabled);
|
214 | } catch (e) {
|
215 | if (e.code === "ENOENT" && !(yield (0, _fs().exists)(dirToArchive))) {
|
216 | throw new Error(`Cannot create archive: "${dirToArchive}" doesn't exist`);
|
217 | } else {
|
218 | throw e;
|
219 | }
|
220 | }
|
221 |
|
222 | return outFile;
|
223 | });
|
224 |
|
225 | return function archive(_x7, _x8, _x9) {
|
226 | return _ref2.apply(this, arguments);
|
227 | };
|
228 | })(); exports.archive = archive;
|
229 |
|
\ | No newline at end of file |