Skip to content

ADD: Theme and module scaffolding templates - #49

Merged
GrimLink merged 1 commit into
mainfrom
feature/scaffold-templates
Aug 3, 2026
Merged

ADD: Theme and module scaffolding templates#49
GrimLink merged 1 commit into
mainfrom
feature/scaffold-templates

Conversation

@GrimLink

@GrimLink GrimLink commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Follow up on #48. mage new theme and mage new module now scaffold a complete package from the templates folder, instead of echoing a handful of strings built in the script.

Templates

templates/theme/         registration.php  theme.xml  composer.json
                         README.md  CHANGELOG.md  SECURITY.md  .editorconfig  .gitignore

templates/module/        registration.php  etc/module.xml  composer.json
                         README.md  CHANGELOG.md  SECURITY.md  .editorconfig  .gitignore

templates/module-hyva/   Observer/RegisterModuleForHyvaConfig.php
                         etc/frontend/events.xml
                         view/frontend/tailwind/module.css
                         view/frontend/tailwind/tailwind.config.js

The module template follows hyva-module-template and keeps its placeholder names, so files can move between the two projects with only a <VENDOR> to {{VENDOR}} swap.

mage new module asks whether this is a Hyvä module, defaulting to what the project has installed. When it is, module-hyva is copied on top of the base template and the module sequences Hyva_Theme instead of Magento_Theme. Keeping the Hyvä parts in a separate folder means the base template stays usable for a plain Magento module, and no file exists twice.

Two deliberate deviations from the source repo: setup_version is dropped from module.xml, deprecated since 2.3 in favour of declarative schema, and the .gitignore uses node_modules/ rather than /node_modules, since a Hyvä module keeps its tailwind under view/frontend/tailwind.

Fetching

Per file downloads would need a hardcoded file list in the script, which defeats the point of templates as files. mage_sync_templates now pulls the repo tarball once and swaps the whole templates folder into ~/.config/mage/templates, refreshed after 30 days. A failed sync leaves the previous folder in place, so it still works offline. mage_cached_file is replaced by mage_templates_dir, mage_template_file and mage_copy_template, and the gitignore from #48 now reads through the same path.

Shared prompts

Both generators asked for a vendor and name in the same way, so that moved to mage_ask_new_package. The three hand rolled yes/no questions moved to mage_confirm, which renders [y/N] or [Y/n] from the default it is given.

That also fixes a real bug. mage_new_in_folder runs inside a command substitution, so the blank line it printed for spacing was captured into the folder name. It went unnoticed because every use was unquoted and word splitting dropped the empty field, but the quoted paths in this PR would have created a directory whose name starts with a newline. mage_confirm writes its spacing to stderr.

Verified

Both generators run end to end against a temporary project. php -l on the generated PHP, xmllint on the XML, and a JSON parse of both composer.json files.

Not included

mage is not rebuilt, following the convention that the built artifact is regenerated on Release commits. The sync pulls from main, so template changes only reach users after merge.

The files for mage new theme and mage new module now live in the
templates folder instead of being built as strings, so files can be
added or removed without a rebuild. The module template follows the
hyva-module-template, with a Hyva overlay copied on top when the
module is a Hyva module.

The templates folder is synced in one download, which replaces the
per file cache, and the shared prompts of both generators moved to
mage_ask_new_package and mage_confirm.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@GrimLink
GrimLink merged commit 177839d into main Aug 3, 2026
@GrimLink
GrimLink deleted the feature/scaffold-templates branch August 3, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant