cargo-forge 0.1.1

A powerful, interactive Rust project generator with intelligent templates and enterprise features
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# Contributing to Cargo-Forge

First off, thank you for considering contributing to Cargo-Forge! It's people like you that make Cargo-Forge such a great tool for the Rust community.

## Table of Contents

- [Code of Conduct]#code-of-conduct
- [Getting Started]#getting-started
- [How Can I Contribute?]#how-can-i-contribute
- [Development Setup]#development-setup
- [Project Structure]#project-structure
- [Making Changes]#making-changes
- [Testing]#testing
- [Documentation]#documentation
- [Submitting Changes]#submitting-changes
- [Style Guidelines]#style-guidelines
- [Template Development]#template-development
- [Release Process]#release-process

## Code of Conduct

This project and everyone participating in it is governed by the [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct). By participating, you are expected to uphold this code.

## Getting Started

1. Fork the repository on GitHub
2. Clone your fork locally
3. Create a new branch for your feature/fix
4. Make your changes
5. Run tests
6. Submit a pull request

## How Can I Contribute?

### Reporting Bugs

Before creating bug reports, please check existing issues to avoid duplicates. When creating a bug report, include:

- A clear and descriptive title
- Steps to reproduce the issue
- Expected behavior
- Actual behavior
- System information (OS, Rust version)
- Any error messages or logs

### Suggesting Enhancements

Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, include:

- A clear and descriptive title
- A detailed description of the proposed enhancement
- Any possible drawbacks
- Examples of how it would be used

### Contributing Code

#### First Time Contributors

Look for issues labeled `good first issue` or `help wanted`. These are great starting points for new contributors.

#### Pull Requests

1. Follow the [style guidelines]#style-guidelines
2. Include tests for new functionality
3. Update documentation as needed
4. Ensure all tests pass
5. Write a clear commit message

## Development Setup

### Prerequisites

- Rust 1.70.0 or later
- Git
- A code editor (VS Code, IntelliJ IDEA with Rust plugin, etc.)

### Building from Source

```bash
# Clone your fork
git clone https://github.com/marcuspat/cargo-forge
cd cargo-forge

# Build the project
cargo build

# Run the project
cargo run -- new test-project

# Run in release mode
cargo build --release
```

### Development Tools

```bash
# Install development tools
cargo install cargo-watch cargo-tarpaulin cargo-audit

# Watch for changes and rebuild
cargo watch -x build

# Run tests on file change
cargo watch -x test

# Check code coverage
cargo tarpaulin

# Security audit
cargo audit
```

## Project Structure

```
cargo-forge/
├── src/
│   ├── main.rs              # CLI entry point
│   ├── lib.rs               # Library root
│   ├── forge.rs             # Core forge logic
│   ├── generator.rs         # Project generation
│   ├── project_types.rs     # Project type definitions
│   ├── config.rs            # Configuration handling
│   ├── features/            # Optional features
│   │   ├── mod.rs
│   │   ├── ci.rs            # CI/CD integration
│   │   ├── database.rs      # Database features
│   │   └── docker.rs        # Docker support
│   └── templates/           # Template handling
│       ├── mod.rs
│       └── conditional.rs   # Conditional rendering
├── templates/               # Project templates
│   ├── api_server/
│   ├── cli_tool/
│   ├── library/
│   ├── wasm_app/
│   ├── game_engine/
│   ├── embedded/
│   └── workspace/
├── tests/                   # Test suite
│   ├── integration.rs       # Integration tests
│   ├── e2e_*.rs            # End-to-end tests
│   └── fixtures/           # Test fixtures
└── docs/                   # Additional documentation
```

## Making Changes

### Adding a New Project Type

1. Add the type to `ProjectType` enum in `src/project_types.rs`
2. Create a new template directory in `templates/`
3. Add template files (use `.tera` extension)
4. Update the `default_features()` method
5. Add tests for the new project type
6. Update documentation

Example:
```rust
// In src/project_types.rs
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub enum ProjectType {
    // ... existing types ...
    MyNewType,
}

impl ProjectType {
    pub fn default_features(&self) -> Vec<&'static str> {
        match self {
            // ... existing matches ...
            ProjectType::MyNewType => vec!["some-crate", "another-crate"],
        }
    }
}
```

### Adding a New Feature

1. Create a new module in `src/features/`
2. Implement the `Plugin` trait
3. Add integration logic
4. Create templates in `templates/features/`
5. Add tests
6. Update documentation

Example:
```rust
// In src/features/my_feature.rs
use crate::features::{Plugin, ProjectContext};
use std::error::Error;

pub struct MyFeaturePlugin;

impl Plugin for MyFeaturePlugin {
    fn name(&self) -> &str {
        "my-feature"
    }

    fn configure(&self, context: &mut ProjectContext) -> Result<(), Box<dyn Error>> {
        // Add dependencies
        context.add_dependency("my-crate", "1.0");
        
        // Create directories
        context.create_directory("src/my_feature");
        
        // Add template files
        context.add_template_file(
            "src/my_feature/mod.rs",
            include_str!("../../templates/features/my_feature/mod.rs.tera")
        );
        
        Ok(())
    }
}
```

### Template Syntax

