forked from bugsnag/bugsnag-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
221 lines (188 loc) · 6.39 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
module.exports = (grunt) ->
# Configuration
grunt.initConfig
# Package information
pkg: grunt.file.readJSON "package.json"
# JSHint (see http://www.jshint.com/docs/)
jshint:
options:
# Predefined globals
browser: true
globals:
BUGSNAG_TESTING: false
global: true
module: true
define: true
# The Good Parts
eqeqeq: true
eqnull: true
curly: true
latedef: true
undef: true
forin: true
# Style preferences
indent: 2
camelcase: true
trailing: true
quotmark: "double"
newcap: true
dist:
files:
src: ["src/bugsnag.js"]
"regex-replace":
dist:
src:
["src/bugsnag.js", "README.md"]
actions: [
name: "version"
search: /var NOTIFIER_VERSION =[^;]*;/
replace: -> "var NOTIFIER_VERSION = \"#{require("./package.json").version}\";"
,
name: "readme"
search: /cloudfront.net\/bugsnag-([0-9]+\.)+[0-9]+.min.js/g
replace: -> "cloudfront.net/bugsnag-#{require("./package.json").version}.min.js"
]
# Upload to s3
s3:
options:
bucket: "bugsnagcdn"
access: "public-read"
gzip: true
headers: {
'Cache-Control': 'public, max-age=315360000'
}
release:
upload: [{
src: "src/bugsnag.js"
dest: "bugsnag-<%= pkg.version %>.js"
}, {
src: "dist/bugsnag.min.js"
dest: "bugsnag-<%= pkg.version %>.min.js"
}, {
src: "dist/bugsnag.min.map",
dest: "bugsnag-<%= pkg.version %>.min.map"
}]
major:
options: {
headers: {
'Cache-Control': 'public, max-age=604800'
}
}
upload: [{
src: "src/bugsnag.js"
dest: "bugsnag-<%= pkg.version.split('.')[0] %>.js"
},
{
src: "dist/bugsnag.min.js"
dest: "bugsnag-<%= pkg.version.split('.')[0] %>.min.js"
}]
invalidate_cloudfront:
options:
key: process.env.AWS_ACCESS_KEY_ID
secret: process.env.AWS_SECRET_ACCESS_KEY
distribution: 'E205JDPNKONLN7'
production:
files: [
{dest: 'bugsnag-2.min.js'},
{dest: 'bugsnag-2.js'}
]
# Version bumping
bump:
options:
part: "patch"
onBumped: ->
grunt.task.run("regex-replace")
files: ["package.json", "component.json", "bower.json"]
watch:
test:
options:
livereload: 35729
files: ['test/*.js', 'src/*.js'],
tasks: ['jshint']
# Web server
connect:
test:
options:
hostname: 'localhost'
port: 9002
livereload: 35729
open: true
base: [
'test'
'./'
]
# Headless tests
mocha_phantomjs:
options:
reporter: 'spec'
all: ['test/index.html'],
# Documentation
docco:
dist:
src: ["src/**/*.js"]
dest: "docs/"
# Load tasks from plugins
grunt.loadNpmTasks "grunt-mocha-phantomjs"
grunt.loadNpmTasks "grunt-contrib-jshint"
grunt.loadNpmTasks "grunt-contrib-connect"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-bumpx"
grunt.loadNpmTasks "grunt-s3"
grunt.loadNpmTasks "grunt-docco"
grunt.loadNpmTasks "grunt-regex-replace"
grunt.loadNpmTasks "grunt-invalidate-cloudfront"
# Task to tag a version in git
grunt.registerTask "git-tag", "Tags a release in git", ->
exec = require("child_process").exec
done = this.async()
releaseVersion = grunt.template.process("<%= pkg.version %>")
child = exec "git commit -am \"v#{releaseVersion}\" && git tag --force v#{releaseVersion}", (error, stdout, stderr) ->
console.log releaseVersion
console.log("Error running git tag: " + error) if error?
done(!error?)
grunt.registerTask "git-push", "Push a release to github", ->
exec = require("child_process").exec
done = this.async()
releaseVersion = grunt.template.process("<%= pkg.version %>")
child = exec "git push origin master \"v#{releaseVersion}\"", (error, stdout, stderr) ->
console.log("Error running git push: " + error) if error?
done(!error?)
grunt.registerTask "npm_publish", "Publish a release to npm", ->
exec = require("child_process").exec
done = this.async()
exec "npm publish", (error, stdout, stderr) ->
console.log("Error running npm publish: " + error) if error?
done(!error?)
grunt.registerTask "stats", ["uglify", "uglify-stats"]
grunt.registerTask "uglify", "Uglifies bugsnag.js", () ->
exec = require("child_process").exec
done = this.async()
child = exec "./bin/uglify.coffee", (error, stdout, stderr) ->
console.log("Error running uglify.coffee: " + error) if error?
done(!error?)
grunt.registerTask "uglify-stats", "Outputs stats about uglification", ->
exec = require("child_process").exec
done = this.async()
exec ['echo "Size: $(cat src/bugsnag.js | wc -c)"',
'echo "Ugly: $(cat dist/bugsnag.min.js | wc -c)"',
'echo "Gzip: $(cat dist/bugsnag.min.js | gzip | wc -c)"'].join(" && "), (error, stdout, stderr) ->
grunt.log.write(stdout.toString())
grunt.log.write(stderr.toString())
done(!error?)
grunt.registerTask "browserstack", "Run tests on browser stack", ->
exec = require("child_process").exec
done = this.async()
child = exec "./node_modules/browserstack-test/bin/browserstack-test -t 90 -b browsers.json -u #{process.env.BROWSERSTACK_USERNAME} -p #{process.env.BROWSERSTACK_PASSWORD} -k #{process.env.BROWSERSTACK_ACCESS_KEY} http://localhost:80/bugsnag-js/test/", (error, stdout, stderr) ->
console.log stdout
console.log stderr
done(!error?)
# Release meta-task
grunt.registerTask "release", ["jshint", "uglify", "docco", "git-tag", "git-push", "s3", "npm_publish", "invalidate_cloudfront"]
# Run a webserver for testing
grunt.registerTask "server", ["connect:server:keepalive"]
# Run tests in browser
grunt.registerTask "browsertest", ["jshint", "connect:test", "watch:test"]
# Run tests headless
grunt.registerTask "test", ["jshint", "mocha_phantomjs"]
# Default meta-task
grunt.registerTask "default", ["jshint", "uglify", "docco"]