Skip to content

Commit f9f2233

Browse files
authored
Merge pull request #75 from tdwesten/version-2
version-2
2 parents fbe1b9c + 6dd0d8c commit f9f2233

File tree

106 files changed

+5268
-1604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+5268
-1604
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
linting:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: "8.3"
20+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
21+
coverage: none
22+
23+
- name: Install dependencies
24+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
25+
26+
- name: Execute PHP Linting via Pint
27+
run: ./vendor/bin/pint --bail
28+
29+
test:
30+
needs: [ linting ]
31+
runs-on: ubuntu-latest
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
php: [ 8.2, 8.3, 8.4 ]
36+
laravel: [ 11.*, 12.* ]
37+
statamic: [ 5.* ]
38+
stability: [ prefer-stable ]
39+
exclude:
40+
- php: 8.2
41+
laravel: 11.*
42+
- php: 8.2
43+
laravel: 12.*
44+
45+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }} - ${{ matrix.stability }}
46+
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v4
50+
51+
- name: Setup PHP
52+
uses: shivammathur/setup-php@v2
53+
with:
54+
php-version: ${{ matrix.php }}
55+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
56+
coverage: pcov
57+
58+
- name: Install dependencies
59+
run: |
60+
composer require "laravel/framework:${{ matrix.laravel }}" "statamic/cms:${{ matrix.statamic }}" "orchestra/testbench:${{ matrix.laravel == '11.*' && '^9.0' || '^10.0' }}" --no-interaction --no-update
61+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction -W
62+
63+
- name: Execute tests
64+
run: vendor/bin/pest --coverage-clover coverage.xml
65+
66+
- name: Upload coverage reports to Codecov
67+
uses: codecov/codecov-action@v4
68+
with:
69+
file: ./coverage.xml
70+
token: ${{ secrets.CODECOV_TOKEN }}
71+
fail_ci_if_error: false

.junie/guidelines.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
### Project Guidelines
2+
3+
#### Purpose
4+
The Statamic Builder speeds up building Statamic sites by providing a fluent, PHP-based API to define sites, blueprints, fieldsets, collections, navigations, and taxonomies. This approach enhances code readability and maintainability by replacing traditional YAML configuration with PHP classes.
5+
6+
#### Build and Configuration
7+
8+
This project is a Statamic addon that integrates deeply with Statamic's core systems and provides a fluent API for
9+
building blueprints and fieldsets.
10+
11+
- **Requirements**: PHP 8.2+, Statamic 5.4+, Laravel 10/11/12.
12+
- **Installation**:
13+
```bash
14+
composer install
15+
```
16+
- **Service Provider**: `Tdwesten\StatamicBuilder\ServiceProvider` is automatically registered via Laravel's package
17+
discovery. It handles component discovery, repository binding, and command registration.
18+
- **Configuration**:
19+
Publish the configuration file to customize discovery paths and register components manually:
20+
```bash
21+
php artisan vendor:publish --tag=statamic
22+
```
23+
- **Exporting to YAML**:
24+
If you need to generate standard Statamic YAML files from your PHP definitions:
25+
```bash
26+
php artisan statamic-builder:export
27+
```
28+
29+
#### Testing
30+
The project uses [Pest](https://pestphp.com/) for testing, along with `orchestra/testbench` for Laravel/Statamic integration.
31+
32+
- **Configuring Tests**:
33+
- Tests extend `Tests\TestCase`, which boots the Statamic environment.
34+
- No additional database configuration is typically required as it uses in-memory storage for testing.
35+
- **Running Tests**:
36+
Execute the following command to run the full test suite:
37+
```bash
38+
./vendor/bin/pest
39+
```
40+
To run tests and static analysis (Rector):
41+
```bash
42+
composer test
43+
```
44+
- **Adding Tests**:
45+
- Place new tests in `tests/Unit` or `tests/Feature`.
46+
- For new field types, use the generator to create a starting test: `composer generate-field MyField`.
47+
48+
**Verified Example Test Case:**
49+
```php
50+
<?php
51+
52+
use Tdwesten\StatamicBuilder\Blueprint;
53+
use Tdwesten\StatamicBuilder\FieldTypes\Section;
54+
use Tdwesten\StatamicBuilder\FieldTypes\Tab;
55+
use Tdwesten\StatamicBuilder\FieldTypes\Text;
56+
57+
test('it can build a simple blueprint', function () {
58+
$blueprint = new class('test_handle') extends Blueprint {
59+
public function registerTabs(): array
60+
{
61+
return [
62+
Tab::make('main', [
63+
Section::make('General', [
64+
Text::make('title')->displayName('Title'),
65+
]),
66+
]),
67+
];
68+
}
69+
};
70+
71+
$array = $blueprint->toArray();
72+
73+
expect($blueprint->getHandle())->toBe('test_handle');
74+
expect($array['tabs']['main']['sections'][0]['display'])->toBe('General');
75+
});
76+
```
77+
78+
#### Development Information
79+
80+
- **Mandatory Tasks**: Always perform the following tasks when completing a task or before submitting a pull request:
81+
- **Update README**: Ensure `README.md` reflects any new features or changes.
82+
- **Format Code**: Run `vendor/bin/pint` to maintain consistent code style.
83+
- **Run Tests**: Ensure all tests pass by running `./vendor/bin/pest`.
84+
- **Code Style**: Follow PSR-12 and Laravel coding standards. `laravel/pint` is included for formatting.
85+
- **Static Analysis/Refactoring**: Rector is used for automated refactoring and code quality. Run it via:
86+
```bash
87+
./vendor/bin/rector
88+
```
89+
- **Fluent API Design**: Always use the `make()` static method for instantiating fields and chainable setters (e.g.,
90+
`->displayName()`, `->instructions()`, `->required()`) for configuration.
91+
- **Custom Field Types**: New field types should extend `Tdwesten\StatamicBuilder\FieldTypes\Field`.
92+
- **Field Generator**:
93+
```bash
94+
composer generate-field MyFieldName
95+
```
96+
This command populates `src/FieldTypes/` and `tests/Unit/` using templates in the `field-generator/` directory.
97+
98+
#### Auto Registration & Discovery
99+
100+
The addon supports auto-discovery to avoid manual registration in `config/statamic/builder.php`.
101+
102+
- **Enable**: Set `'auto_registration' => true` in the config.
103+
- **Requirements**:
104+
- **Blueprints**: Must implement `public static function handle(): string` and
105+
`public static function blueprintNamespace(): string`.
106+
- **Collections, Taxonomies, Globals, Navigations**: Must implement `public static function handle(): string`.
107+
- **Sites**: Must implement `public function handle(): string`.
108+
- **Default Paths**: Components are discovered in `app/Blueprints`, `app/Collections`, etc. These can be customized in
109+
the `auto_discovery` configuration.

0 commit comments

Comments
 (0)