-
-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathconfig.ts
More file actions
51 lines (47 loc) · 1.57 KB
/
Copy pathconfig.ts
File metadata and controls
51 lines (47 loc) · 1.57 KB
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
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { v4 as uuid } from 'uuid';
import { Config } from './types/Config';
const basePath = path.join(os.homedir(), '.cache', 'appium-device-farm');
const deviceFarmHome = getDeviceFarmHome();
function getDeviceFarmHome() {
let deviceFarmHome = basePath;
if (process.env.DEVICE_FARM_HOME) {
deviceFarmHome = process.env.DEVICE_FARM_HOME;
}
if (!fs.existsSync(deviceFarmHome)) {
fs.mkdirSync(deviceFarmHome, { recursive: true });
}
console.info('Using Metadata Path: ', deviceFarmHome);
return deviceFarmHome;
}
export function getServerMetadata() {
const metaFile = path.join(getDeviceFarmHome(), 'metadata.json');
const defaultMetadata = {
id: uuid(),
};
if (fs.existsSync(metaFile)) {
const metadata = JSON.parse(fs.readFileSync(metaFile, 'utf-8'));
if (!metadata || !metadata.id) {
fs.writeFileSync(metaFile, JSON.stringify(Object.assign(defaultMetadata, metadata)));
return {
...defaultMetadata,
...metadata,
};
}
return metadata;
} else {
fs.writeFileSync(metaFile, JSON.stringify(defaultMetadata));
}
return defaultMetadata;
}
export const config: Config = {
cacheDir: deviceFarmHome,
databasePath: `${deviceFarmHome}/device-farm-latest.db?connection_limit=1`,
sessionAssetsPath: path.join(deviceFarmHome, 'assets', 'sessions'),
takeScreenshotsFor: ['click', 'setUrl', 'setValue', 'performActions'],
appsPath: path.join(deviceFarmHome, 'assets'),
serverMetadata: { id: '' },
goIOSTunnelInfoPort: 0,
};