maker-bundle icon indicating copy to clipboard operation
maker-bundle copied to clipboard

[RFC][WIP] add scaffolding system (`make:scaffold`)

Open kbond opened this issue 3 years ago • 13 comments

This adds a make:scaffold ...<scaffold> command. This is an alternative to what I'm calling single-use makers like make:register/make:user. We could potentially deprecate these other makers.

A scaffold consists of:

  1. files that are copied to your project to create the feature (including tests that are immediately runnable and pass!)
  2. required Composer packages (these are auto-installed)
  3. required JS packages (these are auto-installed)
  4. dependent scaffolds (most current scaffolds depend on others, ie register requires auth)
  5. A little configuration system to allow more advanced file manipulations (ie update an exiting yaml file)

Some additional notes about this feature:

  • Scaffolds are grouped by Symfony major versions with 6.0 being the only supplied version currently.
  • These are meant to be run on new projects. Running them on an established project is possible but since the supplied files override existing files, you'll have to be careful and use git to help with conflicts.
  • Copying files from a scaffold is currently "dumb" and they just replace existing files without confirming. It could be possible to make this smarter.
  • Scaffolds could be grouped into "starter-kits" like what's provided with Laravel Breeze/Jetstream.
  • I don't really want a wizard for these scaffolds. I think these add a huge amount of complexity. If we want a variation on a scaffold, we'd create a new scaffold.
  • A future iteration could provide styling options? tailwind/bootstrap versions of each scaffold
  • The generated code (especially the tests) is opinionated and use several of my personal libraries (zenstruck/browser|foundry). This is really "How Kevin Writes Symfony Apps" :). I don't have an issue if we want to make changes to code/tests to make them "more generic".
  • bin/console make:scaffold (no arguments) lists the available scaffolds to choose from.
  • bin/console make:scaffold x y z installs scaffolds x, y and z.

This PR provides the following scaffolds:

  1. homepage: basic homepage controller, template, functional test for other scaffolds to use
  2. user: user entity/repository, foundry factory and unit test
  3. auth: form login with functional tests
  4. register: registration form with functional tests
  5. change-password: change password form with functional tests
  6. profile: user profile management form with functional tests
  7. reset-password: using symfonycasts/password-reset-bundle
  8. bootstrapcss: installs/configures bootstrap with encore

Included is also a starter-kit. This is just another scaffold but it includes all the above scaffolds (styled with bootstrap) and an application shell. The shell has the following features:

  • navbar on every page with:
    • login & register links if not logged in
    • manage profile, change password & logout user menu
  • forgot password link on login page

Future ideas for scaffolds:

  • reset-password:stateless: using signed urls instead of db token table
  • register:verification: similar to register but with email verification
  • change-email: change email system for verified emails
  • tailwindcss: similar to the current bootstrapcss scaffold but for Tailwind CSS

Future ideas for starter-kits:

  • starter-kit:verifcation: similar to the current starter kit but with email verification
  • starter-kit:tailwind: similar to the current starter kit but for Tailwind CSS
  • starter-kit:verification:tailwind: combination of the above two starter kits

Test this PR:

symfony new project
cd project
composer config repositories.maker vcs [email protected]:kbond/maker-bundle
composer require symfony/maker-bundle:dev-scaffolding
composer require process # required for this maker
composer require log # (optional) to surpress logs in console

bin/console make:scaffold starter-kit

# run unit tests
DATABASE_URL="sqlite:///%kernel.project_dir%/var/test.db" bin/phpunit

# test in browser!
echo DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" > .env.local

symfony server:start -d

Some TODOS:

  • [x] add better descriptions/help for each scaffold, post install notes ("what's next")
  • [x] deprecate some existing maker's that are replaced by scaffolds
  • [x] smarter overwrites: if contents is the same, skip, if contents are different, ask user to confirm.
  • [x] ~Adjust password-reset to flash the "email sent" message instead of a separate template.~ Decided to leave the email sent template as there is more detail than we'd probably want in a flash message.
  • [ ] base.html.twig patch with flashes...
  • [x] cleanup configuration system, add some helper methods to FileManager (ie modifyYaml, modifyJson, appendToFile, replaceInFile).
  • [x] suffix the scaffold files with .tpl to avoid your IDE from suggesting
  • [x] instead of using Filesystem::mirror() to copy scaffold files, use FilesystemManager - this will allow the tests to lint the php/template files.
  • [x] replace require package "aliases" with real packages to improve perf

kbond avatar Mar 29 '22 18:03 kbond

The following labels could not be found: plugins.

dependabot[bot] avatar Jan 12 '24 22:01 dependabot[bot]

A newer version of bootstrap exists, but since this PR has been edited by someone other than Dependabot I haven't updated it. You'll get a PR for the updated version as normal once this PR is merged.

dependabot[bot] avatar Mar 01 '24 07:03 dependabot[bot]

OK, I won't notify you again about this release, but will get in touch when a new version is available. If you'd rather skip all updates until the next major or minor version, let me know by commenting @dependabot ignore this major version or @dependabot ignore this minor version. You can also ignore all major, minor, or patch releases for a dependency by adding an ignore condition with the desired update_types to your config file.

If you change your mind, just re-open this PR and I'll resolve any conflicts on it.

dependabot[bot] avatar Mar 14 '24 08:03 dependabot[bot]

reopening...

rusackas avatar Apr 18 '24 15:04 rusackas

@dependabot recreate

rusackas avatar Apr 26 '24 18:04 rusackas