Cargo-Forge uses [Tera](https://tera.netlify.app/) templates. Key features:

```rust
// Variables
{{ name }}
{{ author | default(value="Anonymous") }}

// Conditionals
{% if feature_enabled %}
use some_crate::SomeType;
{% endif %}

// Loops
{% for dep in dependencies %}
{{ dep.name }} = "{{ dep.version }}"
{% endfor %}

// Filters
{{ project_name | snake_case }}
{{ struct_name | pascal_case }}

// Comments
{# This is a comment #}
```

## Testing

### Running Tests

```bash
# Run all tests
cargo test

# Run specific test
cargo test test_name

# Run tests with output
cargo test -- --nocapture

# Run tests in parallel
cargo test -- --test-threads=4
```

### Test Categories

1. **Unit Tests**: Test individual functions and modules
2. **Integration Tests**: Test component interactions
3. **E2E Tests**: Test complete project generation
4. **Feature Tests**: Test optional features

### Writing Tests

```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_project_generation() {
        let temp_dir = tempfile::tempdir().unwrap();
        let forge = Forge::new(temp_dir.path());
        
        let result = forge.generate_project(
            "test-project",
            ProjectType::Library,
            None,
        );
        
        assert!(result.is_ok());
        assert!(temp_dir.path().join("test-project/Cargo.toml").exists());
    }
}
```

### Test Coverage

We aim for >80% test coverage. Check coverage with:

```bash
cargo tarpaulin --out Html
# Open tarpaulin-report.html in your browser
```

## Documentation

### Code Documentation

- Add doc comments to all public items
- Include examples in doc comments
- Use `cargo doc --open` to preview

```rust
/// Creates a new Forge instance
/// 
/// # Arguments
/// 
/// * `base_path` - The base directory for project generation
/// 
/// # Examples
/// 
/// ```
/// use cargo_forge::Forge;
/// 
/// let forge = Forge::new(".");
/// ```
pub fn new(base_path: &str) -> Self {
    // ...
}
```

### README Updates

Update the README.md when:
- Adding new features
- Changing CLI interface
- Adding new project types
- Modifying configuration options

## Submitting Changes

### Commit Messages

Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification:

```
feat: add new project type for GraphQL APIs
fix: correct template rendering for Windows paths
docs: update README with new CLI options
test: add E2E tests for workspace generation
refactor: simplify feature plugin system
```

### Pull Request Process

1. Update documentation
2. Add tests for new functionality
3. Ensure all tests pass
4. Update CHANGELOG.md
5. Request review from maintainers

### PR Title Format

```
[Type] Brief description

Examples:
[Feature] Add GraphQL API project type
[Fix] Handle spaces in project names correctly
[Docs] Add troubleshooting guide
```

## Style Guidelines

### Rust Code Style

We use the standard Rust style guide with some additions:

```rust
// Use explicit imports for clarity
use std::path::PathBuf;
use std::fs;

// Prefer const over static for constants
const DEFAULT_PORT: u16 = 3000;

// Use descriptive variable names
let project_config = load_config()?;

// Group related functionality
mod database {
    pub mod connection;
    pub mod migrations;
}

// Error handling - use anyhow for applications
use anyhow::{Result, Context};

fn do_something() -> Result<()> {
    std::fs::read_to_string("file.txt")
        .context("Failed to read configuration file")?;
    Ok(())
}
```

### Formatting

Always run `cargo fmt` before committing:

```bash
# Format all files
cargo fmt

# Check formatting without changes
cargo fmt -- --check
```

### Linting

Use Clippy for additional checks:

```bash
# Run clippy
cargo clippy

# Run clippy with all features
cargo clippy --all-features

# Run clippy and fail on warnings
cargo clippy -- -D warnings
```

## Template Development

### Best Practices

1. **Use meaningful variable names**: `{{ project_name }}` not `{{ name }}`
2. **Provide sensible defaults**: `{{ port | default(value=3000) }}`
3. **Add helpful comments**: Explain complex template logic
4. **Consider cross-platform**: Use path separators correctly
5. **Validate inputs**: Check for edge cases

### Template Testing

Create test fixtures for templates:

```rust
#[test]
fn test_template_rendering() {
    let mut context = Context::new();
    context.insert("name", "test-project");
    context.insert("author", "Test Author");
    
    let template = include_str!("../templates/library/Cargo.toml.tera");
    let rendered = Tera::one_off(template, &context, false).unwrap();
    
    assert!(rendered.contains("name = \"test-project\""));
    assert!(rendered.contains("authors = [\"Test Author\"]"));
}
```

## Release Process

### Version Numbering

We follow [Semantic Versioning](https://semver.org/):

- MAJOR: Incompatible API changes
- MINOR: New functionality (backwards compatible)
- PATCH: Bug fixes (backwards compatible)

### Release Checklist

1. [ ] Update version in `Cargo.toml`
2. [ ] Update CHANGELOG.md
3. [ ] Run full test suite
4. [ ] Build release binaries
5. [ ] Create GitHub release
6. [ ] Publish to crates.io

```bash
# Prepare release
cargo release --dry-run

# Create release
cargo release patch # or minor, major
```

## Getting Help

- **Discord**: Join our Discord server (coming soon)
- **Discussions**: Use GitHub Discussions for questions
- **Issues**: Report bugs via GitHub Issues

## Recognition

Contributors are recognized in:
- CHANGELOG.md (for each release)
- GitHub contributors page
- Annual contributor spotlight blog posts

Thank you for contributing to Cargo-Forge!