Skip to content

Commit 1f8438d

Browse files
authored
feat!: move logging logic to launch method (#57)
* feat!: remove SimCtlExtensions.log & tail dependency * feat!: restructured launch method 1. Removed 'waitForDebugger' launch param. (Moved to 'options') 2. Added param 'options' for the launch options. Valid Options: - waitForDebugger (boolean) - stderr (string) - path to the log file - stdout (string) - path to the log file - arch (string)
1 parent d1c7f79 commit 1f8438d

File tree

5 files changed

+13
-48
lines changed

5 files changed

+13
-48
lines changed

lib/simctl-extensions.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ THE SOFTWARE.
2323
*/
2424

2525
const path = require('path')
26-
const fs = require('fs')
2726
const { spawnSync } = require('child_process')
28-
const { Tail } = require('tail')
2927

3028
const extensions = {
3129
start: function (deviceid) {
@@ -78,31 +76,6 @@ const extensions = {
7876
// Xcode 8 or older
7977
return spawnSync('xcrun', ['instruments', '-w', deviceid])
8078
}
81-
},
82-
83-
log: function (deviceid, filepath) {
84-
const tail = new Tail(
85-
path.join(process.env.HOME, 'Library', 'Logs', 'CoreSimulator', deviceid, 'system.log')
86-
)
87-
88-
tail.on('line', function (data) {
89-
if (filepath) {
90-
fs.appendFile(filepath, data + '\n', function (error) {
91-
if (error) {
92-
console.error('ERROR: ', error)
93-
throw error
94-
}
95-
})
96-
} else {
97-
console.log(data)
98-
}
99-
})
100-
101-
tail.on('error', function (error) {
102-
console.error('ERROR: ', error)
103-
})
104-
105-
return tail
10679
}
10780
}
10881

package-lock.json

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"url": "https://github.com/ios-control/simctl.git"
88
},
99
"main": "simctl.js",
10-
"dependencies": {
11-
"tail": "^2.2.6"
12-
},
1310
"scripts": {
1411
"test": "node --test --experimental-test-coverage",
1512
"posttest": "npm run eslint",

simctl.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,27 @@ module.exports = {
102102
return spawnSync('xcrun', ['simctl', 'uninstall', device, appIdentifier])
103103
},
104104

105-
launch: function (waitForDebugger, device, appIdentifier, argv) {
105+
launch: function (device, appIdentifier, argv = [], options = {}) {
106106
const args = ['simctl', 'launch']
107107

108-
if (waitForDebugger) {
108+
if (options.waitForDebugger) {
109109
args.push('--wait-for-debugger')
110110
}
111+
if (options.stderr) {
112+
args.push(`--stderr=${options.stderr}`)
113+
}
114+
if (options.stdout) {
115+
args.push(`--stderr=${options.stdout}`)
116+
}
117+
if (options.arch) {
118+
args.push(`--arch=${options.arch}`)
119+
}
111120

112121
args.push(device)
113122
args.push(appIdentifier)
123+
args.push(...argv)
114124

115-
return spawnSync('xcrun', args.concat(argv))
125+
return spawnSync('xcrun', args)
116126
},
117127

118128
spawn: function (waitForDebugger, arch, device, pathToExecutable, argv) {

test/simctl-extensions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ test('exports', (t) => {
3333
t.assert ||= require('node:assert')
3434

3535
t.assert.equal(typeof SimCtlExtensions.start, 'function')
36-
t.assert.equal(typeof SimCtlExtensions.log, 'function')
3736
})
3837

3938
test('start', async (ctx) => {

0 commit comments

Comments
 (0)