forked from Alan-TheGentleman/UIDevFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
378 lines (332 loc) · 8.93 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
module.exports = function (grunt) {
'use strict';
// Load Grunt tasks declared in the package.json file
require('load-grunt-tasks')(grunt);
// Project settings
var config = {
// Folders for assets, development environment and production environment
folder_dev: 'dev', // If this path gets changed, remember to update .gitignore with the proper path to ignore images and css
folder_build: 'build',
folder_dist: 'dist',
folder_assets: 'assets',
// Local server info
server_address: 'localhost',
server_port: '1337',
server_doc_port: '1338'
};
// Configure Grunt
grunt.initConfig({
// Project settings
config: config,
/* ====================================================================================== */
/* Development tasks */
/* ====================================================================================== */
// Fire a small web server to serve the HTML project
connect: {
server: {
options: {
port: config.server_port,
base: '<%= config.folder_dev %>/',
hostname: '*',
livereload: true,
debug: true
}
},
doc: {
options: {
port: config.server_doc_port,
base: 'assets/doc',
livereload: true,
debug: true
}
}
},
// Templating engine
processhtml: {
dist:{
options: {
process: true
},
files: [{
expand: true,
cwd: '<%= config.folder_assets %>/templates/',
src: ['*.html'],
dest: './<%= config.folder_dev %>',
ext: '.html'
}]
}
},
// grunt-watch monitors the projects files and execute actions when a file changes
watch: {
options: {
livereload: true
},
scss: {
files: ['<%= config.folder_assets %>/styles/**'],
tasks: [
'sass:ui',
'postcss',
'sassdoc'
],
options: {
spawn: false
}
},
js: {
files: '<%= config.folder_dev %>/js/**.*'
},
templates: {
files: [
'<%= config.folder_assets %>/templates/*.*'
],
tasks: ['processhtml']
},
html: {
files: [
'<%= config.folder_dev %>/*.html'
]
},
images: {
files: '<%= config.folder_assets %>/images/**.*',
tasks: ['copy:images']
},
icons: {
files: '<%= config.folder_assets %>/icons/*.*',
tasks: ['webfont']
}
},
// Run Sass compile
sass: {
options: {
sourceMap: true,
outputStyle: 'compressed'
},
ui: {
files: {
'<%= config.folder_dev %>/css/styles.css': '<%= config.folder_assets %>/styles/styles.scss'
}
},
},
// Run autoprefixer after Sass is compiled
postcss: {
options: {
map: true,
processors: [
require('autoprefixer')({browsers: ['last 2 versions']}),
require('cssnano')({zindex: false}) // minify the result
]
},
dist: {
src: '<%= config.folder_dev %>/css/*.css'
}
},
// Create an icon font from SVG files insode /icons folder
webfont: {
icons: {
src: '<%= config.folder_assets %>/icons/*.svg',
dest: '<%= config.folder_dev %>/fonts',
destCss: '<%= config.folder_assets %>/styles/libs/iconfont',
options: {
font: 'icon-font',
hashes: false,
engine: 'node',
stylesheet: 'scss',
relativeFontPath: '../fonts/',
// syntax: 'bootstrap',
template: 'grunt-icontemplate.css',
htmlDemo: false,
skip: false, // Set this variable to false to create the icon font. If /icons folder is empty, leave this variable as is
templateOptions: {
baseClass: 'ms-icon',
classPrefix: 'icon-',
fontPath: '../fonts/'
}
}
}
},
// grunt-open will open your browser at the project's URL
open: {
source: {
path: 'http://<%= config.server_address %>:<%= config.server_port %>'
},
doc: {
path: 'http://<%= config.server_address %>:<%= config.server_doc_port %>'
}
},
// Copy only the needed resources from Bower
bowercopy: {
options: {
// Bower components folder will be removed afterwards
clean: false
},
dev: {
files: {
'<%= config.folder_assets %>/styles/libs/jeet': 'jeet.gs/scss/jeet',
'<%= config.folder_assets %>/styles/libs/normalize': 'normalize-scss',
'<%= config.folder_assets %>/styles/libs/sassy-cast': 'sassy-cast/dist',
'<%= config.folder_dev %>/js/vendor/jquery.min.js': 'jquery-latest/dist/jquery.min.js'
}
}
},
// Every time an image gets updated or a new image is saved in the images folder, Grunt will copy all the images to the source folder
copy: {
images: {
expand: true,
cwd: '<%= config.folder_assets %>/images',
src: '**',
dest: '<%= config.folder_dev %>/img',
filter: 'isFile',
},
build: {
expand: true,
cwd: '<%= config.folder_dev %>',
src: '**',
dest: '<%= config.folder_build %>',
filter: 'isFile',
},
deploy: {
expand: true,
cwd: '<%= config.folder_dev %>',
src: '**',
dest: '<%= config.folder_dist %>',
filter: 'isFile',
}
},
// Execute concurrent tasks in Grunt
concurrent: {
watch: {
tasks: [
'watch', // Watch if files change
'sass:ui', // Run Sass
'open:source' // Open the webserver URL in a browser
],
options: {
logConcurrentOutput: true,
limit: 4 // Limit CPU cores usage to 4
}
}
},
// Uglify JS
uglify: {
options: {
beautify: {
width: 80,
beautify: false
}
},
deploy: {
files: [{
expand: true,
cwd: '<%= config.folder_dist %>/js',
src: '**/*.js',
dest: '<%= config.folder_dist %>/js'
}]
},
build: {
files: [{
expand: true,
cwd: '<%= config.folder_build %>/js',
src: '**/*.js',
dest: '<%= config.folder_build %>/js'
}]
}
},
// Image compression
kraken: {
options: {
key: '',
secret: '',
lossy: true
},
dynamic: {
files: [{
expand: true,
cwd: '<%= config.folder_dist %>/img/',
src: ['**/*.{png,jpg,jpeg,gif}'],
dest: '<%= config.folder_dist %>/img/'
}]
}
},
// Push everything to FTP server
'sftp-deploy': {
build: {
auth: {
host: '',
port: 22,
authKey: 'key1' // Config credentials in .ftppass file
},
cache: 'sftpCache.json',
src: '<%= config.folder_build %>',
dest: '',
concurrency: 4,
progress: true
}
},
// Generate Sass Documentation
sassdoc: {
default: {
src: 'assets/styles/',
options: {
dest: 'assets/doc/',
exclude: ['assets/styles/libs/*'],
display: {
watermark: false
},
"groups": {
"undefined": "General"
},
}
}
}
});
grunt.loadNpmTasks('grunt-webfont');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-kraken');
grunt.loadNpmTasks('grunt-sftp-deploy');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-processhtml');
grunt.loadNpmTasks('grunt-notify');
grunt.loadNpmTasks('grunt-sassdoc');
/* ====================================================================================== */
/* Tasks @registration */
/* ====================================================================================== */
grunt.registerTask('run', [
'connect:server',
'bowercopy',
'copy:images',
'webfont',
'processhtml',
'concurrent:watch'
]);
grunt.registerTask('build', [
'bowercopy',
'webfont',
'processhtml',
'sass',
'copy:build',
'copy:images',
'uglify:build'
]);
grunt.registerTask('deploy', [
'bowercopy',
'copy:images',
'webfont',
'processhtml',
'sass',
'copy:deploy',
'uglify:deploy',
'kraken',
'sftp-deploy'
]);
grunt.registerTask('doc', [
'sassdoc',
'connect:doc',
'open:doc',
'watch:scss'
]);
};