Skip to content

Commit

Permalink
Wrap node commands with Capistrano
Browse files Browse the repository at this point in the history
This code is based on what the rvm1-capistrano and capistrano-nvm gems
do, but simplified a bit to take advantage of the `fnm exec` command.

Since ExecJS will check for a JavaScript runtime every time the
application is started, we need to include commands like `bundle` and
`rake` so Node.js is found. I've also included the default commands gems
like capistrano-nvm use because we will add the `npm` command in the
near future.
  • Loading branch information
javierm committed Oct 11, 2023
1 parent db7fd28 commit f15474a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def main_deploy_server
"cd #{release_path} && eval \"$(fnm env)\""
end
set :fnm_install_node_command, -> { "#{fetch(:fnm_setup_command)} && fnm use --install-if-missing" }
set :fnm_map_bins, %w[bundle node npm rake yarn]

set :puma_conf, "#{release_path}/config/puma/#{fetch(:rails_env)}.rb"

Expand All @@ -61,6 +62,7 @@ def main_deploy_server

after :updating, "install_ruby"
after "bundler:install", "install_node"
after "bundler:install", "map_node_bins"

after "deploy:migrate", "add_new_settings"

Expand Down Expand Up @@ -120,6 +122,20 @@ def main_deploy_server
end
end

task :map_node_bins do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
prefix = "#{fetch(:fnm_setup_command)} && fnm exec"

fetch(:fnm_map_bins).each do |command|
SSHKit.config.command_map.prefix[command.to_sym].unshift(prefix)
end
end
end
end
end

task :refresh_sitemap do
on roles(:app) do
within release_path do
Expand Down

0 comments on commit f15474a

Please sign in to comment.