vae 0.6.10 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63081ad59417e6e9f40b02e742a226337eb22ba6
4
- data.tar.gz: 1e1be82239bd0578f1a90e94f11a26d8a8e7d8bc
3
+ metadata.gz: acfbc6120a34efdcc155c6893b47538f47bb2da5
4
+ data.tar.gz: d9ef76554fcab3d7ace9348ab543e701e0708d3b
5
5
  SHA512:
6
- metadata.gz: a65fe80f05ef6d8904e1184fcdae1ea1daaa9d4b0b9df598f48fd7da74c2f9ace44e8faca3db51db3bd543828b0ddfe5b2e4947852df5cdf8197c7f6fee97c15
7
- data.tar.gz: 39d4e419dfdc703648aaeff80b054a44e17ba1b828ac19fc692ae1e46ac8f6cae0120a2576d9faf74499a2fbf62aa7790070469ba1f406f4bc68d83cf9b94f03
6
+ metadata.gz: 6fa33a2e3bedd4b78cf56cbaedc4e385a8b8230074fb62673718ecf1fc1dcd8f7060bea026c45756b80147593c2f0403d1d04a8f350b9e7caa2b34eb656c2b04
7
+ data.tar.gz: 84ce9c1c794f5fc18c4228270e25aa9f0861a915dae6ad85bb4cb8ef5483f62aa17484bb9fbc0270377c5c79d47b662d2bd3b6e229d5a8483e15f4a518109907
data/bin/vae CHANGED
@@ -3,6 +3,36 @@
3
3
  THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
4
4
  $:.unshift File.dirname(THIS_FILE) + '/../lib'
5
5
 
6
- require 'vae'
6
+ require 'version'
7
7
 
