DFE-Digital / rails-template

Rails 7 template with GOV.UK Frontend
27 stars 5 forks source link

Make template idempotent #2

Closed tvararu closed 2 years ago

tvararu commented 2 years ago

By making the template idempotent, it makes it possible to iterate and continue adding optional features to the template, with downstream users being able to benefit from these improvements by re-running it against their project.

This change makes it possible to run the template against an existing project. It will skip over any already applied changes:

$ rails new --skip-bundle --skip-jbuilder --skip-test --skip-action-text --skip-action-mailer --skip-action-mailbox \
  -m rails-template/template.rb test-project
$ cd test-project
$ bin/rails app:template LOCATION=../rails-template/template.rb
         run  bundle install from "."
   identical  Procfile.dev
   identical  bin/dev
         run  chmod +x bin/dev from "."
   identical  app/assets/config/manifest.js
   identical  package.json
      remove  app/assets/stylesheets/application.css
   identical  app/assets/stylesheets/application.scss
   identical  app/javascript/application.js
   identical  app/views/layouts/application.html.erb
       exist  app/assets/builds
         run  yarn from "."
$ git status 
On branch main 
nothing to commit, working tree clean 

A follow-up PR will document this feature and add a bin/template script to newly bootstrapped projects to make it easy to re-run the template.

tvararu commented 2 years ago

I don't think this will fully work actually for certain files, like package.json, after we add more deps. Going to see what we can do about that.

Later edit: fixed!