-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.coffee
152 lines (118 loc) · 3.58 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
module.exports = (grunt) ->
# Load npm tasks
#-----------------------------------------------
require('matchdep').filterDev('grunt-*').forEach grunt.loadNpmTasks
# Config
#-----------------------------------------------
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
banner:
"""
/*!
* <%= pkg.title || pkg.name %> - v<%= pkg.version %> (<%= grunt.template.today("yyyy-mm-dd") %>)
*
* @author <%= pkg.author %>
* @url <%= pkg.homepage %>
* @copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>
* @license <%= pkg.license %>
*/
"""
watch:
coffee:
files: ['src/*.coffee', 'spec/scripts/*.coffee']
tasks: ['coffee', 'notifydone']
compass:
files: ['src/*.scss']
tasks: ['compass:dev']
dev:
files: ['dist/*.js', 'dist/*.css', 'example/index.html']
tasks: ['reload']
coffee:
coffee:
expand: true
cwd: 'src'
src: ['*.coffee']
dest: 'dist'
ext: '.js'
compass:
options:
config: 'src/config.rb'
sassDir: 'src/'
cssDir: 'dist/'
imagesDir: 'dist/images'
relativeAssets: true
dev:
options:
outputStyle: 'expanded'
noLineComments: false
prod:
options:
# outputStyle: 'compressed'
outputStyle: 'expanded'
noLineComments: true
concat:
dist:
src: 'dist/minimalSharer.js'
dest: 'dist/minimalSharer.js'
options:
stripBanners: true
banner: '<%= banner %>'
uglify:
options:
preserveComments: 'some'
dist:
src: 'dist/minimalSharer.js'
dest: 'dist/minimalSharer.min.js'
copy:
dist:
src: 'components/jquery/jquery.min.js'
dest: 'dist/jquery.min.js'
# Tasks
#-----------------------------------------------
grunt.registerTask 'default', ['dev']
grunt.registerTask 'dev', [
'coffee'
'compass:dev'
'notifydone'
]
grunt.registerTask 'prod', [
'coffee'
'compass:prod'
'concat'
'uglify'
'copy'
'notifydone'
]
grunt.registerTask 'notifydone', 'done!', ->
growlnotify 'All tasks done', title: 'Grunt Done', name: 'Grunt'
grunt.registerTask 'reload', 'reload', ->
require('child_process').exec 'osascript -e \'tell application \"Google Chrome\" to tell the active tab of its first window to reload\''
growlnotify 'Reloaded', title: 'Chrome', name: 'Grunt'
# Notification
#-----------------------------------------------
hooker = require 'hooker'
['warn', 'fatal'].forEach (level) ->
hooker.hook grunt.fail, level, (message) ->
level = level.charAt(0).toUpperCase() + level.substr 1
growlnotify message, title: "Grunt #{level}", name: 'Grunt'
hooker.hook grunt.log, 'write', (message) ->
message = grunt.log.uncolor message
if message.indexOf('>> Error: ') >= 0
growlnotify message.substr(10), title: 'Grunt Error', name: 'Grunt', sticky: true
#=== Growl
#==============================================================================================
exec = require('child_process').exec
escapeshellarg = (str) ->
str = JSON.stringify str
str = str.replace /\\n/g, '\n'
growlnotify = (message, option = {}) ->
args = ['growlnotify']
if message
args.push '-m', escapeshellarg message
if option.sticky
args.push '-s'
if option.name
args.push '-n', escapeshellarg option.name
if option.title
args.push '-t', escapeshellarg option.title
exec args.join ' '