# sketch:generate

The primary command in Sketch package is `sketch:generate`. This command processes your YAML file and generates all the necessary files for your Laravel application.

### Basic Usage

```bash
php artisan sketch:generate --file=path/to/your/schema.yaml
```

### Command Option

| Option               | Mandatory | Description                                 |
| -------------------- | --------- | ------------------------------------------- |
| --file               | required  | Path to your YAML schema file               |
| --option             | nullable  | Override existing files                     |
| --service-repository | nullable  | Generate both service and repository layers |
| --service-only       | nullable  | Generate service layer only                 |
| --repository-only    | nullable  | Generate repository layer only              |

### Examples

Basic Generation

```bash
php artisan sketch:generate --file=post.yaml
```

Using Relative Path

```bash
php artisan sketch:generate --file=database/schemas/post.yaml
```

Using Absolute Path

```bash
php artisan sketch:generate --file=/var/www/html/your-project/schemas/post.yaml
```

## Using Force Flag

The `--force` flag allows you to override existing files. This is useful when you want to regenerate files after making changes to your YAML schema.

### Without Force Flag

When you run the command without `--force`, the command will:

* Skip generating files that already exist
* Show warning messages for skipped files

```bash
php artisan sketch:generate --file=post.yaml
```

Output

```bash
Warning: Model file already exists: app/Models/Post.php
Warning: Migration file already exists: database/migrations/xxx_create_posts_table.php
Warning: Action file already exists: app/Actions/Post/PostAction.php
```

### With Force Flag

Using the `--force` flag will:

* Override any existing files
* Generate fresh copies of all files

```bash
php artisan sketch:generate --file=post.yaml --force
```

Output

```bash
Model generated: app/Models/Post.php
Migration generated: database/migrations/xxx_create_posts_table.php
Actions generated: app/Actions/Post/PostAction.php
```

### Best Practice for Using Force Flag

* **Version Control**: Always commit your changes before using `--force`
* **Development Environment**: Only use `--force` in development environment
* **Backup**: Consider backing up existing files before using `--force`
* **Review Changes**: After using `--force`, review the generated files to ensure everything is as expected

### Common Scenarios for Using Force Flag

Schema Updates

```bash
# After updating post.yaml with new fields
php artisan sketch:generate --file=post.yaml --force
```

Multiple Generations

```bash
# Generate multiple schemas with force
php artisan sketch:generate --file=post.yaml --force
php artisan sketch:generate --file=user.yaml --force
```

Development Iterations

```bash
# During development and testing
php artisan sketch:generate --file=test.yaml --force
```
