-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.ts
executable file
·51 lines (37 loc) · 1.03 KB
/
command.ts
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
#!/usr/bin/env node
import type { Arguments, Diff, Lockfile } from './lib/types';
const { parseArgs } = require( "node:util" );
import { printMarkdownList, printMarkdownTable } from './lib/markdown' ;
import { diffPackages, getBaselineLockfile, getCurrentLockfile } from './lib/operations';
/**
* Run the command
*/
const run = () => {
const args: Arguments = parseArgs({
options: {
base: {
type: "string",
short: "b",
},
format: {
type: "string",
short: "f",
},
},
});
const base: string = args.values.base ?? 'HEAD';
const format: string = args.values.format ?? 'mdlist';
const baselineLockfile: Lockfile = getBaselineLockfile( base );
const currentLockfile: Lockfile = getCurrentLockfile();
const packageChanges: Diff = diffPackages( baselineLockfile, currentLockfile );
if ( format === 'json') {
console.log( JSON.stringify( packageChanges, null, 4 ) );
return;
}
if ( format === 'mdlist' ) {
printMarkdownList( packageChanges );
return;
}
printMarkdownTable( packageChanges );
}
run();