sprockets-es6 0.8.2 → 0.9.0
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/sprockets/es6.rb +56 -19
- data/lib/sprockets/es6/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8c3813d1da084f0cb3f7fd15095c6ed34dc7d498
|
|
4
|
+
data.tar.gz: a1ae1ebc0ae0bd51dedcd352dc61327226543245
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d1173d2c5a564f5d6fa4a544ce63c7da7d7ac4bc5ea1f488545cacf1b28a51ac5879e0d9e64651b974fdec728a100e5ec2cb0861d7e14905a06743215c06f3f
|
|
7
|
+
data.tar.gz: 8c34559fd43eadd7e30e7c50a5d972aae788f8b2598db0e1c20288067ca0241b7cbc7c51a97d301ea9675702ffc3a4dee69c2efccf31615ee5ba562552246721
|
data/lib/sprockets/es6.rb
CHANGED
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
require 'babel/transpiler'
|
|
2
2
|
require 'sprockets'
|
|
3
3
|
require 'sprockets/es6/version'
|
|
4
|
+
require 'ostruct'
|
|
4
5
|
|
|
5
6
|
module Sprockets
|
|
6
7
|
class ES6
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
|
|
11
|
+
attr_accessor :configuration
|
|
12
|
+
|
|
13
|
+
def configuration_hash
|
|
14
|
+
configuration.to_h.reduce({}) do |hash, (key, val)|
|
|
15
|
+
hash[key.to_s] = val
|
|
16
|
+
hash
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def instance
|
|
21
|
+
@instance ||= new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def configure
|
|
25
|
+
self.configuration ||= OpenStruct.new
|
|
26
|
+
yield configuration
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def reset_configuration
|
|
30
|
+
self.configuration = OpenStruct.new
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def call(input)
|
|
34
|
+
instance.call(input)
|
|
35
|
+
end
|
|
36
|
+
|
|
9
37
|
end
|
|
10
38
|
|
|
11
|
-
def
|
|
12
|
-
|
|
39
|
+
def configuration_hash
|
|
40
|
+
self.class.configuration_hash
|
|
13
41
|
end
|
|
14
42
|
|
|
15
43
|
def initialize(options = {})
|
|
16
|
-
@options = options.
|
|
44
|
+
@options = configuration_hash.merge(options).freeze
|
|
17
45
|
|
|
18
46
|
@cache_key = [
|
|
19
47
|
self.class.name,
|
|
@@ -27,23 +55,32 @@ module Sprockets
|
|
|
27
55
|
def call(input)
|
|
28
56
|
data = input[:data]
|
|
29
57
|
result = input[:cache].fetch(@cache_key + [input[:filename]] + [data]) do
|
|
30
|
-
|
|
31
|
-
'sourceRoot' => input[:load_path],
|
|
32
|
-
'moduleRoot' => nil,
|
|
33
|
-
'filename' => input[:filename],
|
|
34
|
-
'filenameRelative' => input[:environment].split_subpath(input[:load_path], input[:filename])
|
|
35
|
-
}.merge(@options)
|
|
36
|
-
|
|
37
|
-
if opts['moduleIds'] && opts['moduleRoot']
|
|
38
|
-
opts['moduleId'] ||= File.join(opts['moduleRoot'], input[:name])
|
|
39
|
-
elsif opts['moduleIds']
|
|
40
|
-
opts['moduleId'] ||= input[:name]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
Babel::Transpiler.transform(data, opts)
|
|
58
|
+
transform(data, transformation_options(input))
|
|
44
59
|
end
|
|
45
60
|
result['code']
|
|
46
61
|
end
|
|
62
|
+
|
|
63
|
+
def transform(data, opts)
|
|
64
|
+
Babel::Transpiler.transform(data, opts)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def transformation_options(input)
|
|
68
|
+
opts = {
|
|
69
|
+
'sourceRoot' => input[:load_path],
|
|
70
|
+
'moduleRoot' => nil,
|
|
71
|
+
'filename' => input[:filename],
|
|
72
|
+
'filenameRelative' => input[:environment].split_subpath(input[:load_path], input[:filename])
|
|
73
|
+
}.merge(@options)
|
|
74
|
+
|
|
75
|
+
if opts['moduleIds'] && opts['moduleRoot']
|
|
76
|
+
opts['moduleId'] ||= File.join(opts['moduleRoot'], input[:name])
|
|
77
|
+
elsif opts['moduleIds']
|
|
78
|
+
opts['moduleId'] ||= input[:name]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
opts
|
|
82
|
+
end
|
|
83
|
+
|
|
47
84
|
end
|
|
48
85
|
|
|
49
86
|
append_path Babel::Transpiler.source_path
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sprockets-es6
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joshua Peek
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: babel-transpiler
|
|
@@ -80,8 +80,8 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
-
description:
|
|
84
|
-
|
|
83
|
+
description: " A Sprockets transformer that converts ES6 code into vanilla ES5
|
|
84
|
+
with Babel JS.\n"
|
|
85
85
|
email: josh@joshpeek.com
|
|
86
86
|
executables: []
|
|
87
87
|
extensions: []
|
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
111
111
|
version: '0'
|
|
112
112
|
requirements: []
|
|
113
113
|
rubyforge_project:
|
|
114
|
-
rubygems_version: 2.
|
|
114
|
+
rubygems_version: 2.5.1
|
|
115
115
|
signing_key:
|
|
116
116
|
specification_version: 4
|
|
117
117
|
summary: Sprockets ES6 transformer
|