Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of init command #94

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cli/commands/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ local function cli_dump(args)
return zeebo_bootstrap.dump(dist)
end

local function cli_init(args)
local project_name = args[1] or 'my_project'
init.init_project(project_name)
end

local P = {
['cli-build'] = cli_build,
['cli-test'] = cli_test,
['cli-dump'] = cli_dump
['cli-dump'] = cli_dump,
['cli-init'] = cli_init
}

return P
62 changes: 62 additions & 0 deletions src/cli/commands/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
local os = require('os')

local function create_file(filepath, content)
local file = io.open(filepath, "w")
if file then
file:write(content)
file:close()
else
print("Error while creating file: " .. filepath)
end
end

local function create_directory(path)
local success = os.execute("mkdir " .. path)
if not success then
print("Error while creating directory: " .. path)
end
end

local function init_project(project_name)
create_directory(project_name)
create_file(project_name .. "/.gitignore", ".DS_Store\nThumbs.db\n")

create_directory(project_name .. "/dist")
create_directory(project_name .. "/vendor")

create_file(project_name .. "/README.md", "# " .. project_name .. "\n\n * **use:** `./cli.sh run src/game.lua`\n")

create_directory(project_name .. "/src")

local game_lua_content = 'local function init(std, game)\n\nend\n\n'
..'local function loop(std, game)\n\nend\n\n'
..'local function draw(std, game)\n'
..' std.draw.clear(std.color.black)\n'
..' std.draw.color(std.color.white)\n'
..' std.draw.text(8, 8, "hello world")\n'
..'end\n\n'
..'local function exit(std, game)\n\nend\n\n'
..'local P = {\n'
..' meta={\n'
..' title="' .. project_name .. '",\n'
..' author="YourName",\n'
..' description="description about the game",\n'
..' version="1.0.0"\n'
..' },\n'
..' callbacks={\n'
..' init=init,\n'
..' loop=loop,\n'
..' draw=draw,\n'
..' exit=exit\n'
..' }\n'
..'}\n\n'
..'return P\n'

create_file(project_name .. "/src/game.lua", game_lua_content)

print("Project " .. project_name .. " created with success!")
end

return {
init_project = init_project
}
Loading