summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-11-07 23:29:56 +0800
committerruki <[email protected]>2017-11-07 14:59:40 +0800
commitc911900a035e04a301f938526c6d224fba14f46d (patch)
tree0797003b953f57221ae2b04f0cfd5721464cc21a
parentc3d0714e0524329b1223357d49d792d9cecce29f (diff)
improve to create project
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/actions/create/xmake.lua14
-rw-r--r--xmake/core/project/template.lua29
-rw-r--r--xmake/templates/c++/console/template.lua3
-rw-r--r--xmake/templates/c++/console_tbox/template.lua3
-rw-r--r--xmake/templates/c++/shared_library/template.lua3
-rw-r--r--xmake/templates/c++/shared_library_tbox/template.lua3
-rw-r--r--xmake/templates/c++/static_library/template.lua3
-rw-r--r--xmake/templates/c++/static_library_tbox/template.lua3
-rw-r--r--xmake/templates/c/console/template.lua3
-rw-r--r--xmake/templates/c/console_tbox/template.lua3
-rw-r--r--xmake/templates/c/shared_library/template.lua3
-rw-r--r--xmake/templates/c/shared_library_tbox/template.lua3
-rw-r--r--xmake/templates/c/static_library/template.lua3
-rw-r--r--xmake/templates/c/static_library_tbox/template.lua3
-rw-r--r--xmake/templates/dlang/console/template.lua3
-rw-r--r--xmake/templates/dlang/shared_library/template.lua3
-rw-r--r--xmake/templates/dlang/static_library/template.lua3
-rw-r--r--xmake/templates/go/console/template.lua3
-rw-r--r--xmake/templates/go/static_library/template.lua3
-rw-r--r--xmake/templates/objc++/console/template.lua3
-rw-r--r--xmake/templates/objc/console/template.lua3
-rw-r--r--xmake/templates/rust/console/template.lua3
-rw-r--r--xmake/templates/rust/static_library/template.lua3
-rw-r--r--xmake/templates/swift/console/template.lua3
25 files changed, 97 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d136ad288..6e4d483fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
* Improve support for IDE/editor plugins (.e.g vscode, sublime, intellij-idea)
* Add `.gitignore` file when creating new projects
+* Improve to create template project
### Bugs fixed
@@ -395,6 +396,7 @@
* 改进对IDE和编辑器插件的集成支持,例如:Visual Studio Code, Sublime Text 以及 IntelliJ IDEA
* 当生成新工程的时候,自动生成一个`.gitignore`文件,忽略一些xmake的临时文件和目录
+* 改进创建模板工程,使用模板名代替模板id作为参数
### Bugs修复
diff --git a/xmake/actions/create/xmake.lua b/xmake/actions/create/xmake.lua
index d1a9e7f84..af33b8afd 100644
--- a/xmake/actions/create/xmake.lua
+++ b/xmake/actions/create/xmake.lua
@@ -60,7 +60,7 @@ task("create")
-- get it
return description
end }
- , {'t', "template", "kv", "1", "Select the project template id of the given language."
+ , {'t', "template", "kv", "console", "Select the project template id or name of the given language."
-- show the description of all templates
, function ()
@@ -69,13 +69,17 @@ task("create")
import("core.project.template")
-- make description
+ local templates = {}
local description = {}
- for _, language in ipairs(template.languages()) do
- table.insert(description, format(" - language: %s", language))
- for i, t in ipairs(template.templates(language)) do
- table.insert(description, format(" %d. %s", i, ifelse(t.description, t.description, "The Unknown Project")))
+ for _, l in ipairs(template.languages()) do
+ for _, t in ipairs(template.templates(l)) do
+ templates[t.name] = templates[t.name] or {}
+ table.insert(templates[t.name], l)
end
end
+ for name, languages in pairs(templates) do
+ table.insert(description, " - " .. name .. ": " .. table.concat(languages, ", "))
+ end
-- get it
return description
diff --git a/xmake/core/project/template.lua b/xmake/core/project/template.lua
index a325bfe0d..139988712 100644
--- a/xmake/core/project/template.lua
+++ b/xmake/core/project/template.lua
@@ -55,7 +55,8 @@ function template._interpreter()
values =
{
-- set_xxx
- "set_description"
+ "set_name"
+ , "set_description"
, "set_projectdir"
-- add_xxx
, "add_macrofiles"
@@ -178,10 +179,6 @@ function template.create(language, templateid, targetname)
return false, "no template id!"
end
- templateid = tonumber(templateid)
- if type(templateid) ~= "number" then
- return false, "invalid template id!"
- end
-- get interpreter
local interp = template._interpreter()
@@ -214,16 +211,30 @@ function template.create(language, templateid, targetname)
-- load all templates for the given language
local templates = template.templates(language)
- -- load the template module
+ -- get the given template module
local module = nil
- if templates then module = templates[templateid] end
+ if templates then
+ local id = tonumber(templateid)
+ if type(id) == "number" then
+ module = templates[id]
+ else
+ for _, t in ipairs(templates) do
+ if t.name == templateid then
+ module = t
+ break
+ end
+ end
+ end
+ end
+
+ -- load the template module
if not module then
- return false, string.format("invalid template id: %d!", templateid)
+ return false, string.format("invalid template id: %s!", templateid)
end
-- enter the template directory
if not module._DIRECTORY or not os.cd(module._DIRECTORY) then
- return false, string.format("not found template id: %d!", templateid)
+ return false, string.format("not found template id: %s!", templateid)
end
-- check the template project
diff --git a/xmake/templates/c++/console/template.lua b/xmake/templates/c++/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/c++/console/template.lua
+++ b/xmake/templates/c++/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")
diff --git a/xmake/templates/c++/console_tbox/template.lua b/xmake/templates/c++/console_tbox/template.lua
index b7e432ca2..e205071e6 100644
--- a/xmake/templates/c++/console_tbox/template.lua
+++ b/xmake/templates/c++/console_tbox/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console_tbox")
+
-- set description
set_description("The Console Program (tbox)")
diff --git a/xmake/templates/c++/shared_library/template.lua b/xmake/templates/c++/shared_library/template.lua
index 87e2f7183..666542844 100644
--- a/xmake/templates/c++/shared_library/template.lua
+++ b/xmake/templates/c++/shared_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("shared")
+
-- set description
set_description("The Shared Library")
diff --git a/xmake/templates/c++/shared_library_tbox/template.lua b/xmake/templates/c++/shared_library_tbox/template.lua
index e42fab4ce..c092427ed 100644
--- a/xmake/templates/c++/shared_library_tbox/template.lua
+++ b/xmake/templates/c++/shared_library_tbox/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("shared_tbox")
+
-- set description
set_description("The Shared Library (tbox)")
diff --git a/xmake/templates/c++/static_library/template.lua b/xmake/templates/c++/static_library/template.lua
index fdc5ae91c..f05045e07 100644
--- a/xmake/templates/c++/static_library/template.lua
+++ b/xmake/templates/c++/static_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("static")
+
-- set description
set_description("The Static Library")
diff --git a/xmake/templates/c++/static_library_tbox/template.lua b/xmake/templates/c++/static_library_tbox/template.lua
index 63cac3706..07c3141a2 100644
--- a/xmake/templates/c++/static_library_tbox/template.lua
+++ b/xmake/templates/c++/static_library_tbox/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("static_tbox")
+
-- set description
set_description("The Static Library (tbox)")
diff --git a/xmake/templates/c/console/template.lua b/xmake/templates/c/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/c/console/template.lua
+++ b/xmake/templates/c/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")
diff --git a/xmake/templates/c/console_tbox/template.lua b/xmake/templates/c/console_tbox/template.lua
index b7e432ca2..e205071e6 100644
--- a/xmake/templates/c/console_tbox/template.lua
+++ b/xmake/templates/c/console_tbox/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console_tbox")
+
-- set description
set_description("The Console Program (tbox)")
diff --git a/xmake/templates/c/shared_library/template.lua b/xmake/templates/c/shared_library/template.lua
index 87e2f7183..666542844 100644
--- a/xmake/templates/c/shared_library/template.lua
+++ b/xmake/templates/c/shared_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("shared")
+
-- set description
set_description("The Shared Library")
diff --git a/xmake/templates/c/shared_library_tbox/template.lua b/xmake/templates/c/shared_library_tbox/template.lua
index b6eafa97a..aa48cc2fa 100644
--- a/xmake/templates/c/shared_library_tbox/template.lua
+++ b/xmake/templates/c/shared_library_tbox/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("shared_tbox")
+
-- set description
set_description("The Shared Library (tbox)")
diff --git a/xmake/templates/c/static_library/template.lua b/xmake/templates/c/static_library/template.lua
index fdc5ae91c..f05045e07 100644
--- a/xmake/templates/c/static_library/template.lua
+++ b/xmake/templates/c/static_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("static")
+
-- set description
set_description("The Static Library")
diff --git a/xmake/templates/c/static_library_tbox/template.lua b/xmake/templates/c/static_library_tbox/template.lua
index b5dc8170e..99f223e1b 100644
--- a/xmake/templates/c/static_library_tbox/template.lua
+++ b/xmake/templates/c/static_library_tbox/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("static_tbox")
+
-- set description
set_description("The Static Library (tbox)")
diff --git a/xmake/templates/dlang/console/template.lua b/xmake/templates/dlang/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/dlang/console/template.lua
+++ b/xmake/templates/dlang/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")
diff --git a/xmake/templates/dlang/shared_library/template.lua b/xmake/templates/dlang/shared_library/template.lua
index 87e2f7183..666542844 100644
--- a/xmake/templates/dlang/shared_library/template.lua
+++ b/xmake/templates/dlang/shared_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("shared")
+
-- set description
set_description("The Shared Library")
diff --git a/xmake/templates/dlang/static_library/template.lua b/xmake/templates/dlang/static_library/template.lua
index fdc5ae91c..f05045e07 100644
--- a/xmake/templates/dlang/static_library/template.lua
+++ b/xmake/templates/dlang/static_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("static")
+
-- set description
set_description("The Static Library")
diff --git a/xmake/templates/go/console/template.lua b/xmake/templates/go/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/go/console/template.lua
+++ b/xmake/templates/go/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")
diff --git a/xmake/templates/go/static_library/template.lua b/xmake/templates/go/static_library/template.lua
index fdc5ae91c..f05045e07 100644
--- a/xmake/templates/go/static_library/template.lua
+++ b/xmake/templates/go/static_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("static")
+
-- set description
set_description("The Static Library")
diff --git a/xmake/templates/objc++/console/template.lua b/xmake/templates/objc++/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/objc++/console/template.lua
+++ b/xmake/templates/objc++/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")
diff --git a/xmake/templates/objc/console/template.lua b/xmake/templates/objc/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/objc/console/template.lua
+++ b/xmake/templates/objc/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")
diff --git a/xmake/templates/rust/console/template.lua b/xmake/templates/rust/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/rust/console/template.lua
+++ b/xmake/templates/rust/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")
diff --git a/xmake/templates/rust/static_library/template.lua b/xmake/templates/rust/static_library/template.lua
index fdc5ae91c..f05045e07 100644
--- a/xmake/templates/rust/static_library/template.lua
+++ b/xmake/templates/rust/static_library/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("static")
+
-- set description
set_description("The Static Library")
diff --git a/xmake/templates/swift/console/template.lua b/xmake/templates/swift/console/template.lua
index 09412f86d..52c362723 100644
--- a/xmake/templates/swift/console/template.lua
+++ b/xmake/templates/swift/console/template.lua
@@ -1,3 +1,6 @@
+-- set name
+set_name("console")
+
-- set description
set_description("The Console Program")