Config Generator
Build a Lua command-line tool that turns one short, simple configuration file into the longer config files another tool needs. For example, you describe your websites in a few lines each (name, domain, port, whether to use HTTPS), and the generator writes a complete, correctly formatted nginx server block for each one. The input is itself a Lua file loaded in a safe sandbox, so it can't run dangerous code. Values are checked before anything is written, and output is built from templates. You'll learn Lua tables and functions, safely loading data files, string templates, validation with helpful errors, writing files, and installing tools with LuaRocks.
- Estimate
- ~9h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Lua · LuaRocks · nginx · busted
Project roadmap
- 01
Define the input and output
~1hWrite README.md showing an example input file, sites.lua, which returns a table of sites, each with a name, domain, port, an optional https flag and an optional list of extra paths, and the exact nginx config that should be generated for it. List every rule, such as ports being between 1 and 65535. Done when: README.md shows a complete example of input and matching output.
- 02
Load the config safely
~1.5hLoad the input file with loadfile, running it in an empty environment (a table with no access to os, io or require) so it can only define data. Catch syntax errors and show the file name and line. Check that it returns a table. Done when: a valid file loads, and a file calling os.execute fails with a clear error.
- 03
Validate every value
~1.5hWrite a validate function that checks each site: required fields are present, the name uses only letters, digits and dashes, the domain looks like a domain, the port is a whole number in range, and https is a boolean. Also check that no two sites use the same name or domain. Collect all errors and print them together, such as site 2 (blog): port must be between 1 and 65535. Done when: an input with several mistakes lists all of them at once.
- 04
Generate files from templates
~2hWrite a small template function that replaces {{name}} placeholders using string.gsub and fails when a placeholder has no value. Use it to build each site's nginx server block, with an HTTPS section only when https is true. Write one file per site into an output folder (--out, default ./out), creating it when needed. Done when: running the tool on the README example produces exactly the expected files.
- 05
Add options and package it
~1.5hAdd command-line options: the input file, --out, --dry-run (print what would be written without writing) and --help. Write a rockspec file so the tool can be installed with luarocks make and run as a command. Done when: after luarocks make, the command works from any folder.
- 06
Test it
~1.5hWrite tests with busted: valid input produces the expected output, every validation rule catches its error, duplicate names are caught, the sandbox blocks os and io, and unknown template placeholders fail. Done when: busted passes.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack