Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Shazron Abdullah
Copyright (c) 2026 Darryl Pogue

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

55 changes: 53 additions & 2 deletions lib/devicectl.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
}
},

list: function () {
const result = spawnSync('xcrun', ['devicectl', 'list', 'devices', '--quiet', '--json-output', '/dev/stdout'], { encoding: 'utf8' });
list: function (type = 'devices') {
const result = spawnSync('xcrun', ['devicectl', 'list', type, '--quiet', '--json-output', '/dev/stdout'], { encoding: 'utf8' });

if (result.status === 0) {
try {
Expand All @@ -72,5 +72,56 @@
}

return result;
},

InfoTypes: Object.freeze({
AppIcon: 'appIcon',

Check failure on line 78 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'AppIcon'

Check failure on line 78 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'AppIcon'
Apps: 'apps',

Check failure on line 79 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'Apps'

Check failure on line 79 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'Apps'
AuthListing: 'authListing',

Check failure on line 80 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'AuthListing'

Check failure on line 80 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'AuthListing'
DDIServices: 'ddiServices',

Check failure on line 81 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'DDIServices'

Check failure on line 81 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'DDIServices'
Details: 'details',

Check failure on line 82 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'Details'

Check failure on line 82 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'Details'
Displays: 'displays',

Check failure on line 83 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'Displays'

Check failure on line 83 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'Displays'
Files: 'files',

Check failure on line 84 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'Files'

Check failure on line 84 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'Files'
LockState: 'lockState',

Check failure on line 85 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'LockState'

Check failure on line 85 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'LockState'
Processes: 'processes'

Check failure on line 86 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Extra space before value for key 'Processes'

Check failure on line 86 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Extra space before value for key 'Processes'
}),

info: function (infoType, deviceId) {
if (!Object.values(module.exports.InfoTypes).contains(infoType)) {
throw new TypeError(`Unexpected device info command '${infoType}'`);

Check failure on line 91 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 20.x on macOS

Expected indentation of 6 spaces but found 8

Check failure on line 91 in lib/devicectl.js

View workflow job for this annotation

GitHub Actions / NodeJS 22.x on macOS

Expected indentation of 6 spaces but found 8
}

const result = spawnSync('xcrun', ['devicectl', 'device', 'info', infoType, '--device', deviceId, '--quiet', '--json-output', '/dev/stdout'], { encoding: 'utf8' });

if (result.status === 0) {
try {
result.json = JSON.parse(result.stdout);
} catch (err) {
console.error(err.stack);
}
}

return result;
},

install: function (deviceId, appPath) {
return spawnSync('xcrun', ['devicectl', 'device', 'install', 'app', '--device', deviceId, appPath], { encoding: 'utf8' });
},

launch: function (deviceId, bundleId, argv = [], options = {}) {
const args = ['devicectl', 'device', 'process', 'launch', '--device', deviceId];

if (options.waitForDebugger || options.startStopped) {
args.push('--start-stopped');
}

if (options.console) {
args.push('--console');
}

args.push(bundleId);
args.push(...argv);

return spawnSync('xcrun', args, { encoding: 'utf8' });
}
};
84 changes: 77 additions & 7 deletions test/devicectl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const spawnMock = test.mock.method(childProcess, 'spawnSync');

const devicectl = require('../lib/devicectl');

test.beforeEach(() => {
spawnMock.mock.resetCalls();
});

test('exports', (t) => {
t.assert ||= require('node:assert');

Expand All @@ -38,6 +42,9 @@ test('exports', (t) => {
t.assert.equal(typeof devicectl.xcode_version, 'function');
t.assert.equal(typeof devicectl.help, 'function');
t.assert.equal(typeof devicectl.list, 'function');
t.assert.equal(typeof devicectl.info, 'function');
t.assert.equal(typeof devicectl.install, 'function');
t.assert.equal(typeof devicectl.launch, 'function');
});

test('check_prerequisites fail', (t) => {
Expand Down Expand Up @@ -86,10 +93,6 @@ test('devicectl version', (t) => {
});

test('devicectl help', async (ctx) => {
ctx.beforeEach((t) => {
spawnMock.mock.resetCalls();
});

await ctx.test('with no arguments', (t) => {
t.assert ||= require('node:assert');

Expand All @@ -115,12 +118,10 @@ test('devicectl help', async (ctx) => {

test('devicectl list', async (ctx) => {
ctx.beforeEach((t) => {
spawnMock.mock.resetCalls();

t.mock.method(console, 'error', () => {});
});

await ctx.test('with a successful response', (t) => {
await ctx.test('with no arguments', (t) => {
t.assert ||= require('node:assert');

spawnMock.mock.mockImplementationOnce(() => {
Expand All @@ -132,6 +133,18 @@ test('devicectl list', async (ctx) => {
t.assert.deepEqual(retObj.json, { result: { devices: [] } });
});

await ctx.test('with preferredDDI argument', (t) => {
t.assert ||= require('node:assert');

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '{"result":{"platforms":[]}}' };
});

const retObj = devicectl.list('preferredDDI');
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['devicectl', 'list', 'preferredDDI', '--quiet', '--json-output', '/dev/stdout']);
t.assert.deepEqual(retObj.json, { result: { platforms: [] } });
});

await ctx.test('with parsing error', (t) => {
t.assert ||= require('node:assert');

Expand All @@ -144,3 +157,60 @@ test('devicectl list', async (ctx) => {
t.assert.equal(retObj.json, undefined);
});
});

test('devicectl install', (t) => {
t.assert ||= require('node:assert');

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' };
});

devicectl.install('device_id', 'path/to/bundle.app');
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['devicectl', 'device', 'install', 'app', '--device', 'device_id', 'path/to/bundle.app']);
});

test('devicectl launch', async (ctx) => {
await ctx.test('with no argv arguments', (t) => {
t.assert ||= require('node:assert');

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' };
});

devicectl.launch('device_id', 'com.example.myapp');
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['devicectl', 'device', 'process', 'launch', '--device', 'device_id', 'com.example.myapp']);
});

await ctx.test('with argv arguments', (t) => {
t.assert ||= require('node:assert');

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' };
});

devicectl.launch('device_id', 'com.example.myapp', ['https://example.com']);
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['devicectl', 'device', 'process', 'launch', '--device', 'device_id', 'com.example.myapp', 'https://example.com']);
});

await ctx.test('with startStopped option', (t) => {
t.assert ||= require('node:assert');

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' };
});

devicectl.launch('device_id', 'com.example.myapp', [], { startStopped: true });
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['devicectl', 'device', 'process', 'launch', '--device', 'device_id', '--start-stopped', 'com.example.myapp']);
});

await ctx.test('with console option', (t) => {
t.assert ||= require('node:assert');

spawnMock.mock.mockImplementationOnce(() => {
return { status: 0, stdout: '' };
});

devicectl.launch('device_id', 'com.example.myapp', [], { console: true });
t.assert.deepEqual(spawnMock.mock.calls[0].arguments[1], ['devicectl', 'device', 'process', 'launch', '--device', 'device_id', '--console', 'com.example.myapp']);
});
});
Loading