fxos_rails 1.1.0 → 1.2.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 +4 -4
- data/MIT-LICENSE +1 -1
- data/lib/fxos_rails/manifest.rb +1 -1
- data/lib/fxos_rails/packager.rb +100 -15
- data/lib/fxos_rails/version.rb +1 -1
- data/lib/tasks/fxos_tasks.rake +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20e89d5597fc110f3b7477b65320d0d4a5ff0947
|
4
|
+
data.tar.gz: f98e45f059f9d5cee05aba5b774c9ecaeb85639c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f4570aac31eebc8d7ac85ed23cad648243096300fd3c56842d10b6960c97d9b4b4a47a8fc881dc66cd4167dadd707a6e7d54667113ead54abfb2dae736afdfe
|
7
|
+
data.tar.gz: 3274598cb3ecb33fba71cc4cb4cfa13e70f35cb8868d2cb7d553f560e3fa11dcd49f6e8eae8d1e2fe6f0f61b68aab3a278997efc6d5f205ac01144abcc87cab7
|
data/MIT-LICENSE
CHANGED
data/lib/fxos_rails/manifest.rb
CHANGED
data/lib/fxos_rails/packager.rb
CHANGED
@@ -3,33 +3,56 @@ require 'nokogiri'
|
|
3
3
|
module FxosRails
|
4
4
|
class Packager
|
5
5
|
|
6
|
+
class Error < StandardError; end
|
7
|
+
class DownloadError < Error; end
|
8
|
+
class BuildError < Error; end
|
9
|
+
|
10
|
+
def clean!
|
11
|
+
system <<-SHELL
|
12
|
+
rm -rf #{tmp_path}/#{app_host} &&
|
13
|
+
rm -rf public/assets
|
14
|
+
SHELL
|
15
|
+
end
|
16
|
+
|
6
17
|
def package!
|
18
|
+
check_environment_exists!
|
7
19
|
precompile
|
8
20
|
with_local_build_server do
|
9
21
|
download
|
10
22
|
end
|
23
|
+
check_download_success!
|
11
24
|
unify_js
|
12
25
|
add_manifest
|
13
26
|
put_files_in_package
|
27
|
+
rescue Error
|
28
|
+
puts $!.message
|
14
29
|
end
|
15
30
|
|
16
31
|
|
17
32
|
private
|
18
33
|
|
34
|
+
def build_env
|
35
|
+
'build'
|
36
|
+
end
|
37
|
+
|
38
|
+
def ip
|
39
|
+
'127.0.0.1'
|
40
|
+
end
|
41
|
+
|
19
42
|
def port
|
20
43
|
3001
|
21
44
|
end
|
22
45
|
|
23
46
|
def with_local_build_server
|
24
47
|
app_url = "http://#{app_host}/#{launch_path}"
|
25
|
-
|
48
|
+
run %{DISABLE_SPRING=1 ./bin/rails server -e #{build_env} -p #{port} -b #{ip} -d}
|
26
49
|
yield(app_url)
|
27
50
|
ensure
|
28
|
-
|
51
|
+
run %{kill -TERM `cat tmp/pids/server.pid`}
|
29
52
|
end
|
30
53
|
|
31
54
|
def app_host
|
32
|
-
"
|
55
|
+
"#{ip}:#{port}"
|
33
56
|
end
|
34
57
|
|
35
58
|
def add_manifest
|
@@ -40,27 +63,74 @@ module FxosRails
|
|
40
63
|
def put_files_in_package
|
41
64
|
puts "Packaging..."
|
42
65
|
package_path = local_app_path.join(package_filename)
|
43
|
-
|
44
|
-
cd #{local_app_path} &&
|
45
|
-
zip #{package_path} -r .
|
46
|
-
SHELL
|
66
|
+
run %{cd #{local_app_path} && zip #{package_path} -r .}
|
47
67
|
puts "Done. The package is now at #{package_path}"
|
48
68
|
end
|
49
69
|
|
50
70
|
def precompile
|
51
|
-
|
71
|
+
run %{RAILS_ENV=#{build_env} ./bin/rake assets:precompile}
|
72
|
+
end
|
73
|
+
|
74
|
+
def check_download_success!
|
75
|
+
return unless download_errors.present?
|
76
|
+
bullet = ' * '
|
77
|
+
errors_list = bullet + download_errors.join("\n" + bullet)
|
78
|
+
msg = <<-EOM
|
79
|
+
ERROR: failed to grab some application files. Common causes include:
|
80
|
+
* Your app cannot be accessed at #{launch_path}
|
81
|
+
* Your app doesn't work locally when using the `#{build_env}` environment. For example, it could be missing a `#{build_env}` entry on `config/database.yml`
|
82
|
+
* Your app doesn't serve static files. Ensure the setting `config.serve_static_assets = true` on `config/environments/#{build_env}.rb`
|
83
|
+
* Some third-party assets are not being precompiled. This can happen with assets from gems. Ensure they are listed in the setting `config.assets.precompile` on `config/application.rb`
|
84
|
+
|
85
|
+
Specifically, the following URLs returned errors:
|
86
|
+
#{errors_list}
|
87
|
+
EOM
|
88
|
+
raise DownloadError, msg
|
89
|
+
end
|
90
|
+
|
91
|
+
def environment_config_path
|
92
|
+
Rails.root.join('config', 'environments', "#{build_env}.rb")
|
93
|
+
end
|
94
|
+
|
95
|
+
def check_environment_exists!
|
96
|
+
return if Rails.root.join(environment_config_path).exist?
|
97
|
+
msg = <<-EOM
|
98
|
+
The build process requires a `#{build_env}` environment. Please create it at #{environment_config_path}. You can simply follow these steps:
|
99
|
+
1. Copy the production environment from config/environments/production.rb
|
100
|
+
2. Edit the file to ensure the setting `config.serve_static_assets = true`
|
101
|
+
3. Done!
|
102
|
+
EOM
|
103
|
+
raise BuildError, msg
|
52
104
|
end
|
53
105
|
|
54
106
|
def download
|
55
|
-
|
56
|
-
cd #{tmp_path} &&
|
57
|
-
rm -rf #{app_host} &&
|
58
|
-
wget -r #{launch_url}
|
59
|
-
SHELL
|
107
|
+
run %{cd #{tmp_path} && wget -nv -o #{wget_log_path} -r #{launch_url}}
|
60
108
|
remove_query_strings
|
61
109
|
add_icons
|
62
110
|
end
|
63
111
|
|
112
|
+
def download_errors
|
113
|
+
@download_errors ||= begin
|
114
|
+
last_url = nil
|
115
|
+
url_re = %r{\b(https?://[^ ]+):}
|
116
|
+
timestamp_re = %r{\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d}
|
117
|
+
error_re = %r{#{timestamp_re} ERROR}
|
118
|
+
errors = []
|
119
|
+
wget_log_path.open.each_line do |line|
|
120
|
+
if url_re =~ line
|
121
|
+
last_url = $~[1]
|
122
|
+
elsif error_re =~ line
|
123
|
+
errors << last_url
|
124
|
+
end
|
125
|
+
end
|
126
|
+
errors.reject{|url| url =~ %r{/robots.txt$} }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def download_successful?
|
131
|
+
download_errors.blank?
|
132
|
+
end
|
133
|
+
|
64
134
|
def remove_query_strings
|
65
135
|
Dir[local_app_path + '**' + '*'].each do |path|
|
66
136
|
if path['?']
|
@@ -71,7 +141,9 @@ module FxosRails
|
|
71
141
|
|
72
142
|
def add_icons
|
73
143
|
icons_path = Rails.root.join(*%w{app assets images icons})
|
74
|
-
|
144
|
+
if icons_path.exist?
|
145
|
+
FileUtils.cp_r(icons_path, local_app_path)
|
146
|
+
end
|
75
147
|
end
|
76
148
|
|
77
149
|
def unify_js
|
@@ -80,6 +152,10 @@ module FxosRails
|
|
80
152
|
File.open(local_launch_path, 'r+') do |f|
|
81
153
|
doc = Nokogiri::HTML(f)
|
82
154
|
doc.css('script').each do |node|
|
155
|
+
type = node['type']
|
156
|
+
if type.present? && type != 'text/javascript'
|
157
|
+
next
|
158
|
+
end
|
83
159
|
if src = node['src']
|
84
160
|
src.gsub!(%r{^/}, '')
|
85
161
|
full_path = local_app_path.join(src)
|
@@ -110,7 +186,7 @@ module FxosRails
|
|
110
186
|
end
|
111
187
|
|
112
188
|
def launch_url
|
113
|
-
app_host + '/' + launch_path
|
189
|
+
'http://' + app_host + '/' + launch_path
|
114
190
|
end
|
115
191
|
|
116
192
|
def launch_path
|
@@ -125,5 +201,14 @@ module FxosRails
|
|
125
201
|
local_app_path + launch_path
|
126
202
|
end
|
127
203
|
|
204
|
+
def run(command)
|
205
|
+
puts "*** #{command}"
|
206
|
+
system(command)
|
207
|
+
end
|
208
|
+
|
209
|
+
def wget_log_path
|
210
|
+
tmp_path.join('wget.log')
|
211
|
+
end
|
212
|
+
|
128
213
|
end
|
129
214
|
end
|
data/lib/fxos_rails/version.rb
CHANGED
data/lib/tasks/fxos_tasks.rake
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
+
require 'fxos_rails/packager'
|
2
|
+
|
1
3
|
namespace :fxos do
|
2
4
|
desc "Delete files created by the build process"
|
3
5
|
task :clean do
|
4
|
-
|
5
|
-
rm -rf tmp/package &&
|
6
|
-
rm -rf public/assets
|
7
|
-
SHELL
|
6
|
+
FxosRails::Packager.new.clean!
|
8
7
|
end
|
9
8
|
|
10
9
|
desc "Build your app's package"
|
11
10
|
task build: %w{clean environment} do
|
12
|
-
require 'fxos_rails/packager'
|
13
11
|
FxosRails::Packager.new.package!
|
14
12
|
end
|
15
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fxos_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Brasero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|