Skip to content

Commit

Permalink
fix: Fix the return type of mobile: removeCertificate extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored and boneskull committed Apr 14, 2023
1 parent 853c65e commit 10cfce1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/commands/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ export default {
* is available on the server machine.
*
* @param {string} name - Name of certificate to remove
* @returns {Promise<object>} Returns status acknowledgment if successfully removed certificate or 'None'
* @returns {Promise<string>} Returns status acknowledgment status if
* tht certificate is successfully removed or 'None' (basically just
* forwards the original pyidevice output)
* @throws {Error} If attempting to remote certificates for simulated device or if py-ios-device
* is not installed
* @group Real Device Only
Expand Down
43 changes: 41 additions & 2 deletions lib/py-ios-device-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import path from 'path';
const BINARY_NAME = 'pyidevice';

class Pyidevice {
/**
* @param {string} udid
*/
constructor (udid) {
this.udid = udid;
this.binaryPath = null;
}

/**
* @param {boolean} isStrict
* @return {Promise<boolean>}
*/
async assertExists (isStrict = true) {
if (this.binaryPath) {
return true;
Expand All @@ -31,6 +38,19 @@ class Pyidevice {
}
}

/**
* @typedef {Object} ExecuteOptions
* @property {string} cwd
* @property {string} format [json]
* @property {boolean} logStdout [false]
* @property {boolean} asynchronous [false]
*/

/**
* @param {string[]} args
* @param {Partial<ExecuteOptions>} opts
* @return {Promise<import('teen_process').TeenProcessExecResult|import('teen_process').SubProcess>}
*/
async execute (args, opts = {}) {
await this.assertExists();
const {
Expand Down Expand Up @@ -62,6 +82,9 @@ class Pyidevice {
}
}

/**
* @return {Promise<object>}
*/
async listProfiles () {
const {stdout} = /** @type {import('teen_process').TeenProcessExecResult} */(await this.execute(['profiles', 'list']));
return JSON.parse(stdout);
Expand Down Expand Up @@ -96,23 +119,39 @@ class Pyidevice {
}
}

/**
* @param {string} name
* @returns {Promise<string>}
*/
async removeProfile (name) {
await this.execute(['profiles', 'remove', '--name', name], {logStdout: true});
return /** @type {import('teen_process').TeenProcessExecResult} */ (await this.execute([
'profiles', 'remove', '--name', name
], {logStdout: true})).stdout;
}

/**
* @returns {Promise<object>}
*/
async listCrashes () {
const {stdout} = /** @type {import('teen_process').TeenProcessExecResult} */(await this.execute(['crash', 'list']));
return JSON.parse(stdout.replace(/'/g, '"')).filter((x) => !['.', '..'].includes(x));
}

/**
* @param {string} name
* @param {string} dstFolder
* @returns {Promise<void>}
*/
async exportCrash (name, dstFolder) {
await this.execute(['crash', 'export', '--name', name], {
logStdout: true,
// The tool exports crash reports to the current working dir
cwd: dstFolder
});
}

/**
* @param {string} dstFile
*/
async collectPcap (dstFile) {
return await this.execute(['pcapd', dstFile], {
format: null,
Expand Down

0 comments on commit 10cfce1

Please # to comment.