-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
60 lines (50 loc) · 1.49 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
/* eslint-disable camelcase */
'use strict';
const fs = require('fs');
const path = require('path');
const execa = require('execa');
const findUp = require('find-up');
const plist = require('plist');
const tempy = require('tempy');
const Conf = require('conf');
const CacheConf = require('cache-conf');
const env = require('./lib/env');
const {AlfyTestError} = require('./lib/error');
const mainFile = require('./lib/main-file');
const fsP = fs.promises;
module.exports = options => {
options = {
...options,
workflow_data: tempy.directory(),
workflow_cache: tempy.directory()
};
if (options.userConfig) {
fs.writeFileSync(path.join(options.workflow_data, 'user-config.json'), JSON.stringify(options.userConfig), 'utf8');
}
const alfyTest = async (...input) => {
const filePath = await findUp('info.plist');
const directory = path.dirname(filePath);
const info = plist.parse(await fsP.readFile(filePath, 'utf8'));
// Detect executable file
let file = path.join(directory, mainFile(info));
file = path.relative(process.cwd(), file);
const {stdout} = await execa('run-node', [file, ...input], {
env: env(info, options),
preferLocal: true,
localDir: __dirname
});
try {
return JSON.parse(stdout).items;
} catch (_) {
throw new AlfyTestError('Could not parse result as JSON', stdout);
}
};
alfyTest.config = new Conf({
cwd: options.workflow_data
});
alfyTest.cache = new CacheConf({
configName: 'cache',
cwd: options.workflow_cache
});
return alfyTest;
};