mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
Necessary to reflect Hanami ports instead of the older Sinatra ports that this was originally sourced from. Co-authored-by: Ryan Kulp <ryanckulp@gmail.com> Milestone: patch
79 lines
2.0 KiB
Ruby
Executable File
79 lines
2.0 KiB
Ruby
Executable File
#! /usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require "fileutils"
|
|
require "pathname"
|
|
|
|
class Runner
|
|
def initialize root = Pathname(__dir__).join("..").expand_path, kernel: Kernel, kit: FileUtils
|
|
@root = root
|
|
@kernel = kernel
|
|
@kit = kit
|
|
end
|
|
|
|
def call
|
|
kit.chdir root do
|
|
setup_development_environment
|
|
setup_test_environment
|
|
setup_development_procfile
|
|
step "Installing dependencies...", "bundle install"
|
|
step "Installing packages...", "npm install"
|
|
step "Configuring databases...", "hanami db prepare"
|
|
step "Compiling assets...", "hanami assets compile"
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :root, :kernel, :kit
|
|
|
|
def step(message, *arguments)
|
|
kernel.puts message
|
|
kernel.system(*arguments) || kernel.abort("\nERROR: Command #{arguments.inspect} failed.")
|
|
end
|
|
|
|
def setup_development_environment
|
|
path = root.join ".env.development"
|
|
|
|
return kernel.puts ".env.development exists. Skipped." if path.exist?
|
|
|
|
kernel.puts "Creawting .env.development..."
|
|
|
|
path.write <<~BODY
|
|
APP_HOST=0.0.0.0
|
|
APP_URL=https://localhost:2443
|
|
DATABASE_URL=sqlite://db/terminus.sqlite
|
|
IMAGES_ROOT=#{root}/public/assets/images
|
|
BODY
|
|
end
|
|
|
|
def setup_test_environment
|
|
path = root.join ".env.test"
|
|
|
|
return kernel.puts ".env.test exists. Skipped." if path.exist?
|
|
|
|
kernel.puts "Creating .env.test..."
|
|
|
|
path.write <<~BODY
|
|
APP_HOST=localhost
|
|
APP_URL=https://localhost:2443
|
|
DATABASE_URL=sqlite://db/terminus.sqlite
|
|
IMAGES_ROOT=#{root}/tmp/rspec
|
|
BODY
|
|
end
|
|
|
|
def setup_development_procfile
|
|
path = root.join "Procfile.dev"
|
|
|
|
return kernel.puts "Procfile.dev exists. Skipped." if path.exist?
|
|
|
|
kernel.puts "Creating Procfile.dev..."
|
|
|
|
path.write %(web: rerun --dir app,config,lib,slices --pattern="**/*.{erb,rb}" -- ) +
|
|
"bundle exec puma --config ./config/puma.rb\n" \
|
|
"assets: bundle exec hanami assets watch"
|
|
end
|
|
end
|
|
|
|
Runner.new.call
|