Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save valpackett/961425 to your computer and use it in GitHub Desktop.
Save valpackett/961425 to your computer and use it in GitHub Desktop.
" File: commonjs-package-json
" Author: Ash Berlin <ash.berlin@gmail.com>, Grigory V. <me@myfreeweb.ru>
" Last Change: 8-May-2011.
" Version: 2.0
" Usage:
"
" Use by placing something like the following in your .vimrc:
"
" let g:maintainer='{ "name": "Ash Berlin", "web": "http://ashberlin.com" }'
"
" and then save this file to ~/.vim/plugins/commonjs-package-json.vim:
"
" mkdir -p ~/.vim/plugin
" curl -q#L http://gist.github.com/gists/961425/download | tar xz -C ~/.vim/plugin --strip 1
"
" or install as a submodule with pathogen
"
" git submodule add git://gist.github.com/961425.git bundle/commonjs-package-json/plugin
function! CommonJSPackageJsonTemplate()
let l:module_name=expand('%:p:h:t')
if !exists('g:maintainer')
echoerr "PackageJsonTemplate: g:maintainer needs to be set"
return
endif
call append(0, [
\'{',
\' "name": "' . l:module_name . '",',
\' "description": "",',
\' "version": "0.1.0",',
\' "keywords": [""],',
\' "maintainers": [',
\' ' . g:maintainer,
\' ],',
\' "contributors": [',
\' ' . g:maintainer,
\' ],',
\' "engines": {',
\' "node": ">=0.4.0"',
\' },',
\ ] )
" g:github_user is used by gist.vim, so lets reuse that.
if (exists('g:github_user') || executable('git'))
if !exists('g:github_user')
let g:github_user = substitute(system('git config --global github.user'), "\n", '', '')
endif
call append(line('$')-1, [
\' "repository": {',
\' "type": "git",',
\' "url": "git://github.com/' . g:github_user . '/' . l:module_name . '.git"',
\' },',
\' "bugs": {',
\' "email": "",',
\' "url": "https://github.com/' . g:github_user . '/' . l:module_name . '/issues"',
\' },',
\' "licenses": [',
\' "type": "MIT",',
\' "url": "https://github.com/' . g:github_user . '/' . l:module_name . '/raw/master/LICENSE"',
\' ],',
\' "dependencies": {',
\' }',
\ ] )
endif
call append(line('$')-1, [ '}' ] )
" And remove the empty line at the end
normal dd
endfunction
if !exists("s:autocommands_loaded")
let s:autocommands_loaded = 1
autocmd BufNewFile package.json :call CommonJSPackageJsonTemplate()
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment