-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
109 lines (92 loc) · 4.1 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
###
#
# Build Script
# Compiles Sass and Coffee files to CSS and JavaScript
#
###
# ------------------------------------------------------
# -- Load dependencies ---------------------------------
fs = require "fs"
{ spawn, exec } = require "child_process"
# ------------------------------------------------------
# -- console colors ------------------------------------
red = "\u001b[31m"
blue = "\u001b[34m"
green = "\u001b[32m"
reset = "\u001b[0m"
# ------------------------------------------------------
# -- Define directory path -----------------------------
coffee =
srcDir: 'coffee'
outDir: 'html/js'
inFiles: ['hipster']
outFile: 'hipster'
joinedFiles = ("#{coffee.srcDir}/#{file}.coffee" for file in coffee.inFiles).join ' '
jsOutput = "#{coffee.outDir}/#{coffee.outFile}"
sass =
srcDir: 'sass'
outDir: 'html/css'
file: 'hipster'
# ------------------------------------------------------
# -- time function -------------------------------------
gettime = () ->
d = new Date()
curr_hour = d.getHours()
if curr_hour < 12
a_p = "AM"
else
a_p = "PM"
curr_hour = 12 if curr_hour is 0
curr_hour = curr_hour - 12 if curr_hour > 12
curr_min = d.getMinutes()
curr_min = curr_min + ""
curr_min = "0" + curr_min if curr_min.length is 1
curr_hour + ":" + curr_min + " " + a_p
# ------------------------------------------------------
# -- Deal with the errors ------------------------------
exerr = (err, sout, serr) ->
process.stdout.write "[#{red}#{gettime()}#{reset}] " + err if err
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + sout if sout
process.stdout.write "[#{red}#{gettime()}#{reset}] " + serr if serr
# ------------------------------------------------------
# -- Compile & Watch functions -------------------------
compileCoffee = () ->
exec "coffee -j #{jsOutput}.js -c #{joinedFiles}", exerr
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + green + "compiled" + reset + " #{joinedFiles}\n"
compileSass = () ->
exec "sass -t compressed #{sass.srcDir}/#{sass.file}.scss #{sass.outDir}/#{sass.file}.css", exerr
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + green + "compiled" + reset + " #{sass.srcDir}/#{sass.file}.scss\n"
watchCoffeeFiles = (filename) ->
unless filename.charAt(0) is "."
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + "#{blue}watching#{reset}: " + "#{coffee.srcDir}/" + filename + "\n"
fs.watchFile "#{coffee.srcDir}" + filename, (curr, prev) ->
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + "#{blue}changed!#{reset}: " + filename + "\n"
compileCoffee()
watchSassFiles = (filename) ->
unless filename.charAt(0) is "."
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + "#{blue}watching#{reset}: " + "#{sass.srcDir}/" + filename + "\n"
fs.watchFile "#{sass.srcDir}/" + filename, (curr, prev) ->
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + "#{blue}changed!#{reset}: " + filename + "\n"
compileSass()
# ------------------------------------------------------
# -- All the tasks -------------------------------------
task 'build', 'join and compile *.coffee and *.scss files', ->
compileCoffee()
compileSass()
task 'build:js', 'join and compile *.coffee', ->
compileCoffee()
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + green + "compiled" + reset + " #{strFiles}\n"
task 'build:css', 'compile *.scss files', ->
compileSass()
process.stdout.write "[#{blue}#{gettime()}#{reset}] " + green + "compiled" + reset + " #{sass.file}.css\n"
task 'watch', 'watch coffee and sass directory for changes and compile', ->
filearrayCoffee = fs.readdirSync coffee.srcDir
watchCoffeeFiles filename for filename in filearrayCoffee
filearraySass = fs.readdirSync sass.srcDir
watchSassFiles filename for filename in filearraySass
task 'watch:js', 'watch coffee directory for changes and compile', ->
filearray = fs.readdirSync coffee.srcDir
watchCoffeeFiles filename for filename in filearray
task 'watch:css', 'watch sass directory for changes and compile', ->
filearray = fs.readdirSync sass.srcDir
watchSassFiles filename for filename in filearray