Skip to content

Commit b74f7ee

Browse files
committed
feat: auto install vm
1 parent 68c032d commit b74f7ee

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nerdctl",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Node wrapper for nerdctl",

src/vms/lima.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,35 @@ import {
44
RunCommandFlags,
55
StopCommandFlags,
66
} from "@/types/container";
7+
import { ShellString, which } from "shelljs";
78

89
import BaseBackend from "./base";
910
import { ChildProcess } from "child_process";
1011
import { ImageResult } from "@/types/images";
1112
import { LimaListResult } from "@/types/lima";
1213
import { LoginCommandFlags } from "@/types/registry";
13-
import { ShellString } from "shelljs";
1414

1515
export default class LimaBackend extends BaseBackend {
1616
async initVM(): Promise<boolean> {
17+
if (!which("brew")) return false;
18+
if (!which(this.vm)) {
19+
const child = (await this.exec(`brew install lima`)) as ChildProcess;
20+
await new Promise((resolve, reject) => {
21+
child?.stdout?.on("data", (data) => {
22+
console.log(data);
23+
});
24+
child?.stdout?.on("close", () => {
25+
resolve(true);
26+
});
27+
child?.stderr?.on("data", (data) => {
28+
console.log(data);
29+
});
30+
child?.stderr?.on("close", () => {
31+
reject(false);
32+
});
33+
});
34+
}
35+
1736
const listChild = (await this.exec(
1837
`${this.vm} list --json`
1938
)) as ChildProcess;

0 commit comments

Comments
 (0)