ichiban 1.2.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a67d27e89bd72f4afd96687d4bdd0497433fc4c4
4
- data.tar.gz: 725e54db4c392ce2437c7499aa6674733f7abbf5
3
+ metadata.gz: 5e9455b270799fb2c632f4457bd396e623c4d235
4
+ data.tar.gz: dd03bed5cdb8bd51bb2f21b0184dc31738d7a9c0
5
5
  SHA512:
6
- metadata.gz: b95a07d33bb48d4c6f8b36272d011c661e5253dc578935573fade28f8dc28f26784fe5da7ace00b3cb369942e9c38cbbacd8c94369c24bb760e2cc383ae7efeb
7
- data.tar.gz: ec539fd3c4224f33112b85fdff5efe33d4e535d58c53783a6f9dfae15f7055e5e3aa25b2345e96b788bf45a8ef03df725286da3c3eebeede684e644d6da24e18
6
+ metadata.gz: 4c7f3a21eb7899774c9f0739e7176771085e5d63d8c41936c46494487dae5f7347a9bd160fdbe6e2e91fd4608a516a611c392b8fbe41c5f10a3ff13bd979dca2
7
+ data.tar.gz: 4a2c29534e6ce1bc8fbe780f6af53f1f891e6411a94dc87539267f28aa1c2e60d065a7a8ddf999743ad495570131aa6b0c5c4d8e19bc943c56ddc4a45cd8a11a
@@ -1,44 +1,70 @@
1
1
  module Ichiban
2
- # This class uses source_map and uglifier to concatenate, minify, and source-map JS files.
2
+ # This class uses the UglifyJS2 binary to concatenate and minify JS source files.
3
3
  class JSCompiler
4
4
  def compile
5
5
  rel = @file.rel_to 'assets/js'
6
6
  Ichiban.config.js_manifests.each do |dest, sources|
7
7
  if sources.include? rel
8
- # Make the source paths absolute.
9
- sources = sources.map do |source|
10
- abs = File.join Ichiban.project_root, 'assets/js', source
11
- unless File.exists? abs
12
- raise "Something's wrong with Ichiban.config.js_manifests. JS source file does not exist: #{abs.inspect}"
13
- end
14
- abs
8
+ # Make the destination folder if necessary.
9
+ dest_folder = File.expand_path(File.join(
10
+ Ichiban.project_root, 'compiled', 'js',
11
+ File.dirname(dest)
12
+ ))
13
+ unless File.exists? dest_folder
14
+ FileUtils.mkdir_p dest_folder
15
15
  end
16
16
 
17
- # Make two code strings. The first contains the minified JS. The second
18
- # contains the source map.
19
- js, map = compile_paths(
20
- sources,
21
- File.join(Ichiban.config.relative_url_root, 'js'),
22
- dest,
23
- dest + '.map'
24
- )
17
+ # Build the name of the source map.
18
+ map_name = File.basename(dest, File.extname(dest)) + '.js.map'
25
19
 
26
- # Make sure the JS folder exists.
27
- FileUtils.mkdir_p File.join(Ichiban.project_root, 'compiled/js')
20
+ # Shell out to UglifyJS2.
21
+ uglify_stdout = `
22
+ cd #{File.join(Ichiban.project_root, 'assets', 'js')} && \
23
+ uglifyjs \
24
+ #{sources.join(' ')} \
25
+ --output #{File.join(Ichiban.project_root, 'compiled', 'js', dest)} \
26
+ --source-map #{map_name} \
27
+ --source-map-url /js/#{map_name} \
28
+ --source-map-root /js \
29
+ 2>&1 # Redirect STDERR to STDOUT.
30
+ `
31
+ unless $?.success?
32
+ raise UglifyError, "uglifyjs command failed:\n\n#{uglify_stdout}"
33
+ end
28
34
 
29
- # Write the minified JS.
30
- compiled_js_path = File.join(Ichiban.project_root, 'compiled/js', dest)
31
- File.open(compiled_js_path, 'w') do |f|
32
- f << js
35
+ # Uglify populates the source map's "file" property with the absolute path.
36
+ # Replace it with the filename.
37
+ map_path = File.join Ichiban.project_root, 'assets', 'js', map_name
38
+ map_json = JSON.parse(File.read(map_path))
39
+ File.open map_path, 'w' do |f|
40
+ f << JSON.dump(map_json.merge('file' => dest))
33
41
  end
34
42
 
35
- # Write the source map.
36
- File.open(File.join(Ichiban.project_root, 'compiled/js', dest + '.map'), 'w') do |f|
37
- f << map
43
+ # Uglify writes the source map in assets/js.
44
+ # Move it into compiled/js.
45
+ FileUtils.mv(
46
+ File.join(Ichiban.project_root, 'assets', 'js', map_name),
47
+ File.join(Ichiban.project_root, 'compiled', 'js')
48
+ )
49
+
50
+ # Copy each of the source files into compiled/js so that JS debuggers
51
+ # can use them with the source map.
52
+ sources.each do |filename|
53
+ folder = File.expand_path(File.join(
54
+ Ichiban.project_root, 'compiled', 'js',
55
+ File.dirname(filename)
56
+ ))
57
+ unless File.exists? folder
58
+ FileUtils.mkdir_p folder
59
+ end
60
+ FileUtils.cp(
61
+ File.join(Ichiban.project_root, 'assets', 'js', filename),
62
+ File.join(Ichiban.project_root, 'compiled', 'js')
63
+ )
38
64
  end
39
65
 
40
66
  # Log the compilation of the JS file, but don't log the compilation of the map.
41
- Ichiban.logger.compilation(@file.abs, compiled_js_path)
67
+ Ichiban.logger.compilation(@file.abs, dest)
42
68
  end
43
69
  end
44
70
  end
@@ -50,40 +76,47 @@ module Ichiban
50
76
  private
51
77
 
52
78
  # Pass in absolute source_paths.
53
- def compile_paths(source_paths, source_root, js_filename, map_filename)
54
- js, map = concat(
55
- source_paths.map { |p| [File.read(p), File.basename(p)] },
56
- source_root
57
- )
58
-
59
- js, map = uglify js, map, js_filename
60
-
61
- map_url = File.join Ichiban.config.relative_url_root, 'js', map_filename
62
- js << "\n//# sourceMappingURL=#{map_url}"
63
-
64
- [js, map]
65
- end
79
+ #def compile_paths(source_paths, source_root, js_filename, map_filename)
80
+ # # The Uglify gem, unlike UglifyJS2, doesn't support concatenation as of August 2015.
81
+ # # Thus, before we call Uglify, we have to concatenate ourselves. We also generate an
82
+ # # intermediate source map for the concatenated JS. Uglify will use the intermediate
83
+ # # source map when it creates its own source map.
84
+ # js, map = concat(
85
+ # source_paths.map { |p| [File.read(p), File.basename(p)] },
86
+ # source_root
87
+ # )
88
+ #
89
+ # js, map = uglify js, map, js_filename
90
+ #
91
+ # map_url = File.join Ichiban.config.relative_url_root, 'js', map_filename
92
+ # js << "\n//# sourceMappingURL=#{map_url}"
93
+ #
94
+ # [js, map]
95
+ #end
66
96
 
67
97
  # Sources should be an array of form: [['alert("foo");', 'alert.js']] Returns a tuple. The
68
98
  # first element is the concatenated JS. The second element is the map string.
69
- def concat(sources, source_root)
70
- js = StringIO.new
71
- map = SourceMap.new(
72
- generated_output: js,
73
- source_root: source_root
74
- )
75
- sources.each do |source_js, source_filename|
76
- map.add_generated source_js, source: source_filename
77
- end
78
- js.rewind
79
- [js.read, map.to_s]
80
- end
99
+ #def concat(sources, source_root)
100
+ # js = StringIO.new
101
+ # map = SourceMap.new(
102
+ # generated_output: js,
103
+ # source_root: source_root
104
+ # )
105
+ # sources.each do |source_js, source_filename|
106
+ # map.add_generated source_js, source: File.join(source_filename)
107
+ # end
108
+ # js.rewind
109
+ # puts map.to_s
110
+ # [js.read, map.to_s]
111
+ #end
81
112
 
82
- def uglify(js, map, js_filename)
83
- Uglifier.new(
84
- input_source_map: map,
85
- output_filename: js_filename
86
- ).compile_with_map(js)
87
- end
113
+ #def uglify(js, map, js_filename)
114
+ # Uglifier.new(
115
+ # input_source_map: map,
116
+ # output_filename: js_filename
117
+ # ).compile_with_map(js)
118
+ #end
88
119
  end
