lux_assets 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/bin/lux_assets +5 -0
- data/lib/lux_assets/asset.rb +10 -7
- data/lib/lux_assets/base.rb +3 -28
- data/lib/lux_assets/cli.rb +55 -0
- data/lib/lux_assets/element.rb +4 -3
- data/lib/lux_assets/manifest.rb +1 -4
- data/lib/lux_assets.rb +1 -0
- data/lib/vendor/lux/assets_routes.rb +0 -1
- data/lib/vendor/tasks.rb +5 -0
- data/public/manifest.json +1 -0
- data/spec/assets/js/test.coffee +2 -1
- data/spec/tests/common_spec.rb +7 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ba2b3c00e281b88fce7778d3625bfb78039d023ad288945a5835b0878721e40
|
4
|
+
data.tar.gz: ca4bf2c15022da0ed16e3662aeb0a6509ff9d76e6d64941a9788f3c51e9e7297
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bddce098f693c140b676bfaf4d276758ee2d1d90819be1f3ef64d61596336b56390ade0def18cd4c68a5ac465fe84516de66e5d5f8738dc8f343f632c04e0ed
|
7
|
+
data.tar.gz: 628c3d656ac78aae471a951d9ea338bedf7c5b48a697280e1a56929375ab44d9c8221f1eb8d2242365f1774deee63bdec9326af8e4e85c2af538d06aae83ee6b
|
data/README.md
CHANGED
@@ -41,6 +41,7 @@ Commands:
|
|
41
41
|
lux_assets compile # Compile assets for production
|
42
42
|
lux_assets help [COMMAND] # Describe available commands or one specific command
|
43
43
|
lux_assets install # Install all needed packages via yarn
|
44
|
+
lux_assets monitor # Montitor and compile changed files
|
44
45
|
lux_assets show # Show all files/data in manifest
|
45
46
|
```
|
46
47
|
|
data/bin/lux_assets
CHANGED
data/lib/lux_assets/asset.rb
CHANGED
@@ -20,7 +20,7 @@ class LuxAssets::Asset
|
|
20
20
|
def compile
|
21
21
|
@data = []
|
22
22
|
|
23
|
-
die "No files found for [#{@ext}/#{@name}]" unless @files[0]
|
23
|
+
LuxAssets::Cli.die "No files found for [#{@ext}/#{@name}]" unless @files[0]
|
24
24
|
|
25
25
|
for file in @files
|
26
26
|
if file.is_a?(Proc)
|
@@ -47,15 +47,18 @@ class LuxAssets::Asset
|
|
47
47
|
def tag_public_assets
|
48
48
|
data = @asset_path.read
|
49
49
|
data = data.gsub(/url\(([^\)]+)\)/) do
|
50
|
-
if $1.include?('data:') || $1.include?('#') || $1.include?('?')
|
50
|
+
if $1.include?('data:') || $1.include?('#') || $1.include?('?') || $1.include?('::')
|
51
51
|
'url(%s)' % $1
|
52
52
|
else
|
53
53
|
path = $1.gsub(/^['"]|['"]$/, '')
|
54
54
|
path = path[0,1] == '/' ? Pathname.new('./public%s' % path) : Pathname.new('./public/assets').join(path)
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
if path.exist?
|
57
|
+
'url("%s?%s")' % [path.to_s.sub('./public', ''), Digest::SHA1.hexdigest(path.read)[0, 6]]
|
58
|
+
else
|
59
|
+
LuxAssets::Cli.warn 'Resource "%s" referenced in "%s/%s" but not found' % [path, @ext, @name]
|
60
|
+
'url("%s")' % path
|
61
|
+
end
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
@@ -75,7 +78,7 @@ class LuxAssets::Asset
|
|
75
78
|
def compile_js
|
76
79
|
save_data @data.join(";\n") do
|
77
80
|
# babel fix and minify
|
78
|
-
LuxAssets.run 'node_modules/babel-cli/.bin/babel --minified --no-comments --compact true -o "%{file}" "%{file}"' % { file: @asset_path }
|
81
|
+
LuxAssets::Cli.run 'node_modules/babel-cli/.bin/babel --minified --no-comments --compact true -o "%{file}" "%{file}"' % { file: @asset_path }
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
@@ -84,7 +87,7 @@ class LuxAssets::Asset
|
|
84
87
|
tag_public_assets
|
85
88
|
|
86
89
|
#autoprefixer
|
87
|
-
LuxAssets.run './node_modules/.bin/autoprefixer-cli %s' % @asset_path
|
90
|
+
LuxAssets::Cli.run './node_modules/.bin/autoprefixer-cli %s' % @asset_path
|
88
91
|
end
|
89
92
|
end
|
90
93
|
end
|
data/lib/lux_assets/base.rb
CHANGED
@@ -18,11 +18,6 @@ module LuxAssets
|
|
18
18
|
@relative_root
|
19
19
|
end
|
20
20
|
|
21
|
-
def die text
|
22
|
-
puts text.try(:red)
|
23
|
-
exit
|
24
|
-
end
|
25
|
-
|
26
21
|
def asset name
|
27
22
|
@name = name.to_s
|
28
23
|
yield
|
@@ -73,7 +68,7 @@ module LuxAssets
|
|
73
68
|
if files[0]
|
74
69
|
add_local_files files
|
75
70
|
else
|
76
|
-
die 'No files found in "%s -> :%s" (%s)'.red % [@ext, @name, added]
|
71
|
+
LuxAssets::Cli.die 'No files found in "%s -> :%s" (%s)'.red % [@ext, @name, added]
|
77
72
|
end
|
78
73
|
end
|
79
74
|
end
|
@@ -106,7 +101,7 @@ module LuxAssets
|
|
106
101
|
# gzip if needed
|
107
102
|
files = Dir['./public/assets/*.css'] + Dir['./public/assets/*.js']
|
108
103
|
files.each do |file|
|
109
|
-
LuxAssets.run 'gzip -k %s' % file unless File.exist?('%s.gz' % file)
|
104
|
+
LuxAssets::Cli.run 'gzip -k %s' % file unless File.exist?('%s.gz' % file)
|
110
105
|
end
|
111
106
|
|
112
107
|
# touch all files and reset the timestamp
|
@@ -117,7 +112,7 @@ module LuxAssets
|
|
117
112
|
# get all files as a hash
|
118
113
|
def to_h
|
119
114
|
unless @assets_loaded
|
120
|
-
die 'Assets file not found in %s' % CONFIG_PATH unless CONFIG_PATH.exist?
|
115
|
+
LuxAssets::Cli.die 'Assets rb config file not found in %s' % CONFIG_PATH unless CONFIG_PATH.exist?
|
121
116
|
@assets_loaded = true
|
122
117
|
eval CONFIG_PATH.read
|
123
118
|
end
|
@@ -151,26 +146,6 @@ module LuxAssets
|
|
151
146
|
end
|
152
147
|
end
|
153
148
|
|
154
|
-
def run what, cache_file=nil
|
155
|
-
puts what.yellow
|
156
|
-
|
157
|
-
stdin, stdout, stderr, wait_thread = Open3.popen3(what)
|
158
|
-
|
159
|
-
error = stderr.gets
|
160
|
-
while line = stderr.gets do
|
161
|
-
error += line
|
162
|
-
end
|
163
|
-
|
164
|
-
# node-sass prints to stderror on complete
|
165
|
-
error = nil if error && error.index('Rendering Complete, saving .css file...')
|
166
|
-
|
167
|
-
if error
|
168
|
-
cache_file.unlink if cache_file && cache_file.exist?
|
169
|
-
|
170
|
-
puts error.red
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
149
|
private
|
175
150
|
|
176
151
|
def add_local_files files
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# command line helpers
|
2
|
+
|
3
|
+
module LuxAssets::Cli
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def die text
|
7
|
+
text = text.red if text.respond_to?(:red)
|
8
|
+
puts text
|
9
|
+
puts caller.slice(0, 10)
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
def warn text
|
14
|
+
text = text.magenta if text.respond_to?(:magenta)
|
15
|
+
puts text
|
16
|
+
end
|
17
|
+
|
18
|
+
def run what, cache_file=nil
|
19
|
+
puts what.yellow
|
20
|
+
|
21
|
+
stdin, stdout, stderr, wait_thread = Open3.popen3(what)
|
22
|
+
|
23
|
+
error = stderr.gets
|
24
|
+
while line = stderr.gets do
|
25
|
+
error += line
|
26
|
+
end
|
27
|
+
|
28
|
+
# node-sass prints to stderror on complete
|
29
|
+
error = nil if error && error.include?('Rendering Complete, saving .css file...')
|
30
|
+
|
31
|
+
if error
|
32
|
+
cache_file.unlink if cache_file && cache_file.exist?
|
33
|
+
warn error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# monitor for file changes
|
38
|
+
def monitor
|
39
|
+
puts 'Lux assets - looking for file changes'
|
40
|
+
|
41
|
+
files = LuxAssets.to_h.values.map(&:values).flatten.map { |it| Pathname.new it }
|
42
|
+
last_change = Time.now
|
43
|
+
|
44
|
+
while true
|
45
|
+
for file in files
|
46
|
+
if file.mtime > last_change
|
47
|
+
last_change = Time.now
|
48
|
+
LuxAssets.compile file.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
sleep 2
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/lux_assets/element.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# One file that can be scss, js, coffee, ts, etc...
|
2
|
+
|
2
3
|
class LuxAssets::Element
|
3
4
|
def initialize source
|
4
5
|
@source = Pathname.new source
|
@@ -38,7 +39,7 @@ class LuxAssets::Element
|
|
38
39
|
coffee_path = './node_modules/coffee-script/bin/coffee'
|
39
40
|
coffee_opts = production? ? '-cp' : '-Mcp --no-header'
|
40
41
|
|
41
|
-
LuxAssets.run "#{coffee_path} #{coffee_opts} '#{@source}' > '#{@cache}'", @cache
|
42
|
+
LuxAssets::Cli.run "#{coffee_path} #{coffee_opts} '#{@source}' > '#{@cache}'", @cache
|
42
43
|
|
43
44
|
data = @cache.read
|
44
45
|
data = data.gsub(%r{//#\ssourceURL=[\w\-\.\/]+/app/assets/}, '//# sourceURL=/raw_asset/')
|
@@ -51,7 +52,7 @@ class LuxAssets::Element
|
|
51
52
|
def compile_scss
|
52
53
|
node_sass = './node_modules/node-sass/bin/node-sass'
|
53
54
|
node_opts = production? ? '--output-style compressed' : '--source-comments'
|
54
|
-
LuxAssets.run "#{node_sass} #{node_opts} '#{@source}' '#{@cache}'", @cache
|
55
|
+
LuxAssets::Cli.run "#{node_sass} #{node_opts} '#{@source}' '#{@cache}'", @cache
|
55
56
|
@cache.read
|
56
57
|
end
|
57
58
|
alias :compile_sass :compile_scss
|
@@ -62,7 +63,7 @@ class LuxAssets::Element
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def compile_ts
|
65
|
-
LuxAssets.run "node_modules/typescript/.bin/tsc --outFile '#{@cache}' '#{@source}'"
|
66
|
+
LuxAssets::Cli.run "node_modules/typescript/.bin/tsc --outFile '#{@cache}' '#{@source}'"
|
66
67
|
end
|
67
68
|
|
68
69
|
end
|
data/lib/lux_assets/manifest.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module LuxAssets::Manifest
|
4
4
|
MANIFEST = Pathname.new(ENV.fetch('ASSETS_MANIFEST') { './public/manifest.json' })
|
5
|
+
MANIFEST.write '{"files":{}}' unless MANIFEST.exist?
|
5
6
|
|
6
7
|
extend self
|
7
8
|
|
@@ -20,10 +21,6 @@ module LuxAssets::Manifest
|
|
20
21
|
json = JSON.load MANIFEST.read
|
21
22
|
json['files'][name]
|
22
23
|
end
|
23
|
-
|
24
|
-
###
|
25
|
-
|
26
|
-
MANIFEST.write '{"files":{}}' unless MANIFEST.exist?
|
27
24
|
end
|
28
25
|
|
29
26
|
|
data/lib/lux_assets.rb
CHANGED
data/lib/vendor/tasks.rb
CHANGED
@@ -28,6 +28,11 @@ namespace :assets do
|
|
28
28
|
LuxAssets.examine
|
29
29
|
end
|
30
30
|
|
31
|
+
desc 'Monitor for file changes'
|
32
|
+
task monitor: :env do
|
33
|
+
LuxAssets::Cli.monitor
|
34
|
+
end
|
35
|
+
|
31
36
|
desc 'Upload assets to S3'
|
32
37
|
task :s3_upload do
|
33
38
|
puts 'aws s3 sync ./public s3://bucket.location --cache-control "max-age=31536000, public"'
|
@@ -0,0 +1 @@
|
|
1
|
+
{"files":{}}
|
data/spec/assets/js/test.coffee
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
alert 123
|
1
|
+
alert 123
|
2
|
+
|
data/spec/tests/common_spec.rb
CHANGED
@@ -32,8 +32,15 @@ describe LuxAssets do
|
|
32
32
|
expect(css).to include('-webkit')
|
33
33
|
|
34
34
|
expect(Dir.entries('./public/assets').length > 8).to be true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'deletes folders and files' do
|
35
38
|
`rm -rf ./public/assets`
|
36
39
|
Dir.rmdir('./public') if Dir.entries('./public').length == 2
|
40
|
+
|
41
|
+
if LuxAssets::Manifest::MANIFEST.exist?
|
42
|
+
LuxAssets::Manifest::MANIFEST.delete
|
43
|
+
end
|
37
44
|
end
|
38
45
|
end
|
39
46
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lux_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- "./lib/lux_assets.rb"
|
67
67
|
- "./lib/lux_assets/asset.rb"
|
68
68
|
- "./lib/lux_assets/base.rb"
|
69
|
+
- "./lib/lux_assets/cli.rb"
|
69
70
|
- "./lib/lux_assets/element.rb"
|
70
71
|
- "./lib/lux_assets/manifest.rb"
|
71
72
|
- "./lib/vendor/lux/assets_helper.rb"
|
@@ -7355,6 +7356,7 @@ files:
|
|
7355
7356
|
- "./node_modules/yargs/package.json"
|
7356
7357
|
- "./node_modules/yargs/yargs.js"
|
7357
7358
|
- "./package.json"
|
7359
|
+
- "./public/manifest.json"
|
7358
7360
|
- "./spec/assets/assets.rb"
|
7359
7361
|
- "./spec/assets/css/test.css"
|
7360
7362
|
- "./spec/assets/css/test.scss"
|