Class: Kaze::Commands::App::InertiaReactStack

Inherits:
BaseStack
  • Object
show all
Defined in:
lib/kaze/commands/app/inertia_react_stack.rb

Instance Method Summary collapse

Instance Method Details

#installObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/kaze/commands/app/inertia_react_stack.rb', line 2

def install
  # Gems...
  return unless remove_gems([ 'sprockets-rails', 'turbo-rails', 'stimulus-rails' ])
  return unless install_gems([ 'propshaft', 'tailwindcss-rails', 'inertia_rails', 'vite_rails', 'dotenv', 'bcrypt', 'js-routes' ])
  return unless install_gems([ 'factory_bot_rails', 'faker' ], 'development, test')

  # NPM Packages...
  FileUtils.copy_file("#{stubs_path}/inertia-react-ts/package.json", "#{Dir.pwd}/package.json")

  # Controllers...
  FileUtils.copy_entry("#{stubs_path}/inertia-common/app/controllers", "#{Dir.pwd}/app/controllers")

  # Models...
  FileUtils.copy_entry("#{stubs_path}/default/app/models", "#{Dir.pwd}/app/models")

  # Forms...
  ensure_directory_exists("#{Dir.pwd}/app/forms")
  FileUtils.copy_entry("#{stubs_path}/default/app/forms", "#{Dir.pwd}/app/forms")

  # Validators...
  ensure_directory_exists("#{Dir.pwd}/app/validators")
  FileUtils.copy_entry("#{stubs_path}/default/app/validators", "#{Dir.pwd}/app/validators")

  # Mailers...
  ensure_directory_exists("#{Dir.pwd}/app/mailers")
  FileUtils.copy_entry("#{stubs_path}/default/app/mailers", "#{Dir.pwd}/app/mailers")

  # Views...
  ensure_directory_exists("#{Dir.pwd}/app/views/layouts")
  ensure_directory_exists("#{Dir.pwd}/app/views/user_mailer")
  FileUtils.copy_file("#{stubs_path}/inertia-react-ts/app/views/layouts/application.html.erb", "#{Dir.pwd}/app/views/layouts/application.html.erb")
  FileUtils.copy_file("#{stubs_path}/default/app/views/layouts/mailer.html.erb", "#{Dir.pwd}/app/views/layouts/mailer.html.erb")
  FileUtils.copy_file("#{stubs_path}/default/app/views/layouts/mailer.text.erb", "#{Dir.pwd}/app/views/layouts/mailer.text.erb")
  FileUtils.copy_entry("#{stubs_path}/default/app/views/user_mailer", "#{Dir.pwd}/app/views/user_mailer")

  # Components + Pages...
  ensure_directory_exists("#{Dir.pwd}/app/javascript")
  FileUtils.copy_entry("#{stubs_path}/inertia-react-ts/app/javascript", "#{Dir.pwd}/app/javascript")

  # Tests...
  install_tests
  FileUtils.copy_entry("#{stubs_path}/inertia-common/test/integration", "#{Dir.pwd}/test/integration")

  # Routes...
  FileUtils.copy_file("#{stubs_path}/default/config/routes.rb", "#{Dir.pwd}/config/routes.rb")

  # Migrations...
  install_migrations

  # Tailwind / Vite...
  FileUtils.copy_file("#{stubs_path}/default/app/assets/stylesheets/application.css", "#{Dir.pwd}/app/assets/stylesheets/application.css")
  FileUtils.copy_file("#{stubs_path}/default/app/assets/stylesheets/application.tailwind.css", "#{Dir.pwd}/app/assets/stylesheets/application.tailwind.css")
  FileUtils.copy_file("#{stubs_path}/inertia-react-ts/config/tailwind.config.js", "#{Dir.pwd}/config/tailwind.config.js")
  FileUtils.copy_file("#{stubs_path}/inertia-common/config/vite.json", "#{Dir.pwd}/config/vite.json")
  FileUtils.copy_file("#{stubs_path}/inertia-react-ts/tsconfig.json", "#{Dir.pwd}/tsconfig.json")
  FileUtils.copy_file("#{stubs_path}/inertia-react-ts/vite.config.ts", "#{Dir.pwd}/vite.config.ts")
  FileUtils.copy_file("#{stubs_path}/default/bin/dev", "#{Dir.pwd}/bin/dev")
  FileUtils.copy_file("#{stubs_path}/inertia-common/bin/vite", "#{Dir.pwd}/bin/vite")
  FileUtils.copy_file("#{stubs_path}/default/Procfile.dev", "#{Dir.pwd}/Procfile.dev")
  File.write("#{Dir.pwd}/Procfile.dev", "#{File.read("#{Dir.pwd}/Procfile.dev")}\nvite: bin/vite dev\n")
  run_command("#{Dir.pwd}/bin/rails generate js_routes:middleware")
  run_command("#{Dir.pwd}/bin/rails tailwindcss:build")

  say ''
  say 'Installing and building Node dependencies.', :magenta

  if File.exist?("#{Dir.pwd}/pnpm-lock.yaml")
    run_commands([ 'pnpm install', 'pnpm run build' ])
  elsif File.exist?("#{Dir.pwd}/yarn.lock")
    run_commands([ 'yarn install', 'yarn build' ])
  elsif File.exist?("#{Dir.pwd}/bun.lockb")
    run_commands([ 'bun install', 'bun run build' ])
  else
    run_commands([ 'npm install', 'npm run build' ])
  end

  say ''
  say 'Kaze scaffolding installed successfully.', :green
end