aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/cmd/init.lua38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua
index f4309945..e037fb55 100644
--- a/src/luarocks/cmd/init.lua
+++ b/src/luarocks/cmd/init.lua
@@ -26,12 +26,20 @@ init.help = [[
26]] 26]]
27 27
28local function write_gitignore() 28local function write_gitignore()
29 if fs.exists(".gitignore") then 29 local gitignore = ""
30 return 30 local fd = io.open(".gitignore", "r")
31 if fd then
32 gitignore = fd:read("*a")
33 fd:close()
34 gitignore = "\n" .. gitignore .. "\n"
35 end
36
37 fd = io.open(".gitignore", gitignore and "a" or "w")
38 for _, entry in ipairs({"/lua", "/lua_modules"}) do
39 if not gitignore:find("\n"..entry.."\n", 1, true) then
40 fd:write(entry.."\n")
41 end
31 end 42 end
32 local fd = io.open(".gitignore", "w")
33 fd:write("lua_modules\n")
34 fd:write("lua\n")
35 fd:close() 43 fd:close()
36end 44end
37 45
@@ -45,19 +53,35 @@ function init.command(flags, name, version)
45 name = dir.base_name(pwd) 53 name = dir.base_name(pwd)
46 end 54 end
47 55
48 util.printout("Initializing project " .. name) 56 util.printout("Initializing project " .. name .. " ...")
49 57
50 local ok, err = write_rockspec.command(flags, name, version or "dev", pwd) 58 local ok, err = write_rockspec.command(flags, name, version or "dev", pwd)
51 if not ok then 59 if not ok then
52 util.printerr(err) 60 util.printerr(err)
53 end 61 end
54 62
63 util.printout("Adding entries to .gitignore ...")
55 write_gitignore() 64 write_gitignore()
56 65
66 util.printout("Preparing ./.luarocks/ ...")
67 fs.make_dir(".luarocks")
68 local config_file = ".luarocks/config-" .. cfg.lua_version .. ".lua"
69 if not fs.exists(config_file) then
70 local fd = io.open(config_file, "w")
71 fd:write("-- add your configuration here\n")
72 fd:close()
73 end
74
75 util.printout("Preparing ./lua_modules/ ...")
76
57 fs.make_dir("lua_modules/lib/luarocks/rocks-" .. cfg.lua_version) 77 fs.make_dir("lua_modules/lib/luarocks/rocks-" .. cfg.lua_version)
58 local tree = dir.path(pwd, "lua_modules") 78 local tree = dir.path(pwd, "lua_modules")
59 79
60 fs.wrap_script(arg[0], "luarocks", nil, nil, "--tree", tree) 80 util.printout("Preparing ./luarocks ...")
81
82 fs.wrap_script(arg[0], "luarocks", nil, nil, "--project-tree", tree)
83
84 util.printout("Preparing ./lua ...")
61 85
62 path.use_tree(tree) 86 path.use_tree(tree)
63 fs.wrap_script(nil, "lua") 87 fs.wrap_script(nil, "lua")