-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
187 lines (163 loc) · 5.59 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
/*global module:false*/
module.exports = function(grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
dev: ['.tmp/scripts/*.js', '.tmp/scripts/modules/**/*.js'],
stage: ['.tmp.stage/scripts/*.js', '.tmp.stage/scripts/modules/**/*.js'],
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true,
globals: {
jQuery: true,
require: true,
define: true,
console: true
}
},
},
csslint: {
dev: {
src: '.tmp/styles/main.css',
rules: {
import: false,
'universal-selector': false
}
},
stage: {
src: '.tmp.stage/styles/main.css',
rules: {
import: false,
'universal-selector': false
}
}
},
watch: {
scripts: {
files: '<%= jshint.dev %>',
tasks: ['jshint:dev']
},
styles: {
files: '<%= csslint.dev.src %>',
tasks: ['csslint:dev']
}
},
clean: {
stage: [".tmp.stage"],
// After RequireJS optimizes staging files it leaves all the original
// files untouched. So instead of letting it delete automatically and
// trying to preserve files we don't want to delete, we can
// manually tweak it like we do it here
//
// More details on:
// https://github.com/sergeylukin/emmet.docpad/commit/d0b4265e8b4dc8dd364e69059512220868892ff3
js_prod: ["dist/scripts/modules", "dist/scripts/vendor"],
// same for stylesheets
css_prod: ["dist/styles/reset.css"]
},
exec: {
// Generate staging files (not optimized, but after preprocessing)
// In docpad, static is used for production ready build
// We use it as a pre-production build (staging), but
// still environment name for docpad is "static"
//
// TODO: replace this with docpad wrapper using docpad API
//
docpad_stage: {
command: 'docpad generate --env static',
stdout: true
},
// Switch to dist directory and push it to remote Github repo
deploy_ghpages: {
command: 'cd ./dist' +
// Remove unnecessary stuff
' && rm -f build.txt' +
// Save current remote URL in variable
' && target_repo=`git config remote.origin.url`' +
' && git init' +
' && git add .' +
" && git commit -m'build'" +
// Push commit to URL saved in variable
' && git push $target_repo master:master --force' +
' && rm -fr .git' +
// Return back like nothing happened :)
' && cd ../' +
'',
stdout: true
}
},
// Optimize production website
requirejs: {
compile: {
options: eval(grunt.file.read('./require.build.js'))
}
},
// Rename asset files to include content's hash in filenames
// For example: main.js -> 9e34vn.main.js
rev: {
dist: {
files: {
src: [
'./dist/scripts/{,*/}*.js',
'./dist/styles/{,*/}*.css',
'./dist/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
'./dist/styles/fonts/*'
]
}
}
},
// Replace HTML markup blocks
usemin: {
html: ['./dist/**/*.html']
},
// Set paths for bower components in RequireJS configuration file
bower: {
stage: {
rjsConfig: './.tmp.stage/scripts/main.js'
}
}
});
// Load tasks from NPM
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-css');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-rev');
grunt.loadNpmTasks('grunt-bower-requirejs');
// Default task - results in ready to deploy production website
grunt.registerTask('default', [
'clean:stage', // delete old staging files
'exec:docpad_stage', // generate staging files
'jshint:stage', // validate JS in staging directory
'csslint:stage', // validate CSS in staging directory
// Add bower components path to RequireJS
// 'bower:stage',
'requirejs', // optimize staging files to
// distribution directory
'clean:js_prod', // clean unused JS files
'clean:css_prod', // clean unused CSS files
// Revision assets
'rev',
'usemin', // update HTML markup references
// in distribution directory
// ..and finally..
'clean:stage' // ..delete staging files
// voila! we're done, now I only need `grunt cup:coffee`
]);
// Deploys production website to Github pages
grunt.registerTask('deploy:gh', ['default', 'exec:deploy_ghpages']);
};