1
1
import { Command } from "@commander-js/extra-typings" ;
2
2
import { Logger } from "npmlog" ;
3
+ import { loadProjectManifestUsing } from "../app/get-dependencies" ;
4
+ import { partialApply } from "../domain/fp-utils" ;
3
5
import type { DebugLog } from "../domain/logging" ;
6
+ import { makePackageSpec } from "../domain/package-spec" ;
7
+ import { recordEntries } from "../domain/record-utils" ;
4
8
import type { ReadTextFile } from "../io/fs" ;
5
9
import { withErrorLogger } from "./error-logging" ;
10
+ import { workDirOpt } from "./opt-wd" ;
6
11
7
12
/**
8
13
* Makes the `openupm ls` cli command with the given dependencies.
@@ -16,12 +21,30 @@ export function makeLsCmd(
16
21
debugLog : DebugLog ,
17
22
log : Logger
18
23
) {
24
+ const getDependencies = partialApply (
25
+ loadProjectManifestUsing ,
26
+ readTextFile ,
27
+ debugLog
28
+ ) ;
29
+
19
30
return new Command ( "ls" )
20
31
. aliases ( [ "list" ] )
21
32
. summary ( "list all currently installed packages" )
22
33
. description (
23
34
`Print the names and versions of all installed packages.
24
35
openupm ls`
25
36
)
26
- . action ( withErrorLogger ( log , async function ( options ) { } ) ) ;
37
+ . addOption ( workDirOpt )
38
+ . action (
39
+ withErrorLogger ( log , async function ( options ) {
40
+ const projectDirectory = options . chdir ;
41
+ const manifest = await getDependencies ( projectDirectory ) ;
42
+
43
+ const dependencies = recordEntries ( manifest . dependencies ?? { } ) ;
44
+
45
+ dependencies . forEach ( ( [ name , version ] ) => {
46
+ log . notice ( "" , makePackageSpec ( name , version ) ) ;
47
+ } ) ;
48
+ } )
49
+ ) ;
27
50
}
0 commit comments