https://github.com/abenz1267/related
Related is a simple cli utility tool to create files or a group of files.
https://github.com/abenz1267/related
cli golang productivity tooling
Last synced: 4 months ago
JSON representation
Related is a simple cli utility tool to create files or a group of files.
- Host: GitHub
- URL: https://github.com/abenz1267/related
- Owner: abenz1267
- License: mit
- Created: 2022-04-15T14:00:03.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-01T17:35:39.000Z (about 4 years ago)
- Last Synced: 2026-02-10T06:22:24.866Z (5 months ago)
- Topics: cli, golang, productivity, tooling
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/abenz1267/related)
# Related - Create files based on individual definitions or groups
Related helps with common file-creation-based tasks. You can predefine single types as well as groups. Scripts (lua, binary, javascript [needs node]) can be executed pre/post file creation as well as pre/post groups.
## Installation
Download binary for your platform from the releases here or simply build from source.
## Usage
!! You can use either _.json or _.yaml for configuration files !!
Place a "(.)related.json" file in your project folder. You can also place `.json` files in the `.related` folder. Wherever you like. Paths should be relative to the `.related` or `config/related` folder though. Type and group names can't be ambiguous, Related will check this on start.
Splitting into multiple config files can help with organization.
Content example:
```json
{
"types": [
{
"name": "component",
"template": "typescript/NextFuncComponent.tmpl",
"path": "",
"pre": "typescript/MyCustomJS.lua",
"post": "typescript/MyCustomPostScript.lua",
"suffix": ".tsx"
},
{
"name": "cssmodule",
"path": "styles",
"suffix": ".module.css"
}
],
"groups": [
{
"name": "component",
"types": ["component", "cssmodule"],
"pre": "typescript/MyCustomGroupPreScript",
"post": "typescript/MyCustomGroupPostScript"
}
]
}
```
If no template is provided, the file will be empty.
### Type-Inheritance
You can inherit types like this:
```yaml
types:
- name: parent
suffix: .tsx
path: components
template: typescript/rfc.tmpl
- name: parent/other
path: othercomponents
```
The `path` will be relative to the `parent` type, so in this case the `path` of `parent/other` will be `components/othercomponents`.
Parents can be any type defined wherever. They don't have to be in the same file.
**Important**: properties can be set to an empty string by overwriting it with `CLEAR`, so f.e. `path: CLEAR` will set the path to `""` instead of `"components"`
### Commands
| Command | Function |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `list ` | Lists all available template/scripts, grouped by parent-folder, or groups and types. The parent is optional for listing templates/scripts. |
| ` ` | Creates the file(s) based on the type or group provided |
### Custom Files
Custom files like templates or scripts can be either placed in a `.related` folder near the config or in a `related` folder in your users config directory. Templates must be placed inside `templates` and scripts inside `scripts`. You can nest further.
Related will prioritize project-level files over config ones.
### Templates
Templates are vanilla Golang templates. Data passed to templates:
| data | read via |
| ----------------- | ----------------- |
| working directory | `{{.workingDir}}` |
| path | `{{.path}}` |
| name | `{{.name}}` |
| suffix | `{{.suffix}}` |
### Scripts
The following types are executable: lua scripts, javascript (via node), and binaries.
You can execute scripts by settings pre- and post-scripts in the type or group definition. Related will look for the script and execute it according to the lifecycle.
Passed command-line arguments:
1. current working directory
2. path
3. filename
4. suffix
### Hints
1. A failure creating a single type won't result in the whole group-creation aborting. This means if f.e. you create a single type and later want to create a group but the type has already been created, it'll simply print out an error and continue creating the rest of the types.
2. A failures trying to execute a script will result in abortion of the type at that certain lifecycle. F.e. a failure in a script running pre-creation will stop the creation process there.