Class: Frozen::Generators::UiGenerator
- Inherits:
-
FrozenRails::Generator
- Object
- Rails::Generators::Base
- FrozenRails::Generator
- Frozen::Generators::UiGenerator
- Defined in:
- lib/generators/frozen/ui_generator.rb
Instance Method Summary collapse
- #add_gems ⇒ Object
- #add_js_dependencies ⇒ Object
- #add_routes ⇒ Object
- #bundle_gems ⇒ Object
- #configure_esbuild ⇒ Object
- #copy_demo_component ⇒ Object
- #prepare_js_environment ⇒ Object
- #replace_assets ⇒ Object
- #setup_jasmine ⇒ Object
- #setup_lookbook ⇒ Object
- #setup_view_component ⇒ Object
- #switch_to_precompiled_assets ⇒ Object
Instance Method Details
#add_gems ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/generators/frozen/ui_generator.rb', line 10 def add_gems add_frozen_gems <<~RUBY # frozen:ui gem "view_component" gem "precompiled_assets" RUBY comment_lines "Gemfile", /propshaft/ comment_lines "Gemfile", /jsbundling-rails/ add_frozen_gems <<~RUBY, env: "development" # frozen:ui gem "listen" gem "propshaft" RUBY add_frozen_gems <<~RUBY, env: "local" # frozen:ui gem "lookbook" RUBY end |
#add_js_dependencies ⇒ Object
53 54 55 56 57 58 |
# File 'lib/generators/frozen/ui_generator.rb', line 53 def add_js_dependencies in_root do run "yarn add unpoly" run "yarn add --dev jasmine jasmine_dom_matchers" end end |
#add_routes ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/generators/frozen/ui_generator.rb', line 159 def add_routes append_to_routes <<~RUBY # frozen:ui if Rails.env.local? mount Lookbook::Engine, at: "/lookbook" resources :jasmine, only: [ :index ] end RUBY end |
#bundle_gems ⇒ Object
31 32 33 |
# File 'lib/generators/frozen/ui_generator.rb', line 31 def bundle_gems bundle! end |
#configure_esbuild ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/generators/frozen/ui_generator.rb', line 44 def configure_esbuild in_root do run "yarn add --dev esbuild-plugin-import-glob esbuild-plugin-text-replace esbuild-manifest-plugin" copy_file "esbuild.config.js" run 'npm pkg set type="module"' run 'npm pkg set scripts.build="node esbuild.config.js"' end end |
#copy_demo_component ⇒ Object
169 170 171 172 |
# File 'lib/generators/frozen/ui_generator.rb', line 169 def copy_demo_component copy_directory "demo_component", "app/components" copy_directory "demo_component_test", "tests/components" end |
#prepare_js_environment ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/generators/frozen/ui_generator.rb', line 35 def prepare_js_environment in_root do run "mv .node-version .nvmrc" run "nvm use" run "nvm install" run "npm install -g yarn" end end |
#replace_assets ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/generators/frozen/ui_generator.rb', line 60 def replace_assets # Remove everything from app/assets except app/assets/rouge in_root do assets_path = Pathname.new("app/assets") FileUtils.mkdir_p(assets_path) unless assets_path.exist? assets_path.children.each do |entry| next if entry.basename.to_s == "rouge" FileUtils.rm_rf(entry) end end remove_dir "app/javascript" copy_directory "assets", "app/assets" copy_file "application.html.erb", "app/views/layouts/application.html.erb", force: true end |
#setup_jasmine ⇒ Object
154 155 156 157 |
# File 'lib/generators/frozen/ui_generator.rb', line 154 def setup_jasmine copy_directory "jasmine/views", "app/views" copy_file "jasmine/controllers/jasmine_controller.rb", "app/controllers/jasmine_controller.rb" end |
#setup_lookbook ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/generators/frozen/ui_generator.rb', line 137 def setup_lookbook copy_file "lookbook/lookbook_helper.rb", "app/helpers/lookbook_helper.rb" config = <<~RUBY # frozen:ui config.lookbook.preview_paths = [ "test/components" ] config.lookbook.preview_collection_label = "Components" config.lookbook.page_collection_label = "Documentation" config.lookbook.page_route = "docs" config.lookbook.page_paths = [ "test/components/docs" ] config.lookbook.ui_theme = "zinc" RUBY append_to_application_config config, env: "development" append_to_application_config config, env: "test" end |
#setup_view_component ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/generators/frozen/ui_generator.rb', line 122 def setup_view_component copy_file "application_component.rb", "app/components/application_component.rb" copy_directory "lib", "lib" append_to_application_config <<~RUBY # frozen:ui config.i18n.available_locales = [ :en, :de ] config.view_component.parent_class = "ApplicationComponent" config.view_component.generate.preview = true config.view_component.generate.preview_path = "test/components" config.view_component.generate.locale = true config.asset_path = "/assets" RUBY end |
#switch_to_precompiled_assets ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/generators/frozen/ui_generator.rb', line 77 def switch_to_precompiled_assets in_root do # CAUTION: Very brittle! FileUtils.move("content/pages/rails-static", "app/assets/images/pages/rails-static") end comment_lines "config/application.rb", /config\.assets\.paths/ prepend_to_file "config/initializers/assets.rb", "return unless Rails.env.development?\n" insert_into_file ".github/workflows/ci.yml", <<YAML1, before: "\n - name: Run tests", force: true - uses: actions/setup-node@v6 with: node-version-file: '.nvmrc' cache: 'yarn' - run: npm install -g yarn - run: yarn install --frozen-lockfile YAML1 insert_into_file ".github/workflows/ci.yml", <<YAML2, before: "\n - name: Run System Tests", force: true - uses: actions/setup-node@v6 with: node-version-file: '.nvmrc' cache: 'yarn' - run: npm install -g yarn - run: yarn install --frozen-lockfile YAML2 insert_into_file ".github/workflows/parklife.yml", <<YAML3, after: "bundler-cache: true\n" - uses: actions/setup-node@v6 with: node-version-file: '.nvmrc' cache: 'yarn' - run: npm install -g yarn - run: yarn install --frozen-lockfile YAML3 insert_into_file ".gitlab-ci.yml", <<YAML4, after: " - bundle install\n" - npm install -g yarn - yarn install --frozen-lockfile YAML4 end |