fusion 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/fusion.rb +87 -7
  2. metadata +6 -6
@@ -12,9 +12,12 @@ module Fusion
12
12
  @options ||= {}
13
13
  @options.update(options)
14
14
 
15
- raise Exception("Configuration error -- must specify #{:bundle_file_path} when configuring Fusion javascript bundler") if @options[:bundle_file_path].nil?
15
+ if @options[:bundle_file_path].nil? && @options[:bundle_configs].nil?
16
+ raise Exception("Configuration error -- must specify #{:bundle_file_path} when configuring Fusion javascript bundler")
17
+ end
16
18
 
17
- @options[:project_path] = File.join(@options[:bundle_file_path].split("/")[0..-2])
19
+ @options[:project_path] = File.join(@options[:bundle_file_path].split("/")[0..-2]) if @options[:bundle_file_path]
20
+
18
21
  end
19
22
 
20
23
  # So that the bundler can be configured and run in two different places ... like Sass
@@ -26,17 +29,24 @@ module Fusion
26
29
  @bundle_options = Fusion.instance_variable_get('@options')
27
30
  @log = @bundle_options[:logger] || Logger.new(STDOUT)
28
31
 
29
- @bundle_configs = YAML::load(File.open(@bundle_options[:bundle_file_path]))
32
+ if @bundle_options[:bundle_configs]
33
+ @bundle_configs = @bundle_options[:bundle_configs]
34
+ else
35
+ @bundle_configs = YAML::load(File.open(@bundle_options[:bundle_file_path]))
36
+ end
37
+
30
38
  end
31
39
 
32
40
  def run
33
41
  start = Time.now
34
42
 
35
- @bundle_configs.each do |config|
43
+ bundles = @bundle_configs.collect do |config|
36
44
  bundle(config)
37
45
  end
38
46
 
39
47
  @log.debug "Javascript Reloaded #{@bundle_configs.size} bundle(s) (#{Time.now - start}s)"
48
+
49
+ bundles
40
50
  end
41
51
 
42
52
  def gather_files(config)
@@ -46,7 +56,13 @@ module Fusion
46
56
  config[:input_files].each do |input_file|
47
57
  if (input_file =~ URI::regexp).nil?
48
58
  # Not a URL
49
- input_files << File.join(@bundle_options[:project_path], input_file)
59
+ file_path = input_file
60
+
61
+ unless input_file == File.absolute_path(input_file)
62
+ file_path = File.join(@bundle_options[:project_path], input_file)
63
+ end
64
+
65
+ input_files << file_path
50
66
  else
51
67
  # This is a remote file, if we don't have it, get it
52
68
  input_files << get_remote_file(input_file)
@@ -75,7 +91,15 @@ module Fusion
75
91
 
76
92
  def get_output_file(config)
77
93
  raise Exception.new("Undefined js bundler output file") if config[:output_file].nil?
78
- File.join(@bundle_options[:project_path], config[:output_file])
94
+ output_file = File.join(@bundle_options[:project_path], config[:output_file])
95
+ path_directories = output_file.split("/")
96
+
97
+ if path_directories.size > 1
98
+ path = File.join(File.expand_path("."), path_directories[0..-2].join("/"))
99
+ FileUtils::mkpath(File.join(path,"/"))
100
+ end
101
+
102
+ output_file
79
103
  end
80
104
 
81
105
  def get_remote_file(url)
@@ -110,7 +134,6 @@ module Fusion
110
134
 
111
135
  def bundle(config)
112
136
  js = []
113
-
114
137
  input_files = gather_files(config)
115
138
 
116
139
  input_files.each do |input_file|
@@ -120,6 +143,8 @@ module Fusion
120
143
  js = js.join("\n")
121
144
 
122
145
  File.open(get_output_file(config), "w") { |f| f << js }
146
+
147
+ js
123
148
  end
124
149
 
125
150
  end
@@ -151,4 +176,59 @@ module Fusion
151
176
 
152
177
  end
153
178
 
179
+ class DebugOptimized < Optimized
180
+ def gather_files(config)
181
+ @log.debug "Warning ... using Debug compiler."
182
+ input_files = []
183
+
184
+ if(config[:input_files])
185
+ config[:input_files].each do |input_file|
186
+ @log.debug "Remote file? #{!(input_file =~ URI::regexp).nil?}"
187
+
188
+ if (input_file =~ URI::regexp).nil?
189
+ # Not a URL
190
+ input_files << File.join(@bundle_options[:project_path], input_file)
191
+ else
192
+ # This is a remote file, if we don't have it, get it
193
+ input_files << get_remote_file(input_file)
194
+ end
195
+ end
196
+ end
197
+
198
+ if (config[:input_directory])
199
+ directory = File.join(@bundle_options[:project_path],config[:input_directory])
200
+
201
+ file_names = Dir.open(directory).entries.sort.find_all {|filename| filename.end_with?(".js") }
202
+
203
+ input_files += file_names.collect do |file_name|
204
+ File.join(directory, file_name)
205
+ end
206
+ end
207
+
208
+ input_files.uniq!
209
+
210
+ # Now wrap each file in a try/catch block and update the input_files list
211
+
212
+ FileUtils::mkpath(File.join(@bundle_options[:project_path],".debug"))
213
+
214
+ input_files.collect do |input_file|
215
+ contents = File.open(input_file).read
216
+ new_input_file =""
217
+ file_name = input_file.split("/").last
218
+
219
+ if input_file.include?(".remote")
220
+ new_input_file = input_file.gsub(".remote",".debug")
221
+ else
222
+ new_input_file = File.join(@bundle_options[:project_path], ".debug", file_name)
223
+ end
224
+
225
+ new_contents = "///////////////////\n//mw_bundle: #{input_file}\n///////////////////\n\n try{\n#{contents}\n}catch(e){\nconsole.log('Error (' + e + 'generated in : #{input_file}');\n}"
226
+ File.open(new_input_file,"w") {|f| f << new_contents}
227
+
228
+ new_input_file
229
+ end
230
+
231
+ end
232
+ end
233
+
154
234
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-30 00:00:00.000000000Z
12
+ date: 2011-10-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: open4
16
- requirement: &2152851700 !ruby/object:Gem::Requirement
16
+ requirement: &2153789700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152851700
24
+ version_requirements: *2153789700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mechanize
27
- requirement: &2152851260 !ruby/object:Gem::Requirement
27
+ requirement: &2153789260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152851260
35
+ version_requirements: *2153789260
36
36
  description: Fusion bundles and re-bundles your javascript in two modes - quick (dumb
37
37
  concatenation) and optimized (google closure compiler's SIMPLE_OPTIMIZATIONS level
38
38
  email: