ichiban 1.2.0 → 1.2.2
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/lib/ichiban/js_compiler.rb +90 -57
- data/lib/ichiban/loader.rb +1 -1
- data/lib/ichiban/manual_compiler.rb +1 -0
- data/lib/ichiban/version.rb +3 -0
- data/lib/ichiban.rb +5 -2
- metadata +30 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e9455b270799fb2c632f4457bd396e623c4d235
|
4
|
+
data.tar.gz: dd03bed5cdb8bd51bb2f21b0184dc31738d7a9c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c7f3a21eb7899774c9f0739e7176771085e5d63d8c41936c46494487dae5f7347a9bd160fdbe6e2e91fd4608a516a611c392b8fbe41c5f10a3ff13bd979dca2
|
7
|
+
data.tar.gz: 4a2c29534e6ce1bc8fbe780f6af53f1f891e6411a94dc87539267f28aa1c2e60d065a7a8ddf999743ad495570131aa6b0c5c4d8e19bc943c56ddc4a45cd8a11a
|
data/lib/ichiban/js_compiler.rb
CHANGED
@@ -1,44 +1,70 @@
|
|
1
1
|
module Ichiban
|
2
|
-
# This class uses
|
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
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
#
|
18
|
-
|
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
|
-
#
|
27
|
-
|
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
|
-
#
|
30
|
-
|
31
|
-
File.
|
32
|
-
|
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
|
-
#
|
36
|
-
|
37
|
-
|
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,
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
data/lib/ichiban/loader.rb
CHANGED
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
366
|
-
When you run `ichiban watch`,
|
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
|
|