8
- VaeLocal.run_trapping_exceptions!
8
+ require 'rubygems'
9
+
10
+ require 'cgi'
11
+ require 'digest/md5'
12
+ require 'fileutils'
13
+ require 'json'
14
+ require 'mongrel'
15
+ require 'net/http'
16
+ require 'net/https'
17
+ require 'optparse'
18
+ require 'ptools'
19
+ require 'shellwords'
20
+ require 'thread'
21
+ require 'webrick'
22
+ require 'yaml'
23
+
24
+ require 'directory_watcher'
25
+ require 'highline/import'
26
+ require 'compass'
27
+ require 'haml'
28
+
29
+ require 'full_stack'
30
+ require 'logging'
31
+ require 'proxy_server'
32
+ require 'servlet'
33
+ require 'site'
34
+ require 'vae_error'
35
+ require 'vae_site_servlet'
36
+ require 'vae_local'
37
+
38
+ VaeLocal.run_trapping_exceptions
@@ -0,0 +1,122 @@
1
+ class FullStack
2
+ attr_reader :options
3
+
4
+ def initialize(site, options)
5
+ @site = site
6
+ @options = options
7
+ @stop = false
8
+ @pids = []
9
+ end
10
+
11
+ def authenticate
12
+ req = Net::HTTP::Post.new("/api/local/v1/authorize")
13
+ req.body = "username=#{CGI.escape(@site.username)}&password=#{CGI.escape(@site.password)}"
14
+ res = VaeLocal.fetch_from_vaeplatform(@site.subdomain, req)
15
+ data = JSON.parse(res.body)
16
+ if data['valid'] == "valid"
17
+ FileUtils.mkdir_p(@site.data_path)
18
+ if !File.exists?(@site.data_path + "/assets/")
19
+ FileUtils.ln_s("#{vae_remote_path}/public", @site.data_path + "/assets")
20
+ end
21
+ @site.secret_key = data['secret_key']
22
+ generation = File.exists?("#{@site.data_path}feed_generation") ? File.open("#{@site.data_path}feed_generation").read.to_i : 0
23
+ if data['feed_url'] and data['feed_generation'].to_i > generation
24
+ puts "Downloading updated Site Data Feed..."
25
+ if curl = File.which("curl")
26
+ `curl -o #{Shellwords.shellescape(@site.data_path)}feed.xml #{Shellwords.shellescape(data['feed_url'])}`
27
+ else
28
+ download_feed(data['feed_url'])
29
+ end
30
+ File.open("#{@site.data_path}feed_generation",'w') { |f| f.write(data['feed_generation']) }
31
+ end
32
+ File.open("#{@site.data_path}settings.php",'w') { |f| f.write(data['settings']) }
33
+ else
34
+ raise VaeError, "Error Connecting to Vae with the supplied Username and Password. Please make sure this user has Vae Local permissions assigned."
35
+ end
36
+ rescue JSON::ParserError
37
+ raise VaeError, "An unknown error occurred signing into Vae Platform. Please email support for help."
38
+ end
39
+
40
+ def download_feed(url)
41
+ url_base = url.split('/')[2]
42
+ url_path = '/'+url.split('/')[3..-1].join('/')
43
+ Net::HTTP.start(url_base) { |http|
44
+ File.open("#{@site.data_path}feed.xml", 'w') { |f|
45
+ http.get(URI.escape(url_path)) { |str|
46
+ f.write str
47
+ }
48
+ }
49
+ }
50
+ end
51
+
52
+ def run
53
+ authenticate
54
+ launch_daemons
55
+ trap("INT") { @stop = true }
56
+ loop { break if @stop; sleep 0.5 }
57
+ puts "Quit signal received, cleaning up ..."
58
+ @pids.map { |pid| Process.kill("TERM", pid) }
59
+ end
60
+
61
+ def launch_daemons
62
+ if VaeLocal.port_open?(9090)
63
+ @pids << fork {
64
+ Dir.chdir("#{vae_thrift_path}/rb/")
65
+ STDOUT.reopen("/dev/null", "w")
66
+ STDERR.reopen("/dev/null", "w")
67
+ exec "bundle exec ./vaerubyd.rb"
68
+ }
69
+ end
70
+ port = 9091
71
+ serve_root = @site.root
72
+ loop {
73
+ break if VaeLocal.port_open?(port)
74
+ port = port + 1
75
+ }
76
+ if File.exists?(@site.root + "/.jekyll")
77
+ serve_root = @site.root + "/_site/"
78
+ FileUtils.mkdir_p(serve_root)
79
+ @pids << fork {
80
+ exec "bundle exec jekyll build --watch --source #{Shellwords.shellescape(@site.root)} --destination #{Shellwords.shellescape(serve_root)}"
81
+ }
82
+ end
83
+ @pids << fork {
84
+ Dir.chdir("#{vae_thrift_path}/cpp/")
85
+ ENV['VAE_LOCAL_VAEDB_PORT'] = port.to_s
86
+ exec "./vaedb --port #{port} --busaddress 'tcp://*:#{port-4000}' --test --log_level #{options[:log_level]}"
87
+ }
88
+ @pids << fork {
89
+ Dir.chdir(serve_root)
90
+ ENV['VAE_LOCAL_BACKSTAGE'] = @site.subdomain + ".vaeplatform." + (ENV['VAEPLATFORM_LOCAL'] ? "dev" : "com")
91
+ ENV['VAE_LOCAL_SECRET_KEY'] = @site.secret_key
92
+ ENV['VAE_LOCAL_DATA_PATH'] = @site.data_path
93
+ exec "php -c #{vae_remote_path}/tests/dependencies/php.ini -S 0.0.0.0:#{options[:port]} #{vae_remote_path}/lib/index.php"
94
+ }
95
+ end
96
+
97
+ def vae_remote_path
98
+ return @vae_remote_path if @vae_remote_path
99
+ thisdir = File.dirname(__FILE__)
100
+ [ "#{thisdir}/../../vae_remote", "#{thisdir}/../../../vae_remote", "/usr/local/vae_remote", "/usr/local/opt/vae-thrift", "/usr/local/Cellar/vae_thrift/1.0.0", "~/vae_remote" ].each { |path|
101
+ if File.exists?(path)
102
+ return @vae_remote_path = path
103
+ end
104
+ }
105
+ raise VaeError, "Could not find Vae Remote on your system.#{brew_message}"
106
+ end
107
+
108
+ def vae_thrift_path
109
+ return @vae_thrift_path if @vae_thrift_path
110
+ thisdir = File.dirname(__FILE__)
111
+ [ "#{thisdir}/../../vae_thrift", "#{thisdir}/../../../vae_thrift", "/usr/local/vae_thrift", "/usr/local/opt/vae-thrift", "/usr/local/Cellar/vae_thrift/1.0.0", "~/vae_thrift", "#{vae_remote_path}/tests/dependencies/vae_thrift" ].each { |path|
112
+ if File.exists?(path)
113
+ return @vae_remote_path = path
114
+ end
115
+ }
116
+ raise VaeError, "Could not find Vae Thrift on your system.#{brew_message}"
117
+ end
118
+
119
+ def brew_message
120
+ "\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-remote vae-thrift vaeql\n\nMake sure you resolve any errors from Homebrew before proceeding."
121
+ end
122
+ end
@@ -4,12 +4,12 @@ module Logging
4
4
  def self.logger
5
5
  @logger ||= new_logger
6
6
  end
7
-
7
+
8
8
  private
9
-
9
+
10
10
  def self.new_logger
11
11
  logger = Logger.new(STDOUT)
12
12
  logger.level = Logger::Severity::WARN
13
13
  logger
14
14
  end
