Introduction
Crane is a CLI tool that allows you to create bricks that you can later add to any project.
A brick is an instruction. It can be a file that gets added, a command that executes or lines getting replaced in a target file.
Quick Examples
License brick
Instead of having to look up and copy your desired license from the web, you can create a brick out of it and then run crane add some-license.
Language specific bricks
You can create multiple bricks and combine them behind an alias.
This way, you can easily bootstrap new projects!
$ cargo new my_project && cd my_project
# ...
$ crane add rust
→ Executing 4 bricks
• mit
• serde
• rustfmt
• rustauthor
# ...
Configuration
Crane Config File
The crane config file is located by default at ~/.config/crane/config.toml, but the config directory can be changed by setting the CRANE_CONFIG_DIR env variable.
Brick Directories
You can define where crane should look for bricks. If no paths are set, crane will look for a bricks folder in the same directory as the config is placed.
brick_dirs = [
"./bricks"
]
Aliases
You can define aliases for multiple bricks.
[[alias]]
name = "rust"
bricks = [ "mit", "rustfmt", "serde" ]
Brick Config
The brick config defines what the brick should do. The file must be called brick.toml
and must be located at the root of the brick directory.
To get started, create a new directory in a defined brick directory.
Inside, create a file called brick.toml and add a name for your brick.
name = "my_brick_name"
No Config
If you have a brick directory without a brick.toml file, it will still work. By default, this will take the directory name as brick name and add the insert file action.
Shared options
# Name must always be set if a brick.toml exists
name = ""
Actions
You can define as many actions as you want. For all actions, you may specify a specific working_dir,
which is a relative path from where the action would execute to where it should actually execute.
This is useful if you want to add files from a project root that are located in subfolders.
working_dir = "./src/"
Insert File
[[actions]]
action = "insert_file"
if_file_exists = "append" # or "replace" or "pass"
# Which files should be inserted
sources = [
"file.txt"
]
If no sources are defined, it will use all files in the brick directory (except the config file).
Modify File
Allows you to modify a specific part of a file. You can do different operations, like replace, append or prepend.
[[actions]]
action = "modify_file"
# The content that will be inserted into the file.
content = "text" # or file (prefix path with file:)
# Where the modification should happen
selector = "[dependencies]" # either text or regex (prefix with re:)
# Modify can be type "append" (default), "prepend" or "replace":
# append text inside file
type = "append"
# Specify which files this action applies to
sources = [
"file.txt"
]
If no sources are defined, it will use all files in the brick directory (except the config file).
Run Script
Allows you to run a command or a script file.
[[actions]]
action = "run_command"
command = "echo 'hi'" # command or a script file (prefix with file:)
This is by far the most simple yet powerful action. If you need more complex behaviour, you can add a custom script that does what you need.