forked from appium/WebDriverAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
126 lines (105 loc) · 3.35 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
117
118
119
120
121
122
123
124
125
126
import { fs, logger } from 'appium-support';
import { getDevices } from 'node-simctl';
import { asyncify } from 'asyncbox';
import _ from 'lodash';
import { exec } from 'teen_process';
import path from 'path';
import { EOL } from 'os';
import { fileCompare } from './lib/utils';
const log = logger.getLogger('WebDriverAgent');
const execLogger = {
// logger that gets rid of empty lines
logNonEmptyLines (data, fn) {
data = Buffer.isBuffer(data) ? data.toString() : data;
for (const line of data.split(EOL)) {
if (line) {
fn(line);
}
}
},
debug (data) {
this.logNonEmptyLines(data, log.debug.bind(log));
},
error (data) {
this.logNonEmptyLines(data, log.error.bind(log));
},
};
const IOS = 'iOS';
const TVOS = 'tvOS';
const CARTHAGE_CMD = 'carthage';
const CARTFILE = 'Cartfile.resolved';
const CARTHAGE_ROOT = 'Carthage';
const BOOTSTRAP_PATH = __dirname.endsWith('build')
? path.resolve(__dirname, '..')
: __dirname;
const WDA_BUNDLE_ID = 'com.apple.test.WebDriverAgentRunner-Runner';
const WDA_RUNNER_BUNDLE_ID = 'com.facebook.WebDriverAgentRunner';
const PROJECT_FILE = 'project.pbxproj';
async function hasTvOSSims () {
const devices = _.flatten(Object.values(await getDevices(null, TVOS)));
return !_.isEmpty(devices);
}
function getCartfileLocations () {
const cartfile = path.resolve(BOOTSTRAP_PATH, CARTFILE);
const installedCartfile = path.resolve(BOOTSTRAP_PATH, CARTHAGE_ROOT, CARTFILE);
return {
cartfile,
installedCartfile,
};
}
async function needsUpdate (cartfile, installedCartfile) {
return !await fileCompare(cartfile, installedCartfile);
}
async function fetchDependencies (useSsl = false) {
log.info('Fetching dependencies');
if (!await fs.which(CARTHAGE_CMD)) {
log.errorAndThrow('Please make sure that you have Carthage installed (https://github.com/Carthage/Carthage)');
}
// check that the dependencies do not need to be updated
const {
cartfile,
installedCartfile,
} = getCartfileLocations();
if (!await needsUpdate(cartfile, installedCartfile)) {
// files are identical
log.info('Dependencies up-to-date');
return false;
}
let platforms = [IOS];
if (await hasTvOSSims()) {
platforms.push(TVOS);
} else {
log.debug('tvOS platform will not be included into Carthage bootstrap, because no Simulator devices have been created for it');
}
log.info(`Installing/updating dependencies for platforms ${platforms.map((p) => `'${p}'`).join(', ')}`);
let args = ['bootstrap'];
if (useSsl) {
args.push('--use-ssh');
}
args.push('--platform', platforms.join(','));
try {
await exec(CARTHAGE_CMD, args, {
logger: execLogger,
cwd: BOOTSTRAP_PATH,
});
} catch (err) {
// remove the carthage directory, or else subsequent runs will see it and
// assume the dependencies are already downloaded
await fs.rimraf(path.resolve(BOOTSTRAP_PATH, CARTHAGE_ROOT));
throw err;
}
// put the resolved cartfile into the Carthage directory
await fs.copyFile(cartfile, installedCartfile);
log.debug(`Finished fetching dependencies`);
return true;
}
async function checkForDependencies (opts = {}) {
return await fetchDependencies(opts.useSsl);
}
if (require.main === module) {
asyncify(checkForDependencies);
}
export {
checkForDependencies, BOOTSTRAP_PATH, WDA_BUNDLE_ID,
WDA_RUNNER_BUNDLE_ID, PROJECT_FILE,
};