sewing_kit 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7f11b53cd7599867f27fe7bba0af1435d27713a
4
- data.tar.gz: 9729034b26d91852ce43904dc8aa4b45198613a3
3
+ metadata.gz: 414255f60aa685249721e994b55a325c2651c46a
4
+ data.tar.gz: e30a4f36e0b77439df7f0195b8332716b464e712
5
5
  SHA512:
6
- metadata.gz: 3fe8cb746cbd96023e855ba86ed583c2b86abd712e401999f1f960a75d94f24832f4d21aa1ba08890fc39d1d0471d6eff7fb65c428942dc4e10effe524cfe972
7
- data.tar.gz: b30db6c8bf6f28aaf267ab79f4f1ecd797f6d7b1a618b8c7949efef6081e21a4dfbdfbe158e8bc428aaffe8030a15cd8c24c44cfb7b37e82b2dfba7fadb605dd
6
+ metadata.gz: 3eaed1acd08aeb49ca206c5e8f324bdff9b5e3f8d457771959122e51716cf3fda9e0ab1fdd4f6695f9eec51f2e17938baf17994ca20601bb5dde539789c9adaa
7
+ data.tar.gz: 0d312b594a84f4de70e9a73712ca8dd07e69ae7f16452849b16f24cfdee8b0b9b8ce5491af2caa7a065fb2cd9a1d99bda40680467338bbb76b79508baf8ad29f
@@ -1,3 +1,3 @@
1
1
  module SewingKit
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -10,22 +10,24 @@ module SewingKit
10
10
  class UnknownJavaScriptAssetError < StandardError
11
11
  end
12
12
 
13
- def sewing_kit_asset_paths(source, extension: 'js')
14
- return '' unless source.present?
15
- return '/webpack/assets/dll/vendor.js' if serve_development_asests? && 'vendor' == source && extension == 'js'
13
+ def sewing_kit_asset_paths(entrypointName, extension: 'js')
14
+ return '' unless entrypointName.present?
16
15
 
17
- paths = SewingKit::Webpack::Manifest.asset_paths(source)
18
- return '' unless paths[extension]
16
+ paths = SewingKit::Webpack::Manifest.asset_paths(entrypointName)
17
+ return '' unless paths && paths[extension]
19
18
 
20
- [paths[extension]].flatten.reject { |path| path =~ /.*\.map$/ }
19
+ entryPaths = paths[extension]
20
+ if serve_development_assets? && extension == 'js'
21
+ entryPaths.unshift('/webpack/assets/dll/vendor.js')
22
+ end
23
+ entryPaths
21
24
  end
22
25
 
23
26
  def sewing_kit_link_tag(*paths)
24
- return '' unless serve_compiled_assets?
25
-
26
27
  options = paths.extract_options!
27
28
 
28
29
  tags = paths.uniq.map { |path|
30
+ next '' if path == ''
29
31
  create_asset_tag(:link, path, options)
30
32
  }
31
33
 
@@ -36,9 +38,7 @@ module SewingKit
36
38
  options = paths.extract_options!
37
39
 
38
40
  tags = paths.uniq.map { |path|
39
- if path == ''
40
- next ''
41
- end
41
+ next '' if path == ''
42
42
 
43
43
  create_asset_tag(:script, path, options)
44
44
  }
@@ -79,12 +79,8 @@ module SewingKit
79
79
  path.rpartition('-').last.split('.').first
80
80
  end
81
81
 
82
- def serve_compiled_assets?
83
- Rails.env.production? || ENV['SK_SIMULATE_PRODUCTION'] == '1'
84
- end
85
-
86
- def serve_development_asests?
87
- return false if serve_compiled_assets?
82
+ def serve_development_assets?
83
+ return false if ENV['SK_SIMULATE_PRODUCTION'] == '1'
88
84
  Rails.env.development?
89
85
  end
90
86
  end
@@ -11,43 +11,54 @@ module SewingKit
11
11
  end
12
12
  end
13
13
 
14
+ class LegacyManifestError < StandardError
15
+ def initialize(manifest)
16
+ super "manifest must contain 'entrypoints' key (found: #{manifest})"
17
+ end
18
+ end
19
+
14
20
  class << self
15
21
  # :nodoc:
16
- def asset_paths(source)
17
- paths = manifest[source]
18
- paths || {}
22
+ def asset_paths(entrypointName)
23
+ metadata['entrypoints'][entrypointName]
19
24
  end
20
25
 
21
26
  def clear_cache!
22
- @manifest = nil
23
- @manifest_expiry_time = nil
27
+ @metadata = nil
28
+ @metadata_expiry_time = nil
24
29
  end
25
30
 
26
31
  def manifest
32
+ metadata['assets']
33
+ end
34
+
35
+ private
36
+
37
+ def metadata
27
38
  if ::Rails.env.production?
28
39
  # Cache at class level, as JSON loading/parsing can be expensive.
29
- @manifest ||= load_manifest
40
+ @metadata ||= load_metadata
30
41
  else
31
42
  # In development, the manifest may change.
32
43
  # A short cache lifetime avoids time consuming node callouts.
33
- if self.instance_variable_defined?('@manifest_expiry_time') && @manifest_expiry_time && @manifest_expiry_time >= Time.now
34
- @manifest
44
+ if self.instance_variable_defined?('@metadata_expiry_time') && @metadata_expiry_time && @metadata_expiry_time >= Time.now
45
+ @metadata
35
46
  else
36
- @manifest = load_manifest
37
- @manifest_expiry_time = Time.now + 4
47
+ @metadata = load_metadata
48
+ @metadata_expiry_time = Time.now + 4
38
49
  end
39
50
  end
40
51
 
41
- @manifest
42
- end
52
+ raise LegacyManifestError.new(@metadata) if !@metadata['entrypoints']
43
53
 
44
- private
54
+ @metadata
55
+ end
45
56
 
46
57
  def manifest_bundled?
47
58
  !manifest["errors"].any? { |error| error.include? "Module build failed" }
48
59
  end
49
60
 
50
- def load_manifest
61
+ def load_metadata
51
62
  JSON.parse(`node_modules/.bin/sewing-kit manifest --mode #{mode}`)
52
63
  rescue => e
53
64
  raise ManifestLoadError.new("Could not load compiled manifest - have you run `rake sewing_kit:build`?", e)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sewing_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sauve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-22 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties