ios-sim-portable
Advanced tools
Comparing version 3.4.5 to 4.0.0
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const _ = require("lodash"); | ||
@@ -48,8 +56,8 @@ function getSimulator() { | ||
let isResolved = false; | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
const libraryPath = require("./iphone-simulator-xcode-simctl"); | ||
const simulator = new libraryPath.XCodeSimctlSimulator(); | ||
const tryGetBootedDevices = () => { | ||
const tryGetBootedDevices = () => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return simulator.getBootedDevices.apply(simulator, args); | ||
return yield simulator.getBootedDevices.apply(simulator, args); | ||
} | ||
@@ -62,4 +70,4 @@ catch (err) { | ||
} | ||
}; | ||
let result = tryGetBootedDevices(); | ||
}); | ||
let result = yield tryGetBootedDevices(); | ||
if (result && result.length) { | ||
@@ -71,4 +79,4 @@ isResolved = true; | ||
if (!isResolved && (!result || !result.length)) { | ||
const timer = setTimeout(() => { | ||
result = tryGetBootedDevices(); | ||
const timer = setTimeout(() => __awaiter(this, void 0, void 0, function* () { | ||
result = yield tryGetBootedDevices(); | ||
if (!isResolved) { | ||
@@ -78,5 +86,5 @@ isResolved = true; | ||
} | ||
}, 500); | ||
}), 500); | ||
} | ||
}); | ||
})); | ||
}; | ||
@@ -83,0 +91,0 @@ } |
///<reference path="./.d.ts"/> | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const childProcess = require("./child-process"); | ||
@@ -26,17 +34,21 @@ const errors = require("./errors"); | ||
getSdks() { | ||
let devices = this.simctl.getDevices(); | ||
return _.map(devices, device => { | ||
return { | ||
displayName: `iOS ${device.runtimeVersion}`, | ||
version: device.runtimeVersion | ||
}; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let devices = yield this.simctl.getDevices(); | ||
return _.map(devices, device => { | ||
return { | ||
displayName: `iOS ${device.runtimeVersion}`, | ||
version: device.runtimeVersion | ||
}; | ||
}); | ||
}); | ||
} | ||
run(applicationPath, applicationIdentifier, options) { | ||
const device = this.getDeviceToRun(options); | ||
this.startSimulator(options, device); | ||
if (!options.skipInstall) { | ||
this.simctl.install(device.id, applicationPath); | ||
} | ||
return this.simctl.launch(device.id, applicationIdentifier, options); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const device = yield this.getDeviceToRun(options); | ||
this.startSimulator(options, device); | ||
if (!options.skipInstall) { | ||
this.simctl.install(device.id, applicationPath); | ||
} | ||
return this.simctl.launch(device.id, applicationIdentifier, options); | ||
}); | ||
} | ||
@@ -48,3 +60,3 @@ sendNotification(notification, deviceId) { | ||
} | ||
this.simctl.notifyPost(deviceId, notification); | ||
return this.simctl.notifyPost(deviceId, notification); | ||
} | ||
@@ -64,79 +76,87 @@ getApplicationPath(deviceId, applicationIdentifier) { | ||
startApplication(deviceId, appIdentifier, options) { | ||
// simctl launch command does not launch the process immediately and we have to wait a little bit, | ||
// just to ensure all related processes and services are alive. | ||
const launchResult = this.simctl.launch(deviceId, appIdentifier, options); | ||
utils.sleep(0.5); | ||
return launchResult; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// simctl launch command does not launch the process immediately and we have to wait a little bit, | ||
// just to ensure all related processes and services are alive. | ||
const launchResult = yield this.simctl.launch(deviceId, appIdentifier, options); | ||
utils.sleep(0.5); | ||
return launchResult; | ||
}); | ||
} | ||
stopApplication(deviceId, appIdentifier, bundleExecutable) { | ||
try { | ||
let xcodeMajorVersion = null; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const xcodeVersion = xcode.getXcodeVersionData(); | ||
xcodeMajorVersion = +xcodeVersion.major; | ||
let xcodeMajorVersion = null; | ||
try { | ||
const xcodeVersion = xcode.getXcodeVersionData(); | ||
xcodeMajorVersion = +xcodeVersion.major; | ||
} | ||
catch (err) { | ||
} | ||
let resultOfTermination; | ||
if (xcodeMajorVersion && xcodeMajorVersion < 8) { | ||
// Xcode 7.x does not have support for `xcrun simctl terminate` command | ||
resultOfTermination = childProcess.execSync(`killall ${bundleExecutable}`, { skipError: true }); | ||
} | ||
else { | ||
resultOfTermination = yield this.simctl.terminate(deviceId, appIdentifier); | ||
} | ||
// killall command does not terminate the processes immediately and we have to wait a little bit, | ||
// just to ensure all related processes and services are dead. | ||
// Same is valid for simctl terminate when Simulator's OS version is below 10. | ||
utils.sleep(0.5); | ||
return resultOfTermination; | ||
} | ||
catch (err) { | ||
catch (e) { | ||
} | ||
let resultOfTermination; | ||
if (xcodeMajorVersion && xcodeMajorVersion < 8) { | ||
// Xcode 7.x does not have support for `xcrun simctl terminate` command | ||
resultOfTermination = childProcess.execSync(`killall ${bundleExecutable}`, { skipError: true }); | ||
} | ||
else { | ||
resultOfTermination = this.simctl.terminate(deviceId, appIdentifier); | ||
} | ||
// killall command does not terminate the processes immediately and we have to wait a little bit, | ||
// just to ensure all related processes and services are dead. | ||
// Same is valid for simctl terminate when Simulator's OS version is below 10. | ||
utils.sleep(0.5); | ||
return resultOfTermination; | ||
} | ||
catch (e) { | ||
} | ||
}); | ||
} | ||
getDeviceLogProcess(deviceId, predicate) { | ||
if (!this.isDeviceLogOperationStarted) { | ||
const device = this.getDeviceFromIdentifier(deviceId); | ||
const deviceVersion = device ? device.runtimeVersion : ""; | ||
const majorVersion = deviceVersion.split(".")[0]; | ||
if (majorVersion && parseInt(majorVersion) >= 11) { | ||
this.deviceLogChildProcess = this.simctl.getLog(deviceId, predicate); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.isDeviceLogOperationStarted) { | ||
const device = yield this.getDeviceFromIdentifier(deviceId); | ||
const deviceVersion = device ? device.runtimeVersion : ""; | ||
const majorVersion = deviceVersion.split(".")[0]; | ||
if (majorVersion && parseInt(majorVersion) >= 11) { | ||
this.deviceLogChildProcess = this.simctl.getLog(deviceId, predicate); | ||
} | ||
else { | ||
const logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log"); | ||
this.deviceLogChildProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]); | ||
} | ||
this.isDeviceLogOperationStarted = true; | ||
} | ||
else { | ||
const logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log"); | ||
this.deviceLogChildProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]); | ||
} | ||
this.isDeviceLogOperationStarted = true; | ||
} | ||
return this.deviceLogChildProcess; | ||
return this.deviceLogChildProcess; | ||
}); | ||
} | ||
getDeviceToRun(options, device) { | ||
let devices = _.sortBy(this.simctl.getDevices(), (device) => device.runtimeVersion), sdkVersion = options.sdkVersion || options.sdk, deviceIdOrName = options.device; | ||
if (device && (device.sdkVersion || device.sdk)) { | ||
sdkVersion = device.sdkVersion || device.sdk; | ||
} | ||
if (device && device.id) { | ||
deviceIdOrName = device.id; | ||
} | ||
let result = _.find(devices, (device) => { | ||
if (sdkVersion && !deviceIdOrName) { | ||
return device.runtimeVersion === sdkVersion; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let devices = _.sortBy(yield this.simctl.getDevices(), (device) => device.runtimeVersion), sdkVersion = options.sdkVersion || options.sdk, deviceIdOrName = options.device; | ||
if (device && (device.sdkVersion || device.sdk)) { | ||
sdkVersion = device.sdkVersion || device.sdk; | ||
} | ||
if (deviceIdOrName && !sdkVersion) { | ||
return device.name === deviceIdOrName || device.id === deviceIdOrName; | ||
if (device && device.id) { | ||
deviceIdOrName = device.id; | ||
} | ||
if (deviceIdOrName && sdkVersion) { | ||
return device.runtimeVersion === sdkVersion && (device.name === deviceIdOrName || device.id === deviceIdOrName); | ||
let result = _.find(devices, (device) => { | ||
if (sdkVersion && !deviceIdOrName) { | ||
return device.runtimeVersion === sdkVersion; | ||
} | ||
if (deviceIdOrName && !sdkVersion) { | ||
return device.name === deviceIdOrName || device.id === deviceIdOrName; | ||
} | ||
if (deviceIdOrName && sdkVersion) { | ||
return device.runtimeVersion === sdkVersion && (device.name === deviceIdOrName || device.id === deviceIdOrName); | ||
} | ||
if (!sdkVersion && !deviceIdOrName) { | ||
return this.isDeviceBooted(device); | ||
} | ||
}); | ||
if (!result) { | ||
result = _.find(devices, (device) => device.name === this.defaultDeviceIdentifier); | ||
} | ||
if (!sdkVersion && !deviceIdOrName) { | ||
return this.isDeviceBooted(device); | ||
if (!result) { | ||
result = _.last(devices); | ||
} | ||
return result; | ||
}); | ||
if (!result) { | ||
result = _.find(devices, (device) => device.name === this.defaultDeviceIdentifier); | ||
} | ||
if (!result) { | ||
result = _.last(devices); | ||
} | ||
return result; | ||
} | ||
@@ -147,44 +167,52 @@ isDeviceBooted(device) { | ||
getBootedDevice() { | ||
let devices = this.simctl.getDevices(); | ||
return _.find(devices, device => this.isDeviceBooted(device)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let devices = yield this.simctl.getDevices(); | ||
return _.find(devices, device => this.isDeviceBooted(device)); | ||
}); | ||
} | ||
getBootedDevices() { | ||
const devices = this.simctl.getDevices(); | ||
return _.filter(devices, device => this.isDeviceBooted(device)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const devices = yield this.simctl.getDevices(); | ||
return _.filter(devices, device => this.isDeviceBooted(device)); | ||
}); | ||
} | ||
startSimulator(options, device) { | ||
if (!device && options.device) { | ||
this.verifyDevice(options.device); | ||
} | ||
device = device || this.getDeviceToRun(options); | ||
// In case the id is undefined, skip verification - we'll start default simulator. | ||
if (device && device.id) { | ||
this.verifyDevice(device); | ||
} | ||
if (!device || !device.runtimeVersion || !device.fullId) { | ||
device = this.getDeviceToRun(options, device); | ||
} | ||
if (!this.isDeviceBooted(device)) { | ||
const isSimulatorAppRunning = this.isSimulatorAppRunning(); | ||
const haveBootedDevices = this.haveBootedDevices(); | ||
if (isSimulatorAppRunning) { | ||
// In case user closes simulator window but simulator app is still alive | ||
if (!haveBootedDevices) { | ||
device = this.getDeviceToRun(options); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!device && options.device) { | ||
this.verifyDevice(options.device); | ||
} | ||
device = device || (yield this.getDeviceToRun(options)); | ||
// In case the id is undefined, skip verification - we'll start default simulator. | ||
if (device && device.id) { | ||
this.verifyDevice(device); | ||
} | ||
if (!device || !device.runtimeVersion || !device.fullId) { | ||
device = yield this.getDeviceToRun(options, device); | ||
} | ||
if (!this.isDeviceBooted(device)) { | ||
const isSimulatorAppRunning = this.isSimulatorAppRunning(); | ||
const haveBootedDevices = this.haveBootedDevices(); | ||
if (isSimulatorAppRunning) { | ||
// In case user closes simulator window but simulator app is still alive | ||
if (!haveBootedDevices) { | ||
device = yield this.getDeviceToRun(options); | ||
} | ||
this.simctl.boot(device.id); | ||
} | ||
this.simctl.boot(device.id); | ||
} | ||
else { | ||
else { | ||
common.startSimulator(device.id); | ||
} | ||
common.startSimulator(device.id); | ||
// startSimulaltor doesn't always finish immediately, and the subsequent | ||
// install fails since the simulator is not running. | ||
// Give it some time to start before we attempt installing. | ||
utils.sleep(1); | ||
} | ||
common.startSimulator(device.id); | ||
// startSimulaltor doesn't always finish immediately, and the subsequent | ||
// install fails since the simulator is not running. | ||
// Give it some time to start before we attempt installing. | ||
utils.sleep(1); | ||
} | ||
}); | ||
} | ||
haveBootedDevices() { | ||
const bootedDevices = this.getBootedDevices(); | ||
return bootedDevices && bootedDevices.length > 0; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const bootedDevices = yield this.getBootedDevices(); | ||
return bootedDevices && bootedDevices.length > 0; | ||
}); | ||
} | ||
@@ -202,11 +230,15 @@ isSimulatorAppRunning() { | ||
verifyDevice(device) { | ||
const availableDevices = this.getDevices(); | ||
const deviceId = device.id || device; | ||
if (!_.find(availableDevices, { id: deviceId }) && !_.find(availableDevices, { name: deviceId })) { | ||
errors.fail(`No simulator image available for device identifier '${deviceId}'.`); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const availableDevices = yield this.getDevices(); | ||
const deviceId = device.id || device; | ||
if (!_.find(availableDevices, { id: deviceId }) && !_.find(availableDevices, { name: deviceId })) { | ||
errors.fail(`No simulator image available for device identifier '${deviceId}'.`); | ||
} | ||
}); | ||
} | ||
getDeviceFromIdentifier(deviceId) { | ||
const availableDevices = this.getDevices(); | ||
return _.find(availableDevices, { id: deviceId }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const availableDevices = yield this.getDevices(); | ||
return _.find(availableDevices, { id: deviceId }); | ||
}); | ||
} | ||
@@ -213,0 +245,0 @@ killSimulator() { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const fs = require("fs"); | ||
@@ -13,32 +21,38 @@ const os = require("os"); | ||
run(applicationPath, applicationIdentifier, options) { | ||
if (!fs.existsSync(applicationPath)) { | ||
errors.fail("Path does not exist ", applicationPath); | ||
} | ||
if (options.device) { | ||
const hasSuchDevice = _.find(this.simulator.getDevices(), device => device.name === options.device || device.id === options.device); | ||
if (!hasSuchDevice) { | ||
errors.fail(`Unable to find device ${options.device}.`); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!fs.existsSync(applicationPath)) { | ||
errors.fail("Path does not exist ", applicationPath); | ||
} | ||
} | ||
let sdkVersion = options.sdkVersion || options.sdk; | ||
if (sdkVersion) { | ||
let runtimeVersions = _.unique(_.map(this.simulator.getDevices(), (device) => device.runtimeVersion)); | ||
if (!_.contains(runtimeVersions, sdkVersion)) { | ||
errors.fail(`Unable to find sdk ${sdkVersion}. The valid runtime versions are ${runtimeVersions.join(", ")}`); | ||
if (options.device) { | ||
const hasSuchDevice = _.find(yield this.simulator.getDevices(), device => device.name === options.device || device.id === options.device); | ||
if (!hasSuchDevice) { | ||
errors.fail(`Unable to find device ${options.device}.`); | ||
} | ||
} | ||
} | ||
return this.simulator.run(applicationPath, applicationIdentifier, options); | ||
let sdkVersion = options.sdkVersion || options.sdk; | ||
if (sdkVersion) { | ||
let runtimeVersions = _.unique(_.map(yield this.simulator.getDevices(), (device) => device.runtimeVersion)); | ||
if (!_.contains(runtimeVersions, sdkVersion)) { | ||
errors.fail(`Unable to find sdk ${sdkVersion}. The valid runtime versions are ${runtimeVersions.join(", ")}`); | ||
} | ||
} | ||
return this.simulator.run(applicationPath, applicationIdentifier, options); | ||
}); | ||
} | ||
printDeviceTypes() { | ||
let devices = this.simulator.getDevices(); | ||
_.each(devices, device => console.log(`Device Identifier: ${device.fullId}. ${os.EOL}Runtime version: ${device.runtimeVersion} ${os.EOL}`)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let devices = yield this.simulator.getDevices(); | ||
_.each(devices, device => console.log(`Device Identifier: ${device.fullId}. ${os.EOL}Runtime version: ${device.runtimeVersion} ${os.EOL}`)); | ||
}); | ||
} | ||
printSDKS() { | ||
let sdks = this.simulator.getSdks(); | ||
_.each(sdks, (sdk) => { | ||
let output = ` Display Name: ${sdk.displayName} ${os.EOL} Version: ${sdk.version} ${os.EOL}`; | ||
if (sdk.rootPath) { | ||
output += ` Root path: ${sdk.rootPath} ${os.EOL}`; | ||
} | ||
console.log(output); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let sdks = yield this.simulator.getSdks(); | ||
_.each(sdks, (sdk) => { | ||
let output = ` Display Name: ${sdk.displayName} ${os.EOL} Version: ${sdk.version} ${os.EOL}`; | ||
if (sdk.rootPath) { | ||
output += ` Root path: ${sdk.rootPath} ${os.EOL}`; | ||
} | ||
console.log(output); | ||
}); | ||
}); | ||
@@ -45,0 +59,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const childProcess = require("./child-process"); | ||
@@ -8,99 +16,105 @@ const child_process = require("child_process"); | ||
launch(deviceId, appIdentifier, options) { | ||
options = options || {}; | ||
let args = []; | ||
if (options.waitForDebugger) { | ||
args.push("-w"); | ||
} | ||
args = args.concat([deviceId, appIdentifier]); | ||
if (options.args) { | ||
let applicationArgs = options.args.trim().split(/\s+/); | ||
_.each(applicationArgs, (arg) => args.push(arg)); | ||
} | ||
let result = this.simctlExec("launch", args); | ||
if (options.waitForDebugger) { | ||
console.log(`${appIdentifier}: ${result}`); | ||
} | ||
return result; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
options = options || {}; | ||
let args = []; | ||
if (options.waitForDebugger) { | ||
args.push("-w"); | ||
} | ||
args = args.concat([deviceId, appIdentifier]); | ||
if (options.args) { | ||
let applicationArgs = options.args.trim().split(/\s+/); | ||
_.each(applicationArgs, (arg) => args.push(arg)); | ||
} | ||
let result = yield this.spawnAsync("launch", args); | ||
if (options.waitForDebugger) { | ||
console.log(`${appIdentifier}: ${result}`); | ||
} | ||
return result; | ||
}); | ||
} | ||
boot(deviceId) { | ||
return this.simctlExec("boot", [deviceId]); | ||
return this.spawnAsync("boot", [deviceId]); | ||
} | ||
terminate(deviceId, appIdentifier) { | ||
return this.simctlExec("terminate", [deviceId, appIdentifier]); | ||
return this.spawnAsync("terminate", [deviceId, appIdentifier]); | ||
} | ||
install(deviceId, applicationPath) { | ||
this.simctlExec("install", [deviceId, applicationPath]); | ||
return this.spawnAsync("install", [deviceId, applicationPath]); | ||
} | ||
uninstall(deviceId, appIdentifier, opts) { | ||
this.simctlExec("uninstall", [deviceId, appIdentifier], opts); | ||
return this.spawnAsync("uninstall", [deviceId, appIdentifier], opts); | ||
} | ||
notifyPost(deviceId, notification) { | ||
this.simctlExec("notify_post", [deviceId, notification]); | ||
return this.spawnAsync("notify_post", [deviceId, notification]); | ||
} | ||
getAppContainer(deviceId, appIdentifier) { | ||
try { | ||
return this.simctlExec("get_app_container", [deviceId, appIdentifier]); | ||
} | ||
catch (e) { | ||
if (e.message.indexOf("No such file or directory") > -1) { | ||
return null; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield this.spawnAsync("get_app_container", [deviceId, appIdentifier]); | ||
} | ||
throw e; | ||
} | ||
catch (e) { | ||
if (e.message.indexOf("No such file or directory") > -1) { | ||
return null; | ||
} | ||
throw e; | ||
} | ||
}); | ||
} | ||
getDevices() { | ||
let rawDevices = this.simctlExec("list", ["devices"]); | ||
// expect to get a listing like | ||
// -- iOS 8.1 -- | ||
// iPhone 4s (3CA6E7DD-220E-45E5-B716-1E992B3A429C) (Shutdown) | ||
// ... | ||
// -- iOS 8.2 -- | ||
// iPhone 4s (A99FFFC3-8E19-4DCF-B585-7D9D46B4C16E) (Shutdown) | ||
// ... | ||
// so, get the `-- iOS X.X --` line to find the sdk (X.X) | ||
// and the rest of the listing in order to later find the devices | ||
let deviceSectionRegex = /-- (iOS) (.+) --(\n .+)*/mg; | ||
let match = deviceSectionRegex.exec(rawDevices); | ||
let matches = []; | ||
// make an entry for each sdk version | ||
while (match !== null) { | ||
matches.push(match); | ||
match = deviceSectionRegex.exec(rawDevices); | ||
} | ||
if (matches.length < 1) { | ||
errors.fail('Could not find device section. ' + match); | ||
} | ||
// get all the devices for each sdk | ||
let devices = []; | ||
for (match of matches) { | ||
let sdk = match[2]; | ||
// split the full match into lines and remove the first | ||
for (let line of match[0].split('\n').slice(1)) { | ||
// a line is something like | ||
// iPhone 4s (A99FFFC3-8E19-4DCF-B585-7D9D46B4C16E) (Shutdown) | ||
// iPad Air 2 (9696A8ED-3020-49FC-90D6-DAFD29A0EA8D) (Shutdown) | ||
// iPad Pro (9.7 inch) (7FF984D4-0755-432D-BE0E-6EB44F0489CB) (Shutdown) | ||
// iPad Pro (12.9 inch) (F02012C8-6D4D-46FF-90D7-5DF90EF579E8) (Booted) | ||
// retrieve: | ||
// iPhone 4s | ||
// A99FFFC3-8E19-4DCF-B585-7D9D46B4C16E | ||
// Shutdown | ||
let lineRegex = /^\s+(.*?)\s+\(([0-9A-F]{8}(?:-[0-9A-F]{4}){3}-[0-9A-F]{12})\)\s+\((.*?)\)(\s+\((?:.*?)\))?/; | ||
let lineMatch = lineRegex.exec(line); | ||
if (lineMatch === null) { | ||
errors.fail('Could not match line. ' + line); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let rawDevices = yield this.spawnAsync("list", ["devices"]); | ||
// expect to get a listing like | ||
// -- iOS 8.1 -- | ||
// iPhone 4s (3CA6E7DD-220E-45E5-B716-1E992B3A429C) (Shutdown) | ||
// ... | ||
// -- iOS 8.2 -- | ||
// iPhone 4s (A99FFFC3-8E19-4DCF-B585-7D9D46B4C16E) (Shutdown) | ||
// ... | ||
// so, get the `-- iOS X.X --` line to find the sdk (X.X) | ||
// and the rest of the listing in order to later find the devices | ||
let deviceSectionRegex = /-- (iOS) (.+) --(\n .+)*/mg; | ||
let match = deviceSectionRegex.exec(rawDevices); | ||
let matches = []; | ||
// make an entry for each sdk version | ||
while (match !== null) { | ||
matches.push(match); | ||
match = deviceSectionRegex.exec(rawDevices); | ||
} | ||
if (matches.length < 1) { | ||
errors.fail('Could not find device section. ' + match); | ||
} | ||
// get all the devices for each sdk | ||
let devices = []; | ||
for (match of matches) { | ||
let sdk = match[2]; | ||
// split the full match into lines and remove the first | ||
for (let line of match[0].split('\n').slice(1)) { | ||
// a line is something like | ||
// iPhone 4s (A99FFFC3-8E19-4DCF-B585-7D9D46B4C16E) (Shutdown) | ||
// iPad Air 2 (9696A8ED-3020-49FC-90D6-DAFD29A0EA8D) (Shutdown) | ||
// iPad Pro (9.7 inch) (7FF984D4-0755-432D-BE0E-6EB44F0489CB) (Shutdown) | ||
// iPad Pro (12.9 inch) (F02012C8-6D4D-46FF-90D7-5DF90EF579E8) (Booted) | ||
// retrieve: | ||
// iPhone 4s | ||
// A99FFFC3-8E19-4DCF-B585-7D9D46B4C16E | ||
// Shutdown | ||
let lineRegex = /^\s+(.*?)\s+\(([0-9A-F]{8}(?:-[0-9A-F]{4}){3}-[0-9A-F]{12})\)\s+\((.*?)\)(\s+\((?:.*?)\))?/; | ||
let lineMatch = lineRegex.exec(line); | ||
if (lineMatch === null) { | ||
errors.fail('Could not match line. ' + line); | ||
} | ||
let available = lineMatch[4]; | ||
if (available === null || available === undefined) { | ||
devices.push({ | ||
name: lineMatch[1], | ||
id: lineMatch[2], | ||
fullId: "com.apple.CoreSimulator.SimDeviceType." + lineMatch[1], | ||
runtimeVersion: sdk, | ||
state: lineMatch[3] | ||
}); | ||
} | ||
} | ||
let available = lineMatch[4]; | ||
if (available === null || available === undefined) { | ||
devices.push({ | ||
name: lineMatch[1], | ||
id: lineMatch[2], | ||
fullId: "com.apple.CoreSimulator.SimDeviceType." + lineMatch[1], | ||
runtimeVersion: sdk, | ||
state: lineMatch[3] | ||
}); | ||
} | ||
} | ||
} | ||
return devices; | ||
return devices; | ||
}); | ||
} | ||
@@ -134,4 +148,7 @@ getLog(deviceId, predicate) { | ||
} | ||
spawnAsync(command, args, opts) { | ||
return childProcess.spawn("xcrun", ["simctl", command].concat(args), opts); | ||
} | ||
} | ||
exports.Simctl = Simctl; | ||
//# sourceMappingURL=simctl.js.map |
{ | ||
"name": "ios-sim-portable", | ||
"version": "3.4.5", | ||
"version": "4.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/ios-sim.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55801
947