120
+
121
+ class UglifyError < RuntimeError; end
89
122
  end
@@ -1,6 +1,6 @@
1
1
  module Ichiban
2
2
  class Loader
3
- # Pass in an IchibanFile
3
+ # Pass in an Ichiban::ProjectFile.
4
4
  def change(file)
5
5
  if file.is_a?(Ichiban::HelperFile) or file.is_a?(Ichiban::ModelFile)
6
6
  delete_all
@@ -10,6 +10,7 @@ module Ichiban
10
10
  end
11
11
 
12
12
  def paths(paths_to_compile)
13
+ Ichiban::Loader.new
13
14
  paths_to_compile.each do |path|
14
15
  unless path.start_with? Ichiban.project_root
15
16
  path = File.join(Ichiban.project_root, path)
@@ -0,0 +1,3 @@
1
+ module Ichiban
2
+ VERSION = '1.2.2'
3
+ end
data/lib/ichiban.rb CHANGED
@@ -1,3 +1,8 @@
1
+ if RUBY_VERSION.match(/[0-9]+-[0-9]+-[0-9]+/) and Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1.0')
2
+ puts 'Ichiban requires '
3
+ exit 1
4
+ end
5
+
1
6
  # Standard lib
2
7
  require 'fileutils'
3
8
  require 'json'
@@ -38,8 +43,6 @@ require 'ichiban/markdown'
38
43
  require 'ichiban/scripts'
39
44
 
40
45
  module Ichiban
41
- VERSION = '1.1.0'
42
-
43
46
  # In addition to setting the variable, this loads the config file
44
47
  def self.project_root=(path)
45
48
  @project_root = path
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ichiban
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrett Colby
@@ -76,7 +76,7 @@ dependencies:
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 2.7.9
79
+ version: 2.10.1
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2'
@@ -86,7 +86,7 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 2.7.9
89
+ version: 2.10.1
90
90
  - - "~>"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '2'
@@ -136,7 +136,7 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 2.5.3
139
+ version: 2.7.2
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '2'
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 2.5.3
149
+ version: 2.7.2
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2'
@@ -156,7 +156,7 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.12.1
159
+ version: 0.12.2
160
160
  - - "~>"
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
@@ -166,7 +166,7 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 0.12.1
169
+ version: 0.12.2
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
@@ -304,6 +304,26 @@ dependencies:
304
304
  - - "~>"
305
305
  - !ruby/object:Gem::Version
306
306
  version: '2'
307
+ - !ruby/object:Gem::Dependency
308
+ name: json-compare
309
+ requirement: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - ">="
312
+ - !ruby/object:Gem::Version
313
+ version: 0.1.8
314
+ - - "~>"
315
+ - !ruby/object:Gem::Version
316
+ version: '0'
317
+ type: :development
318
+ prerelease: false
319
+ version_requirements: !ruby/object:Gem::Requirement
320
+ requirements:
321
+ - - ">="
322
+ - !ruby/object:Gem::Version
323
+ version: 0.1.8
324
+ - - "~>"
325
+ - !ruby/object:Gem::Version
326
+ version: '0'
307
327
  description: Static website compiler with advanced features, including watcher script.
308
328
  email: jarrett@madebyhq.com
309
329
  executables:
@@ -347,6 +367,7 @@ files:
347
367
  - lib/ichiban/project_file.rb
348
368
  - lib/ichiban/project_generator.rb
349
369
  - lib/ichiban/scripts.rb
370
+ - lib/ichiban/version.rb
350
371
  - lib/ichiban/watcher.rb
351
372
  homepage: https://github.com/jarrett/ichiban
352
373
  licenses: []
@@ -362,8 +383,8 @@ post_install_message: |2-
362
383
  maruku
363
384
  rdiscount
364
385
 
365
- Ichiban uses Guard (http://github.com/guard/guard).
366
- When you run `ichiban watch`, Guard may prompt
386
+ Ichiban uses Listen (https://github.com/guard/listen).
387
+ When you run `ichiban watch`, Listen may prompt
367
388
  you to install an event listener specific to your
368
389
  operating system. Follow its advice.
369
390