sprockets-rollup 0.1.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.
@@ -0,0 +1,88 @@
1
+ require 'shellwords'
2
+ require 'sprockets'
3
+ require 'ostruct'
4
+
5
+ module Sprockets
6
+ class Rollup
7
+
8
+ class << self
9
+
10
+ attr_accessor :configuration
11
+
12
+ def configuration_hash
13
+ configuration.to_h.reduce({}) do |hash, (key, val)|
14
+ hash[key.to_s] = val
15
+ hash
16
+ end
17
+ end
18
+
19
+ def instance
20
+ @instance ||= new
21
+ end
22
+
23
+ def configure
24
+ self.configuration ||= OpenStruct.new
25
+ yield configuration
26
+ end
27
+
28
+ def reset_configuration
29
+ self.configuration = OpenStruct.new
30
+ end
31
+
32
+ def call(input)
33
+ instance.call(input)
34
+ end
35
+
36
+ def cache_key
37
+ instance.cache_key
38
+ end
39
+
40
+ end
41
+
42
+ attr_reader :cache_key
43
+
44
+ def configuration_hash
45
+ self.class.configuration_hash
46
+ end
47
+
48
+ def initialize(options = {})
49
+ @options = configuration_hash.merge(options).freeze
50
+
51
+ @cache_key = [
52
+ self.class.name,
53
+ '0.1.0',
54
+ @options
55
+ ].freeze
56
+ end
57
+
58
+ def call(input)
59
+ data = input[:data]
60
+ input[:cache].fetch(@cache_key + [input[:filename]] + [data]) do
61
+ transform input
62
+ end
63
+ end
64
+
65
+ def transform(input)
66
+ #byebug
67
+ path_to_rollup = File.join File.dirname(__FILE__), "rollup.js"
68
+ `node #{path_to_rollup} #{input[:filename].shellescape}`
69
+ #file_path = File.dirname(input[:filename])
70
+ #base_name = File.basename(input[:filename])
71
+ #`(cd #{file_path.shellescape}; node #{path_to_rollup.shellescape} #{base_name.shellescape})`
72
+ end
73
+
74
+ end
75
+
76
+ if respond_to?(:register_transformer)
77
+ register_mime_type 'text/js-rollup', extensions: ['.rollup'], charset: :unicode
78
+ register_transformer 'text/js-rollup', 'text/ecmascript-6', Rollup
79
+ register_preprocessor 'text/js-rollup', DirectiveProcessor
80
+ end
81
+
82
+ if respond_to?(:register_engine)
83
+ args = ['.rollup', Rollup]
84
+ args << { mime_type: 'text/js-rollup', silence_deprecation: true } if Sprockets::VERSION.start_with?("3")
85
+ register_engine(*args)
86
+ end
87
+
88
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-rollup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Liam P. White
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sprockets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ description: " A Sprockets transformer that converts ES6 imports into bundles\n"
28
+ email: foo@example.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - lib/sprockets/rollup.js
35
+ - lib/sprockets/rollup.rb
36
+ homepage:
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.5.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Sprockets Rollup
60
+ test_files: []
61
+ has_rdoc: