Skip to content

Commit 3635b07

Browse files
authored
feat!: replace shelljs.exec with child_process.spawnSync
Closes #43
1 parent 5cfc2b0 commit 3635b07

File tree

6 files changed

+2906
-5886
lines changed

6 files changed

+2906
-5886
lines changed

lib/simctl-extensions.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,33 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
THE SOFTWARE.
2323
*/
2424

25-
const shell = require('shelljs')
2625
const path = require('path')
2726
const fs = require('fs')
28-
const util = require('util')
29-
const Tail = require('tail').Tail
27+
const { spawnSync } = require('child_process')
28+
const { Tail } = require('tail')
3029

3130
const extensions = {
3231
start: function (deviceid) {
3332
let isAtLeastXcode9 = false
34-
35-
let command = 'xcodebuild -version'
36-
const res = shell.exec(command, { silent: true })
33+
const res = spawnSync('xcodebuild', ['-version'])
3734

3835
// parse output for Xcode version
3936
const versionMatch = /Xcode (.*)/.exec(res.stdout)
40-
if (res.code !== 0 || !versionMatch) {
37+
if (res.status !== 0 || !versionMatch) {
4138
console.error('Unable to parse xcodebuild version.')
4239
return
4340
} else {
44-
isAtLeastXcode9 = (parseInt(versionMatch[1]) >= 9)
41+
isAtLeastXcode9 = (parseInt(versionMatch[1], 10) >= 9)
4542
}
4643

4744
if (isAtLeastXcode9) {
4845
// Xcode 9 or greater
49-
command = util.format('xcrun simctl list -j')
50-
let res = shell.exec(command, { silent: true })
51-
if (res.code !== 0) {
46+
let res = spawnSync('xcrun', ['simctl', 'list', '--json'])
47+
if (res.status !== 0) {
5248
console.error('Could not get device list.')
5349
return
5450
}
51+
5552
const listOutput = JSON.parse(res.stdout)
5653
const device = Object.keys(listOutput.devices)
5754
.reduce(function (acc, key) { return acc.concat(listOutput.devices[key]) }, [])
@@ -62,26 +59,30 @@ const extensions = {
6259
console.error('Simulator already running.')
6360
return
6461
}
65-
command = util.format('xcrun simctl boot "%s"', deviceid)
66-
res = shell.exec(command, { silent: true })
6762

68-
if (res.code !== 0) {
63+
res = spawnSync('xcrun', ['simctl', 'boot', deviceid])
64+
if (res.status !== 0) {
6965
console.error(`Could not boot simulator ${deviceid}`)
7066
return
7167
}
7268

73-
command = 'open `xcode-select -p`/Applications/Simulator.app'
74-
return shell.exec(command, { silent: true })
69+
res = spawnSync('xcode-select', ['-p'])
70+
if (res.status !== 0) {
71+
console.error('Failed to get Xcode path')
72+
return
73+
}
74+
75+
const simulatorPath = path.join(res.stdout, 'Applications', 'Simulator.app')
76+
return spawnSync('open', ['-a', simulatorPath])
7577
} else {
7678
// Xcode 8 or older
77-
command = util.format('xcrun instruments -w "%s"', deviceid)
78-
return shell.exec(command, { silent: true })
79+
return spawnSync('xcrun', ['instruments', '-w', deviceid])
7980
}
8081
},
8182

8283
log: function (deviceid, filepath) {
8384
const tail = new Tail(
84-
path.join(process.env.HOME, 'Library/Logs/CoreSimulator', deviceid, 'system.log')
85+
path.join(process.env.HOME, 'Library', 'Logs', 'CoreSimulator', deviceid, 'system.log')
8586
)
8687

8788
tail.on('line', function (data) {

0 commit comments

Comments
 (0)