-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruntfile.js
executable file
·179 lines (157 loc) · 4.38 KB
/
gruntfile.js
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
var fs = require("fs");
var request = require("request");
var config = require("./project.config");
module.exports = function(grunt) {
'use strict';
// URL endpoint
var sitePath = config.sitePath;
// stage URL for humans
var stage_url = ['https://s3-us-west-2.amazonaws.com/dev.apps.statesman.com', config.sitePath, 'index.html'].join("/");
// prod URL for humans
var prod_url = ['https://s3-us-west-2.amazonaws.com/apps.statesman.com', config.sitePath, 'index.html'].join("/");
grunt.initConfig({
// Copy FontAwesome files to the fonts/ directory
copy: {
fonts: {
src: [
'node_modules/bootstrap/fonts/**'
],
dest: 'public/fonts/',
flatten: true,
expand: true
}
},
// Transpile LESS
less: {
options: {
sourceMap: true,
paths: ['node_modules/bootstrap/less']
},
prod: {
options: {
compress: true,
cleancss: false
},
files: {
"public/style.css": "src/main.less"
}
}
},
// Run our JavaScript through JSHint
jshint: {
js: {
src: ['src/main.js']
}
},
// Squish all that js into one file
uglify: {
options: {
sourceMap: true
},
prod: {
files: {
'public/scripts.js': [
'node_modules/pym.js/dist/pym.v1.js',
'src/main.js'
]
}
}
},
// Watch for changes in LESS and JavaScript files,
// relint/retranspile when a file changes
watch: {
options: {
livereload: true
},
scripts: {
files: ['src/**js'],
tasks: ['jshint', 'uglify']
},
styles: {
files: ['src/**less'],
tasks: ['less']
},
templates: {
files: ['src/njk/*'],
tasks: ['nunjucks']
}
},
nunjucks: {
options: {
data: grunt.file.readJSON('src/data/data.json'),
paths: 'src/njk'
},
dev: {
files: [{
expand: true,
cwd: 'src/njk',
src: [
'*.html'
],
dest: 'public',
ext: '.html'
}]
}
},
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true,
preserveLineBreaks: true
},
files: {
'public/index.html': 'public/index.html',
'public/tease.html': 'public/tease.html'
}
}
}
});
// Load the task plugins
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-nunjucks-2-html');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadTasks('tasks/');
// register a custom task to hit slack
grunt.registerTask('slack', function(where_dis_go) {
// first, check to see if there's a .slack file
// (this file has the webhook endpoint)
if(grunt.file.isFile('.slack')) {
// homeboy here runs async, so
var done = this.async();
// prod or stage?
var s3Path = where_dis_go === "prod" ? prod_url : stage_url;
var payload = {
"text": "deploying property-tax-impact *" + config.sitePath + "*: " + s3Path,
"channel": "#bakery",
"username": "Taxbot",
"icon_emoji": ":moneybag:"
};
// send the request
request.post(
{
url: fs.readFileSync('.slack', {encoding: 'utf8'}),
json: payload
},
function callback(err, res, body) {
done();
if (body !== "ok") {
return console.error('upload failed:', body);
}
console.log('we slacked it up just fine people, good work');
});
}
// if no .slack file, log it
else {
grunt.log.warn('No .slack file exists. Skipping Slack notification.');
}
});
grunt.registerTask('default', ['copy', 'nunjucks', 'htmlmin', 'less', 'jshint', 'uglify']);
// Publishing tasks
grunt.registerTask('stage', ['default', 'deployS3:stage', 'slack:stage']);
grunt.registerTask('prod', ['default', 'deployS3:prod', 'slack:prod']);
};