Last active
          February 3, 2016 09:57 
        
      - 
      
- 
        Save HerringtonDarkholme/34b57329f04d4ec8df6c to your computer and use it in GitHub Desktop. 
    Read tsconfig dynamically
  
        
  
    
      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
    
  
  
    
  | let s:enabled_options = [ | |
| \ 'target', 'emitDecoratorMetadata', 'experimentalDecorators', 'module', | |
| \ 'noImplicitAny', 'rootDir', 'noEmit', 'allowSyntheticDefaultImports', | |
| \ 'noImplicitReturn', 'allowUnreachableCode', 'allowUnusedLabels' | |
| ] | |
| function! neomake#makers#ft#typescript#tsc() | |
| let l:tsconfig = findfile('tsconfig.json', '.;') | |
| if len(l:tsconfig) | |
| let true = 1 | |
| let false = 0 | |
| let null = 0 | |
| " ugly shortcut | |
| let l:jsonText = join(readfile(l:tsconfig, 'b'), '') | |
| let l:json = eval(l:jsonText) | |
| let l:option = get(l:json, 'compilerOptions', {}) | |
| let l:option['noEmit'] = 1 | |
| let l:args = [] | |
| if !len(get(l:option, 'rootDir', '')) | |
| let l:option['rootDir'] = fnamemodify(l:tsconfig, ':h') | |
| endif | |
| for [key, value] in items(l:option) | |
| if index(s:enabled_options, key) == -1 | |
| continue | |
| endif | |
| if value == 1 | |
| call insert(l:args, '--'.key) | |
| elseif type(value) == type('') | |
| call insert(l:args, value) | |
| call insert(l:args, '--'.key) | |
| endif | |
| endfor | |
| else | |
| let l:args = [ | |
| \ '-m', 'commonjs', '--noEmit', '--rootDir', '.' | |
| \ ] | |
| endif | |
| return { | |
| \ 'args': l:args, | |
| \ 'errorformat': | |
| \ '%E%f %#(%l\,%c): error %m,' . | |
| \ '%E%f %#(%l\,%c): %m,' . | |
| \ '%Eerror %m,' . | |
| \ '%C%\s%\+%m' | |
| \ } | |
| endfunction | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment