forked from stoneman/appium-windows-driver
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathutils.js
More file actions
41 lines (38 loc) · 1.24 KB
/
utils.js
File metadata and controls
41 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import _ from 'lodash';
import { util, net } from 'appium/support';
import { promisify } from 'node:util';
import { exec } from 'node:child_process';
import B from 'bluebird';
const execAsync = promisify(exec);
/**
* This API triggers UAC when necessary
* unlike the 'spawn' call used by teen_process's exec.
* See https://github.com/nodejs/node-v0.x-archive/issues/6797
*
* @param {string} cmd
* @param {string[]} args
* @param {import('node:child_process').ExecOptions & {timeoutMs?: number}} opts
* @returns {Promise<{stdout: string; stderr: string;}>}
* @throws {import('node:child_process').ExecException}
*/
export async function shellExec(cmd, args = [], opts = {}) {
const {
timeoutMs = 60 * 1000 * 5
} = opts;
const fullCmd = util.quote([cmd, ...args]);
const { stdout, stderr } = await B.resolve(execAsync(fullCmd, opts))
.timeout(timeoutMs, `The command '${fullCmd}' timed out after ${timeoutMs}ms`);
return {
stdout: _.isString(stdout) ? stdout : stdout.toString(),
stderr: _.isString(stderr) ? stderr : stderr.toString(),
};
}
/**
*
* @param {string} srcUrl
* @param {string} dstPath
* @returns {Promise<void>}
*/
export async function downloadToFile(srcUrl, dstPath) {
await net.downloadFile(srcUrl, dstPath);
}