-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·73 lines (67 loc) · 1.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
const readline = require("readline");
const path = require("path");
const fs = require("fs");
const exec = require("child_process").exec;
const chalk = require("chalk");
const log = console.log;
const ora = require("ora");
const program = require("commander");
const currentPath = process.cwd();
program
.version("0.1.0")
.option("-d, --device", "Device")
.parse(process.argv);
var selectedDevice = program.args.join(" ");
if (fs.existsSync(currentPath + "/package.json")) {
exec("xcrun simctl list devices --json", (error, stdout, stderr) => {
const simulators = JSON.parse(stdout);
if (simulators.devices) {
const devices = simulators.devices;
let list = [];
let copyList = [];
Object.keys(devices).forEach(function(key, index) {
const result = devices[key].filter(
item => item.availability === "(available)"
);
list = list.concat(result);
});
copyList = list.map((item, index) => {
return item.name;
});
list = list.map((item, index) => {
return index + ".) " + item.name;
});
log(list.join("\n"));
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
if (selectedDevice) {
const yourAnswer = copyList[selectedDevice];
run(yourAnswer);
} else {
rl.question(chalk.green("Please Select Device \n"), answer => {
const yourAnswer = copyList[answer];
run(yourAnswer);
rl.close();
});
}
}
});
} else {
chalk.red("Not a React-Native project \n");
}
function run(param) {
log(chalk.green("Selected Device => " + param));
exec(
'react-native run-ios --simulator="' + param + '"',
(error, stdout, stderr) => {
console.log(stdout);
if (stderr == null) {
const spinner = ora("Running on Simulator").start();
}
console.log("" + stderr);
}
);
}