/
Cakefile
69 lines (59 loc) · 2.22 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
fs = require "fs"
FFI = require "node-ffi"
libc = new FFI.Library(null, "system": ["int32", ["string"]])
run = libc.system
pkg = require "./package"
VERSION = pkg.version
OUTPUT = "pkg/annotator.readmill.min.js"
STYLES = "pkg/annotator.readmill.css"
COFFEE = "node_modules/.bin/coffee"
UGLIFY = "node_modules/.bin/uglifyjs"
HEADER = """
/* Readmill Annotator Plugin - v#{VERSION}
* Copyright 2011, Aron Carroll
* Released under the MIT license
* More Information: http://github.com/aron/readmill.annotator.js
*/
"""
task "watch", "Watch the coffee directories and output to ./lib", ->
run "#{COFFEE} --watch --output ./lib ./src"
task "serve", "Serve the example files using a python server", ->
run "python -m SimpleHTTPServer 8000"
run "open http://localhost:8000/index.html"
task "proxy", "Run the proxy server locally on port 8080", ->
run """
PORT=8080 \\
PROXY_DOMAIN=http://localhost:8080 \\
READMILL_CLIENT_CALLBACK=http://localhost:8000/callback.html \\
#{COFFEE} proxy.coffee
"""
task "test", "Open the test suite in the browser", ->
invoke "serve"
run "open http://localhost:8000/test/index.html"
task "build", "Compile production ready files", ->
run "mkdir -p pkg"
run """
echo "#{HEADER}" > #{OUTPUT} &&
find ./src/readmill -not -name "utils.coffee" -type f -print |
xargs cat src/readmill.coffee src/readmill/utils.coffee |
#{COFFEE} --stdio --print |
#{UGLIFY} >> #{OUTPUT} &&
echo "" >> #{OUTPUT}
"""
utils.inline ["css/annotator.readmill.css"], STYLES
task "pkg", "Build a packaged zip of production files", ->
invoke "build"
run "zip -jJ pkg/annotator.readmill.#{VERSION}.zip #{OUTPUT} #{STYLES}"
task "clean", "Remove all temporary pkg and lib files", ->
run "rm -rf lib pkg"
utils =
dataurlify: (css) ->
# NB: path to image is "src/..." because the CSS urls start with "../img"
b64_str = (name) -> fs.readFileSync("src/#{name}.png").toString('base64')
b64_url = (m...) -> "url('data:image/png;base64,#{b64_str(m[2])}')"
css.replace(/(url\(([^)]+)\.png\))/g, b64_url)
inline: (src, dest) ->
run "echo '#{HEADER}' > #{dest}"
run "cat #{src.join(' ')} >> #{dest}"
code = fs.readFileSync(dest, 'utf8')
fs.writeFileSync(dest, @dataurlify(code))