coffee_without_nodejs 0.1.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/coff +1 -3
- data/lib/coffee_without_nodejs/compiler.rb +12 -8
- data/lib/coffee_without_nodejs/version.rb +1 -1
- data/lib/coffee_without_nodejs/watcher.rb +38 -9
- data/lib/coffee_without_nodejs.rb +5 -7
- metadata +6 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e008eecd5898d77b74eb2c105e1ef1a62d87c973
         | 
| 4 | 
            +
              data.tar.gz: a2c3a585c6f360830379458a691f97658ed1d474
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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  | 
| 55 | 
            -
            You can found  | 
| 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 | 
| 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,  | 
| 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')  | 
| 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 "[1m[32m==>[0m #{js_path.relative_path_from( | 
| 55 | 
            +
                    puts "[1m[32m==>[0m #{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 | 
            -
                         | 
| 64 | 
            -
                         | 
| 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 [ | 
| 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')
         | 
| @@ -1,21 +1,50 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 2 | 
             
            # -*- coding: utf-8 -*-
         | 
| 3 3 |  | 
| 4 | 
            -
            require ' | 
| 4 | 
            +
            require 'rb-inotify'
         | 
| 5 | 
            +
            require 'singleton'
         | 
| 5 6 |  | 
| 6 7 | 
             
            module CoffeeWithoutNodejs
         | 
| 7 | 
            -
              class CoffeeWatcher | 
| 8 | 
            -
                 | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 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 | 
            -
                 | 
| 14 | 
            -
             | 
| 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  | 
| 18 | 
            -
                   | 
| 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( | 
| 9 | 
            -
                if File.file?( | 
| 10 | 
            -
                   | 
| 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( | 
| 12 | 
            +
                  CoffeeCompiler.compile(coffee, bare)
         | 
| 15 13 | 
             
                end
         | 
| 16 14 | 
             
              end
         | 
| 17 15 |  | 
| 18 16 | 
             
              def self.watch!
         | 
| 19 | 
            -
                CoffeeWatcher. | 
| 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. | 
| 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:  | 
| 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:  | 
| 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. | 
| 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. | 
| 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. | 
| 105 | 
            +
            rubygems_version: 2.4.5
         | 
| 106 106 | 
             
            signing_key: 
         | 
| 107 107 | 
             
            specification_version: 4
         | 
| 108 108 | 
             
            summary: Simple & Smart CoffeeScript command-line compiler.
         |