-
Notifications
You must be signed in to change notification settings - Fork 2
/
loader.js
42 lines (36 loc) · 824 Bytes
/
loader.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
/**
* Created by WindomZ on 17-7-3.
*/
'use strict';
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
function loadScripts(dir) {
dir = path.resolve(dir || process.cwd());
let filePath = path.join(dir, '.ciscript.yml');
try {
fs.accessSync(filePath, fs.R_OK);
} catch (e) {
filePath = path.join(dir, '.travis.yml');
}
let doc = yaml.safeLoad(fs.readFileSync(filePath, 'utf8'));
if (doc.script) {
if (Array.isArray(doc.script)) {
return doc.script;
}
return [doc.script];
}
return [];
}
function loadSync(dir) {
return loadScripts(dir);
}
function* load(dir) {
return yield loadScripts(dir);
}
module.exports.load = dir =>
new Promise(resolve => {
load(dir).next();
resolve();
});
module.exports.loadSync = loadSync;