Class: Ui::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/ui/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#detect_asset_pipelineObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/ui/install_generator.rb', line 7

def detect_asset_pipeline
  @asset_pipeline = if defined?(Propshaft)
    :propshaft
  elsif defined?(Sprockets)
    :sprockets
  else
    :unknown
  end

  @js_bundler = if File.exist?(Rails.root.join("config/importmap.rb"))
    :importmap
  elsif File.exist?(Rails.root.join("package.json"))
    :node
  else
    :none
  end
end

#install_javascriptObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/ui/install_generator.rb', line 69

def install_javascript
  case @js_bundler
  when :importmap
    install_importmap_javascript
  when :node
    install_node_javascript
  else
    say "\nNo JavaScript bundler detected", :yellow
  end
end

#install_package_jsonObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/ui/install_generator.rb', line 48

def install_package_json
  if @js_bundler == :node || !File.exist?(Rails.root.join("package.json"))
    say "\nSetting up package.json...\n", :yellow
    template "package.json", Rails.root.join("package.json")
    say "  Created package.json with Tailwind CLI", :green
  else
    say "\nUpdating existing package.json...\n", :yellow
    say "  Please add Tailwind scripts to your package.json manually", :yellow
  end
end

#install_procfileObject



59
60
61
62
63
64
65
66
67
# File 'lib/generators/ui/install_generator.rb', line 59

def install_procfile
  if !File.exist?(Rails.root.join("Procfile.dev"))
    say "\nSetting up Procfile.dev...\n", :yellow
    template "Procfile.dev", Rails.root.join("Procfile.dev")
    say "  Created Procfile.dev", :green
  else
    say "\n  Procfile.dev already exists, skipping", :yellow
  end
end

#install_tailwind_cssObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/ui/install_generator.rb', line 32

def install_tailwind_css
  say "Installing Tailwind CSS 4...\n", :yellow

  # Create Tailwind CSS config file
  template "application.tailwind.css", Rails.root.join("app/assets/stylesheets/application.tailwind.css")

  # Create builds directory
  create_file Rails.root.join("app/assets/builds/.keep")

  # Add to gitignore
  append_to_file Rails.root.join(".gitignore"), "\n# Compiled CSS\n/app/assets/builds/**/*.css\n"

  say "  Created app/assets/stylesheets/application.tailwind.css", :green
  say "  Created app/assets/builds directory", :green
end

#show_asset_pipeline_infoObject



25
26
27
28
29
30
# File 'lib/generators/ui/install_generator.rb', line 25

def show_asset_pipeline_info
  say "\nDetecting your setup...\n", :yellow
  say "  Asset pipeline: #{@asset_pipeline}", :green
  say "  JavaScript bundler: #{@js_bundler}", :green
  say "\n"
end

#show_next_stepsObject



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
# File 'lib/generators/ui/install_generator.rb', line 80

def show_next_steps
  say "\n"
  say "=" * 60, :green
  say "UI Engine installed successfully!", :green
  say "=" * 60, :green
  say "\n"
  say "Next steps:\n", :yellow
  say "\n"

  say "  1. Install dependencies:", :cyan
  say "     $ bun install\n", :white
  say "\n"

  say "  2. Build Tailwind CSS:", :cyan
  say "     $ bun run build:css\n", :white
  say "\n"

  say "  3. Update your layout file to include:", :cyan
  say "     <%= stylesheet_link_tag 'application' %>\n", :white
  say "\n"

  if @js_bundler == :importmap
    say "  4. Import UI Engine in your JavaScript:", :cyan
    say "     import UI from 'ui'\n", :white
    say "     UI.init()\n", :white
    say "\n"
  end

  say "  5. Start development with:", :cyan
  say "     $ bin/dev\n", :white
  say "\n"

  say "=" * 60, :green
  say "Documentation: https://github.com/your-repo/ui", :cyan
  say "=" * 60, :green
  say "\n"
end