This repository has been archived by the owner on Dec 3, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCakefile
89 lines (81 loc) · 3.51 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
# Copyright (c) 2011 github.com/cactus
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
fs = require 'fs'
path = require 'path'
{exec} = require 'child_process'
jade = require 'jade'
coffee = require 'coffee-script'
uglifyjs = require 'uglify-js'
# helper functions
mkcoffee = (str) ->
js = coffee.compile(str, {bare: true})
js.trim()
mkugly = (str) ->
ast = uglifyjs.parser.parse(str)
ast = uglifyjs.uglify.ast_mangle(ast)
ast = uglifyjs.uglify.ast_squeeze(ast, {show_copyright:false})
js = uglifyjs.uglify.gen_code(ast)
js.trim()
## options
option '-n', '--dry-run', 'dry run for deploy'
## cake tasks
task 'clean', 'clean dist dir', ->
if path.existsSync('./dist/')
exec 'rm -rf ./dist/*', (error) ->
console.log('could remove ./dist dir contents') if error?
else
try
fs.mkdirSync('./dist', 0755)
catch e
console.log('"./dist" dir already exists')
throw e unless e.code == 'EEXIST'
task 'compile', 'compile the whole thing', ->
invoke 'clean'
# copy static files
exec 'cp -r static/ dist/static/', (error) ->
console.log('could not copy files') if error?
# build
lc =
AURSEARCHVER: fs.readFileSync('VERSION', 'utf-8').trim()
bp_screen_css: fs.readFileSync('static/bp.screen.css', 'utf-8').trim()
icanhazjs: mkugly(fs.readFileSync('src/ICanHaz.js', 'utf-8'))
dotimeout: fs.readFileSync('src/jquery.ba-dotimeout.min.js', 'utf-8')
modernizrjs: fs.readFileSync('src/modernizr.min.js', 'utf-8').trim()
search_coffee: mkugly(mkcoffee(fs.readFileSync('src/search.coffee', 'utf-8')))
inline_css: fs.readFileSync('src/screen.css', 'utf-8').trim()
jade.renderFile('src/index.jade', { locals: lc }, (err, html) ->
if err
console.log 'failed to compile jade template'
console.log(err.message)
process.exit(1)
fs.writeFileSync("dist/index.html", html, 'utf-8')
)
task 'deploy', 'deploy to prod -- read config.json for prod config', (options) ->
invoke 'compile'
jdata = JSON.parse(fs.readFileSync('./config.json', 'utf-8'))
if not jdata.prod_host_loc
console.log('invalid ./config.json')
process.exit(1)
rsync_extra_args = if options['dry-run'] then '-n' else ''
exec_str = "rsync -e 'ssh -S none' #{rsync_extra_args} -avzc --delete-after dist/ #{jdata.prod_host_loc} 2>&1"
console.log(exec_str)
rsync_child = exec exec_str
rsync_child.stdout.on 'data', (data) -> console.log(data.trim())