-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
129 lines (126 loc) · 2.97 KB
/
index.js
File metadata and controls
129 lines (126 loc) · 2.97 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const { exec } = require('child_process');
const { promisify } = require('util');
const run = promisify(exec);
const simctl = {
exec(command, ...args){
return run([ 'xcrun', 'simctl', command ].concat(args).map(JSON.stringify).join(' '))
.then(({ stderr, stdout }) => {
if(stderr) throw new Error(stderr);
return stdout;
});
},
/**
* open Simulator.app
*/
open(){
return run('open -a Simulator.app');
},
/**
* Create a new device.
* @param {*} name
* @param {*} deviceTypeId
* @param {*} runtimeId
*/
create(name, deviceTypeId, runtimeId) {
return this.exec(`create`, name, deviceTypeId, runtimeId);
},
/**
* Delete a device or all unavailable devices.
*/
delete(device = 'unavailable'){
return this.exec('delete', device);
},
/**
* List available devices, device types, runtimes, or device pairs.
* @param {*} type
*/
list(type){
return this.exec('list', '-j', type).then(JSON.parse);
},
/**
* Open a URL in a device.
* @param {*} device
* @param {*} url
*/
openurl(device, url){
return this.exec('openurl', device, url);
},
/**
* Boot a device.
*/
boot(device){
return this.exec('boot', device);
},
/**
* Shutdown a device.
* @param {*} device
*/
shutdown(device){
return this.exec('shutdown', device);
},
/**
* Add photos, live photos, videos, or contacts to the library of a device.
* @param {*} device
* @param {*} filename
*/
addmedia(device, filename){
return this.exec('addmedia', device, filename);
},
/**
* Install an app on a device.
* @param {*} device
* @param {*} filename
*/
install(device, filename){
return this.exec('install', device, filename);
},
/**
* Launch an application by identifier on a device.
* @param {*} device
* @param {*} app
*/
launch(device, app){
return this.exec('launch', device, app);
},
/**
* Terminate an application by identifier on a device.
* @param {*} device
* @param {*} app
*/
terminate(device, app){
return this.exec('terminate', device, app);
},
/**
* Set up a device IO operation.
* @param {*} device
* @param {*} operation
* @param {...any} args
*/
io(device, operation, ...args){
return this.exec('io', device, operation, ...args);
},
/**
* Saves a screenshot as a PNG to the specified file or url
* @param {*} device
* @param {*} filename
*/
screenshot(device, filename){
return this.io(device, 'screenshot', filename);
},
/**
* Records the display to the specified file or url
*/
recordVideo(device, filename){
return this.io(device, 'recordVideo', filename);
},
/**
* Spawn a process by executing a given executable on a device.
* @param {*} device
* @param {*} command
* @param {...any} args
*/
spawn(device, command, ...args){
return this.exec('spawn', device, command, ...args);
}
};
module.exports = simctl;