Skip to content

vjik/scaffolder-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Scaffolder Template

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.

What is this?

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

Getting Started

Note

PHPTG Scaffolder - a real-world example of a scaffolder tool built using this template.

  1. Create a new project based on this template:
composer create-project vjik/scaffolder-template my-scaffolder
cd my-scaffolder
  1. Customize the scaffolder (see Project Structure below).

  2. Run your scaffolder:

php src/run.php

Or if you want to apply changes to a specific directory:

php src/run.php --directory=/path/to/project

Packaging as Docker Image

For easier distribution and usage, you can package your scaffolder tool as a Docker image.

1. Configure Image Name

Edit Makefile and set your image name:

IMAGE_NAME := myvendor/my-scaffolder

2. Build Docker Image

make build

Or manually:

docker build -t myvendor/my-scaffolder .

3. Publish to Registry

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:latest

4. Usage

Once published, users can run your scaffolder without installing PHP or Composer:

docker run --rm -it -v $(pwd):/project ghcr.io/username/my-scaffolder:latest

Or using the Makefile (for development):

make run

With arguments:

make run RUN_ARGS="--directory=/custom/path"

Project Structure

.
├── 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

Where to Add What

1. src/changes.php - Define What Changes to Apply

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'),
];

2. src/facts.php - Register Custom Facts

This file returns an array of custom Fact classes:

<?php

return [
    // Add your custom Fact classes here
    // MyFact::class,
];

3. src/params.php - Set Default Parameters

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.

Documentation

For detailed information about the library features:

If you have any questions or problems with this template, use author telegram chat for communication.

License

The vjik/scaffolder-template is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

About

PHP Scaffolder Tool Template

Resources

License

Stars

Watchers

Forks

Contributors