-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.coffee
129 lines (114 loc) · 3.82 KB
/
Gruntfile.coffee
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require "shelljs/global"
require 'LiveScript'
async = require('async')
cp = require('child_process')
fs = require('fs')
h = require('./app/server-helpers')
config = require('./config/common')
module.exports = (grunt) ->
# Project configuration.
# for all our js minification needs
#{{{ Load the plugins
grunt.loadNpmTasks "grunt-contrib-uglify"
grunt.loadNpmTasks "grunt-contrib-watch"
#}}}
grunt.initConfig
pkg: grunt.file.readJSON("package.json")
uglify: # TODO try uglify2 against components with --no-mangle
options:
mangle:
except: # XXX don't mangle Components
fs.readdirSync('component', 'utf8')
.filter((f) -> f.match /\.ls$/)
.map((f) -> f.replace /\.ls$/, '')
dist:
files: []
#"public/powerbulletin.min.js": "public/powerbulletin.js"
#"public/powerbulletin-sales.min.js": "public/powerbulletin-sales.js"
watch:
procs:
files: ['plv8_modules/*.ls', 'procedures.sql']
tasks: ['procs', 'launch']
options:
debounceDelay: 50
interrupt: true
socketIO:
files: ['app/io-chat-server.ls', 'app/pb-models.ls', 'app/io-server.ls']
tasks: ['socketIO']
clientJade:
files: ['app/views/*.jade']
tasks: ['clientJade', 'launch']
options:
debounceDelay: 50
interrupt: true
app:
files: ['app/*.ls']
tasks: ['launch']
options:
debounceDelay: 50
interrupt: true
componentJade:
files: ['component/*.jade']
tasks: ['componentJade', 'launch']
options:
debounceDelay: 50
interrupt: true
#{{{ daemonize a command
# - possibly not needed anymore, bin/powerbulletin wipes :)
daemon = (command, pidFile, logFile) ->
pid = false
try # kill running proc
pid = fs.readFileSync(pidFile, "utf8")
process.kill -pid if pid # the minus kills the entire process group
opts =
detached: true
stdio: "inherit"
if logFile
log = fs.openSync(logFile, "a")
opts.stdio = ["ignore", log, log]
proc = cp.spawn(command, [], opts)
fs.writeFileSync pidFile, proc.pid
#}}}
#{{{ Backend tasks
grunt.registerTask "launch", "Launch PowerBulletin!", launch = ->
if process.env.NODE_ENV is "production"
daemon "./bin/powerbulletin", config.tmp + "/pb.pid"
else
#exec "bin/develop &", async:true
daemon "./bin/powerbulletin", config.tmp + "/develop.pid"
grunt.registerTask "procs", "Compile stored procedures to JS", ->
done = this.async()
exec "./bin/build-procs"
silent: true
done()
grunt.registerTask 'socketIO', 'Restart Socket IO', ->
exec 'bin/launch-pb-rt'
#}}}
#{{{ Frontend tasks
grunt.registerTask "clientJade", "compile regular jade", ->
done = this.async()
exec "bin/build-client-jade"
done()
grunt.registerTask "componentJade", "compile component Jade", ->
done = this.async()
exec "bin/build-component-jade"
done()
grunt.registerTask 'css', 'Build master.css for PB, Sales & Community (ltr + emkel, too)', ->
done = this.async()
fn = (id, cb) -> h.renderCssToFile id, 'master.styl', cb
async.each [1, 2, 5, 6, 8], fn, (err) ->
if err then console.log err
h.renderCss 'master-sales.styl', (err, blocks) ->
fs.writeFile 'public/master-sales.css', blocks, (err) ->
if err then console.log err
done()
#}}}
# Default task(s).
if process.env.NODE_ENV is "production"
grunt.registerTask "default", ["launch"] # launch handles everything
else
grunt.registerTask "default", ["launch", "procs", "clientJade", "componentJade", "watch"]
process.on 'SIGINT', ->
exec "killall -s INT -r pb-worker"
process.exit()
# vim:fdm=marker