node-simctl 8.0.9 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/lib/helpers.d.ts +17 -9
- package/build/lib/helpers.d.ts.map +1 -1
- package/build/lib/helpers.js +50 -4
- package/build/lib/helpers.js.map +1 -1
- package/build/lib/logger.d.ts +2 -3
- package/build/lib/logger.d.ts.map +1 -1
- package/build/lib/logger.js +3 -5
- package/build/lib/logger.js.map +1 -1
- package/build/lib/simctl.d.ts +82 -188
- package/build/lib/simctl.d.ts.map +1 -1
- package/build/lib/simctl.js +98 -150
- package/build/lib/simctl.js.map +1 -1
- package/build/lib/subcommands/addmedia.d.ts +14 -16
- package/build/lib/subcommands/addmedia.d.ts.map +1 -1
- package/build/lib/subcommands/addmedia.js +5 -7
- package/build/lib/subcommands/addmedia.js.map +1 -1
- package/build/lib/subcommands/appinfo.d.ts +13 -45
- package/build/lib/subcommands/appinfo.d.ts.map +1 -1
- package/build/lib/subcommands/appinfo.js +31 -42
- package/build/lib/subcommands/appinfo.js.map +1 -1
- package/build/lib/subcommands/boot.d.ts +9 -12
- package/build/lib/subcommands/boot.d.ts.map +1 -1
- package/build/lib/subcommands/boot.js +5 -40
- package/build/lib/subcommands/boot.js.map +1 -1
- package/build/lib/subcommands/bootstatus.d.ts +16 -56
- package/build/lib/subcommands/bootstatus.d.ts.map +1 -1
- package/build/lib/subcommands/bootstatus.js +8 -22
- package/build/lib/subcommands/bootstatus.js.map +1 -1
- package/build/lib/subcommands/create.d.ts +15 -34
- package/build/lib/subcommands/create.d.ts.map +1 -1
- package/build/lib/subcommands/create.js +23 -66
- package/build/lib/subcommands/create.js.map +1 -1
- package/build/lib/subcommands/delete.d.ts +9 -12
- package/build/lib/subcommands/delete.d.ts.map +1 -1
- package/build/lib/subcommands/delete.js +3 -5
- package/build/lib/subcommands/delete.js.map +1 -1
- package/build/lib/subcommands/erase.d.ts +12 -15
- package/build/lib/subcommands/erase.d.ts.map +1 -1
- package/build/lib/subcommands/erase.js +4 -6
- package/build/lib/subcommands/erase.js.map +1 -1
- package/build/lib/subcommands/get_app_container.d.ts +19 -22
- package/build/lib/subcommands/get_app_container.d.ts.map +1 -1
- package/build/lib/subcommands/get_app_container.js +6 -8
- package/build/lib/subcommands/get_app_container.js.map +1 -1
- package/build/lib/subcommands/getenv.d.ts +11 -14
- package/build/lib/subcommands/getenv.d.ts.map +1 -1
- package/build/lib/subcommands/getenv.js +5 -7
- package/build/lib/subcommands/getenv.js.map +1 -1
- package/build/lib/subcommands/install.d.ts +12 -15
- package/build/lib/subcommands/install.d.ts.map +1 -1
- package/build/lib/subcommands/install.js +4 -6
- package/build/lib/subcommands/install.js.map +1 -1
- package/build/lib/subcommands/io.d.ts +12 -15
- package/build/lib/subcommands/io.d.ts.map +1 -1
- package/build/lib/subcommands/io.js +4 -6
- package/build/lib/subcommands/io.js.map +1 -1
- package/build/lib/subcommands/keychain.d.ts +37 -55
- package/build/lib/subcommands/keychain.d.ts.map +1 -1
- package/build/lib/subcommands/keychain.js +16 -25
- package/build/lib/subcommands/keychain.js.map +1 -1
- package/build/lib/subcommands/launch.d.ts +16 -19
- package/build/lib/subcommands/launch.d.ts.map +1 -1
- package/build/lib/subcommands/launch.js +9 -11
- package/build/lib/subcommands/launch.js.map +1 -1
- package/build/lib/subcommands/list.d.ts +94 -125
- package/build/lib/subcommands/list.d.ts.map +1 -1
- package/build/lib/subcommands/list.js +34 -92
- package/build/lib/subcommands/list.js.map +1 -1
- package/build/lib/subcommands/location.d.ts +18 -22
- package/build/lib/subcommands/location.d.ts.map +1 -1
- package/build/lib/subcommands/location.js +11 -13
- package/build/lib/subcommands/location.js.map +1 -1
- package/build/lib/subcommands/openurl.d.ts +15 -17
- package/build/lib/subcommands/openurl.d.ts.map +1 -1
- package/build/lib/subcommands/openurl.js +5 -7
- package/build/lib/subcommands/openurl.js.map +1 -1
- package/build/lib/subcommands/pbcopy.d.ts +14 -17
- package/build/lib/subcommands/pbcopy.d.ts.map +1 -1
- package/build/lib/subcommands/pbcopy.js +5 -7
- package/build/lib/subcommands/pbcopy.js.map +1 -1
- package/build/lib/subcommands/pbpaste.d.ts +14 -17
- package/build/lib/subcommands/pbpaste.d.ts.map +1 -1
- package/build/lib/subcommands/pbpaste.js +5 -7
- package/build/lib/subcommands/pbpaste.js.map +1 -1
- package/build/lib/subcommands/privacy.d.ts +52 -57
- package/build/lib/subcommands/privacy.d.ts.map +1 -1
- package/build/lib/subcommands/privacy.js +15 -17
- package/build/lib/subcommands/privacy.js.map +1 -1
- package/build/lib/subcommands/push.d.ts +22 -25
- package/build/lib/subcommands/push.d.ts.map +1 -1
- package/build/lib/subcommands/push.js +5 -7
- package/build/lib/subcommands/push.js.map +1 -1
- package/build/lib/subcommands/shutdown.d.ts +9 -12
- package/build/lib/subcommands/shutdown.d.ts.map +1 -1
- package/build/lib/subcommands/shutdown.js +5 -40
- package/build/lib/subcommands/shutdown.js.map +1 -1
- package/build/lib/subcommands/spawn.d.ts +24 -27
- package/build/lib/subcommands/spawn.d.ts.map +1 -1
- package/build/lib/subcommands/spawn.js +12 -14
- package/build/lib/subcommands/spawn.js.map +1 -1
- package/build/lib/subcommands/terminate.d.ts +12 -15
- package/build/lib/subcommands/terminate.d.ts.map +1 -1
- package/build/lib/subcommands/terminate.js +4 -6
- package/build/lib/subcommands/terminate.js.map +1 -1
- package/build/lib/subcommands/ui.d.ts +97 -105
- package/build/lib/subcommands/ui.d.ts.map +1 -1
- package/build/lib/subcommands/ui.js +24 -26
- package/build/lib/subcommands/ui.js.map +1 -1
- package/build/lib/subcommands/uninstall.d.ts +13 -16
- package/build/lib/subcommands/uninstall.d.ts.map +1 -1
- package/build/lib/subcommands/uninstall.js +4 -6
- package/build/lib/subcommands/uninstall.js.map +1 -1
- package/build/lib/types.d.ts +231 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/index.ts +13 -0
- package/lib/helpers.ts +81 -0
- package/lib/{logger.js → logger.ts} +2 -5
- package/lib/simctl.ts +221 -0
- package/lib/subcommands/{addmedia.js → addmedia.ts} +6 -8
- package/lib/subcommands/appinfo.ts +39 -0
- package/lib/subcommands/{boot.js → boot.ts} +5 -10
- package/lib/subcommands/bootstatus.ts +108 -0
- package/lib/subcommands/{create.js → create.ts} +29 -35
- package/lib/subcommands/{delete.js → delete.ts} +3 -5
- package/lib/subcommands/{erase.js → erase.ts} +4 -7
- package/lib/subcommands/{get_app_container.js → get_app_container.ts} +10 -8
- package/lib/subcommands/{getenv.js → getenv.ts} +5 -7
- package/lib/subcommands/{install.js → install.ts} +4 -6
- package/lib/subcommands/{io.js → io.ts} +4 -7
- package/lib/subcommands/{keychain.js → keychain.ts} +30 -32
- package/lib/subcommands/{launch.js → launch.ts} +9 -12
- package/lib/subcommands/{list.js → list.ts} +67 -60
- package/lib/subcommands/{location.js → location.ts} +15 -14
- package/lib/subcommands/{openurl.js → openurl.ts} +6 -7
- package/lib/subcommands/{pbcopy.js → pbcopy.ts} +11 -8
- package/lib/subcommands/{pbpaste.js → pbpaste.ts} +5 -7
- package/lib/subcommands/{privacy.js → privacy.ts} +13 -17
- package/lib/subcommands/{push.js → push.ts} +5 -8
- package/lib/subcommands/{shutdown.js → shutdown.ts} +5 -8
- package/lib/subcommands/{spawn.js → spawn.ts} +21 -17
- package/lib/subcommands/{terminate.js → terminate.ts} +4 -6
- package/lib/subcommands/{ui.js → ui.ts} +19 -28
- package/lib/subcommands/{uninstall.js → uninstall.ts} +4 -6
- package/lib/types.ts +243 -0
- package/package.json +2 -2
- package/index.js +0 -4
- package/lib/helpers.js +0 -37
- package/lib/simctl.js +0 -299
- package/lib/subcommands/appinfo.js +0 -51
- package/lib/subcommands/bootstatus.js +0 -119
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Simctl } from '../simctl';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Install the particular application package on Simulator.
|
|
5
5
|
* It is required that Simulator is in _booted_ state.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
8
|
-
* @param {string} appPath - Full path to .app package, which is
|
|
7
|
+
* @param appPath - Full path to .app package, which is
|
|
9
8
|
* going to be installed.
|
|
10
9
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
11
10
|
* returns non-zero return code.
|
|
12
11
|
* @throws {Error} If the `udid` instance property is unset
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
export async function installApp (this: Simctl, appPath: string): Promise<void> {
|
|
15
14
|
await this.exec('install', {
|
|
16
15
|
args: [this.requireUdid('install'), appPath],
|
|
17
16
|
});
|
|
18
|
-
}
|
|
17
|
+
}
|
|
19
18
|
|
|
20
|
-
export default commands;
|
|
@@ -3,21 +3,19 @@ import path from 'path';
|
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import fs from 'fs/promises';
|
|
5
5
|
import { uuidV4 } from '../helpers';
|
|
6
|
-
|
|
7
|
-
const commands = {};
|
|
6
|
+
import type { Simctl } from '../simctl';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Gets base64 screenshot for device
|
|
11
10
|
* It is required that Simulator is in _booted_ state.
|
|
12
11
|
*
|
|
13
|
-
* @this {import('../simctl').Simctl}
|
|
14
12
|
* @since Xcode SDK 8.1
|
|
15
|
-
* @return
|
|
13
|
+
* @return Base64-encoded Simulator screenshot.
|
|
16
14
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
17
15
|
* returns non-zero return code.
|
|
18
16
|
* @throws {Error} If the `udid` instance property is unset
|
|
19
17
|
*/
|
|
20
|
-
|
|
18
|
+
export async function getScreenshot (this: Simctl): Promise<string> {
|
|
21
19
|
const udid = this.requireUdid('io screenshot');
|
|
22
20
|
const pathToScreenshotPng = path.resolve(os.tmpdir(), `${await uuidV4()}.png`);
|
|
23
21
|
try {
|
|
@@ -28,6 +26,5 @@ commands.getScreenshot = async function getScreenshot () {
|
|
|
28
26
|
} finally {
|
|
29
27
|
await rimraf(pathToScreenshotPng);
|
|
30
28
|
}
|
|
31
|
-
}
|
|
29
|
+
}
|
|
32
30
|
|
|
33
|
-
export default commands;
|
|
@@ -4,15 +4,17 @@ import { uuidV4 } from '../helpers';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
import { rimraf } from 'rimraf';
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import type { Simctl } from '../simctl';
|
|
8
|
+
import type { CertOptions } from '../types';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param {(filePath: string) => Promise<any>} onPayloadStored
|
|
11
|
+
* @param payload - Certificate payload (string or Buffer)
|
|
12
|
+
* @param onPayloadStored - Callback function to execute with the file path
|
|
14
13
|
*/
|
|
15
|
-
async function handleRawPayload (
|
|
14
|
+
async function handleRawPayload (
|
|
15
|
+
payload: string | Buffer,
|
|
16
|
+
onPayloadStored: (filePath: string) => Promise<any>
|
|
17
|
+
): Promise<void> {
|
|
16
18
|
const filePath = path.resolve(os.tmpdir(), `${await uuidV4()}.pem`);
|
|
17
19
|
try {
|
|
18
20
|
if (_.isBuffer(payload)) {
|
|
@@ -26,81 +28,77 @@ async function handleRawPayload (payload, onPayloadStored) {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {Object} CertOptions
|
|
32
|
-
* @property {boolean} [raw=false] - whether the `cert` argument
|
|
33
|
-
* is the path to the certificate on the local file system or
|
|
34
|
-
* a raw certificate content
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
31
|
/**
|
|
38
32
|
* Adds the given certificate to the Trusted Root Store on the simulator
|
|
39
33
|
*
|
|
40
34
|
* @since Xcode 11.4 SDK
|
|
41
|
-
* @
|
|
42
|
-
* @param {string} cert the full path to a valid .cert file containing
|
|
35
|
+
* @param cert the full path to a valid .cert file containing
|
|
43
36
|
* the certificate content or the certificate content itself, depending on
|
|
44
37
|
* options
|
|
45
|
-
* @param
|
|
38
|
+
* @param opts - Certificate options
|
|
46
39
|
* @throws {Error} if the current SDK version does not support the command
|
|
47
40
|
* or there was an error while adding the certificate
|
|
48
41
|
* @throws {Error} If the `udid` instance property is unset
|
|
49
42
|
*/
|
|
50
|
-
|
|
43
|
+
export async function addRootCertificate (
|
|
44
|
+
this: Simctl,
|
|
45
|
+
cert: string | Buffer,
|
|
46
|
+
opts: CertOptions = {}
|
|
47
|
+
): Promise<void> {
|
|
51
48
|
const {
|
|
52
49
|
raw = false,
|
|
53
50
|
} = opts;
|
|
54
|
-
const execMethod = async (
|
|
51
|
+
const execMethod = async (certPath: string) => await this.exec('keychain', {
|
|
55
52
|
args: [this.requireUdid('keychain add-root-cert'), 'add-root-cert', certPath],
|
|
56
53
|
});
|
|
57
54
|
if (raw) {
|
|
58
55
|
await handleRawPayload(cert, execMethod);
|
|
59
56
|
} else {
|
|
60
|
-
await execMethod(cert);
|
|
57
|
+
await execMethod(cert as string);
|
|
61
58
|
}
|
|
62
|
-
}
|
|
59
|
+
}
|
|
63
60
|
|
|
64
61
|
/**
|
|
65
62
|
* Adds the given certificate to the Keychain Store on the simulator
|
|
66
63
|
*
|
|
67
64
|
* @since Xcode 11.4 SDK
|
|
68
|
-
* @
|
|
69
|
-
* @param {string} cert the full path to a valid .cert file containing
|
|
65
|
+
* @param cert the full path to a valid .cert file containing
|
|
70
66
|
* the certificate content or the certificate content itself, depending on
|
|
71
67
|
* options
|
|
72
|
-
* @param
|
|
68
|
+
* @param opts - Certificate options
|
|
73
69
|
* @throws {Error} if the current SDK version does not support the command
|
|
74
70
|
* or there was an error while adding the certificate
|
|
75
71
|
* @throws {Error} If the `udid` instance property is unset
|
|
76
72
|
*/
|
|
77
|
-
|
|
73
|
+
export async function addCertificate (
|
|
74
|
+
this: Simctl,
|
|
75
|
+
cert: string | Buffer,
|
|
76
|
+
opts: CertOptions = {}
|
|
77
|
+
): Promise<void> {
|
|
78
78
|
const {
|
|
79
79
|
raw = false,
|
|
80
80
|
} = opts;
|
|
81
|
-
const execMethod = async (certPath) => await this.exec('keychain', {
|
|
81
|
+
const execMethod = async (certPath: string) => await this.exec('keychain', {
|
|
82
82
|
args: [this.requireUdid('keychain add-cert'), 'add-cert', certPath],
|
|
83
83
|
});
|
|
84
84
|
if (raw) {
|
|
85
85
|
await handleRawPayload(cert, execMethod);
|
|
86
86
|
} else {
|
|
87
|
-
await execMethod(cert);
|
|
87
|
+
await execMethod(cert as string);
|
|
88
88
|
}
|
|
89
|
-
}
|
|
89
|
+
}
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Resets the simulator keychain
|
|
93
93
|
*
|
|
94
94
|
* @since Xcode 11.4 SDK
|
|
95
|
-
* @this {import('../simctl').Simctl}
|
|
96
95
|
* @throws {Error} if the current SDK version does not support the command
|
|
97
96
|
* or there was an error while resetting the keychain
|
|
98
97
|
* @throws {Error} If the `udid` instance property is unset
|
|
99
98
|
*/
|
|
100
|
-
|
|
99
|
+
export async function resetKeychain (this: Simctl): Promise<void> {
|
|
101
100
|
await this.exec('keychain', {
|
|
102
101
|
args: [this.requireUdid('keychain reset'), 'reset'],
|
|
103
102
|
});
|
|
104
|
-
}
|
|
103
|
+
}
|
|
105
104
|
|
|
106
|
-
export default commands;
|
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { retryInterval } from 'asyncbox';
|
|
3
|
-
|
|
4
|
-
const commands = {};
|
|
3
|
+
import type { Simctl } from '../simctl';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Execute the particular application package on Simulator.
|
|
8
7
|
* It is required that Simulator is in _booted_ state and
|
|
9
8
|
* the application with given bundle identifier is already installed.
|
|
10
9
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @param {string} bundleId - Bundle identifier of the application,
|
|
10
|
+
* @param bundleId - Bundle identifier of the application,
|
|
13
11
|
* which is going to be removed.
|
|
14
|
-
* @param
|
|
12
|
+
* @param tries - The maximum number of retries before
|
|
15
13
|
* throwing an exception.
|
|
16
|
-
* @return
|
|
14
|
+
* @return the actual command output
|
|
17
15
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
18
16
|
* returns non-zero return code.
|
|
19
17
|
* @throws {Error} If the `udid` instance property is unset
|
|
20
18
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return await retryInterval(tries, 1000, async () => {
|
|
19
|
+
export async function launchApp (this: Simctl, bundleId: string, tries: number = 5): Promise<string> {
|
|
20
|
+
const result = await retryInterval(tries, 1000, async () => {
|
|
24
21
|
const {stdout} = await this.exec('launch', {
|
|
25
22
|
args: [this.requireUdid('launch'), bundleId],
|
|
26
23
|
});
|
|
27
|
-
return _.trim(stdout);
|
|
24
|
+
return _.trim(stdout) || '';
|
|
28
25
|
});
|
|
29
|
-
|
|
26
|
+
return result || '';
|
|
27
|
+
}
|
|
30
28
|
|
|
31
|
-
export default commands;
|
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { SIM_RUNTIME_NAME, normalizeVersion } from '../helpers';
|
|
3
|
-
import log,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const commands = {};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {Object} DeviceInfo
|
|
10
|
-
* @property {string} name - The device name.
|
|
11
|
-
* @property {string} udid - The device UDID.
|
|
12
|
-
* @property {string} state - The current Simulator state, for example 'booted' or 'shutdown'.
|
|
13
|
-
* @property {string} sdk - The SDK version, for example '10.3'.
|
|
14
|
-
*/
|
|
3
|
+
import { log, LOG_PREFIX } from '../logger';
|
|
4
|
+
import type { Simctl } from '../simctl';
|
|
5
|
+
import type { DeviceInfo } from '../types';
|
|
15
6
|
|
|
16
7
|
/**
|
|
17
8
|
* Parse the list of existing Simulator devices to represent
|
|
18
9
|
* it as convenient mapping.
|
|
19
10
|
*
|
|
20
|
-
* @
|
|
21
|
-
* @
|
|
22
|
-
* @return {Promise<Record<string, any>>} The resulting mapping. Each key is platform version,
|
|
11
|
+
* @param platform - The platform name, for example 'watchOS'.
|
|
12
|
+
* @return The resulting mapping. Each key is platform version,
|
|
23
13
|
* for example '10.3' and the corresponding value is an
|
|
24
|
-
* array of the matching
|
|
14
|
+
* array of the matching DeviceInfo instances.
|
|
25
15
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
26
16
|
* returns non-zero return code.
|
|
27
17
|
*/
|
|
28
|
-
|
|
18
|
+
export async function getDevicesByParsing (
|
|
19
|
+
this: Simctl,
|
|
20
|
+
platform?: string | null
|
|
21
|
+
): Promise<Record<string, DeviceInfo[]>> {
|
|
29
22
|
const {stdout} = await this.exec('list', {
|
|
30
23
|
args: ['devices'],
|
|
31
24
|
});
|
|
@@ -42,8 +35,8 @@ commands.getDevicesByParsing = async function getDevicesByParsing (platform) {
|
|
|
42
35
|
const deviceSectionRe = _.isEmpty(platform) || !platform
|
|
43
36
|
? new RegExp(`\\-\\-\\s+(\\S+)\\s+(\\S+)\\s+\\-\\-(\\n\\s{4}.+)*`, 'mgi')
|
|
44
37
|
: new RegExp(`\\-\\-\\s+${_.escapeRegExp(platform)}\\s+(\\S+)\\s+\\-\\-(\\n\\s{4}.+)*`, 'mgi');
|
|
45
|
-
const matches = [];
|
|
46
|
-
let match;
|
|
38
|
+
const matches: RegExpExecArray[] = [];
|
|
39
|
+
let match: RegExpExecArray | null;
|
|
47
40
|
// make an entry for each sdk version
|
|
48
41
|
while ((match = deviceSectionRe.exec(stdout))) {
|
|
49
42
|
matches.push(match);
|
|
@@ -54,7 +47,7 @@ commands.getDevicesByParsing = async function getDevicesByParsing (platform) {
|
|
|
54
47
|
|
|
55
48
|
const lineRe = /([^\s].+) \((\w+-.+\w+)\) \((\w+\s?\w+)\)/; // https://regex101.com/r/lG7mK6/3
|
|
56
49
|
// get all the devices for each sdk
|
|
57
|
-
const devices = {};
|
|
50
|
+
const devices: Record<string, DeviceInfo[]> = {};
|
|
58
51
|
for (match of matches) {
|
|
59
52
|
const sdk = platform ? match[1] : match[2];
|
|
60
53
|
devices[sdk] = devices[sdk] || [];
|
|
@@ -84,27 +77,40 @@ commands.getDevicesByParsing = async function getDevicesByParsing (platform) {
|
|
|
84
77
|
}
|
|
85
78
|
}
|
|
86
79
|
return devices;
|
|
87
|
-
}
|
|
80
|
+
}
|
|
88
81
|
|
|
89
82
|
/**
|
|
90
83
|
* Parse the list of existing Simulator devices to represent
|
|
91
84
|
* it as convenient mapping for the particular platform version.
|
|
92
85
|
*
|
|
93
|
-
* @
|
|
94
|
-
* @param {string?} [forSdk] - The sdk version,
|
|
86
|
+
* @param forSdk - The sdk version,
|
|
95
87
|
* for which the devices list should be parsed,
|
|
96
88
|
* for example '10.3'.
|
|
97
|
-
* @param
|
|
98
|
-
* @return
|
|
89
|
+
* @param platform - The platform name, for example 'watchOS'.
|
|
90
|
+
* @return If _forSdk_ is set then the list
|
|
99
91
|
* of devices for the particular platform version.
|
|
100
|
-
* Otherwise the same result as for
|
|
92
|
+
* Otherwise the same result as for getDevicesByParsing
|
|
101
93
|
* function.
|
|
102
94
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
103
95
|
* returns non-zero return code or if no matching
|
|
104
96
|
* platform version is found in the system.
|
|
105
97
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
export async function getDevices (
|
|
99
|
+
this: Simctl,
|
|
100
|
+
forSdk: string,
|
|
101
|
+
platform?: string | null
|
|
102
|
+
): Promise<DeviceInfo[]>;
|
|
103
|
+
export async function getDevices (
|
|
104
|
+
this: Simctl,
|
|
105
|
+
forSdk?: undefined | null,
|
|
106
|
+
platform?: string | null
|
|
107
|
+
): Promise<Record<string, DeviceInfo[]>>;
|
|
108
|
+
export async function getDevices (
|
|
109
|
+
this: Simctl,
|
|
110
|
+
forSdk?: string | null,
|
|
111
|
+
platform?: string | null
|
|
112
|
+
): Promise<Record<string, DeviceInfo[]> | DeviceInfo[]> {
|
|
113
|
+
let devices: Record<string, DeviceInfo[]> = {};
|
|
108
114
|
try {
|
|
109
115
|
const {stdout} = await this.exec('list', {
|
|
110
116
|
args: ['devices', '-j'],
|
|
@@ -128,9 +134,9 @@ commands.getDevices = async function getDevices (forSdk, platform) {
|
|
|
128
134
|
const versionMatchRe = _.isEmpty(platform) || !platform
|
|
129
135
|
? new RegExp(`^([^\\s-]+)[\\s-](\\S+)`, 'i')
|
|
130
136
|
: new RegExp(`^${_.escapeRegExp(platform)}[\\s-](\\S+)`, 'i');
|
|
131
|
-
for (
|
|
137
|
+
for (const [sdkNameRaw, entries] of _.toPairs(JSON.parse(stdout).devices)) {
|
|
132
138
|
// there could be a longer name, so remove it
|
|
133
|
-
sdkName =
|
|
139
|
+
const sdkName = sdkNameRaw.replace(SIM_RUNTIME_NAME, '');
|
|
134
140
|
const versionMatch = versionMatchRe.exec(sdkName);
|
|
135
141
|
if (!versionMatch) {
|
|
136
142
|
continue;
|
|
@@ -139,8 +145,8 @@ commands.getDevices = async function getDevices (forSdk, platform) {
|
|
|
139
145
|
// the sdk can have dashes (`12-2`) or dots (`12.1`)
|
|
140
146
|
const sdk = (platform ? versionMatch[1] : versionMatch[2]).replace('-', '.');
|
|
141
147
|
devices[sdk] = devices[sdk] || [];
|
|
142
|
-
devices[sdk].push(...entries.filter((el) => _.isUndefined(el.isAvailable) || el.isAvailable)
|
|
143
|
-
.map((el) => {
|
|
148
|
+
devices[sdk].push(...(entries as any[]).filter((el) => _.isUndefined(el.isAvailable) || el.isAvailable)
|
|
149
|
+
.map((el: any) => {
|
|
144
150
|
delete el.availability;
|
|
145
151
|
return {
|
|
146
152
|
sdk,
|
|
@@ -150,7 +156,7 @@ commands.getDevices = async function getDevices (forSdk, platform) {
|
|
|
150
156
|
})
|
|
151
157
|
);
|
|
152
158
|
}
|
|
153
|
-
} catch (err) {
|
|
159
|
+
} catch (err: any) {
|
|
154
160
|
log.debug(LOG_PREFIX, `Unable to get JSON device list: ${err.stack}`);
|
|
155
161
|
log.debug(LOG_PREFIX, 'Falling back to manual parsing');
|
|
156
162
|
devices = await this.getDevicesByParsing(platform);
|
|
@@ -170,20 +176,22 @@ commands.getDevices = async function getDevices (forSdk, platform) {
|
|
|
170
176
|
? ` Only the following Simulator SDK versions are available on your system: ${availableSDKs.join(', ')}`
|
|
171
177
|
: ` No Simulator SDK versions are available on your system. Please install some via Xcode preferences.`;
|
|
172
178
|
throw new Error(errMsg);
|
|
173
|
-
}
|
|
179
|
+
}
|
|
174
180
|
|
|
175
181
|
/**
|
|
176
182
|
* Get the runtime for the particular platform version using --json flag
|
|
177
183
|
*
|
|
178
|
-
* @
|
|
179
|
-
* @param {string} platformVersion - The platform version name,
|
|
184
|
+
* @param platformVersion - The platform version name,
|
|
180
185
|
* for example '10.3'.
|
|
181
|
-
* @param
|
|
182
|
-
* @return
|
|
186
|
+
* @param platform - The platform name, for example 'watchOS'.
|
|
187
|
+
* @return The corresponding runtime name for the given
|
|
183
188
|
* platform version.
|
|
184
189
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
export async function getRuntimeForPlatformVersionViaJson (
|
|
191
|
+
this: Simctl,
|
|
192
|
+
platformVersion: string,
|
|
193
|
+
platform: string = 'iOS'
|
|
194
|
+
): Promise<string> {
|
|
187
195
|
const {stdout} = await this.exec('list', {
|
|
188
196
|
args: ['runtimes', '--json'],
|
|
189
197
|
});
|
|
@@ -194,20 +202,22 @@ commands.getRuntimeForPlatformVersionViaJson = async function getRuntimeForPlatf
|
|
|
194
202
|
}
|
|
195
203
|
}
|
|
196
204
|
throw new Error(`Could not use --json flag to parse platform version`);
|
|
197
|
-
}
|
|
205
|
+
}
|
|
198
206
|
|
|
199
207
|
/**
|
|
200
208
|
* Get the runtime for the particular platform version.
|
|
201
209
|
*
|
|
202
|
-
* @
|
|
203
|
-
* @param {string} platformVersion - The platform version name,
|
|
210
|
+
* @param platformVersion - The platform version name,
|
|
204
211
|
* for example '10.3'.
|
|
205
|
-
* @param
|
|
206
|
-
* @return
|
|
212
|
+
* @param platform - The platform name, for example 'watchOS'.
|
|
213
|
+
* @return The corresponding runtime name for the given
|
|
207
214
|
* platform version.
|
|
208
215
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
216
|
+
export async function getRuntimeForPlatformVersion (
|
|
217
|
+
this: Simctl,
|
|
218
|
+
platformVersion: string,
|
|
219
|
+
platform: string = 'iOS'
|
|
220
|
+
): Promise<string> {
|
|
211
221
|
// Try with parsing
|
|
212
222
|
try {
|
|
213
223
|
const {stdout} = await this.exec('list', {
|
|
@@ -226,16 +236,15 @@ commands.getRuntimeForPlatformVersion = async function getRuntimeForPlatformVers
|
|
|
226
236
|
|
|
227
237
|
// if nothing was found, pass platform version back
|
|
228
238
|
return platformVersion;
|
|
229
|
-
}
|
|
239
|
+
}
|
|
230
240
|
|
|
231
241
|
/**
|
|
232
242
|
* Get the list of device types available in the current Xcode installation
|
|
233
243
|
*
|
|
234
|
-
* @
|
|
235
|
-
* @return {Promise<string[]>} List of the types of devices available
|
|
244
|
+
* @return List of the types of devices available
|
|
236
245
|
* @throws {Error} If the corresponding simctl command fails
|
|
237
246
|
*/
|
|
238
|
-
|
|
247
|
+
export async function getDeviceTypes (this: Simctl): Promise<string[]> {
|
|
239
248
|
const {stdout} = await this.exec('list', {
|
|
240
249
|
args: ['devicetypes', '-j'],
|
|
241
250
|
});
|
|
@@ -252,17 +261,16 @@ commands.getDeviceTypes = async function getDeviceTypes () {
|
|
|
252
261
|
*/
|
|
253
262
|
try {
|
|
254
263
|
const deviceTypes = JSON.parse(stdout.trim());
|
|
255
|
-
return deviceTypes.devicetypes.map((type) => type.name);
|
|
256
|
-
} catch (err) {
|
|
264
|
+
return deviceTypes.devicetypes.map((type: any) => type.name);
|
|
265
|
+
} catch (err: any) {
|
|
257
266
|
throw new Error(`Unable to get list of device types: ${err.message}`);
|
|
258
267
|
}
|
|
259
|
-
}
|
|
268
|
+
}
|
|
260
269
|
|
|
261
270
|
/**
|
|
262
271
|
* Get the full list of runtimes, devicetypes, devices and pairs as Object
|
|
263
272
|
*
|
|
264
|
-
* @
|
|
265
|
-
* @return {Promise<Object>} Object containing device types, runtimes devices and pairs.
|
|
273
|
+
* @return Object containing device types, runtimes devices and pairs.
|
|
266
274
|
* The resulting JSON will be like:
|
|
267
275
|
* {
|
|
268
276
|
* "devicetypes" : [
|
|
@@ -293,15 +301,14 @@ commands.getDeviceTypes = async function getDeviceTypes () {
|
|
|
293
301
|
* }
|
|
294
302
|
* @throws {Error} If the corresponding simctl command fails
|
|
295
303
|
*/
|
|
296
|
-
|
|
304
|
+
export async function list (this: Simctl): Promise<any> {
|
|
297
305
|
const {stdout} = await this.exec('list', {
|
|
298
306
|
args: ['-j'],
|
|
299
307
|
});
|
|
300
308
|
try {
|
|
301
309
|
return JSON.parse(stdout.trim());
|
|
302
|
-
} catch (e) {
|
|
310
|
+
} catch (e: any) {
|
|
303
311
|
throw new Error(`Unable to parse simctl list: ${e.message}`);
|
|
304
312
|
}
|
|
305
|
-
}
|
|
313
|
+
}
|
|
306
314
|
|
|
307
|
-
export default commands;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Simctl } from '../simctl';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Formats the given location argument for simctl usage
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
6
|
+
* @param name Argument name
|
|
7
|
+
* @param value Location argument value
|
|
8
|
+
* @returns Formatted value, for example -73.768254
|
|
9
9
|
*/
|
|
10
|
-
function formatArg (name, value) {
|
|
10
|
+
function formatArg (name: string, value: string | number): string {
|
|
11
11
|
const flt = parseFloat(`${value}`);
|
|
12
12
|
if (isNaN(flt)) {
|
|
13
13
|
throw new TypeError(`${name} must be a valid number, got '${value}' instead`);
|
|
@@ -19,31 +19,32 @@ function formatArg (name, value) {
|
|
|
19
19
|
* Set the Simulator location to a specific latitude and longitude.
|
|
20
20
|
* This functionality is only available since Xcode 14.
|
|
21
21
|
*
|
|
22
|
-
* @
|
|
23
|
-
* @param
|
|
24
|
-
* @param {string|number} longitude Location longitude value
|
|
22
|
+
* @param latitude Location latitude value
|
|
23
|
+
* @param longitude Location longitude value
|
|
25
24
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
26
25
|
* returns non-zero return code.
|
|
27
26
|
* @throws {TypeError} If any of the arguments is not a valid value.
|
|
28
27
|
*/
|
|
29
|
-
|
|
28
|
+
export async function setLocation (
|
|
29
|
+
this: Simctl,
|
|
30
|
+
latitude: string | number,
|
|
31
|
+
longitude: string | number
|
|
32
|
+
): Promise<void> {
|
|
30
33
|
const lat = formatArg('latitude', latitude);
|
|
31
34
|
const lon = formatArg('longitude', longitude);
|
|
32
35
|
await this.exec('location', {
|
|
33
36
|
args: [this.requireUdid('location'), 'set', `${lat},${lon}`],
|
|
34
37
|
});
|
|
35
|
-
}
|
|
38
|
+
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
41
|
* Stop any running scenario and clear any simulated location.
|
|
39
42
|
*
|
|
40
43
|
* @since Xcode 14.
|
|
41
|
-
* @this {import('../simctl').Simctl}
|
|
42
44
|
*/
|
|
43
|
-
|
|
45
|
+
export async function clearLocation (this: Simctl): Promise<void> {
|
|
44
46
|
await this.exec('location', {
|
|
45
47
|
args: [this.requireUdid('location'), 'clear'],
|
|
46
48
|
});
|
|
47
|
-
}
|
|
49
|
+
}
|
|
48
50
|
|
|
49
|
-
export default commands;
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Simctl } from '../simctl';
|
|
2
|
+
import type { TeenProcessExecResult } from 'teen_process';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Open URL scheme on Simulator. iOS will automatically try
|
|
5
6
|
* to find a matching application, which supports the given scheme.
|
|
6
7
|
* It is required that Simulator is in _booted_ state.
|
|
7
8
|
*
|
|
8
|
-
* @
|
|
9
|
-
* @param {string} url - The URL scheme to open, for example http://appiom.io
|
|
9
|
+
* @param url - The URL scheme to open, for example http://appiom.io
|
|
10
10
|
* will be opened by the built-in mobile browser.
|
|
11
|
-
* @return
|
|
11
|
+
* @return Command execution result.
|
|
12
12
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
13
13
|
* returns non-zero return code.
|
|
14
14
|
* @throws {Error} If the `udid` instance property is unset
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
export async function openUrl (this: Simctl, url: string): Promise<TeenProcessExecResult<string>> {
|
|
17
17
|
return await this.exec('openurl', {
|
|
18
18
|
args: [this.requireUdid('openurl'), url],
|
|
19
19
|
});
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
export default commands;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Simctl } from '../simctl';
|
|
2
|
+
import type { SubProcess } from 'teen_process';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Set the content of Simulator pasteboard.
|
|
5
6
|
* It is required that Simulator is in _booted_ state.
|
|
6
7
|
*
|
|
7
8
|
* @since Xcode SDK 8.1
|
|
8
|
-
* @
|
|
9
|
-
* @param
|
|
10
|
-
* @param {BufferEncoding} [encoding='utf8'] - The encoding of the given pasteboard content.
|
|
9
|
+
* @param content - The actual string content to be set.
|
|
10
|
+
* @param encoding - The encoding of the given pasteboard content.
|
|
11
11
|
* utf8 by default.
|
|
12
12
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
13
13
|
* returns non-zero return code.
|
|
14
14
|
* @throws {Error} If the `udid` instance property is unset
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
export async function setPasteboard (
|
|
17
|
+
this: Simctl,
|
|
18
|
+
content: string,
|
|
19
|
+
encoding: BufferEncoding = 'utf8'
|
|
20
|
+
): Promise<void> {
|
|
17
21
|
const pbCopySubprocess = await this.exec('pbcopy', {
|
|
18
22
|
args: [this.requireUdid('pbcopy')],
|
|
19
23
|
asynchronous: true,
|
|
20
|
-
});
|
|
24
|
+
}) as SubProcess;
|
|
21
25
|
await pbCopySubprocess.start(0);
|
|
22
26
|
const exitCodeVerifier = pbCopySubprocess.join();
|
|
23
27
|
const stdin = pbCopySubprocess.proc?.stdin;
|
|
@@ -27,6 +31,5 @@ commands.setPasteboard = async function setPasteboard (content, encoding = 'utf8
|
|
|
27
31
|
stdin.end();
|
|
28
32
|
}
|
|
29
33
|
await exitCodeVerifier;
|
|
30
|
-
}
|
|
34
|
+
}
|
|
31
35
|
|
|
32
|
-
export default commands;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Simctl } from '../simctl';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the content of Simulator pasteboard.
|
|
5
5
|
* It is required that Simulator is in _booted_ state.
|
|
6
6
|
*
|
|
7
7
|
* @since Xcode 8.1 SDK
|
|
8
|
-
* @
|
|
9
|
-
* @param {string} [encoding='utf8'] - The encoding of the returned pasteboard content.
|
|
8
|
+
* @param encoding - The encoding of the returned pasteboard content.
|
|
10
9
|
* UTF-8 by default.
|
|
11
|
-
* @return
|
|
10
|
+
* @return Current content of Simulator pasteboard or an empty string.
|
|
12
11
|
* @throws {Error} If the corresponding simctl subcommand command
|
|
13
12
|
* returns non-zero return code.
|
|
14
13
|
* @throws {Error} If the `udid` instance property is unset
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
export async function getPasteboard (this: Simctl, encoding: BufferEncoding = 'utf8'): Promise<string> {
|
|
17
16
|
const {stdout} = await this.exec('pbpaste', {
|
|
18
17
|
args: [this.requireUdid('pbpaste')],
|
|
19
18
|
encoding,
|
|
20
19
|
});
|
|
21
20
|
return stdout;
|
|
22
|
-
}
|
|
21
|
+
}
|
|
23
22
|
|
|
24
|
-
export default commands;
|