UNPKG

2.6 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const childProcess = require("child_process");
4const fs = require("fs-extra");
5const os = require("os");
6const path = require("path");
7async function useAndRemoveDirectory(directory, fn) {
8 let result;
9 try {
10 result = await fn(directory);
11 }
12 finally {
13 await fs.remove(directory);
14 }
15 return result;
16}
17async function withTempDirectoryIn(parentDirectory = os.tmpdir(), fn) {
18 const tempDirectoryPrefix = 'electron-download-';
19 const tempDirectory = await fs.mkdtemp(path.resolve(parentDirectory, tempDirectoryPrefix));
20 return useAndRemoveDirectory(tempDirectory, fn);
21}
22exports.withTempDirectoryIn = withTempDirectoryIn;
23async function withTempDirectory(fn) {
24 return withTempDirectoryIn(undefined, fn);
25}
26exports.withTempDirectory = withTempDirectory;
27function normalizeVersion(version) {
28 if (!version.startsWith('v')) {
29 return `v${version}`;
30 }
31 return version;
32}
33exports.normalizeVersion = normalizeVersion;
34/**
35 * Runs the `uname` command and returns the trimmed output.
36 */
37function uname() {
38 return childProcess
39 .execSync('uname -m')
40 .toString()
41 .trim();
42}
43exports.uname = uname;
44/**
45 * Generates an architecture name that would be used in an Electron or Node.js
46 * download file name.
47 */
48function getNodeArch(arch) {
49 if (arch === 'arm') {
50 // eslint-disable-next-line @typescript-eslint/no-explicit-any
51 switch (process.config.variables.arm_version) {
52 case '6':
53 return uname();
54 case '7':
55 default:
56 return 'armv7l';
57 }
58 }
59 return arch;
60}
61exports.getNodeArch = getNodeArch;
62/**
63 * Generates an architecture name that would be used in an Electron or Node.js
64 * download file name, from the `process` module information.
65 */
66function getHostArch() {
67 return getNodeArch(process.arch);
68}
69exports.getHostArch = getHostArch;
70function ensureIsTruthyString(obj, key) {
71 if (!obj[key] || typeof obj[key] !== 'string') {
72 throw new Error(`Expected property "${key}" to be provided as a string but it was not`);
73 }
74}
75exports.ensureIsTruthyString = ensureIsTruthyString;
76function isOfficialLinuxIA32Download(platform, arch, version, mirrorOptions) {
77 return (platform === 'linux' &&
78 arch === 'ia32' &&
79 Number(version.slice(1).split('.')[0]) >= 4 &&
80 typeof mirrorOptions === 'undefined');
81}
82exports.isOfficialLinuxIA32Download = isOfficialLinuxIA32Download;
83//# sourceMappingURL=utils.js.map
\No newline at end of file