node-devicectl 1.0.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 +0 -0
- package/LICENSE +201 -0
- package/README.md +41 -0
- package/lib/devicectl.ts +102 -0
- package/lib/index.ts +2 -0
- package/lib/mixins/copy.ts +60 -0
- package/lib/mixins/info.ts +30 -0
- package/lib/mixins/process.ts +63 -0
- package/lib/types.ts +113 -0
- package/package.json +76 -0
package/CHANGELOG.md
ADDED
|
File without changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# node-devicectl
|
|
2
|
+
|
|
3
|
+
Node.js wrapper around Apple's `devicectl` tool, the command-line utility to control iOS devices. `devicectl` is run as a sub-command of xcrun and requires Xcode 15+ and iOS 17+.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install through npm.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install node-devicectl
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
The module exports a single class `Devicectl`. This class contains methods which wrap various devicectl subcommands.
|
|
16
|
+
|
|
17
|
+
### Advanced Usage
|
|
18
|
+
|
|
19
|
+
Any devicectl subcommand could be called via `execute` method,
|
|
20
|
+
which accepts the subcommand itself as the first argument and the set of options. For example:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { Devicectl } from 'node-devicectl';
|
|
24
|
+
|
|
25
|
+
const devicectl = new Devicectl('device-udid');
|
|
26
|
+
const processes = await devicectl.listProcesses();
|
|
27
|
+
await devicectl.launchApp('com.example.app', {
|
|
28
|
+
env: { DEBUG: '1' },
|
|
29
|
+
terminateExisting: true
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
- Xcode 15+
|
|
36
|
+
- iOS 17+
|
|
37
|
+
- Node.js 20.19.0+ || 22.12.0+ || 24.0.0+
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
Apache-2.0
|
package/lib/devicectl.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { exec, SubProcess } from 'teen_process';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import logger from '@appium/logger';
|
|
4
|
+
import type {
|
|
5
|
+
ExecuteOptions,
|
|
6
|
+
ExecuteResult,
|
|
7
|
+
} from './types';
|
|
8
|
+
import * as processMixins from './mixins/process';
|
|
9
|
+
import * as infoMixins from './mixins/info';
|
|
10
|
+
import * as copyMixins from './mixins/copy';
|
|
11
|
+
|
|
12
|
+
const XCRUN = 'xcrun';
|
|
13
|
+
const LOG_TAG = 'Devicectl';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Node.js wrapper around Apple's devicectl tool
|
|
17
|
+
*
|
|
18
|
+
* This class provides methods to interact with iOS devices using the devicectl command-line tool.
|
|
19
|
+
* It requires Xcode 15+ and iOS 17+ to function properly.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export class Devicectl {
|
|
23
|
+
/** The unique device identifier */
|
|
24
|
+
public readonly udid: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new Devicectl instance
|
|
28
|
+
*
|
|
29
|
+
* @param udid - The unique device identifier
|
|
30
|
+
*/
|
|
31
|
+
constructor(udid: string) {
|
|
32
|
+
this.udid = udid;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Executes a devicectl command
|
|
37
|
+
*
|
|
38
|
+
* @param subcommand - The devicectl subcommand to execute
|
|
39
|
+
* @param opts - Execution options
|
|
40
|
+
* @returns Promise that resolves to the command result
|
|
41
|
+
*/
|
|
42
|
+
async execute<T extends ExecuteOptions>(
|
|
43
|
+
subcommand: string[],
|
|
44
|
+
opts?: T
|
|
45
|
+
): Promise<ExecuteResult<T>> {
|
|
46
|
+
const {
|
|
47
|
+
logStdout = false,
|
|
48
|
+
asynchronous = false,
|
|
49
|
+
asJson = true,
|
|
50
|
+
subcommandOptions,
|
|
51
|
+
timeout,
|
|
52
|
+
} = opts ?? {};
|
|
53
|
+
|
|
54
|
+
const finalArgs = [
|
|
55
|
+
'devicectl', ...subcommand,
|
|
56
|
+
'--device', this.udid,
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
if (subcommandOptions && !_.isEmpty(subcommandOptions)) {
|
|
60
|
+
finalArgs.push(
|
|
61
|
+
...(Array.isArray(subcommandOptions) ? subcommandOptions : [subcommandOptions])
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (asJson) {
|
|
66
|
+
finalArgs.push('--quiet', '--json-output', '-');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const cmdStr = [XCRUN, ...finalArgs].map((arg) => `"${arg}"`).join(' ');
|
|
70
|
+
logger.debug(LOG_TAG, `Executing ${cmdStr}`);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
if (asynchronous) {
|
|
74
|
+
const result = new SubProcess(XCRUN, finalArgs);
|
|
75
|
+
await result.start(0);
|
|
76
|
+
return result as ExecuteResult<T>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const result = await exec(
|
|
80
|
+
XCRUN,
|
|
81
|
+
finalArgs,
|
|
82
|
+
...(_.isNumber(timeout) ? [{ timeout }] : []),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (logStdout) {
|
|
86
|
+
logger.debug(LOG_TAG, `Command output: ${result.stdout}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return result as ExecuteResult<T>;
|
|
90
|
+
} catch (e: any) {
|
|
91
|
+
throw new Error(`'${cmdStr}' failed. Original error: ${e.stderr || e.stdout || e.message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
sendMemoryWarning = processMixins.sendMemoryWarning;
|
|
96
|
+
sendSignalToProcess = processMixins.sendSignalToProcess;
|
|
97
|
+
launchApp = processMixins.launchApp;
|
|
98
|
+
listProcesses = infoMixins.listProcesses;
|
|
99
|
+
listApps = infoMixins.listApps;
|
|
100
|
+
listFiles = copyMixins.listFiles;
|
|
101
|
+
pullFile = copyMixins.pullFile;
|
|
102
|
+
}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ListFilesOptions, PullFileOptions } from '../types';
|
|
2
|
+
import type { Devicectl } from '../devicectl';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Lists files at a specified path on the device
|
|
6
|
+
*/
|
|
7
|
+
export async function listFiles(
|
|
8
|
+
this: Devicectl,
|
|
9
|
+
domainType: string,
|
|
10
|
+
domainIdentifier: string,
|
|
11
|
+
opts: ListFilesOptions = {}
|
|
12
|
+
): Promise<string[]> {
|
|
13
|
+
const subcommandOptions = [
|
|
14
|
+
'--domain-type', domainType,
|
|
15
|
+
'--domain-identifier', domainIdentifier,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
if (opts.username) {
|
|
19
|
+
subcommandOptions.push('--username', opts.username);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (opts.subdirectory) {
|
|
23
|
+
subcommandOptions.push('--subdirectory', opts.subdirectory);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { stdout } = await this.execute(['device', 'info', 'files'], {
|
|
27
|
+
subcommandOptions,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return JSON.parse(stdout).result.files.map(({ name }: { name: string }) => name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pulls a file from the specified path on the device to a local file system
|
|
35
|
+
*/
|
|
36
|
+
export async function pullFile(
|
|
37
|
+
this: Devicectl,
|
|
38
|
+
from: string,
|
|
39
|
+
to: string,
|
|
40
|
+
opts: PullFileOptions
|
|
41
|
+
): Promise<string> {
|
|
42
|
+
const subcommandOptions = [
|
|
43
|
+
'--domain-type', opts.domainType,
|
|
44
|
+
'--domain-identifier', opts.domainIdentifier,
|
|
45
|
+
'--source', from,
|
|
46
|
+
'--destination', to,
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
if (opts.username) {
|
|
50
|
+
subcommandOptions.push('--user', opts.username);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await this.execute(['device', 'copy', 'from'], {
|
|
54
|
+
subcommandOptions,
|
|
55
|
+
timeout: opts.timeout ?? 120000,
|
|
56
|
+
asJson: false,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return to;
|
|
60
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AppInfo, ProcessInfo } from '../types';
|
|
2
|
+
import type { Devicectl } from '../devicectl';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the list of installed apps from the device
|
|
6
|
+
*/
|
|
7
|
+
export async function listApps(
|
|
8
|
+
this: Devicectl,
|
|
9
|
+
bundleId?: string
|
|
10
|
+
): Promise<AppInfo[]> {
|
|
11
|
+
const subcommandOptions = ['--include-all-apps'];
|
|
12
|
+
|
|
13
|
+
if (bundleId) {
|
|
14
|
+
subcommandOptions.push('--bundle-id', bundleId);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { stdout } = await this.execute(['device', 'info', 'apps'], {
|
|
18
|
+
subcommandOptions,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return JSON.parse(stdout).result.apps;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Lists running processes on the device
|
|
26
|
+
*/
|
|
27
|
+
export async function listProcesses(this: Devicectl): Promise<ProcessInfo[]> {
|
|
28
|
+
const { stdout } = await this.execute(['device', 'info', 'processes']);
|
|
29
|
+
return JSON.parse(stdout).result.runningProcesses;
|
|
30
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import type { LaunchAppOptions } from '../types';
|
|
3
|
+
import type { Devicectl } from '../devicectl';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Simulates memory warning for the process with the given PID
|
|
7
|
+
*/
|
|
8
|
+
export async function sendMemoryWarning(
|
|
9
|
+
this: Devicectl,
|
|
10
|
+
pid: number | string
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
await this.execute(['device', 'process', 'sendMemoryWarning'], {
|
|
13
|
+
subcommandOptions: ['--pid', `${pid}`]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Send POSIX signal to the running process
|
|
19
|
+
*/
|
|
20
|
+
export async function sendSignalToProcess(
|
|
21
|
+
this: Devicectl,
|
|
22
|
+
pid: number | string,
|
|
23
|
+
signal: number | string
|
|
24
|
+
): Promise<void> {
|
|
25
|
+
await this.execute(['device', 'process', 'signal'], {
|
|
26
|
+
subcommandOptions: ['--signal', `${signal}`, '--pid', `${pid}`]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Launch the given bundle id application with the given environment variable.
|
|
32
|
+
* This method is over devicectl command, this it may take additional seconds to launch the app.
|
|
33
|
+
* Please use via WDA or via appium-ios-device as primary method to launch app if possible.
|
|
34
|
+
*/
|
|
35
|
+
export async function launchApp(
|
|
36
|
+
this: Devicectl,
|
|
37
|
+
bundleId: string,
|
|
38
|
+
opts: LaunchAppOptions = {}
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
const {
|
|
41
|
+
env,
|
|
42
|
+
terminateExisting = false
|
|
43
|
+
} = opts;
|
|
44
|
+
|
|
45
|
+
const subcommandOptions: string[] = [];
|
|
46
|
+
|
|
47
|
+
if (terminateExisting) {
|
|
48
|
+
subcommandOptions.push('--terminate-existing');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!_.isEmpty(env)) {
|
|
52
|
+
subcommandOptions.push('--environment-variables', JSON.stringify(_.mapValues(env, (v) => _.toString(v))));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The bundle id should be the last to apply arguments properly.
|
|
56
|
+
// devicectl command might not raise exception while the order is wrong.
|
|
57
|
+
subcommandOptions.push(bundleId);
|
|
58
|
+
|
|
59
|
+
await this.execute(['device', 'process', 'launch'], {
|
|
60
|
+
subcommandOptions,
|
|
61
|
+
asJson: false
|
|
62
|
+
});
|
|
63
|
+
}
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { SubProcess, TeenProcessExecResult } from 'teen_process';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Information about a running process on the device
|
|
5
|
+
*/
|
|
6
|
+
export interface ProcessInfo {
|
|
7
|
+
/** The process identifier */
|
|
8
|
+
processIdentifier: number;
|
|
9
|
+
/** The executable path */
|
|
10
|
+
executable: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Information about an installed app on the device
|
|
15
|
+
*/
|
|
16
|
+
export interface AppInfo {
|
|
17
|
+
/** Whether this is an app clip */
|
|
18
|
+
appClip: boolean;
|
|
19
|
+
/** Whether this app was built by a developer */
|
|
20
|
+
builtByDeveloper: boolean;
|
|
21
|
+
/** The bundle identifier */
|
|
22
|
+
bundleIdentifier: string;
|
|
23
|
+
/** The bundle version */
|
|
24
|
+
bundleVersion: string;
|
|
25
|
+
/** Whether this is a default system app */
|
|
26
|
+
defaultApp: boolean;
|
|
27
|
+
/** Whether this app is hidden */
|
|
28
|
+
hidden: boolean;
|
|
29
|
+
/** Whether this is an internal system app */
|
|
30
|
+
internalApp: boolean;
|
|
31
|
+
/** The app name */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Whether this app can be removed */
|
|
34
|
+
removable: boolean;
|
|
35
|
+
/** The app URL/path */
|
|
36
|
+
url: string;
|
|
37
|
+
/** The app version */
|
|
38
|
+
version: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Options for executing devicectl commands
|
|
43
|
+
*/
|
|
44
|
+
export interface ExecuteOptions {
|
|
45
|
+
/** Whether to log stdout output */
|
|
46
|
+
logStdout?: boolean;
|
|
47
|
+
/** Whether to return JSON output */
|
|
48
|
+
asJson?: boolean;
|
|
49
|
+
/** Whether to run the command asynchronously */
|
|
50
|
+
asynchronous?: boolean;
|
|
51
|
+
/** Additional subcommand options */
|
|
52
|
+
subcommandOptions?: string[] | string;
|
|
53
|
+
/** Timeout in milliseconds */
|
|
54
|
+
timeout?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Options for asynchronous execution
|
|
59
|
+
*/
|
|
60
|
+
export interface AsyncExecuteOptions extends ExecuteOptions {
|
|
61
|
+
asynchronous: true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Options for listing files on the device
|
|
66
|
+
*/
|
|
67
|
+
export interface ListFilesOptions {
|
|
68
|
+
/** The username of the user we should target. Only relevant for certain domains. */
|
|
69
|
+
username?: string;
|
|
70
|
+
/** A subdirectory within the domain. If not specified, defaults to the root. */
|
|
71
|
+
subdirectory?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Options for pulling files from the device
|
|
76
|
+
*/
|
|
77
|
+
export interface PullFileOptions {
|
|
78
|
+
/** The username of the user we should target. Only relevant for certain domains. */
|
|
79
|
+
username?: string;
|
|
80
|
+
/** The file service domain. Valid values are: temporary, rootStaging, appDataContainer, appGroupDataContainer, systemCrashLogs */
|
|
81
|
+
domainType: string;
|
|
82
|
+
/** A unique string used to provide additional context to the domain */
|
|
83
|
+
domainIdentifier: string;
|
|
84
|
+
/** The timeout for pulling a file in milliseconds */
|
|
85
|
+
timeout?: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Options for launching an app
|
|
90
|
+
*/
|
|
91
|
+
export interface LaunchAppOptions {
|
|
92
|
+
/** Environment variables for the launching app process */
|
|
93
|
+
env?: Record<string, string | number>;
|
|
94
|
+
/** Whether to terminate the already running app */
|
|
95
|
+
terminateExisting?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Result type for synchronous execution
|
|
100
|
+
*/
|
|
101
|
+
export type SyncExecuteResult = TeenProcessExecResult<string>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Result type for asynchronous execution
|
|
105
|
+
*/
|
|
106
|
+
export type AsyncExecuteResult = SubProcess;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Union type for execute method return
|
|
110
|
+
*/
|
|
111
|
+
export type ExecuteResult<T extends ExecuteOptions> = T extends AsyncExecuteOptions
|
|
112
|
+
? AsyncExecuteResult
|
|
113
|
+
: SyncExecuteResult;
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-devicectl",
|
|
3
|
+
"description": "Node.js wrapper around Apple's devicectl tool",
|
|
4
|
+
"tags": [
|
|
5
|
+
"apple",
|
|
6
|
+
"ios",
|
|
7
|
+
"devicectl",
|
|
8
|
+
"device",
|
|
9
|
+
"xcode"
|
|
10
|
+
],
|
|
11
|
+
"version": "1.0.0",
|
|
12
|
+
"author": "Appium Contributors",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/appium/node-devicectl.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/appium/node-devicectl/issues"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": "^20.19.0 || ^22.12.0 || >=24.0.0",
|
|
23
|
+
"npm": ">=10"
|
|
24
|
+
},
|
|
25
|
+
"main": "./build/index.js",
|
|
26
|
+
"types": "./build/index.d.ts",
|
|
27
|
+
"bin": {},
|
|
28
|
+
"directories": {
|
|
29
|
+
"lib": "./lib"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"lib",
|
|
33
|
+
"build",
|
|
34
|
+
"CHANGELOG.md"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@appium/logger": "^2.0.0-rc.1",
|
|
38
|
+
"lodash": "^4.2.1",
|
|
39
|
+
"teen_process": "^3.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -b",
|
|
43
|
+
"clean": "npm run build -- --clean",
|
|
44
|
+
"rebuild": "npm run clean; npm run build",
|
|
45
|
+
"dev": "npm run build -- --watch",
|
|
46
|
+
"lint": "eslint .",
|
|
47
|
+
"lint:fix": "npm run lint -- --fix",
|
|
48
|
+
"prepare": "npm run build",
|
|
49
|
+
"test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.*js\"",
|
|
50
|
+
"e2e-test": "mocha --exit --timeout 5m \"./test/e2e/**/*-specs.js\""
|
|
51
|
+
},
|
|
52
|
+
"prettier": {
|
|
53
|
+
"bracketSpacing": false,
|
|
54
|
+
"printWidth": 100,
|
|
55
|
+
"singleQuote": true
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@appium/eslint-config-appium-ts": "^2.0.0-rc.1",
|
|
59
|
+
"@appium/tsconfig": "^1.0.0-rc.1",
|
|
60
|
+
"@appium/types": "^1.0.0-rc.1",
|
|
61
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
62
|
+
"@semantic-release/git": "^10.0.1",
|
|
63
|
+
"@types/lodash": "^4.14.196",
|
|
64
|
+
"@types/mocha": "^10.0.1",
|
|
65
|
+
"@types/node": "^24.0.0",
|
|
66
|
+
"@types/teen_process": "^2.0.2",
|
|
67
|
+
"chai": "^6.0.0",
|
|
68
|
+
"chai-as-promised": "^8.0.0",
|
|
69
|
+
"conventional-changelog-conventionalcommits": "^9.0.0",
|
|
70
|
+
"mocha": "^11.0.1",
|
|
71
|
+
"prettier": "^3.0.0",
|
|
72
|
+
"semantic-release": "^25.0.0",
|
|
73
|
+
"ts-node": "^10.9.1",
|
|
74
|
+
"typescript": "^5.4.3"
|
|
75
|
+
}
|
|
76
|
+
}
|