15
- end
15
+ end
@@ -0,0 +1,31 @@
1
+ class ProxyServer
2
+ def initialize(site, options)
3
+ $site = site
4
+ @options = options
5
+
6
+ set_mime_types
7
+ end
8
+
9
+ def run
10
+ server = Mongrel::Configurator.new host: "0.0.0.0", port: @options[:port] do
11
+ listener do
12
+ uri "/", handler: VaeSiteServlet.new($site)
13
+ end
14
+ trap("INT") { raise Mongrel::StopServer }
15
+ run
16
+ end
17
+
18
+ puts "Vae is in action at http://localhost:#{@options[:port]}/"
19
+ puts " (hit Control+C to exit)"
20
+
21
+ begin
22
+ server.join
23
+ rescue Mongrel::StopServer
24
+ end
25
+ end
26
+
27
+ def set_mime_types
28
+ WEBrick::HTTPUtils::DefaultMimeTypes.store 'js', 'application/javascript'
29
+ WEBrick::HTTPUtils::DefaultMimeTypes.store 'svg', 'image/svg+xml'
30
+ end
31
+ end
@@ -6,8 +6,8 @@ class Servlet < Mongrel::HttpHandler
6
6
  out << "Servlet"
7
7
  end
8
8
  end
9
-
9
+
10
10
  end
11
11
 
12
12
  class FileNotFound < ArgumentError
13
- end
13
+ end
@@ -1,27 +1,29 @@
1
1
  class Site
2
- attr_accessor :password, :root, :session_id, :subdomain, :username
3
-
4
- def fetch_from_server(req)
5
- http = Net::HTTP.new("#{subdomain}.vaesite.com")
6
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
7
- http.start { |http|
8
- http.read_timeout = 120
9
- http.request(req)
10
- }
11
- end
12
-
2
+ attr_reader :password, :root, :session_id, :subdomain, :username, :data_path
3
+ attr_accessor :secret_key
4
+
13
5
  def initialize(options)
14
6
  @root = options[:root] if options[:root]
15
7
  @subdomain = options[:subdomain] if options[:subdomain]
16
8
  @username = options[:username] if options[:username]
17
9
  @password = options[:password] if options[:password]
18
10
  @session_id = Digest::MD5.hexdigest(rand.to_s)
11
+ @data_path = options[:data_path] || "#{@root}/.vae/data/"
19
12
  login_to_server
20
13
  end
21
-
14
+
15
+ def fetch_from_server(req)
16
+ http = Net::HTTP.new("#{subdomain}.vaesite.com")
17
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
+ http.start { |http|
19
+ http.read_timeout = 120
20
+ http.request(req)
21
+ }
22
+ end
23
+
22
24
  def login_to_server
23
- req = Net::HTTP::Post.new("/?__vae_local=#{session_id}")
24
- req.body = "__local_username=#{CGI.escape(username)}&__local_password=#{CGI.escape(password)}&__local_version=#{VER}"
25
+ req = Net::HTTP::Post.new("/")
26
+ req.body = "__vae_local=#{session_id}&__local_username=#{CGI.escape(username)}&__local_password=#{CGI.escape(password)}&__local_version=#{VER}"
25
27
  res = fetch_from_server(req)
26
28
  if res.body == "BAD"
27
29
  raise VaeError, "Invalid password or insufficient permissions."
@@ -31,5 +33,4 @@ class Site
31
33
  raise VaeError, "Could not connect to Vae servers. Please check your Internet connection."
32
34
  end
33
35
  end
34
-
35
- end
36
+ end
@@ -1,45 +1,21 @@
1
- require 'rubygems'
2
-
3
- require 'cgi'
4
- require 'digest/md5'
5
- require 'json'
6
- require 'mongrel'
7
- require 'net/http'
8
- require 'net/https'
9
- require 'optparse'
10
- require 'thread'
11
- require 'webrick'
12
- require 'yaml'
13
-
14
- require 'directory_watcher'
15
- require 'highline/import'
16
- require 'compass'
17
- require 'haml'
18
-
19
- require 'logging'
20
- require 'servlet'
21
- require 'site'
22
- require 'vae_error'
23
- require 'vae_site_servlet'
24
- require 'vae_local_servlet'
25
- require 'version'
26
-
27
- SERVER_PARSED = [ ".html", ".haml", ".php", ".xml", ".rss", ".pdf.haml", ".pdf.haml.php", ".haml.php" ]
28
- SERVER_PARSED_GLOB = [ "**/*.html", "**/*.haml", "**/*.php", "**/*.xml", "**/*.rss", "**/*.pdf.haml", "**/*.pdf.haml.php", "**/*.haml.php" ]
29
- BANNER = "Vae local preview server, version #{VER}"
30
-
31
1
  class VaeLocal
