lux_assets 0.2.4 → 0.2.9
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/README.md +4 -3
- data/lib/lux_assets/asset.rb +7 -5
- data/lib/lux_assets/base.rb +6 -9
- data/lib/lux_assets/cli.rb +42 -8
- data/lib/lux_assets/element.rb +26 -24
- data/lib/lux_assets.rb +1 -2
- data/lib/vendor/lux/{assets_routes.rb → misc.rb} +25 -0
- data/tmp/assets/d-spec-assets-css-test.css +1 -0
- data/tmp/assets/d-spec-assets-css-test.scss +10 -0
- data/tmp/assets/spec-assets-js-test.coffee +7 -0
- data/tmp/assets/spec-assets-js-test.ts +5 -0
- metadata +7 -5
- data/lib/vendor/lux/assets_plugin.rb +0 -13
- data/public/manifest.json +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c75902022d21e66908e7e48471de558834e110f4626f9354bc273bd803eddbf0
|
4
|
+
data.tar.gz: ff67b5d01baa0da7d1483aa7d1c03d0257f6e76ec1c99c21fed7c622f3a375ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89954e9a9b594a6a11ae234b163a01222be0d7f9344d1cbe3ec1d87c801be5b17539ba618d15dcf6f1c2918047a22f4d51ef7f6285ed5164b7bb978e50451ad4
|
7
|
+
data.tar.gz: da9b2a0ca0c94bc94131a24f9075698507ca766fa3cd6f4b4663faec33b20a74d27857c7e9e3ae90859779215bb5e212384fe08abddb886e03b37307f1c1c7ef
|
data/README.md
CHANGED
@@ -128,15 +128,16 @@ LuxAssets.files(:js, :main)
|
|
128
128
|
LuxAssets.files('js/main')
|
129
129
|
LuxAssets.js(:main).files
|
130
130
|
|
131
|
-
# compile single asset
|
131
|
+
# compile single asset with debug info for dev
|
132
132
|
LuxAssets.compile('js/main/index.coffee')
|
133
133
|
LuxAssets.compile('css/main/index.scss')
|
134
134
|
|
135
|
-
# compile file group
|
135
|
+
# compile file group for production
|
136
136
|
LuxAssets.js(:main).compile
|
137
137
|
LuxAssets.css(:main).compile
|
138
|
+
LuxAssets.css(:main).compile
|
138
139
|
|
139
|
-
# compile all assets
|
140
|
+
# compile all assets for production
|
140
141
|
LuxAssets.compile_all do |name, path|
|
141
142
|
puts "Compile #{name.green} -> #{path}"
|
142
143
|
end
|
data/lib/lux_assets/asset.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
class LuxAssets::Asset
|
4
4
|
|
5
5
|
def initialize ext, name
|
6
|
-
|
6
|
+
raise ArgumentError.new('name not deinfed') if name.empty?
|
7
|
+
@ext = ext.to_sym == :js ? :js : :css
|
7
8
|
@name = name.to_s
|
8
|
-
@files = LuxAssets.to_h[ext][@name]
|
9
|
+
@files = LuxAssets.to_h[@ext][@name]
|
9
10
|
@target = "#{@ext}/#{@name}"
|
10
11
|
end
|
11
12
|
|
@@ -26,7 +27,7 @@ class LuxAssets::Asset
|
|
26
27
|
if file.is_a?(Proc)
|
27
28
|
@data.push file.call
|
28
29
|
else
|
29
|
-
@data.push LuxAssets
|
30
|
+
@data.push LuxAssets.compile file, production: true
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -78,7 +79,8 @@ class LuxAssets::Asset
|
|
78
79
|
def compile_js
|
79
80
|
save_data @data.join(";\n") do
|
80
81
|
# babel fix and minify
|
81
|
-
|
82
|
+
command = 'node_modules/babel-cli/.bin/babel --minified --no-comments --compact true -o "%{file}" "%{file}"' % { file: @asset_path }
|
83
|
+
LuxAssets::Cli.run command, message: "Babel filter and minify: #{@asset_path}"
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
@@ -87,7 +89,7 @@ class LuxAssets::Asset
|
|
87
89
|
tag_public_assets
|
88
90
|
|
89
91
|
#autoprefixer
|
90
|
-
LuxAssets::Cli.run './node_modules/.bin/autoprefixer-cli %s' % @asset_path
|
92
|
+
LuxAssets::Cli.run './node_modules/.bin/autoprefixer-cli %s' % @asset_path, message: "Autoprefixer: #{@asset_path}"
|
91
93
|
end
|
92
94
|
end
|
93
95
|
end
|
data/lib/lux_assets/base.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module LuxAssets
|
4
4
|
extend self
|
5
5
|
|
6
|
-
CONFIG_PATH
|
6
|
+
CONFIG_PATH ||= Pathname.new ENV.fetch('ASSETS_CONFIG') { './config/assets.rb' }
|
7
7
|
|
8
8
|
ASSET_TYPES ||= {
|
9
9
|
js: ['js', 'coffee', 'ts'],
|
@@ -76,16 +76,13 @@ module LuxAssets
|
|
76
76
|
# get list of files in the resource
|
77
77
|
def files ext, name=nil
|
78
78
|
ext, name = ext.split('/', 2) unless name
|
79
|
-
ext
|
80
|
-
|
81
|
-
raise ArgumentError.new('name not deinfed') if name.empty?
|
82
|
-
|
83
|
-
to_h[ext][name.to_s]
|
79
|
+
Asset.new(ext, name).files
|
84
80
|
end
|
85
81
|
|
86
82
|
# compile single asset
|
87
|
-
def compile path
|
88
|
-
|
83
|
+
def compile path, opts={}
|
84
|
+
opts[:production] = false if opts[:production].nil?
|
85
|
+
LuxAssets::Element.new(path).send :compile, opts
|
89
86
|
end
|
90
87
|
|
91
88
|
# compile all assets
|
@@ -101,7 +98,7 @@ module LuxAssets
|
|
101
98
|
# gzip if needed
|
102
99
|
files = Dir['./public/assets/*.css'] + Dir['./public/assets/*.js']
|
103
100
|
files.each do |file|
|
104
|
-
LuxAssets::Cli.run
|
101
|
+
LuxAssets::Cli.run('gzip -k %s' % file, message: "Gzip: #{file}") unless File.exist?('%s.gz' % file)
|
105
102
|
end
|
106
103
|
|
107
104
|
# touch all files and reset the timestamp
|
data/lib/lux_assets/cli.rb
CHANGED
@@ -15,8 +15,8 @@ module LuxAssets::Cli
|
|
15
15
|
puts text
|
16
16
|
end
|
17
17
|
|
18
|
-
def run what,
|
19
|
-
puts what.yellow
|
18
|
+
def run what, opts={}
|
19
|
+
puts (opts[:message] || what).yellow
|
20
20
|
|
21
21
|
stdin, stdout, stderr, wait_thread = Open3.popen3(what)
|
22
22
|
|
@@ -29,8 +29,15 @@ module LuxAssets::Cli
|
|
29
29
|
error = nil if error && error.include?('Rendering Complete, saving .css file...')
|
30
30
|
|
31
31
|
if error
|
32
|
-
|
32
|
+
puts '--- command '
|
33
|
+
puts what.yellow
|
34
|
+
puts '--- error response'
|
35
|
+
opts[:cache_file].unlink if opts[:cache_file] && opts[:cache_file].exist?
|
33
36
|
warn error
|
37
|
+
puts '--- end'
|
38
|
+
false
|
39
|
+
else
|
40
|
+
true
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
@@ -38,17 +45,44 @@ module LuxAssets::Cli
|
|
38
45
|
def monitor
|
39
46
|
puts 'Lux assets - looking for file changes'
|
40
47
|
|
41
|
-
|
48
|
+
list = LuxAssets
|
49
|
+
.to_h
|
50
|
+
.values
|
51
|
+
.map(&:values)
|
52
|
+
.flatten
|
53
|
+
.map { |it| Pathname.new it }
|
54
|
+
|
55
|
+
files = list.inject({}) do |h, file|
|
56
|
+
if file.to_s.end_with?('.scss')
|
57
|
+
# if target file is scss, monitor all child css and scss files
|
58
|
+
h[file.to_s] = Dir['%s/**/*' % file.dirname]
|
59
|
+
.select { |file| file.end_with?('.scss') || file.end_with?('.css') }
|
60
|
+
.map { |it| Pathname.new it }
|
61
|
+
|
62
|
+
else
|
63
|
+
# othervise monitor only target file
|
64
|
+
h[file.to_s] = [file]
|
65
|
+
end
|
66
|
+
|
67
|
+
h
|
68
|
+
end
|
69
|
+
|
42
70
|
last_change = Time.now
|
43
71
|
|
44
72
|
while true
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
73
|
+
changed = false
|
74
|
+
|
75
|
+
for key, values in files
|
76
|
+
for file in values
|
77
|
+
if file.mtime > last_change
|
78
|
+
changed = true
|
79
|
+
LuxAssets.compile key, force: true
|
80
|
+
end
|
49
81
|
end
|
50
82
|
end
|
51
83
|
|
84
|
+
last_change = Time.now if changed
|
85
|
+
|
52
86
|
sleep 2
|
53
87
|
end
|
54
88
|
end
|
data/lib/lux_assets/element.rb
CHANGED
@@ -1,24 +1,17 @@
|
|
1
1
|
# One file that can be scss, js, coffee, ts, etc...
|
2
2
|
|
3
3
|
class LuxAssets::Element
|
4
|
+
|
4
5
|
def initialize source
|
5
6
|
@source = Pathname.new source
|
6
|
-
@cache = Pathname.new './tmp/assets/%s' % source.gsub('/','-')
|
7
|
-
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
if respond_to?(method_name, true)
|
13
|
-
cached || send(method_name)
|
14
|
-
else
|
15
|
-
@source.read
|
16
|
-
end
|
8
|
+
source = source.sub(/^\.\//, '').sub(/^\//, '').gsub('/', '-')
|
9
|
+
source = '%s-%s' % [@production ? :p : :d, source] if content_type == 'text/css'
|
10
|
+
@cache = Pathname.new './tmp/assets/%s' % source
|
17
11
|
end
|
18
12
|
|
19
13
|
def content_type
|
20
14
|
@ext ||= @source.to_s.split('.').last.to_sym
|
21
|
-
|
22
15
|
[:css, :scss].include?(@ext) ? 'text/css' : 'text/javascript'
|
23
16
|
end
|
24
17
|
|
@@ -26,9 +19,16 @@ class LuxAssets::Element
|
|
26
19
|
|
27
20
|
private
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
# use LuxAsset.compile
|
23
|
+
def compile force:nil, production:nil
|
24
|
+
@production = production || false
|
25
|
+
method_name = 'compile_%s' % @source.to_s.split('.').last.downcase
|
26
|
+
|
27
|
+
if respond_to?(method_name, true)
|
28
|
+
(!force && cached) || send(method_name)
|
29
|
+
else
|
30
|
+
@source.read
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def cached
|
@@ -37,22 +37,24 @@ class LuxAssets::Element
|
|
37
37
|
|
38
38
|
def compile_coffee
|
39
39
|
coffee_path = './node_modules/coffee-script/bin/coffee'
|
40
|
-
coffee_opts = production
|
41
|
-
|
42
|
-
LuxAssets::Cli.run "#{coffee_path} #{coffee_opts} '#{@source}' > '#{@cache}'", @cache
|
40
|
+
coffee_opts = @production ? '-cp' : '-Mcp --no-header'
|
43
41
|
|
44
|
-
|
45
|
-
|
42
|
+
if LuxAssets::Cli.run("#{coffee_path} #{coffee_opts} '#{@source}' > '#{@cache}'", cache_file: @cache, message: "Compile Coffee: #{@source}")
|
43
|
+
data = @cache.read
|
44
|
+
data = data.gsub(%r{//#\ssourceURL=[\w\-\.\/]+/app/assets/}, '//# sourceURL=/raw_asset/')
|
46
45
|
|
47
|
-
|
46
|
+
@cache.write data
|
48
47
|
|
49
|
-
|
48
|
+
data
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
50
52
|
end
|
51
53
|
|
52
54
|
def compile_scss
|
53
55
|
node_sass = './node_modules/node-sass/bin/node-sass'
|
54
|
-
node_opts = production
|
55
|
-
LuxAssets::Cli.run "#{node_sass} #{node_opts} '#{@source}' '#{@cache}'", @cache
|
56
|
+
node_opts = @production ? '--output-style compressed' : '--source-comments'
|
57
|
+
LuxAssets::Cli.run "#{node_sass} #{node_opts} '#{@source}' '#{@cache}'", cache_file: @cache, message: "Compile SCSS: #{@source}"
|
56
58
|
@cache.read
|
57
59
|
end
|
58
60
|
alias :compile_sass :compile_scss
|
@@ -63,7 +65,7 @@ class LuxAssets::Element
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def compile_ts
|
66
|
-
LuxAssets::Cli.run "node_modules/typescript/.bin/tsc --outFile '#{@cache}' '#{@source}'"
|
68
|
+
LuxAssets::Cli.run "node_modules/typescript/.bin/tsc --outFile '#{@cache}' '#{@source}'", cache_file: @cache, message: "Compile TypeScript: #{@source}"
|
67
69
|
end
|
68
70
|
|
69
71
|
end
|
data/lib/lux_assets.rb
CHANGED
@@ -13,9 +13,8 @@ require_relative './lux_assets/manifest'
|
|
13
13
|
|
14
14
|
# lux framework bindings
|
15
15
|
if defined?(Lux)
|
16
|
+
require_relative './vendor/lux/misc'
|
16
17
|
require_relative './vendor/lux/assets_helper'
|
17
|
-
require_relative './vendor/lux/assets_plugin'
|
18
|
-
require_relative './vendor/lux/assets_routes'
|
19
18
|
end
|
20
19
|
|
21
20
|
# rake bindings
|
@@ -31,3 +31,28 @@ Lux.app.before do
|
|
31
31
|
body file.exist? ? file.read : "error: File not found"
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
# additional info for "lux config" cli
|
36
|
+
Lux::Config.info do
|
37
|
+
puts
|
38
|
+
puts 'assets:'
|
39
|
+
for ext in LuxAssets.to_h.keys
|
40
|
+
for key, value in LuxAssets.to_h[ext]
|
41
|
+
name = ' LuxAsset.%s(:%s)' % [ext, key]
|
42
|
+
print name.ljust(35)
|
43
|
+
puts ' - %s' % value.length.pluralize(:file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# include files from a plugin
|
49
|
+
module LuxAssets
|
50
|
+
def plugin name
|
51
|
+
# load pluigin if needed
|
52
|
+
Lux.plugin name
|
53
|
+
|
54
|
+
plugin = Lux.plugin.get name
|
55
|
+
add '%s/**' % plugin[:folder]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
body p{color:blue}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
(function() {
|
2
|
+
alert(123);
|
3
|
+
|
4
|
+
}).call(this);
|
5
|
+
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIuLi8uLi8uLiIsInNvdXJjZXMiOlsic3BlYy9hc3NldHMvanMvdGVzdC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7RUFBQSxLQUFBLENBQU0sR0FBTjtBQUFBIiwic291cmNlc0NvbnRlbnQiOlsiYWxlcnQgMTIzXG5cbiJdfQ==
|
7
|
+
//# sourceURL=/Users/dux/dev/apps/my/gems/lux_assets/spec/assets/js/test.coffee
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -70,8 +70,7 @@ files:
|
|
70
70
|
- "./lib/lux_assets/element.rb"
|
71
71
|
- "./lib/lux_assets/manifest.rb"
|
72
72
|
- "./lib/vendor/lux/assets_helper.rb"
|
73
|
-
- "./lib/vendor/lux/
|
74
|
-
- "./lib/vendor/lux/assets_routes.rb"
|
73
|
+
- "./lib/vendor/lux/misc.rb"
|
75
74
|
- "./lib/vendor/tasks.rb"
|
76
75
|
- "./misc/assets.rb"
|
77
76
|
- "./node_modules/abbrev/LICENSE"
|
@@ -7356,7 +7355,6 @@ files:
|
|
7356
7355
|
- "./node_modules/yargs/package.json"
|
7357
7356
|
- "./node_modules/yargs/yargs.js"
|
7358
7357
|
- "./package.json"
|
7359
|
-
- "./public/manifest.json"
|
7360
7358
|
- "./spec/assets/assets.rb"
|
7361
7359
|
- "./spec/assets/css/test.css"
|
7362
7360
|
- "./spec/assets/css/test.scss"
|
@@ -7365,6 +7363,10 @@ files:
|
|
7365
7363
|
- "./spec/assets/js/test.ts"
|
7366
7364
|
- "./spec/spec_helper.rb"
|
7367
7365
|
- "./spec/tests/common_spec.rb"
|
7366
|
+
- "./tmp/assets/d-spec-assets-css-test.css"
|
7367
|
+
- "./tmp/assets/d-spec-assets-css-test.scss"
|
7368
|
+
- "./tmp/assets/spec-assets-js-test.coffee"
|
7369
|
+
- "./tmp/assets/spec-assets-js-test.ts"
|
7368
7370
|
- "./yarn.lock"
|
7369
7371
|
- bin/lux_assets
|
7370
7372
|
homepage: https://github.com/dux/lux_assets
|
data/public/manifest.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"files":{}}
|