Files
create/README.md

120 lines
2.8 KiB
Markdown
Raw Normal View History

# Template-based file generator
2026-01-26 20:31:06 +03:00
CLI utility for generating files and folder structures from customizable templates.
2026-01-26 20:31:06 +03:00
## Installation
### Quick Start with npx
```bash
npx @gromlab/create <template> <name>
```
### Global Installation (Recommended)
Global installation provides the `create` command with **autocomplete** for template names.
**1. Install:**
```bash
npm i -g @gromlab/create && create install-autocomplete
```
**2. Reload your shell:**
```bash
# macOS (zsh)
source ~/.zshrc
# Linux (bash)
source ~/.bashrc
# Linux (fish)
exec fish
```
## Usage
2026-01-26 20:31:06 +03:00
```bash
create <template> <name> [path] [options]
2026-01-26 20:31:06 +03:00
```
If `[path]` is not specified, files are created in the current directory.
## Example
2026-01-26 20:31:06 +03:00
```bash
# Create a component from template
create component Button
2026-01-26 20:31:06 +03:00
# Specify output folder positionally
create component Button src/components
2026-01-26 20:31:06 +03:00
```
## Templates
Templates are stored in the `.templates/` folder at the project root. Each subfolder is a separate template.
### Creating a Template
1. Create a folder in `.templates/` with the template name
2. Add files and folders using variables in names and content
3. Variables are enclosed in double curly braces: `{{variable}}`
The number of variables is unlimited — use any names you need.
2026-01-26 20:31:06 +03:00
### Structure
2026-01-26 20:31:06 +03:00
```
.templates/
├── component/
│ └── {{name.pascalCase}}/
│ ├── index.ts
│ ├── {{name.pascalCase}}.tsx
│ └── {{name.pascalCase}}.module.css
└── zustand-store/
└── {{name.camelCase}}Store/
├── index.ts
├── {{name.camelCase}}Store.ts
└── {{name.camelCase}}Store.type.ts
2026-01-26 20:31:06 +03:00
```
### Variables
2026-01-26 20:31:06 +03:00
Variables are substituted in file/folder names and file contents. You can use any variables in templates — the CLI will prompt for values for all found variables.
2026-01-26 20:31:06 +03:00
- `name` — required variable, set by positional argument
- Custom variables are passed via flags: `--author "John Doe"`
**Case Modifiers:**
| Syntax | Result for `myButton` |
|--------|----------------------|
| `{{name}}` | myButton |
| `{{name.pascalCase}}` | MyButton |
| `{{name.camelCase}}` | myButton |
| `{{name.kebabCase}}` | my-button |
| `{{name.snakeCase}}` | my_button |
| `{{name.screamingSnakeCase}}` | MY_BUTTON |
```bash
# Template with {{name}} and {{author}} variables
create component Button --author "John Doe"
```
### Template Content Example
```tsx
// {{name.pascalCase}}.tsx
import styles from './{{name.pascalCase}}.module.css'
export const {{name.pascalCase}} = () => {
return <div className={styles.wrapper}>{{name.pascalCase}}</div>
}
```
## Options
2026-01-26 20:31:06 +03:00
| Option | Description |
|--------|-------------|
| `--overwrite` | Overwrite existing files |
| `--skip-update` | Skip CLI update check |
| `--<variable> <value>` | Custom template variable |