summaryrefslogtreecommitdiff
path: root/xmake/plugins/plugin/main.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-01 08:53:30 +0800
committerruki <[email protected]>2026-08-01 08:53:30 +0800
commit8d7a74306556a4c292c0345f1a9aa833116ebcec (patch)
tree49b0b3ae14157a3f24193623d6adb69e282675e9 /xmake/plugins/plugin/main.lua
parentf91724eb1d7f80e81772ad6f20b03b2a0cff8125 (diff)
improve tests
Diffstat (limited to 'xmake/plugins/plugin/main.lua')
-rw-r--r--xmake/plugins/plugin/main.lua26
1 files changed, 8 insertions, 18 deletions
diff --git a/xmake/plugins/plugin/main.lua b/xmake/plugins/plugin/main.lua
index 48bae9cde..5158352c0 100644
--- a/xmake/plugins/plugin/main.lua
+++ b/xmake/plugins/plugin/main.lua
@@ -74,17 +74,17 @@ function _install_plugins_from_repo(name, reponame)
raise("plugin(%s): not found in any repository! try ${bright}xrepo update-repo${clear} first.", name)
end
--- install a plugin from a local directory
-function _install_from_local(dir)
+-- install a single plugin from a source directory (as the given name, default to the directory name)
+function _install_from_local(dir, name)
assert(os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")), "plugin path(%s): ${bright}xmake.lua${clear} not found!", dir)
- local name = path.filename(path.absolute(dir))
+ name = name or path.filename(path.absolute(dir))
local dstdir = _get_plugindir(name)
assert(not os.isdir(dstdir), "plugin(%s) already exists!", name)
os.vcp(dir, dstdir)
- cprint("${color.success}install ${bright}%s${clear} from ${bright}%s${clear} ok!", name, dir)
+ cprint("${color.success}install ${bright}%s${clear} ok!", name)
end
--- install a plugin from a git url or github shortcut
+-- install a single plugin from a git url or github shortcut, e.g. https://github.com/xmake-io/hello-world
function _install_from_git(url)
local branch
if url:startswith("github:") then
@@ -95,9 +95,11 @@ function _install_from_git(url)
end
url = git.asgiturl(url)
end
+ local name = (path.filename(url):gsub("%.git$", ""))
local tmpdir = os.tmpfile() .. ".dir"
git.clone(url, {verbose = option.get("verbose"), branch = branch, outputdir = tmpdir})
- _copy_plugins_from_dir(tmpdir)
+ os.tryrm(path.join(tmpdir, ".git"))
+ _install_from_local(tmpdir, name)
os.tryrm(tmpdir)
end
@@ -131,18 +133,6 @@ function _install_one(name)
_install_plugins_from_repo(name)
end
--- copy every plugin found under the cloned directory into the plugins directory
-function _copy_plugins_from_dir(tmpdir)
- for _, filepath in ipairs(os.files(path.join(tmpdir, "*", "xmake.lua"))) do
- local srcdir = path.directory(filepath)
- local name = path.filename(srcdir)
- local dstdir = _get_plugindir(name)
- assert(not os.isdir(dstdir), "plugin(%s) already exists!", name)
- os.vcp(srcdir, dstdir)
- cprint(" ${color.success}-> ${bright}%s${clear}", name)
- end
-end
-
-- install plugins
function _install()
local names = assert(option.get("plugins"), "please specify the plugins to be installed!")