craftcms / generator
Craft CMS component generator
Installs: 236 056
Dependents: 27
Suggesters: 0
Security: 0
Stars: 84
Watchers: 9
Forks: 8
Open Issues: 0
Type:yii2-extension
Requires
- php: ^8.2
- craftcms/cms: ^5.0.0-beta.1
- nette/php-generator: ^4.0
- nikic/php-parser: ^4.15
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- pestphp/pest: ^1.22
README
Craft Generator
Scaffold new Craft CMS plugins, modules, and system components from the CLI.
Installation
To install, run the following command within a Craft project:
composer require craftcms/generator --dev
Note If you get the following prompt, make sure to answer
y
:yiisoft/yii2-composer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins Do you trust "yiisoft/yii2-composer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json)
Usage
Run the following command to output the usage instructions:
php craft make
Plugin and module generation
You can create new plugins and modules using the following commands:
php craft make plugin php craft make module
System component generation
You can create new system components using the following commands:
php craft make asset-bundle
php craft make behavior
php craft make command
php craft make controller
php craft make element-action
php craft make element-condition-rule
php craft make element-exporter
php craft make element-type
php craft make field-type
php craft make filesystem-type
php craft make generator
php craft make gql-directive
php craft make model
php craft make module
php craft make plugin
php craft make queue-job
php craft make record
php craft make service
php craft make twig-extension
php craft make utility
php craft make validator
php craft make widget-type
All component generation commands require one of the following options to be passed, which identify where the component is going to live:
--app
--module=<module-id>
--plugin=<plugin-handle>
For example, if you’re creating a new field type for a plugin called foo-bar
, you would run:
php craft make field-type --plugin=foo-bar
Creating custom generators
If you have a plugin that has its own component type that could benefit from a custom generator, you can quickly create one with the following command:
php craft make generator --plugin=<plugin-handle>
You’ll be presented with the following prompts:
- Generator name: Your generator’s class name (sans namespace)
- Generator namespace: The namespace your generator class should live in
- Base class for generated [type]: An existing base class which generated classes should extend
- Default namespace for generated [type]: The default namespace which the generator should suggest, relative to the plugin/module’s root namespace
Your generator will be created based on the provided class name and namespace, which extends craft\generator\BaseGenerator
.
Roadmap
The following generator types are being considered for future releases:
- Events
- Exceptions
- GraphQL arguments
- GraphQL directives
- GraphQL interfaces
- GraphQL mutations
- GraphQL queries
- GraphQL resolvers
- GraphQL types
- Migrations
- Tests