-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage.js
72 lines (51 loc) · 1.49 KB
/
package.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
'use strict';
const Fs = require('fs');
const { URL } = require('url');
const GithubActions = require('./github-actions');
const Engines = require('./engines');
const Loader = require('./loader');
const Travis = require('./travis');
const internals = {};
internals.what = (what) => {
if (typeof what !== 'string') {
return what;
}
try {
var url = new URL(what);
}
catch (err) {
// do nothing - attempt to use the string as a package name
}
if (url) {
return { repository: url.href };
}
if (Fs.existsSync(what)) {
return { path: what };
}
if (what.split('/').length === 2 && !what.startsWith('@')) {
return { repository: what };
}
return { packageName: what };
};
exports.detect = async (what) => {
const { path, repository, packageName } = internals.what(what);
const { loadFile, loadFolder, getCommit } = await Loader.create({ path, repository, packageName });
const packageJson = await loadFile('package.json', { json: true });
const meta = {
packageJson,
getCommit,
loadFile,
loadFolder
};
const result = {};
result.name = packageJson.name;
result.version = packageJson.version;
result.commit = await meta.getCommit();
result.timestamp = Date.now();
Object.assign(result, ...await Promise.all([
GithubActions.detect(meta),
Travis.detect(meta),
Engines.detect(meta)
]));
return { result, meta };
};