ios-simulator
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -8,4 +8,2 @@ 'use strict'; | ||
let logger = require('./logger'); | ||
var _ = xutil.merge({}, xutil); | ||
@@ -20,2 +18,3 @@ | ||
_.exec = function(cmd, opts) { | ||
cmd = cmd.replace('"booted"', 'booted'); | ||
return new Promise(function(resolve, reject) { | ||
@@ -34,2 +33,7 @@ childProcess.exec(cmd, _.merge({ | ||
_.execSync = function(cmd) { | ||
cmd = cmd.replace('"booted"', 'booted'); | ||
return childProcess.execSync(cmd).toString(); | ||
}; | ||
_.spawn = function() { | ||
@@ -42,2 +46,5 @@ var args = Array.prototype.slice.call(arguments); | ||
child.stdout.setEncoding('utf8'); | ||
child.stderr.setEncoding('utf8'); | ||
child.on('error', function(error) { | ||
@@ -103,4 +110,4 @@ reject(error); | ||
if (line.match(/--\s(.*)\s--/)) { | ||
var regExp = /--\s(.*)\s--/; | ||
var matches = regExp.exec(line); | ||
let regExp = /--\s(.*)\s--/; | ||
let matches = regExp.exec(line); | ||
runtime = matches[1] || ''; | ||
@@ -113,4 +120,4 @@ return; | ||
var regExp = /(.*)\(([^)]+)\)\s\(([^)]+)\)\s\(([^)]+)\)/; | ||
var matches = regExp.exec(line); | ||
let regExp = /(.*)\(([^)]+)\)\s\(([^)]+)\)\s\(([^)]+)\)/; | ||
let matches = regExp.exec(line); | ||
@@ -117,0 +124,0 @@ if (!matches) { |
@@ -7,3 +7,2 @@ 'use strict'; | ||
const _ = require('./helper'); | ||
const logger = require('./logger'); | ||
@@ -102,2 +101,7 @@ function Simulator(options) { | ||
Simulator.prototype.remove = function() { | ||
var cmd = `xcrun simctl delete "${this.deviceId}"`; | ||
return _.execSync(cmd); | ||
}; | ||
Simulator.prototype.openURL = function() { | ||
@@ -111,3 +115,7 @@ var args = Array.prototype.slice.call(arguments); | ||
Simulator.prototype.spawn = function(args, opt) { | ||
return _.childProcess.spawn('xcrun', ['simctl', 'spawn', this.deviceId].concat(args), opt); | ||
return _.childProcess.spawn('xcrun', [ | ||
'simctl', | ||
'spawn', | ||
this.deviceId | ||
].concat(args), opt); | ||
}; | ||
@@ -128,3 +136,2 @@ | ||
Simulator.prototype.getLogDir = function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
var home = process.env.HOME; | ||
@@ -136,3 +143,2 @@ var dir = path.resolve(home, 'Library', 'Logs', 'CoreSimulator', this.deviceId); | ||
Simulator.prototype.getAppDir = function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
var home = process.env.HOME; | ||
@@ -162,5 +168,5 @@ var dir = path.resolve(home, 'Library', 'Developer', 'CoreSimulator', 'Devices', this.deviceId, 'data', 'Containers', 'Bundle', 'Application'); | ||
var cmd = `xcrun simctl get_app_container ${this.deviceId} ${bundleId}`; | ||
return _.exec(cmd).then(_ => { | ||
return _.exec(cmd).then(() => { | ||
return true; | ||
}).catch(_ => { | ||
}).catch(() => { | ||
return false; | ||
@@ -194,2 +200,8 @@ }); | ||
Simulator.getDevicesSync = () => { | ||
var cmd = 'xcrun simctl list devices'; | ||
const stdout = _.execSync(cmd); | ||
return stdout; | ||
}; | ||
Simulator.killAll = function() { | ||
@@ -201,2 +213,49 @@ var args = Array.prototype.slice.call(arguments); | ||
Simulator.getAvaliableRuntimes = function() { | ||
var cmd = 'xcrun simctl list runtimes'; | ||
const stdout = _.execSync(cmd); | ||
if (!stdout) { | ||
return; | ||
} | ||
const reg = /^(iOS[0-9. -]+)[\s\S]+?(com\.apple\.CoreSimulator\.SimRuntime\.[a-zA-Z0-9.-]+)/i; | ||
const res = []; | ||
_.filter(stdout.split(EOL), item => { | ||
item = item.trim(); | ||
const match = item.match(reg); | ||
if (match && !/unavailable/i.test(item) && !/iOS\s8\..*/.test(match[1])) { | ||
res.push({ | ||
name: match[1].trim(), | ||
value: match[2].trim(), | ||
}); | ||
} | ||
}); | ||
return res; | ||
}; | ||
Simulator.getDeviceTypes = () => { | ||
const cmd = 'xcrun simctl list devicetypes'; | ||
return _.execSync(cmd); | ||
}; | ||
Simulator.create = (name, deviceTypeId, runTimeId) => { | ||
const cmd = `xcrun simctl create '${name}' ${deviceTypeId} ${runTimeId}`; | ||
return _.execSync(cmd).trim(); | ||
}; | ||
Simulator.launchByUDID = (udid) => { | ||
const cmd = 'open `xcode-select -p`/Applications/Simulator.app/ --args -CurrentDeviceUDID ' + udid; | ||
return _.execSync(cmd); | ||
}; | ||
const bootedSingleton = new Simulator({ | ||
deviceId: 'booted' | ||
}); | ||
module.exports = Simulator; | ||
module.exports.singleton = bootedSingleton; |
{ | ||
"name": "ios-simulator", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "iOS Simulator Node.js wrapper", | ||
@@ -21,3 +21,3 @@ "keywords": [ | ||
"commander": "^2.9.0", | ||
"detect-port": "^1.0.0", | ||
"detect-port": "^1.2.1", | ||
"plist": "~1.2.0", | ||
@@ -36,7 +36,7 @@ "xlogger": "^1.0.0", | ||
"scripts": { | ||
"test": "make test", | ||
"jshint": "make jshint" | ||
"test": "mocha", | ||
"lint": "jshint ." | ||
}, | ||
"pre-commit": [ | ||
"jshint" | ||
"lint" | ||
], | ||
@@ -43,0 +43,0 @@ "homepage": "https://github.com/macacajs/ios-simulator", |
@@ -24,3 +24,3 @@ # ios-simulator | ||
``` bash | ||
```bash | ||
$ npm i ios-simulator --save | ||
@@ -33,7 +33,7 @@ ``` | ||
``` bash | ||
```bash | ||
$ DevToolsSecurity -enable | ||
``` | ||
``` bash | ||
```bash | ||
$ npm i ios-simulator -g | ||
@@ -40,0 +40,0 @@ $ ios-simulator -n 'iPhone 6s' |
@@ -146,2 +146,3 @@ 'use strict'; | ||
sim.open().then(function(data) { | ||
console.log(data); | ||
done(); | ||
@@ -148,0 +149,0 @@ }).catch(function(err) { |
Sorry, the diff of this file is not supported yet
18378
505
11
Updateddetect-port@^1.2.1