summaryrefslogtreecommitdiff
path: root/xmake/plugins/plugin/main.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-11-05 23:59:24 +0800
committerruki <[email protected]>2018-11-05 17:56:28 +0800
commit739f6bafa0015f4b8cb6cbef1ab24aa05bee6495 (patch)
tree73c884e287b36990bc2fd0353e5fa991a2a9a0e1 /xmake/plugins/plugin/main.lua
parentd3d05b0c620dbfc318d4c693bc2fb7b556d51d3c (diff)
add plugin manager
Diffstat (limited to 'xmake/plugins/plugin/main.lua')
-rw-r--r--xmake/plugins/plugin/main.lua96
1 files changed, 96 insertions, 0 deletions
diff --git a/xmake/plugins/plugin/main.lua b/xmake/plugins/plugin/main.lua
new file mode 100644
index 000000000..7b670fd63
--- /dev/null
+++ b/xmake/plugins/plugin/main.lua
@@ -0,0 +1,96 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file main.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.base.global")
+import("devel.git")
+import("net.fasturl")
+import("actions.require.impl.environment", {rootdir = os.programdir()})
+
+-- install plugins
+function _install()
+
+ -- enter environment
+ environment.enter()
+
+ -- remove previous plugins if exists
+ local plugindir = path.join(global.directory(), "plugins")
+ if os.isdir(plugindir) then
+ os.rmdir(plugindir)
+ end
+
+ -- do install
+ try
+ {
+ function ()
+
+ -- sort main urls
+ local mainurls = {"https://github.com/tboox/xmake-plugins.git", "https://gitlab.com/tboox/xmake-plugins.git", "https://gitee.com/tboox/xmake-plugins.git"}
+ fasturl.add(mainurls)
+ mainurls = fasturl.sort(mainurls)
+
+ -- add main url
+ for _, url in ipairs(mainurls) do
+ git.clone(url, {verbose = option.get("verbose"), branch = "master", outputdir = plugindir})
+ break
+ end
+
+ -- trace
+ cprint("${bright}all plugins have been installed in %s!", plugindir)
+ end,
+ catch
+ {
+ function (errors)
+ raise(errors)
+ end
+ }
+ }
+
+ -- leave environment
+ environment.leave()
+end
+
+-- clear all installed plugins
+function _clear()
+
+ -- remove all plugins
+ local plugindir = path.join(global.directory(), "plugins")
+ if os.isdir(plugindir) then
+ os.rmdir(plugindir)
+ end
+
+ -- trace
+ cprint("${bright}clear all installed plugins ok!")
+end
+
+-- main
+function main()
+ if option.get("install") then
+ _install()
+ elseif option.get("clear") then
+ _clear()
+ end
+end
+