coffee_without_nodejs 0.1.0 → 0.3.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: cbb00c09bd09487c30b51c26208e0ebf8466a688
4
- data.tar.gz: da9f9c2f7f8132b2e9486a592bd36e5759831983
3
+ metadata.gz: e008eecd5898d77b74eb2c105e1ef1a62d87c973
4
+ data.tar.gz: a2c3a585c6f360830379458a691f97658ed1d474
5
5
  SHA512:
6
- metadata.gz: a77418852a996d2aab53ec30515baaa6751636b4399e36711c474b629f1675e9168988471af5e667b5754a87181c7d496aa1095993b6fc94452dda2d12e7aaf3
7
- data.tar.gz: 75034e0f8f7ec3f5ab5c8b4b2341cfa0bcb8a3766aaf8e6ea8b22883f8cea14d438960a67b112ed25cd4127cb1d2f26cff19924d3683fd2c439dfb6a980c8e3b
6
+ metadata.gz: a3521db2b775df1f75ca658c8af5a941aab8b785c390425ea523f35024cf966457735a4d50968c1843327df40f8182e2824b9a9847bf315b7a66ef50971fa06a
7
+ data.tar.gz: d1b624fdc19c17a57d84233d266a1d2fdca0682641ff6e82a56a04b1f8a897e1811fdbeae4e67f2614c6e28e990cf904d79443e178df46e56701eeb4d8afe7a3
data/README.md CHANGED
@@ -51,8 +51,8 @@ Or ...
51
51
 
52
52
  x = 100;
53
53
 
54
- This script is extract from [Alternative Script Suite](https://github.com/zw963/ass).
55
- You can found massive of useful and interesting bash/ruby script here.
54
+ This gem is extract from [Alternative Script Suite](https://github.com/zw963/ass).
55
+ You can found a lot of useful and interesting scripts here.
56
56
 
57
57
  ## Support
58
58
 
data/bin/coff CHANGED
@@ -10,15 +10,13 @@ if ARGV.first == '-e'
10
10
  else
11
11
  if ARGV.empty?
12
12
  `notify-send 'Starting coffee compiler.' -t 1000` if system 'which notify-send &>/dev/null'
13
- Dir['**/*.coffee'].each {|f| CoffeeWithoutNodejs.compile(f) }
14
13
  CoffeeWithoutNodejs.watch!
15
14
  else
16
15
  ARGV.each do |file|
17
16
  fail "`#{file}' is not valid filename." unless File.exist? file
18
17
 
19
18
  if test ?d, file
20
- Dir["#{file}/**/*.coffee"].each {|f| CoffeeWithoutNodejs.compile(f) }
21
- CoffeeWithoutNodejs.watch!
19
+ Dir.chdir(file) { CoffeeWithoutNodejs.watch! }
22
20
  else
23
21
  js_file = CoffeeWithoutNodejs.compile(file).to_s
24
22
  system "coderay -js \"#{js_file}\"" unless js_file.empty?
@@ -41,15 +41,18 @@ WRAPPER
41
41
  file_path = Pathname(File.expand_path(file))
42
42
  source_code = file_path.read
43
43
 
44
- js_path, map_path, dirname = create_js_path_from(file_path)
44
+ js_path, map_path, js_root = create_js_path_from(file_path)
45
45
 
46
- source_files = file_path.relative_path_from(dirname).to_s
47
- generated_file = js_path.relative_path_from(dirname).to_s
46
+ source_files = file_path.relative_path_from(js_path.dirname).to_s
47
+ generated_file = js_path.relative_path_from(js_path.dirname).to_s
48
48
 
49
- File.open(js_path, 'wb') {|f| f.print compiler.call(wrapper, source_code, bare: bare), "\n//# sourceMappingURL=#{File.basename(map_path)}" }
49
+ File.open(js_path, 'wb') do |f|
50
+ f.print "#{ENV['JS_SHEBANG']}\n\n" if ENV['JS_SHEBANG']
51
+ f.print compiler.call(wrapper, source_code, bare: bare), "\n//# sourceMappingURL=#{File.basename(map_path)}"
52
+ end
50
53
  File.open(map_path, 'wb') {|f| f.print compiler.call(wrapper, source_code, sourceMap: true, sourceFiles: [source_files], generatedFile: generated_file)["v3SourceMap"] }
51
54
 
52
- puts "==> #{js_path.relative_path_from(dirname.parent)}"
55
+ puts "==> #{js_path.relative_path_from(js_root.parent)}"
53
56
 
54
57
  js_path
55
58
  rescue ExecJS::RuntimeError
@@ -60,12 +63,13 @@ WRAPPER
60
63
  def create_js_path_from(path)
61
64
  path.descend do |x|
62
65
  if x.basename.to_s == 'coffee'
63
- js = path.sub('/coffee/', '/js/').sub(/\.js\.coffee$|\.coffee$/, '.js')
64
- dirname = js.dirname
66
+ js_root = x.sub(/\/coffee$/, '/js')
67
+ js_path = path.sub('/coffee/', '/js/').sub(/\.js\.coffee$|\.coffee$/, '.js')
68
+ dirname = js_path.dirname
65
69
 
66
70
  dirname.mkpath unless dirname.exist?
67
71
 
68
- return [js, js.sub_ext('.map'), dirname]
72
+ return [js_path, js_path.sub_ext('.map'), js_root]
69
73
  end
70
74
  end
71
75
  js = path.sub(/\.js\.coffee$|\.coffee$/, '.js')
@@ -2,7 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  module CoffeeWithoutNodejs
5
- VERSION = [0, 1, 0]
5
+ VERSION = [0, 3, 0]
6
6
 
7
7
  class << VERSION
8
8
  def to_s
@@ -1,21 +1,50 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- require 'rev'
4
+ require 'rb-inotify'
5
+ require 'singleton'
5
6
 
6
7
  module CoffeeWithoutNodejs
7
- class CoffeeWatcher < Rev::StatWatcher
8
- def initialize(path)
9
- super
10
- attach(Rev::Loop.default)
8
+ class CoffeeWatcher
9
+ include Singleton
10
+
11
+ def initialize
12
+ @notifier = INotify::Notifier.new
13
+ @path = File.expand_path('.')
14
+
15
+ start_watch_files
16
+
17
+ @notifier.watch(@path, :moved_from, :moved_to, :create, :delete, :onlydir, :recursive) do |event|
18
+ # skip temp file.
19
+ next if event.name =~ /^\.#|^#.*\#$/
20
+
21
+ start_watch_files
22
+ end
23
+
24
+ coffee_files.each do |file|
25
+ CoffeeWithoutNodejs.compile(file)
26
+ end
27
+
28
+ # start loop.
29
+ @notifier.run
30
+ puts 'CoffeeWatcher start successful.'
11
31
  end
12
32
 
13
- def on_change
14
- render_file(path)
33
+ # watch all exist files modify event.
34
+ def start_watch_files
35
+ coffee_files.each do |file|
36
+ @notifier.watch(file, :modify) do
37
+ CoffeeWithoutNodejs.compile(file)
38
+ end
39
+ end
15
40
  end
16
41
 
17
- def self.run
18
- Rev::Loop.default.run
42
+ def coffee_files
43
+ all_files = Dir["#@path/**/*.coffee"]
44
+ if ENV['COFFEE_NOT_WATCH_PATTERN']
45
+ all_files.reject! {|e| e =~ Regexp.union(ENV['COFFEE_NOT_WATCH_PATTERN']) }
46
+ end
47
+ all_files
19
48
  end
20
49
  end
21
50
  end
@@ -5,17 +5,15 @@ require 'coffee_without_nodejs/compiler'
5
5
  require 'coffee_without_nodejs/watcher'
6
6
 
7
7
  module CoffeeWithoutNodejs
8
- def self.compile(js, bare=true)
9
- if File.file?(js)
10
- js_file = CoffeeCompiler.compile_file(js, bare)
11
- CoffeeWatcher.new(js)
12
- js_file
8
+ def self.compile(coffee, bare=true)
9
+ if File.file?(coffee)
10
+ CoffeeCompiler.compile_file(coffee, bare)
13
11
  else
14
- CoffeeCompiler.compile(js, bare)
12
+ CoffeeCompiler.compile(coffee, bare)
15
13
  end
16
14
  end
17
15
 
18
16
  def self.watch!
19
- CoffeeWatcher.run
17
+ CoffeeWatcher.instance
20
18
  end
21
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffee_without_nodejs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
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: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rev
28
+ name: rb-inotify
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coderay
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.2.2
105
+ rubygems_version: 2.4.5
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Simple & Smart CoffeeScript command-line compiler.