-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
116 lines (96 loc) · 2.63 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
const inquirer = require('inquirer');
const chalk = require('chalk');
const program = require('commander');
const getDevices = require('./getAppsByDevice');
const { version } = require('./package.json');
program
.version(version, '-v, --version', 'output the version number')
.parse(process.argv);
function activeDevicesOnlyFilter(device) {
return device.state === 3;
}
function checkRequirements(devices) {
if (devices.length === 0) {
console.log('🛑 There are no devices.');
process.exit();
}
if (devices.every(device => device.apps.length === 0)) {
console.log('🛑 There are no available apps.');
process.exit();
}
}
function prettifyRuntimeVersion(runtime) {
return runtime
.split('.')
.pop()
.split('-')
.reduce((acc, value, index) => {
if (index === 0) {
return `${value} `;
}
if (index > 1) {
return `${acc}.${value}`;
}
return acc + value;
}, '');
}
async function selectAnApp(devices) {
checkRequirements(devices);
const { application } = await inquirer.prompt([
{
type: 'list',
name: 'application',
message: 'Select the application you would like to export',
choices: devices.reduce((acc, device) => {
if (device.apps.length === 0) {
return acc;
}
return [
...acc,
...device.apps.map(app => ({
name: `${device.name} (${prettifyRuntimeVersion(
device.runtime
)}) - ${app.CFBundleDisplayName || app.CFBundleName} [${
app.CFBundleIdentifier
} - ${app.CFBundleVersion}]`,
value: {
device,
app,
},
})),
];
}, []),
},
]);
console.log(`🥧 ${chalk.bold('Full path:')} ${application.app.file}`);
console.log(
`📁 ${chalk.bold('Directory:')} ${application.app.file
.split('/')
.slice(0, -1)
.join('/')}`
);
return application;
}
async function main() {
console.log('🔍 Scanning iOS simulators...');
const devices = getDevices();
let activeDevicesOnly = false;
checkRequirements(devices);
if (devices.some(activeDevicesOnlyFilter)) {
const answer = await inquirer.prompt([
{
type: 'confirm',
name: 'activeDevicesOnly',
message: 'Would you like to filter on active devices?',
default: true,
},
]);
// eslint-disable-next-line prefer-destructuring
activeDevicesOnly = answer.activeDevicesOnly;
}
return selectAnApp(
activeDevicesOnly ? devices.filter(activeDevicesOnlyFilter) : devices
);
}
main();