js-sourcemap 0.0.2

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8bc4ab996a0a4fec99cf1231c75e03ed9653522
4
+ data.tar.gz: 5991aafb7bc1cc902a7528131d38b753ee148f1a
5
+ SHA512:
6
+ metadata.gz: 2aa3f5c97ca01d7f546ab9051c4bd132f707a3bd3485dd3520997e7bec88f2d35a18d845c5b497f9000dd911b9b9f9d3b351310763022859b35b6b9a6b723c84
7
+ data.tar.gz: e1fdc7cfa2dae1148a0b8cef7e97ae06abdb31144a759e4dc9e6c46d61f56f87ef2c460160d07bb22419d3c361d74ab9a111238b914c77bbac4024d33377709b
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,6 @@
1
+ require "js-sourcemap/version"
2
+ require "js-sourcemap/api"
3
+
4
+ module JsSourcemap
5
+ end
6
+ require 'js-sourcemap/railtie' if defined?(Rails)
@@ -0,0 +1,114 @@
1
+ require "js-sourcemap/env"
2
+ require "uglifier"
3
+ require "find"
4
+
5
+ module JsSourcemap
6
+ class Api
7
+ EXTENSIONS = %w(.js)
8
+
9
+ def env
10
+ @env ||= ::JsSourcemap::Env.new
11
+ end
12
+
13
+ def config
14
+ @config ||= Config.new(env)
15
+ end
16
+
17
+ def config_hash
18
+ config.to_h
19
+ end
20
+
21
+ def reload!
22
+ @env = nil
23
+ @config = nil
24
+ end
25
+
26
+ def generate_mapping
27
+ # empty_dirs
28
+ beginning_time = Time.now
29
+ if !File.exists?(env.sources_dir)
30
+ puts ">>> Directory #{env.sources_dir} doesn't exist"
31
+ return
32
+ end
33
+ Find.find(env.sources_dir) do |file|
34
+ if File.file?(file) and correct_file?(file)
35
+ smo = source_map_options file
36
+ if mapping_creation_required?(file,smo)
37
+ # puts ">>>>>>> minified_file_path : #{smo["minified_file_path"]}, original_file_path : #{smo["original_file_path"]} , source_map_path : #{smo["source_map_path"]}, source_map_file_absolute_path : #{smo["source_map_file_absolute_path"]}, original_file_absolute_path : #{smo["original_file_absolute_path"]}"
38
+ puts ">>>>>>> .................... >>>>>>>>>"
39
+
40
+ copy_source(smo)
41
+ #:source_url => "SourceUrl in minified", :source_map_url => "SourceMappingUrl in minified", :source_filename => "original_file_name_in_map", :source_root=> "lol4", :minified_file_path => "lol5", :input_source_map => "lol6"
42
+ uglified, source_map = Uglifier.new(:source_map_url => smo["source_map_file_absolute_path"], :source_filename => smo["original_file_absolute_path"]).compile_with_map(File.read(file))
43
+ create_min_map_gz(smo,uglified,source_map)
44
+ end
45
+ end
46
+ end
47
+ end_time = Time.now
48
+ puts "................... Completed ..................."
49
+ puts "Time elapsed #{(end_time - beginning_time)*1000} milliseconds"
50
+ end
51
+
52
+ def correct_file?(file)
53
+ return (File.extname(file) == ".js" and !(file=~/-original\.js/))
54
+ end
55
+
56
+ def create_min_map_gz(smo, min_content,sourcem_content)
57
+ puts "=> writing minified file : #{smo["minified_file_path"]} ..."
58
+ f = File.open(smo["minified_file_path"], "w")
59
+ f.write(min_content)
60
+ f.close
61
+
62
+ puts "=> writing js-sourcemap file : #{smo["source_map_path"]} ..."
63
+ f = File.open(smo["source_map_path"], "w")
64
+ f.write(sourcem_content)
65
+ f.close
66
+
67
+ gz_file = "#{smo["minified_file_path"]}"
68
+ puts "=> gzip minified file: #{gzname(gz_file)}"
69
+ %x(gzip -c -9 "#{gz_file}" > "#{gzname(gz_file)}") if compress?(gz_file)
70
+ end
71
+
72
+ def compress?(file)
73
+ if EXTENSIONS.include?(File.extname(file))
74
+ !File.exists?(gzname(file)) || File.mtime(gzname(file)) < File.mtime(file)
75
+ end
76
+ end
77
+
78
+ def gzname(file)
79
+ "#{file}.gz"
80
+ end
81
+
82
+ def copy_source(smo)
83
+ puts "=> Copying #{smo["minified_file_path"]} to #{smo["original_file_path"]}"
84
+ FileUtils.cp(smo["minified_file_path"], smo["original_file_path"])
85
+ end
86
+
87
+ def source_map_options(file)
88
+ a = Hash.new
89
+
90
+ a["minified_file_path"] = file # something-digest.js
91
+ a["original_file_path"] = original_file_path file # something-digest-original.js
92
+ a["source_map_path"] = mapping_file_path file # something-digest.js.map
93
+ a["source_map_file_absolute_path"] = File.join(env.build_absolute_path mapping_file_path file) # map absolute url
94
+ a["original_file_absolute_path"] = File.join(env.build_absolute_path original_file_path file) # original file absolute url
95
+
96
+ a
97
+ end
98
+
99
+ def original_file_path(file)
100
+ dirpath = File.dirname(file)
101
+ File.join(dirpath, File.basename(file,'.js')) + "-original.js"
102
+ end
103
+
104
+ def mapping_file_path(file)
105
+ dirpath = File.dirname(file)
106
+ File.join(dirpath, File.basename(file)) + ".map"
107
+ end
108
+
109
+ def mapping_creation_required?(file,smo)
110
+ return !(File.exists?(smo["original_file_path"]) and File.exists?(smo["source_map_path"]))
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,29 @@
1
+ require "json"
2
+
3
+ module JsSourcemap
4
+ class Env
5
+
6
+ attr_accessor :sources_dir, :domain
7
+
8
+
9
+ def initialize
10
+ self.sources_dir = rails_path "public/assets"
11
+ self.domain = "https://housing.com/"
12
+ end
13
+
14
+ def relative_path(path)
15
+ dir = File.dirname(__FILE__)
16
+ File.expand_path path, dir
17
+ end
18
+
19
+ def rails_path(path)
20
+ "#{Rails.root}/#{path}"
21
+ end
22
+
23
+ def build_absolute_path(path)
24
+ path = path.gsub(/.*(#{self.sources_dir}\/)/,'')
25
+ "#{self.domain}assets/#{path}"
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ module JsSourcemap
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load File.expand_path("../tasks/js-sourcemap.rake", File.dirname(__FILE__))
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module JsSourcemap
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,8 @@
1
+ namespace :smap do
2
+ sm = JsSourcemap::Api.new
3
+
4
+ desc "Generate sourcemap for js files"
5
+ task "generate_mapping" => "assets:environment" do
6
+ sm.generate_mapping
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: js-sourcemap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jayprakash
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: uglifier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.6.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.6.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.7'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: JS js-sourcemap support for rails
62
+ email:
63
+ - jayprakashjay91@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - MIT-LICENSE
69
+ - Rakefile
70
+ - lib/js-sourcemap.rb
71
+ - lib/js-sourcemap/api.rb
72
+ - lib/js-sourcemap/env.rb
73
+ - lib/js-sourcemap/railtie.rb
74
+ - lib/js-sourcemap/version.rb
75
+ - lib/tasks/js-sourcemap.rake
76
+ homepage: https://github.com/Jayiitb/js-sourcemap
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.0
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: js-sourcemap support for rails
100
+ test_files: []