class FullStack
Attributes
options[R]
Public Class Methods
new(site, options)
click to toggle source
# File lib/full_stack.rb, line 4 def initialize(site, options) @site = site @options = options @stop = false @pids = [] site.login_to_server end
Public Instance Methods
brew_message()
click to toggle source
# File lib/full_stack.rb, line 120 def brew_message "\n\nTo install Vae Local Full Stack dependencies on macOS via Homebrew, run the following commands:\n brew tap actionverb/tap\n brew install vae-frontend-compiler-service vae-remote vaedb vaeql\n\nMake sure you resolve any errors from Homebrew before proceeding." end
download_feed(url)
click to toggle source
# File lib/full_stack.rb, line 41 def download_feed(url) url_base = url.split('/')[2] url_path = '/'+url.split('/')[3..-1].join('/') Net::HTTP.start(url_base) { |http| File.open("#{@site.data_path}feed.xml", 'w') { |f| http.get(URI.escape(url_path)) { |str| f.write str } } } end
find_dependency_project(folder, main_file, name)
click to toggle source
# File lib/full_stack.rb, line 108 def find_dependency_project(folder, main_file, name) thisdir = File.dirname(__FILE__) paths = [ "#{thisdir}/../../#{folder}", "#{thisdir}/../../../#{folder}", "/usr/local/#{folder}", "/usr/local/opt/#{folder}", "/usr/local/Cellar/#{folder}/1.0.0", "~/#{folder}" ] paths << "#{vae_remote_path}/tests/dependencies/#{folder}" if folder != "vae_remote" paths.each { |path| if File.exists?(path) and File.exists?("#{path}/#{main_file}") return path end } raise VaeError, "Could not find #{name} on your system.#{brew_message}" end
launch_daemons()
click to toggle source
# File lib/full_stack.rb, line 53 def launch_daemons if VaeLocal.port_open?(9092) puts "Starting Vae Frontend Compiler Service using Installation at #{vae_fcs_path}" @pids << fork { Dir.chdir(vae_fcs_path) STDOUT.reopen("/dev/null", "w") STDERR.reopen("/dev/null", "w") exec "bundle exec ./vaefcs.rb" } end port = 9100 serve_root = @site.root loop { break if VaeLocal.port_open?(port) port = port + 1 } if File.exists?(@site.root + "/.jekyll") serve_root = @site.root + "/_site/" FileUtils.mkdir_p(serve_root) @pids << fork { exec "bundle exec jekyll build --watch --source #{Shellwords.shellescape(@site.root)} --destination #{Shellwords.shellescape(serve_root)}" } end ENV['VAE_LOCAL_VAEDB_PORT'] = port.to_s @pids << fork { Dir.chdir(vaedb_path) puts "Starting Vaedb on Port #{port} using Installation at #{vaedb_path}" exec "./vaedb --port #{port} --busaddress 'tcp://*:#{port-4000}' --test --log_level #{options[:log_level]}" } @pids << fork { Dir.chdir(serve_root) ENV['VAE_LOCAL_BACKSTAGE'] = @site.subdomain_base + ".vaeplatform." + (ENV['VAEPLATFORM_LOCAL'] ? "dev" : "com") ENV['VAE_LOCAL_SECRET_KEY'] = @site.secret_key ENV['VAE_LOCAL_DATA_PATH'] = @site.data_path if options[:php_runtime] == "hhvm" ENV['VAE_LOCAL_HHVM'] = "1" exec "hhvm -c #{vae_remote_path}/tests/dependencies/php.ini -m server -d hhvm.pid_file=/tmp/vae_local.hhvm.pid -d auto_prepend_file=#{vae_remote_path}/lib/index.php -d hhvm.server.default_document=#{vae_remote_path}/lib/index.php -d hhvm.server.error_document404=#{vae_remote_path}/lib/index.php -d hhvm.server.port=#{options[:port]} -d hhvm.server.source_root=#{Shellwords.shellescape(@site.root)}" else exec "php -c #{vae_remote_path}/tests/dependencies/php.ini -S 0.0.0.0:#{options[:port]} #{vae_remote_path}/lib/index.php" end } end
run()
click to toggle source
# File lib/full_stack.rb, line 12 def run write_files launch_daemons trap("INT") { @stop = true } loop { break if @stop; sleep 0.5 } puts "Quit signal received, cleaning up ..." @pids.map { |pid| Process.kill("TERM", pid) } end
vae_fcs_path()
click to toggle source
# File lib/full_stack.rb, line 100 def vae_fcs_path @vae_fcs_path ||= find_dependency_project("vae-frontend-compiler-service", "vaefcs.rb", "Vae Frontend Compiler Service") end
vae_remote_path()
click to toggle source
# File lib/full_stack.rb, line 104 def vae_remote_path @vae_remote_path ||= find_dependency_project("vae_remote", "lib/general.php", "Vae Remote") end
vaedb_path()
click to toggle source
# File lib/full_stack.rb, line 96 def vaedb_path @vaedb_path ||= find_dependency_project("vaedb", "vaedb", "Vaedb") end
write_files()
click to toggle source
# File lib/full_stack.rb, line 21 def write_files data = @site.data FileUtils.mkdir_p(@site.data_path) if !File.exists?(@site.data_path + "/assets/") FileUtils.ln_s("#{vae_remote_path}/public", @site.data_path + "/assets") end @site.secret_key = data['secret_key'] generation = File.exists?("#{@site.data_path}feed_generation") ? File.open("#{@site.data_path}feed_generation").read.to_i : 0 if data['feed_url'] and data['feed_generation'].to_i > generation puts "Downloading updated Site Data Feed..." if curl = File.which("curl") `curl -o #{Shellwords.shellescape(@site.data_path)}feed.xml #{Shellwords.shellescape(data['feed_url'])}` else download_feed(data['feed_url']) end File.open("#{@site.data_path}feed_generation",'w') { |f| f.write(data['feed_generation']) } end File.open("#{@site.data_path}settings.php",'w') { |f| f.write(data['settings']) } end