Module: Capistrano::Nuxt2::BaseHelpers
- Defined in:
- lib/capistrano/nuxt2/base_helpers.rb
Instance Method Summary collapse
- #build_deploy_env_var ⇒ Object
- #ensure_shared_log_path ⇒ Object
-
#ensure_shared_output_path ⇒ Object
Nuxt 3 SSR (Nitro) output dir β holds βserver/index.mjs` + `public/`.
-
#ensure_shared_path(path) ⇒ Object
PAth helpers.
- #ensure_shared_path_ownership ⇒ Object
-
#ensure_shared_pids_path ⇒ Object
PID dir for the Nitro systemd service (mirrors recipes2go puma/sidekiq).
- #ensure_shared_www_path ⇒ Object
- #get_template_file(from) ⇒ Object
-
#nuxt3_nvm_prefix ⇒ Object
bash -lc prefix that activates the requested node version via nvm.
-
#remove_app_service(name = "SERVICE", service_path = "/lib/systemd/system", service_file = nil) ⇒ Object
Disable + stop + remove an old systemd service file (no-op if absent).
- #render2go(tmpl) ⇒ Object
- #template2go(from, to) ⇒ Object
- #template_with_role(from, to, role = nil) ⇒ Object
Instance Method Details
#build_deploy_env_var ⇒ Object
8 9 10 11 12 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 8 def build_deploy_env_var app_name = fetch(:application).gsub(/ /,'_').gsub(/-/,'_').upcase stage_name = fetch(:stage) == 'production' ? 'PROD' : 'STG' "#{ app_name }_#{ stage_name }_DEPLOY_MODE" end |
#ensure_shared_log_path ⇒ Object
29 30 31 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 29 def ensure_shared_log_path ensure_shared_path("#{shared_path}/log") end |
#ensure_shared_output_path ⇒ Object
Nuxt 3 SSR (Nitro) output dir β holds βserver/index.mjs` + `public/`
34 35 36 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 34 def ensure_shared_output_path ensure_shared_path("#{shared_path}/#{fetch(:nuxt3_output_folder, 'output')}") end |
#ensure_shared_path(path) ⇒ Object
PAth helpers
15 16 17 18 19 20 21 22 23 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 15 def ensure_shared_path(path) unless test("[ -d #{path} ]") puts "π Directory #{path} does not exist. Creating it..." execute :mkdir, "-p", path else puts "β Directory #{path} already exists." end ensure_shared_path_ownership end |
#ensure_shared_path_ownership ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 67 def ensure_shared_path_ownership # Fix ownership only if needed (avoids unnecessary chown operations) unless test("stat -c '%U:%G' #{shared_path} | grep #{fetch(:user)}:#{fetch(:user)}") puts "π§ Fixing ownership of #{shared_path} and its parent directories..." execute :sudo, :chown, "-R #{fetch(:user)}:#{fetch(:user)} #{shared_path}" execute :sudo, :chown, "#{fetch(:user)}:#{fetch(:user)} #{fetch(:deploy_to)}" else puts "β Ownership is already correct." end end |
#ensure_shared_pids_path ⇒ Object
PID dir for the Nitro systemd service (mirrors recipes2go puma/sidekiq)
39 40 41 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 39 def ensure_shared_pids_path ensure_shared_path("#{shared_path}/pids") end |
#ensure_shared_www_path ⇒ Object
25 26 27 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 25 def ensure_shared_www_path ensure_shared_path("#{shared_path}/www") end |
#get_template_file(from) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 98 def get_template_file( from ) [ File.join('config', 'deploy', 'templates', "#{from}.erb"), File.join('config', 'deploy', 'templates', "#{from}"), File.join('lib', 'capistrano', 'templates', "#{from}.erb"), File.join('lib', 'capistrano', 'templates', "#{from}"), File.("../../../generators/capistrano/nuxt2/templates/#{from}.erb", __FILE__), File.("../../../generators/capistrano/nuxt2/templates/#{from}", __FILE__) ].each do |path| return File.read(path) if File.file?(path) end # false raise "File '#{from}' was not found!!!" end |
#nuxt3_nvm_prefix ⇒ Object
bash -lc prefix that activates the requested node version via nvm. Mirrors the nvm pattern used by the nuxt:/vue: build tasks.
45 46 47 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 45 def nuxt3_nvm_prefix "source #{fetch(:nuxt3_nvm_script)} && nvm use #{fetch(:nuxt3_nvm_version)}" end |
#remove_app_service(name = "SERVICE", service_path = "/lib/systemd/system", service_file = nil) ⇒ Object
Disable + stop + remove an old systemd service file (no-op if absent).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 50 def remove_app_service(name = "SERVICE", service_path = "/lib/systemd/system", service_file = nil) if test("[ -f #{service_path}/#{service_file}.service ]") unless test("systemctl is-enabled #{service_file} || echo disabled") == "disabled" info "π§ Disabling #{service_file} service..." execute :sudo, "systemctl disable #{service_file}" else info "β #{service_file} is already disabled, skipping." end puts "π Stopping old #{name} service: #{service_file}.service" execute :sudo, "systemctl stop #{service_file}" puts "π Removing old #{name} service file: #{service_file}.service" execute :sudo, :rm, "-f", "#{service_path}/#{service_file}.service" else puts "β οΈ Old #{name} service file #{service_file}.service does not exist, skipping removal." end end |
#render2go(tmpl) ⇒ Object
86 87 88 89 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 86 def render2go(tmpl) erb = get_template_file(tmpl) ERB.new(erb).result(binding) end |
#template2go(from, to) ⇒ Object
80 81 82 83 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 80 def template2go(from, to) erb = get_template_file(from) upload! StringIO.new( ERB.new(erb).result(binding) ), to end |
#template_with_role(from, to, role = nil) ⇒ Object
92 93 94 95 |
# File 'lib/capistrano/nuxt2/base_helpers.rb', line 92 def template_with_role(from, to, role = nil) erb = get_template_file(from) upload! StringIO.new(ERB.new(erb).result(binding)), to end |