Skip to content

Commit ddda5eb

Browse files
committed
✨ feat(tools/plugins/smart-create): update smart-create
1 parent a71a7b7 commit ddda5eb

4 files changed

Lines changed: 8 additions & 20 deletions

File tree

tools/plugins/smart-create/main.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import("core.base.option")
2424
import("core.project.project")
2525

26-
function create_project(template, targetname)
26+
function create_project(template, targetname, package)
2727
if not table.contains(os.dirs(path.join(os.scriptdir(), "templates", "*")),
2828
path.join(os.scriptdir(), "templates", template)) then
2929
raise("unsupport template => %s", template)
@@ -68,6 +68,7 @@ function create_project(template, targetname)
6868
local builtinvars = {}
6969
builtinvars.FAQ = io.readfile(path.join(os.scriptdir(), "faq.lua"))
7070
builtinvars.TARGETNAME = targetname
71+
builtinvars.PACKAGE = package
7172

7273
for _, configfile in ipairs(filedirs) do
7374
local pattern = "%${(.-)}"
@@ -94,7 +95,7 @@ function main()
9495
local olddir = os.cd(os.workingdir())
9596
local targetname = option.get("target") or "demo"
9697
cprint("${bright}create %s ...", targetname) -- trace
97-
create_project(option.get("template"), targetname)
98+
create_project(option.get("template"), targetname, option.get("package"))
9899
cprint("${color.success}create ok!") -- trace
99100
os.cd(olddir)
100101
end
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
#include <stdio.h>
2-
#include <string.h>
3-
#include <zlib.h>
42

53
int main()
64
{
7-
int r = 0;
8-
9-
unsigned char str_src[] = "hello world\n";
10-
unsigned char buf[32] = {0};
11-
unsigned char str_dst[32] = {0};
12-
unsigned long src_len = sizeof(str_src);
13-
unsigned long buf_len = sizeof(buf);
14-
unsigned long dst_len = sizeof(str_dst);
15-
16-
compress(buf, &buf_len, str_src, src_len);
17-
uncompress(str_dst, &dst_len, buf, buf_len);
18-
19-
printf("%s\n", str_dst);
5+
printf("hello world\n");
206

217
return 0;
228
}

tools/plugins/smart-create/templates/lib/xmake.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
add_rules("mode.debug", "mode.release")
22

3-
add_requires("zlib")
3+
add_requires("${PACKAGE}")
44

55
target("${TARGETNAME}")
66
do
77
add_files("*.c")
8-
add_packages("zlib")
8+
add_packages("${PACKAGE}")
99
end
1010
target_end()
1111

tools/plugins/smart-create/xmake.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ do
3737
{'f', "force", "k", nil, "Force to create project in a non-empty directory."},
3838
{'t', "template", "kv", "helloworld", "Select the project template id or name of the given language.",
3939
' - helloworld: Create "hello world" project',
40-
' - lib: Create a lib project based on "zlib"',
40+
' - lib: Create a lib project based on "<package>"',
4141
' - app: Create a app project based on "busybox"'},
42+
{'p', "package", "kv", "zlib", "Force to create project in a non-empty directory."},
4243
{},
4344
{nil, "target", "v", nil, "Create the given target.",
4445
"Uses the project name as target if not exists."}

0 commit comments

Comments
 (0)