A template for creating your own scaffolder tool using the vjik/scaffolder library. This template provides a ready-to-use structure for building automated project file modification tools.
This is a starting point for creating custom scaffolder tools that can:
- Automate project initialization
- Generate boilerplate code
- Apply consistent file structures
- Update configuration files
- Copy template files
- Prompt users for project details
Note
PHPTG Scaffolder - a real-world example of a scaffolder tool built using this template.
- Create a new project based on this template:
composer create-project vjik/scaffolder-template my-scaffolder
cd my-scaffolder-
Customize the scaffolder (see Project Structure below).
-
Run your scaffolder:
php src/run.phpOr if you want to apply changes to a specific directory:
php src/run.php --directory=/path/to/projectFor easier distribution and usage, you can package your scaffolder tool as a Docker image.
Edit Makefile and set your image name:
IMAGE_NAME := myvendor/my-scaffoldermake buildOr manually:
docker build -t myvendor/my-scaffolder .You can publish your image to any Docker registry, for example GitHub Container Registry:
# Tag for GitHub Container Registry
docker tag myvendor/my-scaffolder ghcr.io/username/my-scaffolder:latest
# Login to GitHub Container Registry
echo $GITHUB_TOKEN | docker login ghcr.io -u username --password-stdin
# Push the image
docker push ghcr.io/username/my-scaffolder:latestOnce published, users can run your scaffolder without installing PHP or Composer:
docker run --rm -it -v $(pwd):/project ghcr.io/username/my-scaffolder:latestOr using the Makefile (for development):
make runWith arguments:
make run RUN_ARGS="--directory=/custom/path".
├── src/
│ ├── run.php # Entry point - runs the scaffolder
│ ├── changes.php # List of changes to apply
│ ├── facts.php # List of custom facts
│ ├── params.php # Default parameters
│ ├── Change/ # Custom Change classes (optional)
│ └── Fact/ # Custom Fact classes (optional)
├── files/ # Template files to copy
This file returns an array of Change instances that will be executed in order:
<?php
use Vjik\Scaffolder\Change;
return [
// Write a README file
new Change\WriteFile('README.md', 'Hello World'),
// Copy a file from templates
new Change\CopyFile(
from: __DIR__ . '/../files/LICENSE',
to: 'LICENSE',
),
// Update composer.json with package info
new Change\PrepareComposerJson(),
// Create directory with .gitkeep
new Change\EnsureDirectoryWithGitkeep('src'),
];This file returns an array of custom Fact classes:
<?php
return [
// Add your custom Fact classes here
// MyFact::class,
];This file returns an array of default parameter values:
<?php
return [
'package-vendor' => 'myvendor',
'php-constraint-suggestion' => '8.2 - 8.5',
'tests-directory' => 'tests/',
'source-directory' => 'src/',
];Users can override these in their scaffolder.php project file or via CLI options.
For detailed information about the library features:
If you have any questions or problems with this template, use author telegram chat for communication.
The vjik/scaffolder-template is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.