-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
executable file
·199 lines (174 loc) · 5.44 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
var fs = require("fs");
var request = require("request");
module.exports = function(grunt) {
'use strict';
// This is the slug title of the project
// For example, "single-page-project"
var slug = "census";
// This is the projects folder where the project will be deployed
// For example:
// Enter "news" for http://projects.statesman.com/news
// Enter "sports" for http://projects.statesman.com/sports
var projectsDirectory = "news";
// This is the directory path to your project on the stage/prod servers
var site_path = projectsDirectory + "/" + slug;
// Project configuration.
grunt.initConfig({
// Copy FontAwesome files to the fonts/ directory
copy: {
fonts: {
src: 'node_modules/font-awesome/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/dist/style.css": "src/less/style.less"
}
}
},
// Run our JavaScript through JSHint
jshint: {
js: {
src: ['src/js/**.js']
}
},
// Use Uglify to bundle up a pym file for the home page
uglify: {
options: {
sourceMap: true
},
prod: {
files: {
'public/dist/scripts.js': [
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/js/button.js',
'node_modules/bootstrap/js/collapse.js',
'node_modules/bootstrap/js/dropdown.js',
'node_modules/bootstrap/js/transition.js',
'node_modules/masonry-layout/dist/masonry.pkgd.min.js',
'node_modules/imagesloaded/imagesloaded.pkgd.min.js',
'node_modules/underscore/underscore-min.js',
'src/js/main.js'
]
}
}
},
// jqury, button, collapse, transition, dropdown
// Lint our Bootstrap usage
bootlint: {
options: {
relaxerror: ['W005']
},
files: 'public/**.php',
},
// Watch for changes in LESS and JavaScript files,
// relint/retranspile when a file changes
watch: {
options: {
livereload: true
},
markup: {
files: ['public/*.php','public/includes/*.inc']
},
scripts: {
files: ['src/js/*.js'],
tasks: ['jshint', 'uglify']
},
styles: {
files: ['src/less/**/*.less'],
tasks: ['less']
}
},
// stage path needs to be set
// this project includes a `keep` segment to other projects
// inside `/news/census` are not deleted upon deployment
ftpush: {
stage: {
auth: {
host: 'cmgdtcpxahost.cmg.int',
port: 21,
authKey: 'cmg'
},
src: 'public',
dest: '/stage_aas/projects/' + site_path,
exclusions: ['dist/tmp','Thumbs.db','.DS_Store'],
simple: false,
useList: false,
keep: ['*']
},
// prod path will need to change
prod: {
auth: {
host: 'cmgdtcpxahost.cmg.int',
port: 21,
authKey: 'cmg'
},
src: 'public',
dest: '/prod_aas/projects/' + site_path,
exclusions: ['dist/tmp','Thumbs.db','.DS_Store'],
simple: false,
useList: false,
keep: ['*']
}
}
});
// 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 ftp_path = where_dis_go === "prod" ? "http://projects.statesman.com/" + site_path : "http://stage.host.coxmediagroup.com/aas/projects/" + site_path;
// do whatever makes you feel happy here
var payload = {
"text": "Someone just pushed *" + slug + "*: " + ftp_path,
"channel": "#bakery",
"username": "gruntbot",
"icon_url": "http://vermilion1.github.io/presentations/grunt/images/grunt-logo.png"
};
// 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.');
}
});
// Load the task plugins
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-ftpush');
grunt.loadNpmTasks('grunt-bootlint');
grunt.registerTask('default', ['copy', 'less', 'jshint','bootlint','uglify']);
grunt.registerTask('stage', ['default','ftpush:stage','slack:stage']);
grunt.registerTask('prod', ['default','ftpush:prod','slack:prod']);
};