32
-
33
- def fetch_from_vaeplatform(site, req)
34
- http = Net::HTTP.new("#{site}.vaeplatform.com", 443)
35
- http.use_ssl = true
2
+ BANNER = "Vae local preview server, version #{VER}"
3
+
4
+ def self.fetch_from_vaeplatform(site, req)
5
+ local = ENV['VAEPLATFORM_LOCAL']
6
+ http = Net::HTTP.new("#{site}." + (local ? "vaeplatform.dev" : "vaeplatform.com"), (local ? 80 : 443))
7
+ http.use_ssl = true unless local
36
8
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
9
  http.start { |http|
38
10
  http.read_timeout = 120
39
11
  http.request(req)
40
12
  }
41
13
  end
42
-
14
+
15
+ def self.port_open?(port)
16
+ !system("lsof -i:#{port}", out: '/dev/null')
17
+ end
18
+
43
19
  def get_svn_credentials(site)
44
20
  home = Dir.chdir { Dir.pwd }
45
21
  Dir.glob("#{home}/.subversion/auth/svn.simple/*").each do |file|
@@ -50,7 +26,7 @@ class VaeLocal
50
26
  end
51
27
  {}
52
28
  end
53
-
29
+
54
30
  def parse_svn_auth_file(file)
55
31
  key = nil
56
32
  mode = nil
@@ -73,18 +49,27 @@ class VaeLocal
73
49
  end
74
50
  params
75
51
  end
76
-
77
- def run!
78
- options = { :port => 9999 }
52
+
53
+ def run
54
+ options = { port: 9999, server: ProxyServer, log_level: "warning" }
55
+ loop {
56
+ break if VaeLocal.port_open?(options[:port])
57
+ options[:port] = options[:port] - 1
58
+ }
59
+
79
60
  ARGV.options do |opts|
80
- opts.banner = BANNER + "\n\nUsage: vae [options]\n starts a local development server\n vae [options] deploy\n promotes the source in Subversion repository to the FTP\n\n If you are using the Vae Production environment features:\n vae [options] stage\n promotes the source in Subversion repository to the staging environment\n vae [options] stagerelease\n promotes the source in Subversion repository to the staging environment\n and releases it to the production environment\n vae [options] release\n releases the current staging environment to the production environment\n vae [options] rollback\n rolls back the production environment to a previous release\n\nAvailable Options:"
81
- opts.on("-u","--username <username>","Your Vae username") { |o| options[:username] = o }
82
- opts.on("-p","--port <port number>","Start server on this port") { |o| options[:port] = o }
83
- opts.on("-r","--root <path to site root>","Path to the root of the local copy of your Vae site.") { |o| options[:site_root] = o }
84
- opts.on("-s","--site <subdomain>","Vae subdomain for this site") { |o| options[:site] = o }
61
+ opts.banner = BANNER + "\n\nUsage: vae [options]\n starts a local development server\n vae [options] deploy\n promotes the source in Git/Subversion repository to the FTP\n\n If you are using the Vae Production environment features:\n vae [options] stage\n promotes the source in Git/Subversion repository to the staging environment\n vae [options] stagerelease\n promotes the source in Git/Subversion repository to the staging environment\n and releases it to the production environment\n vae [options] release\n releases the current staging environment to the production environment\n vae [options] rollback\n rolls back the production environment to a previous release\n\nAvailable Options:"
62
+ opts.on("-u","--username <username>","Your Vae username") { |o| options[:username] = o }
63
+ opts.on("-p","--port <port number>","Start server on this port") { |o| options[:port] = o.to_i; raise VaeError "Port #{o.to_i} is already in use." unless VaeLocal.port_open?(o.to_i) }
64
+ opts.on("-r","--root <path to site root>","Path to the root of the local copy of your Vae site.") { |o| options[:site_root] = o }
65
+ opts.on("-s","--site <subdomain>","Vae subdomain for this site") { |o| options[:site] = o }
66
+ opts.on("-f","--full-stack","Run in Full Stack Mode (experimental)") { options[:server] = FullStack }
67
+ opts.on("-d","--data-path <path>","Where to Store Content and Image Data When In Full Stack Mode") { |o| options[:data_path] = o }
68
+ opts.on("-l","--log-level <level>","Vaedb Log Level (for Full Stack Mode)") { |o| options[:log_level] = o }
85
69
  opts.on_tail("-h","--help", "Show this help message") { puts opts; exit }
86
70
  opts.parse!
87
71
  end
72
+
88
73
  options[:site_root] = Dir.pwd if options[:site_root].nil? and (File.exists?("#{Dir.pwd}/__vae.yml") or File.exists?("#{Dir.pwd}/__verb.yml"))
89
74
  if options[:site_root]
