-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlibyear.ts
More file actions
70 lines (62 loc) · 1.62 KB
/
Copy pathlibyear.ts
File metadata and controls
70 lines (62 loc) · 1.62 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as child_process from 'child_process';
export { metrics } from 'libyear/src/constants';
import type { Dependencies } from 'libyear/src/types';
export { getTotals } from 'libyear/src/validate';
import * as path from 'path';
import { promisify } from 'util';
const exec = promisify(child_process.exec);
let libyearPath: string | null = null;
/**
* Used for testing to overwrite the path to point to node_modules
*/
export const setLibyearPath = (path: string) => {
libyearPath = path;
};
/**
* Dynamically get the path to the libyear module
*
* (supporting both live (built) and test environments)
*/
const getLibyearModulePath = () => {
/* istanbul ignore else */
if (libyearPath) {
return libyearPath;
} else {
/**
* When run on GitHub, the compiles libyear module is in the file
* ../libyear/index.js relative to the action module in dist/main/index.js
*/
return path.join(path.dirname(__dirname), 'libyear');
}
};
export const runLibyear = async (directory: string): Promise<Dependencies> => {
const path = getLibyearModulePath();
const result = await exec(`node "${path}" --json`, {
cwd: directory,
});
const report: Dependencies = JSON.parse(result.stdout);
return report;
};
export const getResultsTable = (report: Dependencies) =>
report.map(
({
dependency,
drift,
pulse,
releases,
major,
minor,
patch,
available,
}) => ({
dependency,
drift: drift.toFixed(2),
pulse: pulse.toFixed(2),
releases,
major,
minor,
patch,
available,
})
);
export type { Dependencies };