-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
102 lines (87 loc) · 3.31 KB
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
fs = require('fs')
exec = require('child_process').exec
path = require('path')
util = require('util')
https = require('https')
home = process.env.HOME
# Delete non empty folder (synch)
# From rimraf logic
rmnedirSync = (p)->
s = fs.lstatSync(p)
if not s.isDirectory()
fs.unlinkSync(p)
else
fs.readdirSync(p).forEach (f) ->
rmnedirSync(path.join(p, f))
fs.rmdirSync(p)
# Remove if the file already exists
rmIfExists = (filePath)->
if(path.existsSync(filePath))
if fs.statSync(filePath).isFile()
fs.unlinkSync filePath
console.log "Removing file #{filePath}"
else
rmnedirSync filePath
console.log "Removing directory #{filePath}"
else
console.log "File not exist: #{filePath}"
# Verify .vimrc.old, .gvimrc.old and .vim.old if present remove it
rmIfExists "#{home}/.vimrc.old"
rmIfExists "#{home}/.gvimrc.old"
rmIfExists "#{home}/.vim.old"
rmIfExists "#{home}/.backup"
# backup .vim directory if already available
# used the following script from janus.
script = "for i in ~/.vim ~/.vimrc ~/.gvimrc; do [ -e $i ] && mv $i $i.old; done"
child = exec script,(error,stdout,stderr)->
if error is not null
console.log 'Backup failed. Manually do the backup for .vimrc, .gvimrc and .vim folders'
console.log 'error : ' + error
else
console.log 'Backup successfully done for the following files: '
console.log '~/.vimrc ==> ~/.vimrc.old'
console.log '~/.gvimrc ==> ~/.gvimrc.old'
console.log '~/.vim ==> ~/.vim.old'
# Create ~/.vim folder
# Create ~/.vim/autoload folder
# TODO: just given default mode 0777. Not sure much.
# I think 777 gives read,write and execute access to the user
# Looks like node does not support creating folder with relative path. '~/.vim'
# I got error: Error: ENOENT, No such file or directory '~/.vim'
fs.mkdirSync home + '/.vim', 0777
console.log 'Created .vim folder'
fs.mkdirSync home + '/.vim/autoload',0777
console.log 'Created .vim/autoload folder'
fs.mkdirSync home + '/.vim/bundle',0777
console.log 'Created .vim/bundle folder'
fs.mkdirSync home + '/.backup',0777
console.log 'Created .backup folder'
# Retrieving pathogen.vim file
options = {
host: 'raw.github.com',
port: 443,
path: '/tpope/vim-pathogen/HEAD/autoload/pathogen.vim'
}
# Retrieving pathogen.vim file and saving in .vim/autoload
https.get options, (res)->
res.on 'data',(d)->
fs.writeFileSync "#{home}/.vim/autoload/pathogen.vim", d.toString()
console.log 'pathogen.vim copied to ~/.vim/autoload '
# Reading all the git plugin and cloning under .vim/bundle folder
config = fs.readFileSync "config.json"
configJson = JSON.parse(config)
for plugin in configJson["plugin"]
console.log "Cloning #{plugin['git']}"
script = "cd #{home}/.vim/bundle && git clone #{plugin['git']}"
child = exec script,(error,stdout,stderr)->
if error is not null
console.log "git cloning failed : #{error}"
else
console.log "git cloning successful"
# copying .vimrc files to ~/.vimrc
fs.readFile ".vimrc",(err,buf)->
if(err)
console.log "Error reading .vimrc file"
else
fs.writeFileSync "#{home}/.vimrc",buf
console.log ".vimrc file successfully copied to #{home} directory"