Socket
Socket
Sign inDemoInstall

simctl

Package Overview
Dependencies
25
Maintainers
12
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

.eslintrc

144

lib/simctl-extensions.js
/*
The MIT License (MIT)
Copyright (c) 2014 Shazron Abdullah.
Copyright (c) 2022 Shazron Abdullah.

@@ -25,79 +25,85 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

var shell = require('shelljs');
var path = require('path');
var fs = require('fs');
var util = require('util');
var Tail = require('tail').Tail;
const shell = require('shelljs')
const path = require('path')
const fs = require('fs')
const util = require('util')
const Tail = require('tail').Tail
var extensions = {
start: function (deviceid) {
var is_at_least_xcode_9 = false;
const extensions = {
start: function (deviceid) {
let isAtLeastXcode9 = false
var command = 'xcodebuild -version';
var output = shell.exec(command, { silent: true }).output;
let command = 'xcodebuild -version'
const res = shell.exec(command, { silent: true })
// parse output for Xcode version
var versionMatch = /Xcode (.*)/.exec(output);
if (!versionMatch) {
console.log('Unable to parse xcodebuild version.');
return;
} else {
is_at_least_xcode_9 = (parseInt(versionMatch[1]) >= 9);
}
// parse output for Xcode version
const versionMatch = /Xcode (.*)/.exec(res.stdout)
if (res.code !== 0 || !versionMatch) {
console.error('Unable to parse xcodebuild version.')
return
} else {
isAtLeastXcode9 = (parseInt(versionMatch[1]) >= 9)
}
if (is_at_least_xcode_9) {
// Xcode 9 or greater
command = util.format('xcrun simctl list -j');
var res = shell.exec(command, { silent: true });
if (res.code !== 0) {
console.log('Could not get device list.');
return;
}
var list_output = JSON.parse(res.output);
var device = Object.keys(list_output.devices)
.reduce(function (acc, key) { return acc.concat(list_output.devices[key]); }, [])
.find(function (el) { return el.udid === deviceid; });
if (isAtLeastXcode9) {
// Xcode 9 or greater
command = util.format('xcrun simctl list -j')
let res = shell.exec(command, { silent: true })
if (res.code !== 0) {
console.error('Could not get device list.')
return
}
const listOutput = JSON.parse(res.stdout)
const device = Object.keys(listOutput.devices)
.reduce(function (acc, key) { return acc.concat(listOutput.devices[key]) }, [])
.find(function (el) { return el.udid === deviceid })
if (device.state === 'Booted') {
// no need to launch the emulator, it is already running
console.log('Simulator already running.');
return;
}
command = util.format('xcrun simctl boot "%s"', deviceid);
shell.exec(command, { silent: true });
command = 'open `xcode-select -p`/Applications/Simulator.app';
return shell.exec(command, { silent: true });
} else {
// Xcode 8 or older
command = util.format('xcrun instruments -w "%s"', deviceid);
return shell.exec(command, { silent: true });
}
},
if (device.state === 'Booted') {
// no need to launch the emulator, it is already running
console.error('Simulator already running.')
return
}
command = util.format('xcrun simctl boot "%s"', deviceid)
res = shell.exec(command, { silent: true })
log: function (deviceid, filepath) {
var tail = new Tail(
path.join(process.env.HOME, 'Library/Logs/CoreSimulator', deviceid, 'system.log')
);
if (res.code !== 0) {
console.error(`Could not boot simulator ${deviceid}`)
return
}
tail.on('line', function (data) {
if (filepath) {
fs.appendFile(filepath, data + '\n', function (error) {
if (error) {
console.error('ERROR: ', error);
throw error;
}
});
} else {
console.log(data);
}
});
command = 'open `xcode-select -p`/Applications/Simulator.app'
return shell.exec(command, { silent: true })
} else {
// Xcode 8 or older
command = util.format('xcrun instruments -w "%s"', deviceid)
return shell.exec(command, { silent: true })
}
},
tail.on('error', function (error) {
console.error('ERROR: ', error);
});
log: function (deviceid, filepath) {
const tail = new Tail(
path.join(process.env.HOME, 'Library/Logs/CoreSimulator', deviceid, 'system.log')
)
return tail;
}
};
tail.on('line', function (data) {
if (filepath) {
fs.appendFile(filepath, data + '\n', function (error) {
if (error) {
console.error('ERROR: ', error)
throw error
}
})
} else {
console.log(data)
}
})
exports = module.exports = extensions;
tail.on('error', function (error) {
console.error('ERROR: ', error)
})
return tail
}
}
exports = module.exports = extensions
{
"name": "simctl",
"version": "2.0.2",
"version": "2.0.3",
"description": "library for Xcode 8+ simctl utility on macOS",

@@ -15,3 +15,2 @@ "repository": {

"devDependencies": {
"jasmine": "^2",
"eslint": "^8.0.0",

@@ -21,11 +20,12 @@ "eslint-config-semistandard": "^11.0.0",

"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jest": "^26.1.0",
"eslint-plugin-node": "^5.1.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1"
"eslint-plugin-standard": "^3.0.1",
"jest": "^27.5.1"
},
"scripts": {
"test": "npm run jasmine",
"test": "jest test",
"posttest": "npm run eslint",
"eslint": "eslint lib ./simctl.js",
"jasmine": "jasmine --config=spec/support/jasmine.json"
"eslint": "eslint lib ./simctl.js"
},

@@ -32,0 +32,0 @@ "keywords": [

/*
The MIT License (MIT)
Copyright (c) 2014 Shazron Abdullah.
Copyright (c) 2022 Shazron Abdullah.

@@ -25,171 +25,171 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

var shell = require('shelljs');
var util = require('util');
var SimCtlExtensions = require('./lib/simctl-extensions');
const shell = require('shelljs')
const util = require('util')
const SimCtlExtensions = require('./lib/simctl-extensions')
exports = module.exports = {
set noxpc (b) {
this._noxpc = b;
},
set noxpc (b) {
this._noxpc = b
},
get noxpc () {
return this._noxpc;
},
get noxpc () {
return this._noxpc
},
extensions: SimCtlExtensions,
extensions: SimCtlExtensions,
check_prerequisites: function () {
var command = util.format('xcrun simctl help');
var obj = shell.exec(command, {silent: true});
check_prerequisites: function () {
const command = util.format('xcrun simctl help')
const obj = shell.exec(command, {silent: true})
if (obj.code !== 0) {
obj.stdout = 'simctl was not found.\n';
obj.stdout += 'Check that you have Xcode 8.x installed:\n';
obj.stdout += '\txcodebuild --version\n';
obj.stdout += 'Check that you have Xcode 8.x selected:\n';
obj.stdout += '\txcode-select --print-path\n';
}
if (obj.code !== 0) {
obj.stdout = 'simctl was not found.\n'
obj.stdout += 'Check that you have Xcode 8.x installed:\n'
obj.stdout += '\txcodebuild --version\n'
obj.stdout += 'Check that you have Xcode 8.x selected:\n'
obj.stdout += '\txcode-select --print-path\n'
}
return obj;
},
return obj
},
create: function (name, device_type_id, runtime_id) {
var command = util.format('xcrun simctl create "%s" "%s" "%s"', name, device_type_id, runtime_id);
return shell.exec(command);
},
create: function (name, deviceTypeId, runtimeId) {
const command = util.format('xcrun simctl create "%s" "%s" "%s"', name, deviceTypeId, runtimeId)
return shell.exec(command)
},
del: function (device) {
var command = util.format('xcrun simctl delete "%s"', device);
return shell.exec(command);
},
del: function (device) {
const command = util.format('xcrun simctl delete "%s"', device)
return shell.exec(command)
},
erase: function (device) {
var command = util.format('xcrun simctl erase "%s"', device);
return shell.exec(command);
},
erase: function (device) {
const command = util.format('xcrun simctl erase "%s"', device)
return shell.exec(command)
},
boot: function (device) {
var command = util.format('xcrun simctl boot "%s"', device);
return shell.exec(command);
},
boot: function (device) {
const command = util.format('xcrun simctl boot "%s"', device)
return shell.exec(command)
},
shutdown: function (device) {
var command = util.format('xcrun simctl shutdown "%s"', device);
return shell.exec(command);
},
shutdown: function (device) {
const command = util.format('xcrun simctl shutdown "%s"', device)
return shell.exec(command)
},
rename: function (device, name) {
var command = util.format('xcrun simctl rename "%s" "%s"', device, name);
return shell.exec(command);
},
rename: function (device, name) {
const command = util.format('xcrun simctl rename "%s" "%s"', device, name)
return shell.exec(command)
},
getenv: function (device, variable_name) {
var command = util.format('xcrun simctl getenv "%s" "%s"', device, variable_name);
return shell.exec(command);
},
getenv: function (device, variableName) {
const command = util.format('xcrun simctl getenv "%s" "%s"', device, variableName)
return shell.exec(command)
},
openurl: function (device, url) {
var command = util.format('xcrun simctl openurl "%s" "%s"', device, url);
return shell.exec(command);
},
openurl: function (device, url) {
const command = util.format('xcrun simctl openurl "%s" "%s"', device, url)
return shell.exec(command)
},
addphoto: function (device, path) {
var command = util.format('xcrun simctl addphoto "%s" "%s"', device, path);
return shell.exec(command);
},
addphoto: function (device, path) {
const command = util.format('xcrun simctl addphoto "%s" "%s"', device, path)
return shell.exec(command)
},
install: function (device, path) {
var command = util.format('xcrun simctl install "%s" "%s"', device, path);
return shell.exec(command);
},
install: function (device, path) {
const command = util.format('xcrun simctl install "%s" "%s"', device, path)
return shell.exec(command)
},
uninstall: function (device, app_identifier) {
var command = util.format('xcrun simctl uninstall "%s" "%s"', device, app_identifier);
return shell.exec(command);
},
uninstall: function (device, appIdentifier) {
const command = util.format('xcrun simctl uninstall "%s" "%s"', device, appIdentifier)
return shell.exec(command)
},
launch: function (wait_for_debugger, device, app_identifier, argv) {
var wait_flag = '';
if (wait_for_debugger) {
wait_flag = '--wait-for-debugger';
}
launch: function (waitForDebugger, device, appIdentifier, argv) {
let waitFlag = ''
if (waitForDebugger) {
waitFlag = '--wait-for-debugger'
}
var argv_expanded = '';
if (argv.length > 0) {
argv_expanded = argv.map(function (arg) {
return '\'' + arg + '\'';
}).join(' ');
}
let argvExpanded = ''
if (argv.length > 0) {
argvExpanded = argv.map(function (arg) {
return '\'' + arg + '\''
}).join(' ')
}
var command = util.format('xcrun simctl launch %s "%s" "%s" %s',
wait_flag, device, app_identifier, argv_expanded);
return shell.exec(command);
},
const command = util.format('xcrun simctl launch %s "%s" "%s" %s',
waitFlag, device, appIdentifier, argvExpanded)
return shell.exec(command)
},
spawn: function (wait_for_debugger, arch, device, path_to_executable, argv) {
var wait_flag = '';
if (wait_for_debugger) {
wait_flag = '--wait-for-debugger';
}
spawn: function (waitForDebugger, arch, device, pathToExecutable, argv) {
let waitFlag = ''
if (waitForDebugger) {
waitFlag = '--wait-for-debugger'
}
var arch_flag = '';
if (arch) {
arch_flag = util.format('--arch="%s"', arch);
}
let archFlag = ''
if (arch) {
archFlag = util.format('--arch="%s"', arch)
}
var argv_expanded = '';
if (argv.length > 0) {
argv_expanded = argv.map(function (arg) {
return '\'' + arg + '\'';
}).join(' ');
}
let argvExpanded = ''
if (argv.length > 0) {
argvExpanded = argv.map(function (arg) {
return '\'' + arg + '\''
}).join(' ')
}
var command = util.format('xcrun simctl spawn %s %s "%s" "%s" %s',
wait_flag, arch_flag, device, path_to_executable, argv_expanded);
return shell.exec(command);
},
const command = util.format('xcrun simctl spawn %s %s "%s" "%s" %s',
waitFlag, archFlag, device, pathToExecutable, argvExpanded)
return shell.exec(command)
},
list: function (options) {
var sublist = '';
options = options || {};
list: function (options) {
let sublist = ''
options = options || {}
if (options.devices) {
sublist = 'devices';
} else if (options.devicetypes) {
sublist = 'devicetypes';
} else if (options.runtimes) {
sublist = 'runtimes';
} else if (options.pairs) {
sublist = 'pairs';
}
if (options.devices) {
sublist = 'devices'
} else if (options.devicetypes) {
sublist = 'devicetypes'
} else if (options.runtimes) {
sublist = 'runtimes'
} else if (options.pairs) {
sublist = 'pairs'
}
var command = util.format('xcrun simctl list %s --json', sublist);
var obj = shell.exec(command, { silent: options.silent });
const command = util.format('xcrun simctl list %s --json', sublist)
const obj = shell.exec(command, { silent: options.silent })
if (obj.code === 0) {
try {
obj.json = JSON.parse(obj.stdout);
} catch (err) {
console.error(err.stack);
}
}
if (obj.code === 0) {
try {
obj.json = JSON.parse(obj.stdout)
} catch (err) {
console.error(err.stack)
}
}
return obj;
},
return obj
},
notify_post: function (device, notification_name) {
var command = util.format('xcrun simctl notify_post "%s" "%s"', device, notification_name);
return shell.exec(command);
},
notify_post: function (device, notificationName) {
const command = util.format('xcrun simctl notify_post "%s" "%s"', device, notificationName)
return shell.exec(command)
},
icloud_sync: function (device) {
var command = util.format('xcrun simctl icloud_sync "%s"', device);
return shell.exec(command);
},
icloud_sync: function (device) {
const command = util.format('xcrun simctl icloud_sync "%s"', device)
return shell.exec(command)
},
help: function (subcommand) {
var command = util.format('xcrun simctl help "%s"', subcommand);
return shell.exec(command);
}
};
help: function (subcommand) {
const command = util.format('xcrun simctl help "%s"', subcommand)
return shell.exec(command)
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc