Last active
          August 29, 2015 14:10 
        
      - 
      
- 
        Save dmitry-vsl/9214dde791b1a7fbf79a to your computer and use it in GitHub Desktop. 
    Script to refactor requirejs(amd) modules to more convenient style
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | init | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/opt/vagrant_ruby/bin/ruby | |
| file = IO.read ARGV[0] | |
| header = / | |
| define \s* \[ | |
| ([\s\w\.'"\/,]*?) | |
| \] \s* , \s* \( | |
| ([\s\w,]+) | |
| \) \s* -> | |
| /x | |
| match = header.match(file) | |
| unless match | |
| exit 1 | |
| end | |
| def split string | |
| strs = [] | |
| string.split(/[\s,]+/).each do |p| | |
| p = p.strip | |
| if p != '' | |
| strs.push p | |
| end | |
| end | |
| strs | |
| end | |
| paths = split match[1] | |
| names = split match[2] | |
| result = "define (require) ->\n" | |
| i = 0 | |
| while i < paths.length | |
| if names[i] | |
| result += " #{names[i]} = require #{paths[i]}\n" | |
| else | |
| result += " require #{paths[i]}\n" | |
| end | |
| i += 1 | |
| end | |
| result += "\n" | |
| puts file.sub header, result | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| for file in `find app tests -name '*.coffee'` ; do | |
| result=`./ref.rb $file` | |
| if [ $? == 0 ] ; then | |
| echo "$result" > $file | |
| echo OK $file | |
| else | |
| echo SKIPPING $file | |
| fi | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment