js2coffee 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c53a754ff9dcb798a2ce162249d437bc0932fc57
4
- data.tar.gz: eeffa4c0603253e26904a505342e61c6cb002dad
3
+ metadata.gz: d3f5e8fc3d77c373dcb01d744ea74329e228d736
4
+ data.tar.gz: df3c643915d6bc2593ceb7a54257cefbb96efa6d
5
5
  SHA512:
6
- metadata.gz: 1427aa2a01f083a0cc80cbe1b4c3568a3d35ec67474b959736c72da9b5160111fc2cf2d467fcdfdbbf9ea3f8795c091ce234be7b8fd75362637823665b95b546
7
- data.tar.gz: a1d3817734a7269e5b67bafb15c95432991693a54cc61313c000d318552714ab29b7202d594d6ade5d923b3d2afdbaee711a1bb58e28911167020f8a0c324471
6
+ metadata.gz: 806ef54442e0857e080458dbe798d3446185019b29039a86219e1c3684d03e00c2a5295d53a7254fab0615051e1e3d0d5f8920a90d2274d0ef81e73c835be63f
7
+ data.tar.gz: 27cd6718bb81eac9e2841865050b4c3faf3d0d13e6cbec55cb822d9608bb5f37b67e9af5069df805c927044aed98306f29b43dc0c8744e3a891a3d87d959eba4
@@ -51,7 +51,7 @@ if filename.any?
51
51
  else
52
52
  filename.each do |file|
53
53
  unless File.exist? file
54
- puts "cannot open \`\033[0;33m#{file}\033[0m' for reading: No such file or directory, Skipping"
54
+ puts "Can't open \`\033[0;33m#{file}\033[0m' for reading: No such file or directory, Skipping"
55
55
  next
56
56
  end
57
57
  Js2coffee.compile_file(file, bare: true, sourceMap: true)
@@ -8,7 +8,7 @@ require 'js2coffee/compiler'
8
8
 
9
9
  module Js2coffee
10
10
  class CoffeeCompiler < Compiler
11
- self.source = 'coffee-script'
11
+ self.source = 'coffee-script.js'
12
12
 
13
13
  class << self
14
14
  def wrapper
@@ -32,7 +32,7 @@ WRAPPER
32
32
  def watch_file(file)
33
33
  file_path = Pathname(file)
34
34
  source_code = file_path.read
35
- target_file, target_map = Js2coffee::PathHelper.new(file_path).create_js_path!
35
+ target_file, target_map = Js2coffee::PathHelper.new(file_path).create_target_path!
36
36
  # generate js and SourceMap.
37
37
  result = compiler.call(wrapper, source_code, bare: false, sourceMap: true,
38
38
  sourceFiles: [file_path.relative_path_from(target_file.dirname).to_s],
@@ -13,7 +13,7 @@ module Js2coffee
13
13
  end
14
14
 
15
15
  def source=(new_source)
16
- @source = File.read(File.expand_path("../compiler/#{new_source}.js", __FILE__))
16
+ @source = File.read(File.expand_path("../compiler/#{new_source}", __FILE__))
17
17
  end
18
18
 
19
19
  def wrapper
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Js2coffee
5
5
  class JsCompiler < Compiler
6
- self.source = 'js2coffee'
6
+ self.source = 'js2coffee.js'
7
7
 
8
8
  class << self
9
9
  def wrapper
@@ -31,7 +31,7 @@ WRAPPER
31
31
  def watch_file(file)
32
32
  file_path = Pathname(file)
33
33
  source_code = file_path.read
34
- target_file, target_map = Js2coffee::PathHelper.new(file_path).create_coffee_path!
34
+ target_file, target_map = Js2coffee::PathHelper.new(file_path).create_target_path!
35
35
  # generate coffee and SourceMap.
36
36
  result = compiler.call(wrapper, source_code)
37
37
  target_file.write(result['code'])
@@ -6,44 +6,28 @@ module Js2coffee
6
6
  @path = Pathname(path)
7
7
  end
8
8
 
9
- def create_js_path!
9
+ def create_target_path!
10
10
  # if find `coffee' in descend path, will create js directory at the same level.
11
- path.descend do |x|
12
- if x.basename.to_s == 'coffee'
13
- js_path = path.sub('/coffee/', '/js/').sub_ext('.js')
14
- map_path = path.sub('/coffee/', '/.map/').sub_ext('.js.map')
15
-
16
- FileUtils.mkdir_p([js_path.dirname, map_path.dirname])
17
-
18
- return [js_path, map_path]
19
- end
20
- end
11
+ ext = path.extname[1..-1]
12
+ target = ext == 'js' ? 'coffee' : 'js'
21
13
 
22
- # else, just save in the same path with new extname.
23
- js_path = path.sub_ext('.js')
24
- map_path = path.sub_ext('.js.map').sub(/\/([^\/]+)$/, '/.\1')
25
- fail 'filename extension must .coffee!' if path == js_path
26
-
27
- [js_path, map_path]
28
- end
29
-
30
- def create_coffee_path!
31
14
  path.descend do |x|
32
- if x.basename.to_s == 'js'
33
- js_path = path.sub('/js/', '/coffee/').sub_ext('.coffee')
34
- map_path = path.sub('/js/', '/.map/').sub_ext('.js.map')
15
+ if x.basename.to_s == ext
16
+ target_path = path.sub("/#{ext}/", "/#{target}/").sub_ext(".#{target}")
17
+ map_path = path.sub("/#{ext}/", '/.map/').sub_ext('.js.map')
35
18
 
36
- FileUtils.mkdir_p([js_path.dirname, map_path.dirname])
19
+ FileUtils.mkdir_p([target_path.dirname, map_path.dirname])
37
20
 
38
- return [js_path, map_path]
21
+ return [target_path, map_path]
39
22
  end
40
23
  end
41
24
 
42
- js_path = path.sub_ext('.coffee')
43
- map_path = path.sub_ext('.js.map').sub(/\/([^\/]+)$/, '/.\1')
44
- fail 'filename extension must .js!' if path == js_path
25
+ # else, just save in the same path with new extname.
26
+ target_path = path.sub_ext(".#{target}")
27
+ map_path = path.sub_ext('.js.map').sub(%r{/([^/]+)$}, '/.\1')
28
+ fail "filename extension must .#{ext}!" if path == target_path
45
29
 
46
- [js_path, map_path]
30
+ [target_path, map_path]
47
31
  end
48
32
  end
49
33
  end
@@ -2,7 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  module Js2coffee
5
- VERSION = [1, 0, 2]
5
+ VERSION = [1, 0, 3]
6
6
 
7
7
  class << VERSION
8
8
  def to_s
@@ -31,6 +31,8 @@ module Js2coffee
31
31
  puts 'Watcher is started.'
32
32
  end
33
33
 
34
+ private
35
+
34
36
  # watch all exist files modify event.
35
37
  def start_watch_files
36
38
  watched_files.each do |file|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js2coffee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Billy.Zheng(zw963)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-13 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs