forked from substance/substance-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
58 lines (46 loc) · 2.17 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
# Build script adpated from http://github.com/jashkenas/coffee-script/Cakefile
# ==============================================================================
fs = require 'fs'
sys = require 'sys'
CoffeeScript = require 'coffee-script'
{spawn, exec} = require 'child_process'
config = JSON.parse(fs.readFileSync(__dirname+ '/config.json', 'utf-8'))
settings = JSON.parse(fs.readFileSync(__dirname+ '/settings.json', 'utf-8'))
# ANSI terminal colors.
red = '\033[0;31m'
green = '\033[0;32m'
reset = '\033[0m'
# Commands
compressionCmd = (module) ->
"java -jar ./lib/compiler.jar --js public/javascripts/#{module}.js --js_output_file public/javascripts/#{module}.min.js"
couchPushCmd = "cd couch && couchapp push #{config.couchdb_url} && cd .."
# Run a CoffeeScript through the node/coffee interpreter.
run = (args) ->
proc = spawn 'bin/coffee', args
proc.stderr.on 'data', (buffer) -> puts buffer.toString()
proc.on 'exit', (status) -> process.exit(1) if status != 0
# Log a message with a color.
log = (message, color, explanation) ->
console.log "#{color or ''}#{message}#{reset} #{explanation or ''}"
# Build from source
build = ->
# Build Client
content = ''
content += fs.readFileSync("src"+file)+'\n' for file in settings.scripts.source
fs.writeFileSync('./public/javascripts/substance.js', content, encoding='utf8')
# Build Data.js
content = ''
content += fs.readFileSync(file)+'\n' for file in ['lib/data/data.js', 'lib/data/adapters/ajax_adapter.js']
fs.writeFileSync('./public/javascripts/data.js', content, encoding='utf8')
task 'build', 'Rebuild from source', ->
build()
exec compressionCmd('substance'), (err, stdout, stderr) ->
throw err if err
log 'Sucessfully built public/javascripts/substance.js and public/javascripts/substance.min.js', green
exec compressionCmd('data'), (err, stdout, stderr) ->
throw err if err
log 'Sucessfully built public/javascripts/data.js and public/javascripts/data.min.js', green
task 'couch:push', 'Push design documents to the CouchDB instance', ->
exec couchPushCmd, (err, stdout, stderr) ->
throw err if err
log 'Successfully pushed the CouchApp', green