-
Notifications
You must be signed in to change notification settings - Fork 3
/
Cakefile
140 lines (103 loc) · 3.28 KB
/
Cakefile
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
fs = require 'fs'
path = require 'path'
{exec} = require 'child_process'
# ANSI Terminal Colors.
bold = '\033[0;1m'
red = '\033[0;31m'
green = '\033[0;32m'
reset = '\033[0m'
# Built file header.
header = '''
/**
* Cafe Compiler
* http://ich.github.com/cafe
*
* Copyright 2010, Roman I. Kuzmin
* Released under the MIT License
*/
'''
# Log a message with a color.
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
option '-d', '--dir [DIR]', 'set the directory argument'
task 'install', 'install Cafe into /usr/local (need sudo)', (options) ->
base = '/usr/local'
exec "sudo cake uninstall", (error, stdOutput, stdError) ->
if error
console.log stdError.trim()
else
console.log stdOutput.trim() if stdOutput
lib = "#{base}/lib/cafe"
bin = "#{base}/bin"
console.log "Installing Cafe to #{lib}"
console.log "Linking 'cafe' to #{bin}/cafe"
files = []
cwd = process.cwd()
for file in fs.readdirSync(cwd)
stat = fs.statSync("#{cwd}/#{file}")
continue if not stat.isDirectory()
continue if file.charAt(0) is "."
continue if file in ["www", "cache"]
files.push(file)
files.push(".closure-compiler")
files.push(".compile")
files.push("*.coffee")
files.sort()
command = [
"sudo mkdir -p #{lib} #{bin}"
"sudo cp -rf #{files.join(' ')} #{lib}"
"sudo ln -sf #{lib}/.compile/cafe #{bin}/cafe"
"sudo chmod 777 #{lib}/.closure-compiler/*.jar"
].join(' && ')
exec command, (error, stdOutput, stdError) ->
if error
console.log stdError.trim()
else
log('done', green)
task 'uninstall', 'uninstall Cafe from /usr/local (need sudo)', (options) ->
base = '/usr/local'
lib = "#{base}/lib/cafe"
bin = "#{base}/bin"
path.exists("#{lib}/.compile/cafe", (exists) ->
return unless exists and fs.statSync("#{lib}/.compile/cafe").isFile()
console.log "Uninstalling Cafe from #{lib}"
console.log "Unlinking 'cafe' from #{bin}/cafe"
command = [
"sudo rm -rf #{lib}"
"sudo rm -rf #{bin}/cafe"
].join(' && ')
exec command, (error, stdOutput, stdError) ->
if error
console.log stdError.trim()
else
log('done', green)
)
task 'pull', 'pull Cafe into current dir', (options) ->
cwd = fs.realpathSync(process.cwd())
unless (dir = options.dir) and (dir = fs.realpathSync(dir)) and fs.statSync(dir).isDirectory() and fs.statSync("#{dir}/.compile/cafe").isFile()
log('cafe dir no specified', red)
return
if cwd is dir
log('you are already in cafe dir', red)
return
files = []
for file in fs.readdirSync(dir)
stat = fs.statSync("#{dir}/#{file}")
continue if not stat.isDirectory()
continue if file.charAt(0) is "."
continue if file in ["www", "cache"]
files.push("#{dir}/#{file}")
files.push("#{dir}/.closure-compiler")
files.push("#{dir}/.compile")
files.push("#{dir}/*.coffee")
files.push("#{dir}/Cakefile")
files.sort()
command = [
"rm -rf #{cwd}/*"
"cp -rf #{files.join(' ')} #{cwd}"
].join(' && ')
exec command, (error, stdOutput, stdError) ->
if error
console.log stdError.trim()
else
log('done', green)