90
75
  [ "verb", "vae" ].each do |name|
@@ -95,7 +80,9 @@ class VaeLocal
95
80
  end
96
81
  end
97
82
  end
83
+
98
84
  raise VaeError, "We could not determine the Vae subdomain for this site. Please specify it manually by using the --site option or create a __vae.yml file within the site root." if options[:site].nil?
85
+
99
86
  unless options[:username]
100
87
  svn_credentials = get_svn_credentials(options[:site])
101
88
  options[:username] = svn_credentials["username"]
@@ -103,53 +90,23 @@ class VaeLocal
103
90
  end
104
91
  raise VaeError, "We could not determine the Vae username that you use. Please specify it manually by using the --username option." if options[:username].nil?
105
92
  if options[:password].nil?
106
- options[:password] = ask("Please enter the Vae password for username #{options[:username]}:") {|q| q.echo = false}
93
+ options[:password] = ask("Please enter the Vae password for username #{options[:username]}:") { |q| q.echo = false }
107
94
  end
95
+
108
96
  if [ "deploy", "release", "rollback", "stage", "stagerelease" ].include?(ARGV.last)
109
97
  stagerelease(ARGV.last, options[:site], options[:username], options[:password])
110
98
  exit
111
99
  end
112
100
 
113
- # Move mongrel dependency here so not as required on Windows
114
-
115
101
  raise VaeError, "You did not specify the path to the root of the local copy of your Vae site. Please specify it manually by using the --root option or cd to the site root (and make sure it contains a __vae.yml file)." unless options[:site_root]
116
102
  raise VaeError, "You specified an invalid path to the local copy of your Vae site." unless File.exists?(options[:site_root])
117
103
 
118
- $biglock = Mutex.new
119
- dw = DirectoryWatcher.new options[:site_root], :interval => 1.0, :glob => SERVER_PARSED_GLOB, :pre_load => true, :logger => DirectoryWatcher::NullLogger.new
120
- dw.add_observer { |*args|
121
- args.each { |event|
122
- path = event.path.gsub($site.root, "")
123
- $biglock.synchronize {
124
- $changed[path] = event.type
125
- }
126
- }
127
- }
128
- dw.start
129
-
130
- set_mime_types
131
-
132
104
  Dir.chdir File.dirname(__FILE__)
133
105
  puts BANNER
134
- puts "Vae is in action at http://localhost:#{options[:port]}/"
135
- puts " (hit Control+C to exit)"
136
- $site = Site.new(:subdomain => options[:site], :root => options[:site_root], :username => options[:username], :password => options[:password])
137
- $cache = {}
138
- $changed = {}
139
- $server = Mongrel::Configurator.new :host => "0.0.0.0", :port => options[:port] do
140
- listener do
141
- uri "/", :handler => VaeSiteServlet.new
142
- #uri "/__welcome/", :handler => VaeLocalServlet.new
143
- end
144
- trap("INT") { raise Mongrel::StopServer }
145
- run
146
- end
147
106
 
148
- begin
149
- $server.join
150
- rescue Mongrel::StopServer
151
- puts "Thanks for using Vae!"
152
- end
107
+ site = Site.new(subdomain: options[:site], root: options[:site_root], username: options[:username], password: options[:password])
108
+ options[:server].new(site, options).run
109
+ puts "Thanks for using Vae!"
153
110
  end
154
111
 
155
112
  def show_job_status(res, site)
@@ -161,7 +118,7 @@ class VaeLocal
161
118
  loop do
162
119
  sleep 5
163
120
  req = Net::HTTP::Get.new("/api/local/v1/job_status/#{data['job']}")
164
- res = fetch_from_vaeplatform(site, req)
121
+ res = VaeLocal.fetch_from_vaeplatform(site, req)
165
122
  status = JSON.parse(res.body)
166
123
  if status['status'] == "completed"
167
124
  puts data['success']
@@ -175,11 +132,6 @@ class VaeLocal
175
132
  raise VaeError, "An unknown error occurred requesting this operation from Vae Platform. Please email support for help."
176
133
  end
177
134
 
178
- def set_mime_types
179
- WEBrick::HTTPUtils::DefaultMimeTypes.store 'js', 'application/javascript'
180
- WEBrick::HTTPUtils::DefaultMimeTypes.store 'svg', 'image/svg+xml'
181
- end
182
-
183
135
  def stagerelease(action, site, username, password)
184
136
  if action == "deploy"
185
137
  action = "stage"
@@ -190,18 +142,17 @@ class VaeLocal
190
142
  end
191
143
  req = Net::HTTP::Post.new("/api/local/v1/#{action}")
192
144
  req.body = "username=#{CGI.escape(username)}&password=#{CGI.escape(password)}&vae_local=1"
193
- res = fetch_from_vaeplatform(site, req)
145
+ res = VaeLocal.fetch_from_vaeplatform(site, req)
194
146
  if res.is_a?(Net::HTTPFound)
195
147
  raise VaeError, "Invalid username/password or insufficient permissions."
196
148
  else
197
149
  show_job_status(res, site)
198
150
  end
199
151
  end
200
-
201
- def self.run_trapping_exceptions!
152
+
153
+ def self.run_trapping_exceptions
202
154
  begin
203
- v = VaeLocal.new
204
- v.run!
155
+ new.run
205
156
  rescue VaeError => e
206
157
  cmd = $0
207
158
  cmd = "vae" if cmd =~ /\.\.\/vae_local/
@@ -210,5 +161,4 @@ class VaeLocal
210
161
  puts "Type #{cmd} --help for help."
211
162
  end
212
163
  end
213
-
214
164
  end
@@ -1,24 +1,43 @@
1
- class VaeSiteServlet < Servlet
2
-
1
+ class VaeSiteServlet < Servlet
2
+ SERVER_PARSED = [ ".html", ".haml", ".php", ".xml", ".rss", ".pdf.haml", ".pdf.haml.php", ".haml.php" ]
3
+
4
+ def initialize(site)
5
+ @cache = {}
6
+ @changed = {}
7
+ @lock = Mutex.new
8
+ @site = site
9
+
10
+ dw = DirectoryWatcher.new @site.root, interval: 1.0, glob: SERVER_PARSED.map { |ext| "**/*#{ext}" }, pre_load: true, logger: DirectoryWatcher::NullLogger.new
11
+ dw.add_observer { |*args|
12
+ args.each { |event|
13
+ path = event.path.gsub(@site.root, "")
14
+ @lock.synchronize {
15
+ @changed[path] = event.type
16
+ }
17
+ }
18
+ }
19
+ dw.start
20
+ end
21
+
3
22
  def bundle_changed_source_files(source_files)
4
23
  source_files ||= []
5
24
  changed = nil
6
- $biglock.synchronize {
7
- changed = $changed
8
- $changed = {}
25
+ @lock.synchronize {
26
+ changed = @changed
27
+ @changed = {}
9
28
  }
10
29
  source_files.concat(changed.map { |filename,action|
11
30
  get_source_file(filename, (action == :deleted))
12
31
  }).reject { |src| src.nil? }
13
32
  end
14
-
33
+
15
34
  def get_source_file(path, optional = false)
16
35
  full_path = nil
17
- if File.exists?($site.root + path)
36
+ if File.exists?(@site.root + path)
18
37
  full_path = path
19
38
  else
20
39
  SERVER_PARSED.each do |ext|
21
- if full_path.nil? and File.exists?($site.root + path + ext)
40
+ if full_path.nil? and File.exists?(@site.root + path + ext)
22
41
  full_path = path + ext
23
42
  end
24
43
  end
@@ -27,7 +46,7 @@ class VaeSiteServlet < Servlet
27
46
  raise FileNotFound
28
47
  elsif full_path
29
48
  begin
30
- file = File.read($site.root + full_path)
49
+ file = File.read(@site.root + full_path)
31
50
  md5 = Digest::MD5.hexdigest(file)
32
51
  rescue Errno::EISDIR
33
52
  return nil
@@ -37,16 +56,16 @@ class VaeSiteServlet < Servlet
37
56
  md5 = ""
38
57
  file = ""
39
58
  end
40
- if $cache[full_path] != md5
41
- $cache[full_path] = md5
59
+ if @cache[full_path] != md5
60
+ @cache[full_path] = md5
42
61
  [ full_path, file ]
43
62
  else
44
63
  nil
45
64
  end
46
65
  end
47
-
66
+
48
67
  def fetch_from_vae(wb_req, method, source_files = nil)
49
- uri = wb_req.params["REQUEST_URI"] + ((wb_req.params["REQUEST_URI"] =~ /\?/) ? "&" : "?") + "__vae_local=#{$site.session_id}"
68
+ uri = wb_req.params["REQUEST_URI"] + ((wb_req.params["REQUEST_URI"] =~ /\?/) ? "&" : "?") + "__vae_local=#{@site.session_id}"
50
69
  source_files = bundle_changed_source_files(source_files)
51
70
  if method == "GET"
52
71
  if source_files.is_a?(Array) and source_files.size > 0
@@ -68,31 +87,31 @@ class VaeSiteServlet < Servlet
68
87
  if wb_req.params['HTTP_X_REQUESTED_WITH']
69
88
  req['X-Requested-With'] = req_404['X-Requested-With'] = wb_req.params['HTTP_X_REQUESTED_WITH']
70
89
  end
71
- res = $site.fetch_from_server(req)
90
+ res = @site.fetch_from_server(req)
72
91
  if res.body =~ /__vae_local_needs=(.*)/
73
92
  begin
74
93
  return fetch_from_vae(wb_req, method, [ get_source_file($1) ])
75
94
  rescue FileNotFound
76
95
  puts "* Could not find requested file: #{$1}"
77
- return $site.fetch_from_server(req_404)
96
+ return @site.fetch_from_server(req_404)
78
97
  end
79
98
  end
80
99
  res
81
100
  end
82
-
101
+
83
102
  def fetch_from_vae_and_include_source_of_current_page(req, method)
84
103
  fetch_from_vae(req, method, [ find_source_file_from_path(req.params["REQUEST_URI"]), get_source_file("/__vae.php", true), get_source_file("/__verb.php", true) ])
85
104
  end
86
-
105
+
87
106
  def find_source_file_from_path(path)
88
107
  path_parts = path.split("/").reject { |part| part.length < 1 }
89
108
  local_path = ""
90
- loop do
109
+ loop do
91
110
  gotit = false
92
111
  if part = path_parts.shift
93
112
  new_local_path = local_path + "/" + part
94
113
  (SERVER_PARSED + [ "" ]).each do |ext|
95
- if File.exists?($site.root + new_local_path + ext)
114
+ if File.exists?(@site.root + new_local_path + ext)
96
115
  gotit = true
97
116
  local_path = new_local_path + ext
98
117
  end
@@ -103,22 +122,22 @@ class VaeSiteServlet < Servlet
103
122
  return nil unless local_path.length > 0
104
123
  get_source_file(local_path)
105
124
  end
106
-
125
+
107
126
  def get_line_from_sass_exception(exception)
108
127
  return exception.message.scan(/:(\d+)/).first.first if exception.is_a?(::SyntaxError)
109
128
  exception.backtrace[0].scan(/:(\d+)/).first.first
110
- end
129
+ end
111
130
 
112
131
  def not_modified?(req, res, mtime, etag)
113
132
  return true if (ims = req.params['IF_MODIFIED_SINCE']) && Time.parse(ims) >= mtime
114
133
  return true if (inm = req.params['IF_NONE_MATCH']) && WEBrick::HTTPUtils::split_header_value(inm).member?(etag)
115
134
  false
116
135
  end
117
-
136
+
118
137
  def render_sass(local_path)
119
138
  begin
120
139
  options = Compass.sass_engine_options
121
- options[:load_paths] << File.dirname(local_path)
140
+ options[:load_paths] << File.dirname(local_path)
122
141
  options[:syntax] = :scss if local_path =~ /\.scss$/
123
142
  engine = Sass::Engine.new(open(local_path, "rb").read, options)
124
143
  engine.render
@@ -132,10 +151,10 @@ class VaeSiteServlet < Servlet
132
151
  serve(request, response)
133
152
  response.finished
134
153
  end
135
-
154
+
136
155
  def serve(req, res)
137
156
  res.status = 200
138
- local_path = ($site.root+req.params["REQUEST_URI"] || "/").split("?").first
157
+ local_path = (@site.root+req.params["REQUEST_URI"] || "/").split("?").first
139
158
  if File.exists?(local_path) and !File.directory?(local_path) and !server_parsed?(local_path)
140
159
  st = File::stat(local_path)
141
160
  mtime = st.mtime
@@ -158,7 +177,7 @@ class VaeSiteServlet < Servlet
158
177
  end
159
178
  else
160
179
  if req.params["REQUEST_URI"] =~ /^\/__data\// or req.params["REQUEST_URI"] =~ /^\/__assets\//
161
- from_vae = { 'location' => "http://#{$site.subdomain}.vaesite.com#{req.params["REQUEST_URI"]}"}
180
+ from_vae = { 'location' => "http://#{@site.subdomain}.vaesite.com#{req.params["REQUEST_URI"]}"}
162
181
  puts "#{req.params["REQUEST_URI"]} static asset"
163
182
  else
164
183
  from_vae = fetch_from_vae_and_include_source_of_current_page(req, req.params["REQUEST_METHOD"])
@@ -169,7 +188,7 @@ class VaeSiteServlet < Servlet
169
188
  if from_vae['location']
170
189
  res.body << "<p>Redirecting to <a href=\"#{from_vae['location']}\">#{from_vae['location']}</a>"
171
190
  res.status = 302
172
- res.header['Location'] = from_vae['location']
191
+ res.header['Location'] = from_vae['location']
173
192
  else
174
193
  res.header['Etag'] = from_vae['etag']
175
194
  res.header['Last-Modified'] = from_vae['last-modified']
@@ -185,13 +204,11 @@ class VaeSiteServlet < Servlet
185
204
  def req_scss?(req)
186
205
  req.params["REQUEST_URI"] =~ /\.(sass|scss)$/
187
206
  end
188
-
207
+
189
208
  def server_parsed?(path)
190
209
  SERVER_PARSED.each do |ext|
191
210
  return true if Regexp.new("#{ext}$").match(path)
192
211
  end
193
212
  false
194
213
  end
195
-
196
214
  end
197
-
@@ -1 +1 @@
1
- VER = "0.6.10"
1
+ VER = "0.7.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.10
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Action Verb, LLC
@@ -9,92 +9,120 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-05 00:00:00.000000000 Z
12
+ date: 2016-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '1'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: compass
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '='
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.11.5
34
+ version: '1'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '='
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.11.5
41
+ version: '1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: directory_watcher
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '1'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '1'
56
56
  - !ruby/object:Gem::Dependency
57
- name: haml
57
+ name: github-pages
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: 3.1.2
62
+ version: '87'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 3.1.2
69
+ version: '87'
70
+ - !ruby/object:Gem::Dependency
71
+ name: haml
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '4'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '4'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: highline
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - ">="
88
+ - - "~>"
75
89
  - !ruby/object:Gem::Version
76
- version: '0'
90
+ version: '1'
77
91
  type: :runtime
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - ">="
95
+ - - "~>"
82
96
  - !ruby/object:Gem::Version
83
- version: '0'
97
+ version: '1'
98
+ - !ruby/object:Gem::Dependency
99
+ name: jekyll-multiple-languages-plugin
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.4'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.4'
84
112
  - !ruby/object:Gem::Dependency
85
113
  name: json
86
114
  requirement: !ruby/object:Gem::Requirement
87
115
  requirements:
88
- - - ">="
116
+ - - "~>"
89
117
  - !ruby/object:Gem::Version
90
- version: '0'
118
+ version: '1'
91
119
  type: :runtime
92
120
  prerelease: false
93
121
  version_requirements: !ruby/object:Gem::Requirement
94
122
  requirements:
95
- - - ">="
123
+ - - "~>"
96
124
  - !ruby/object:Gem::Version
97
- version: '0'
125
+ version: '1'
98
126
  - !ruby/object:Gem::Dependency
99
127
  name: mongrel
100
128
  requirement: !ruby/object:Gem::Requirement
@@ -109,20 +137,34 @@ dependencies:
109
137
  - - '='
110
138
  - !ruby/object:Gem::Version
111
139
  version: 1.2.0.pre2
140
+ - !ruby/object:Gem::Dependency
141
+ name: ptools
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '1'
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '1'
112
154
  - !ruby/object:Gem::Dependency
113
155
  name: sass
114
156
  requirement: !ruby/object:Gem::Requirement
115
157
  requirements:
116
- - - '='
158
+ - - "~>"
117
159
  - !ruby/object:Gem::Version
118
- version: 3.2.10
160
+ version: '3.4'
119
161
  type: :runtime
120
162
  prerelease: false
121
163
  version_requirements: !ruby/object:Gem::Requirement
122
164
  requirements:
123
- - - '='
165
+ - - "~>"
124
166
  - !ruby/object:Gem::Version
125
- version: 3.2.10
167
+ version: '3.4'
126
168
  description: Supports local development for Vae Platform (http://vaeplatform.com/)
127
169
  email: support@actionverb.com
128
170
  executables:
@@ -131,18 +173,19 @@ extensions: []
131
173
  extra_rdoc_files: []
132
174
  files:
133
175
  - bin/vae
176
+ - lib/full_stack.rb
134
177
  - lib/logging.rb
178
+ - lib/proxy_server.rb
135
179
  - lib/servlet.rb
136
180
  - lib/site.rb
137
- - lib/vae.rb
138
181
  - lib/vae_error.rb
139
- - lib/vae_local_servlet.rb
182
+ - lib/vae_local.rb
140
183
  - lib/vae_site_servlet.rb
141
184
  - lib/version.rb
142
185
  - test/vae_test.rb
143
186
  homepage: http://docs.vaeplatform.com/vae_local
144
187
  licenses:
145
- - GPL
188
+ - GPL-3.0
146
189
  metadata: {}
147
190
  post_install_message:
148
191
  rdoc_options: []
@@ -160,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
203
  version: '0'
161
204
  requirements: []
162
205
  rubyforge_project:
163
- rubygems_version: 2.4.8
206
+ rubygems_version: 2.5.1
164
207
  signing_key:
165
208
  specification_version: 4
166
209
  summary: This gem allows for local development for sites on Vae Platform (http://vaeplatform.com/)
@@ -1,3 +0,0 @@
1
- class VaeLocalServlet < Servlet
2
- end
3
-