-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCakefile
65 lines (58 loc) · 1.8 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
fs = require 'fs'
CoffeeScript = require 'coffee-script'
chromatist = require './lib/chromatist'
log = console.log
# ANSI Terminal Colors.
ansi =
boldblue : '\x1b[1;34m'
boldgreen : '\x1b[1;32m'
reset : '\x1b[0m'
source_dir = 'src/'
index_source = 'chromatist'
sources = [
'mathutils'
'underscore_mixins'
'matrix3'
'cie'
'cat'
'rgb'
'hsl_hsv'
'cielab'
'ciecam'
'gamut'
]
output_filename = "./lib/chromatist.js"
compile = (filename, options) ->
source_path = source_dir + filename + '.coffee'
content = fs.readFileSync source_path, 'utf-8'
output = "/* #{filename}.coffee */\n"
output += CoffeeScript.compile content, options
log "#{ansi.boldgreen}compiled#{ansi.reset} #{source_path}"
return output
header = """
/**
* Chromatist JavaScript library v#{chromatist.VERSION}
*
* Copyright 2011, Jacob Rus
*/
"""
task 'build', 'build the main chromatist library', (options) ->
output = [compile index_source, {bare: true}] # compile the first script "bare"
output = output.concat (compile source for source in sources)
output_script = """
#{header}
(function() {
#{output.join '\n'}
}).call(this);
"""
fs.writeFileSync output_filename, output_script, 'utf-8'
log "saved compiled source in #{output_filename}"
log "#{ansi.boldblue}DONE#{ansi.reset}"
task 'watch_and_build', 'watch the source files and recompile on change', ->
invoke 'build'
all_sources = [index_source].concat sources
for source in all_sources
source_path = source_dir + source + '.coffee'
fs.watchFile source_path, {persistent: true, interval: 500}, (curr, prev) ->
return if curr.size is prev.size and +curr.mtime is +prev.mtime
invoke 'build'