Skip to content

Commit 1309cb3

Browse files
committed
add list logic
1 parent ca714b5 commit 1309cb3

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/cli/cmd-ls.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { Command } from "@commander-js/extra-typings";
22
import { Logger } from "npmlog";
3+
import { loadProjectManifestUsing } from "../app/get-dependencies";
4+
import { partialApply } from "../domain/fp-utils";
35
import type { DebugLog } from "../domain/logging";
6+
import { makePackageSpec } from "../domain/package-spec";
7+
import { recordEntries } from "../domain/record-utils";
48
import type { ReadTextFile } from "../io/fs";
59
import { withErrorLogger } from "./error-logging";
10+
import { workDirOpt } from "./opt-wd";
611

712
/**
813
* Makes the `openupm ls` cli command with the given dependencies.
@@ -16,12 +21,30 @@ export function makeLsCmd(
1621
debugLog: DebugLog,
1722
log: Logger
1823
) {
24+
const getDependencies = partialApply(
25+
loadProjectManifestUsing,
26+
readTextFile,
27+
debugLog
28+
);
29+
1930
return new Command("ls")
2031
.aliases(["list"])
2132
.summary("list all currently installed packages")
2233
.description(
2334
`Print the names and versions of all installed packages.
2435
openupm ls`
2536
)
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+
);
2750
}

test/e2e/ls.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ResultCodes } from "../../src/cli/result-codes";
2+
import { buildProjectManifest } from "../common/data-project-manifest";
3+
import { runOpenupm } from "./run";
4+
import { prepareHomeDirectory } from "./setup/directories";
5+
import { prepareUnityProject } from "./setup/project";
6+
7+
describe("list installed packages", () => {
8+
test("should list installed packages", async () => {
9+
const homeDirectory = await prepareHomeDirectory();
10+
const projectDirectory = await prepareUnityProject(homeDirectory, {
11+
manifest: buildProjectManifest((manifest) =>
12+
manifest
13+
.addDependency("dev.comradevanti.opt-unity", "2.0.0", true, true)
14+
.addDependency("com.unity.ugui", "1.0.0", true, false)
15+
),
16+
});
17+
18+
const result = await runOpenupm(projectDirectory, ["ls"]);
19+
20+
expect(result.code).toEqual(ResultCodes.Ok);
21+
expect(result.stdErr).toEqual(
22+
expect.arrayContaining([
23+
expect.stringContaining("[email protected]"),
24+
expect.stringContaining("[email protected]"),
25+
])
26+
);
27+
});
28+
});

0 commit comments

Comments
 (0)