1 | import * as childProcess from 'child_process';
|
2 | import * as fs from 'fs-extra';
|
3 | import * as os from 'os';
|
4 | import * as path from 'path';
|
5 | async function useAndRemoveDirectory(directory, fn) {
|
6 | let result;
|
7 | try {
|
8 | result = await fn(directory);
|
9 | }
|
10 | finally {
|
11 | await fs.remove(directory);
|
12 | }
|
13 | return result;
|
14 | }
|
15 | export async function withTempDirectoryIn(parentDirectory = os.tmpdir(), fn) {
|
16 | const tempDirectoryPrefix = 'electron-download-';
|
17 | const tempDirectory = await fs.mkdtemp(path.resolve(parentDirectory, tempDirectoryPrefix));
|
18 | return useAndRemoveDirectory(tempDirectory, fn);
|
19 | }
|
20 | export async function withTempDirectory(fn) {
|
21 | return withTempDirectoryIn(undefined, fn);
|
22 | }
|
23 | export function normalizeVersion(version) {
|
24 | if (!version.startsWith('v')) {
|
25 | return `v${version}`;
|
26 | }
|
27 | return version;
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 | export function uname() {
|
33 | return childProcess
|
34 | .execSync('uname -m')
|
35 | .toString()
|
36 | .trim();
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export function getNodeArch(arch) {
|
43 | if (arch === 'arm') {
|
44 |
|
45 | switch (process.config.variables.arm_version) {
|
46 | case '6':
|
47 | return uname();
|
48 | case '7':
|
49 | default:
|
50 | return 'armv7l';
|
51 | }
|
52 | }
|
53 | return arch;
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | export function getHostArch() {
|
60 | return getNodeArch(process.arch);
|
61 | }
|
62 | export function ensureIsTruthyString(obj, key) {
|
63 | if (!obj[key] || typeof obj[key] !== 'string') {
|
64 | throw new Error(`Expected property "${key}" to be provided as a string but it was not`);
|
65 | }
|
66 | }
|
67 | export function isOfficialLinuxIA32Download(platform, arch, version, mirrorOptions) {
|
68 | return (platform === 'linux' &&
|
69 | arch === 'ia32' &&
|
70 | Number(version.slice(1).split('.')[0]) >= 4 &&
|
71 | typeof mirrorOptions === 'undefined');
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | export function getEnv(prefix = '') {
|
78 | const envsLowerCase = {};
|
79 | for (const envKey in process.env) {
|
80 | envsLowerCase[envKey.toLowerCase()] = process.env[envKey];
|
81 | }
|
82 | return (name) => {
|
83 | return (envsLowerCase[`${prefix}${name}`.toLowerCase()] ||
|
84 | envsLowerCase[name.toLowerCase()] ||
|
85 | undefined);
|
86 | };
|
87 | }
|
88 | export function setEnv(key, value) {
|
89 |
|
90 |
|
91 | if (value !== void 0) {
|
92 | process.env[key] = value;
|
93 | }
|
94 | }
|
95 |
|
\ | No newline at end of file |