Installation: get rust and cargo via rustup and run cargo install sculpt
.
Rundown: to create a scaffold directory place a sculpt.rhai
file in its root, when you run sculpt <source> <destination>
the sculpt.rhai
file will be evaluated first using the Rhai scripting engine. You use it to configure sculpt and can set variables for later use when templating files themselves. In each file you can run Rhai code when building each file by surrounding a script in {{
and }}
.
Why: creating a project directory can be tough sometimes, you could run cargo init
but that gives you a project with only a minimal amount of code. You may have specific patterns or templates ready for you copy over every new idea you get, but it's easy to forget to edit some of your CHANGEMEs every time you do. Sculpt is intended to allow you to initialize folder structures dynamically and interactively without these worries.
For example, running this through sculpt ./scaffold ./output
rhai
// scaffold/sculpt.rhai
let project_name = prompt("What is the project called? ");
rs
// scaffold/src/main.rs
fn main() {
println!("Hello, {{ project_name }}!");
}
Will first prompt the user in the terminal with "What is the project called?" and once answered generate a folder structure matching the following:
rs
// out/src/main.rs
fn main() {
println!("Hello, sculpt!");
}
Rhai's language documentation can be found at https://rhai.rs/book, furthermore the [rhai-fs], [rhai-rand], and [rhai-sci] packages are available.
Sculpt currently offers only 1 function outside the aforementioned in its scripting API: prompt
, the function takes a string and returns user input as a string, nothing fancy.
If you wish to edit the template delimiters within files to avoid conflict, you may define the delimiters
variable like so:
let delimiters = ["<%", "%>"];
Now in every file the delimiters to start and end template expressions will be <%
and %>
instead of the default of {{
and }}
.