Skip to content

Commit

Permalink
Merge pull request #57 from prettier/issue/56-allow-option-to-set-pre…
Browse files Browse the repository at this point in the history
…ttier-cli-path

issue/56 - Allowing user path overwrite configuration
  • Loading branch information
mitermayer authored Sep 26, 2017
2 parents 9cc6c74 + c880bd0 commit ade5eb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ When installed via vim-plug, a default prettier executable is installed inside v

vim-prettier executable resolution:

1. Traverse parents and search for Prettier installation inside `node_modules`
2. Look for a global prettier installation
3. Use locally installed vim-prettier prettier executable
1. Look for user defined prettier cli path from vim configuration file
2. Traverse parents and search for Prettier installation inside `node_modules`
3. Look for a global prettier installation
4. Use locally installed vim-prettier prettier executable

### USAGE

Expand Down Expand Up @@ -91,6 +92,12 @@ Disable auto formatting of files that have "@format" tag
let g:prettier#autoformat = 0
```

Set the prettier CLI executable path

```vim
let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
```

The command `:Prettier` by default is synchronous but can also be forced async

```vim
Expand Down
6 changes: 6 additions & 0 deletions autoload/prettier.vim
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,17 @@ function! s:Get_Prettier_Exec_Args(config) abort
endfunction

" By default we will search for the following
" => user defined prettier cli path from vim configuration file
" => locally installed prettier inside node_modules on any parent folder
" => globally installed prettier
" => vim-prettier prettier installation
" => if all fails suggest install
function! s:Get_Prettier_Exec() abort
let l:user_defined_exec_path = fnamemodify(g:prettier#exec_cmd_path, ':p')
if executable(l:user_defined_exec_path)
return l:user_defined_exec_path
endif

let l:local_exec = s:Get_Prettier_Local_Exec()
if executable(l:local_exec)
return l:local_exec
Expand Down
11 changes: 8 additions & 3 deletions doc/prettier.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ When installed via vim-plug, a default prettier executable is installed inside

vim-prettier executable resolution:

1. Traverse parents and search for Prettier installation inside `node_modules`
2. Look for a global prettier installation
3. Use locally installed vim-prettier prettier executable
1. Look for user defined prettier cli path from vim configuration file
2. Traverse parents and search for Prettier installation inside `node_modules`
3. Look for a global prettier installation
4. Use locally installed vim-prettier prettier executable

==============================================================================
INSTALL *vim-prettier-install*
Expand Down Expand Up @@ -81,6 +82,10 @@ Disable auto formatting of files that have "@format" tag
>
let g:prettier#autoformat = 0
<
Set the prettier CLI executable path
>
let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
<
The command `:Prettier` by default is synchronous but can also be forced async
>
let g:prettier#exec_cmd_async = 1
Expand Down
3 changes: 3 additions & 0 deletions plugin/prettier.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ let g:loaded_prettier = 1
" autoformating enabled by default upon saving
let g:prettier#autoformat = get(g:, 'prettier#autoformat', 1)

" path to prettier cli
let g:prettier#exec_cmd_path = get(g:, 'prettier#exec_cmd_path', 0)

" calling :Prettier by default runs synchronous
let g:prettier#exec_cmd_async = get(g:, 'prettier#exec_cmd_async', 0)

Expand Down

0 comments on commit ade5eb1

Please sign in to comment.