Skip to content

Commit 8428f55

Browse files
authored
Remove MISE deps (#3)
1 parent 2c2c06a commit 8428f55

File tree

6 files changed

+107
-25
lines changed

6 files changed

+107
-25
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.lua text eol=lf
2+
*.yaml text eol=lf
3+
mise-tasks text eol=lf

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,51 @@
1-
# echocat's mongod MISE plugin
1+
# echocat's mongod vfox plugin
22

3-
This provides a MISE plugin to use `mongod` and `mongos` in your project as tools.
3+
This provides a vfox plugin to use `mongod` and `mongos` inside your project as tools. It is compatible with [vfox](https://vfox.dev/) itself and [MISE](https://mise.jdx.dev).
44

55
## TOC
66

7-
1. [Usage](#usage)
7+
1. [Usage](#usage) ...with [vfox](#with-vfox) or [MISE](#with-mise)
88
2. [FAQ](#faq)
99
3. [Contributing](#contributing)
1010
4. [License](#license)
1111

1212
## Usage
1313

14+
1. [With vfox](#with-vfox)
15+
2. [With MISE](#with-mise)
16+
17+
### With vfox
18+
19+
1. Install plugin
20+
```shell
21+
vfox add --source https://github.com/echocat/vfox-mongod/archive/refs/tags/<release>.zip mongod
22+
```
23+
24+
2. Install the tool
25+
* Always latest version:
26+
```shell
27+
vfox install mongod@latest
28+
```
29+
* Specific version:
30+
```shell
31+
vfox install mongod@8.2.1
32+
```
33+
34+
3. Check if it is working
35+
```shell
36+
vfox use mongod@8.2.1
37+
mongod --version
38+
```
39+
40+
### With MISE
41+
1442
You have two options, either use it as a [vfox plugin / directly as a MISE tool](#vfox-plugin) or as an [MISE plugin](#mise-plugin).
1543

16-
### vfox Plugin
44+
#### vfox Plugin
1745

1846
1. Add a handy alias
1947
```shell
20-
mise alias set vfox:echocat/mise-plugin-mongod mongod
48+
mise alias set vfox:echocat/vfox-mongod mongod
2149
```
2250

2351
2. Install the tool into your project
@@ -35,11 +63,11 @@ You have two options, either use it as a [vfox plugin / directly as a MISE tool]
3563
mise exec -- mongod --version
3664
```
3765

38-
### MISE Plugin
66+
#### MISE Plugin
3967

4068
1. Install the plugin (ℹ️ this only needs to be done once per user - **not** per project - it will be installed inside your current user)
4169
```shell
42-
mise plugin install mongod https://github.com/echocat/mise-plugin-mongod
70+
mise plugin install mongod https://github.com/echocat/vfox-mongod
4371
```
4472

4573
2. Install the tool into your project
@@ -59,6 +87,10 @@ You have two options, either use it as a [vfox plugin / directly as a MISE tool]
5987

6088
## FAQ
6189

90+
### What is vfox?
91+
92+
See [vfox.dev](https://vfox.dev)
93+
6294
### What is MISE?
6395

6496
See [mise.jdx.dev](https://mise.jdx.dev)
@@ -69,7 +101,7 @@ It uses the [downloads.mongodb.org/full.json](https://downloads.mongodb.org/full
69101

70102
## Contributing
71103

72-
**mise-plugin-mongod** is an open source project by [echocat](https://echocat.org). So if you want to make this project even better, you can contribute to this project on [Github](https://github.com/echocat/mise-plugin-mongod) by [fork us](https://github.com/echocat/mise-plugin-mongod/fork).
104+
**vfox-mongod** is an open source project by [echocat](https://echocat.org). So if you want to make this project even better, you can contribute to this project on [Github](https://github.com/echocat/vfox-mongod) by [fork us](https://github.com/echocat/vfox-mongod/fork).
73105

74106
If you commit code to this project, you have to accept that this code will be released under the [license](#license) of this project.
75107

hooks/post_install.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
function PLUGIN:PostInstall(ctx)
22
local archiver = require("archiver")
33
local cmd = require("cmd")
4-
local file = require("file")
54
local host = require("host")
65
local versions = require("versions")
76

@@ -14,7 +13,7 @@ function PLUGIN:PostInstall(ctx)
1413
--
1514
-- ...because not all archives are extracted automatically. Especially not: .tgz :-(
1615

17-
local origArchiveFn = file.join_path(path, version.url:match("([^/\\]+)$"))
16+
local origArchiveFn = host.path_join(path, version.url:match("([^/\\]+)$"))
1817
local archiveFn = origArchiveFn:gsub("%.tgz$", ".tar.gz")
1918

2019
-- This will only work, if both file names are different.
@@ -43,8 +42,8 @@ find '%s' -mindepth 1 -maxdepth 1 -type d -empty -delete 2>/dev/null
4342
-- END: Ugly workaround
4443
-- --------------------------------------------------------------------------------------------------
4544

46-
local exe = file.join_path(path, "bin", host.with_exec_ext("mongod"))
47-
local success, err = pcall(cmd.exec, exe .. " -version")
45+
local exe = host.path_join(path, "bin", host.with_exec_ext("mongod"))
46+
local success, err = pcall(host.exec, exe .. " -version")
4847
if not success then
4948
error(string.format("%s installation appears to be broken: got error while testing %s: %s", PLUGIN.name, exe, tostring(err)))
5049
end

lib/host.lua

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local file = require("file")
2-
31
local host = {}
42

53
function id_match(what, id, id_like)
@@ -9,6 +7,31 @@ function id_match(what, id, id_like)
97
return id_like:match("(^" .. what .. "%s)|(%s" .. what .. "%s)|(%s" .. what .. "$)|(^" .. what .. "$)")
108
end
119

10+
function host.path_join(...)
11+
local sep = package.config:sub(1, 1) -- unter Windows: "\", sonst "/"
12+
local parts = { ... }
13+
local path = table.concat(parts, sep)
14+
15+
path = path:gsub(sep .. "+", sep)
16+
17+
if sep == "\\" then
18+
path = path:gsub("/", "\\")
19+
end
20+
21+
return path
22+
end
23+
24+
function host.read_file(path)
25+
local f, err = io.open(path, "r")
26+
if not f then
27+
return nil, string.format("Cannot open %q: %s", path, tostring(err))
28+
end
29+
30+
local content = f:read("*a")
31+
f:close()
32+
return content
33+
end
34+
1235
function host.exec_ext()
1336
if RUNTIME.osType:lower() == "windows" then
1437
return ".exe"
@@ -82,9 +105,9 @@ function host.mise_data_dir()
82105
if RUNTIME.osType:lower() == "windows" then
83106
local lad = os.getenv("LOCALAPPDATA")
84107
if not lad then
85-
lad = file.join_path(os.getenv("USERPROFILE"), "AppData", "Local")
108+
lad = host.path_join(os.getenv("USERPROFILE"), "AppData", "Local")
86109
end
87-
return host.mkdirs(file.join_path(lad, "mise"))
110+
return host.mkdirs(host.path_join(lad, "mise"))
88111
end
89112

90113
local share = os.getenv("XDG_DATA_HOME")
@@ -93,14 +116,40 @@ function host.mise_data_dir()
93116
if not hd then
94117
hd = "~"
95118
end
96-
share = file.join_path(hd, ".local", "share")
119+
share = host.path_join(hd, ".local", "share")
97120
end
98121

99-
return host.mkdirs(file.join_path(share, "mise"))
122+
return host.mkdirs(host.path_join(share, "mise"))
123+
end
124+
125+
function host.vfox_cache_dir()
126+
local explicit = os.getenv("VFOX_CACHE")
127+
if explicit then
128+
return host.mkdirs(explicit)
129+
end
130+
131+
local home = os.getenv("VFOX_HOME")
132+
if not home then
133+
local user_home = os.getenv("HOME")
134+
if RUNTIME.osType:lower() == "windows" then
135+
user_home = os.getenv("USERPROFILE")
136+
end
137+
if not user_home then
138+
user_home = "~"
139+
end
140+
home = host.path_join(user_home, ".version-fox")
141+
end
142+
143+
return host.path_join(home, "cache")
100144
end
101145

102146
function host.cache_dir()
103-
return host.mkdirs(file.join_path(host.mise_data_dir(), ".cached", "plugins", "mongod"))
147+
if os.getenv("MISE_PROJECT_ROOT") then
148+
-- We're executed inside MISE... use this one as base.
149+
return host.mkdirs(host.path_join(host.mise_data_dir(), ".cache", "echocat-vfox-mongod"))
150+
end
151+
152+
return host.mkdirs(host.path_join(host.vfox_cache_dir(), "echocat-vfox-mongod"))
104153
end
105154

106155
function host.os()
@@ -143,7 +192,7 @@ function host.target()
143192
end
144193

145194
if osn == "linux" then
146-
local osr = file.read("/etc/os-release")
195+
local osr = host.read_file("/etc/os-release")
147196
local id = osr:match('^ID="?(.-)"?\n') or osr:match('\nID="?(.-)"?\n')
148197
local id_like = osr:match('^ID_LIKE="?(.-)"?\n') or osr:match('\nID_LIKE="?(.-)"?\n')
149198
if not id then

lib/versions.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local http = require("http")
22
local json = require("json")
33
local host = require("host")
4-
local file = require("file")
54

65
local versions = {}
76

@@ -70,16 +69,16 @@ function cache_file_name()
7069
local target = host.target()
7170
local arch = host.arch()
7271

73-
return file.join_path(cache_dir, "versions-" .. target .. "-" .. arch .. ".json")
72+
return host.path_join(cache_dir, "versions-" .. target .. "-" .. arch .. ".json")
7473
end
7574

7675
function get_all()
7776
local now = os.time()
7877
local cache_fn = cache_file_name()
7978

8079
local cache
81-
local rfOk, cache_json = pcall(file.read, cache_fn)
82-
if rfOk then
80+
local cache_json, _ = host.read_file(cache_fn)
81+
if cache_json then
8382
local djOk, cached = pcall(json.decode, cache_json)
8483
if djOk and cached.created and (now - cached.created) < cache_ttl then
8584
cache = cached

metadata.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ PLUGIN = { -- luacheck: ignore
33
version = "1.1.0",
44
description = "A mise tool plugin for mongod",
55
author = "echocat",
6-
updateUrl = "https://github.com/echocat/mise-plugin-mongod",
6+
updateUrl = "https://github.com/echocat/vfox-mongod",
77
minRuntimeVersion = "0.3.0",
88
}

0 commit comments

Comments
 (0)