forked from jxson/indestructibleart.com
/
Gruntfile.js
101 lines (89 loc) · 2.58 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
var globalConfig = {
srcDir: 'public/js/src',
buildDir: 'public/js/build',
testDir: 'public/js/tests',
sass: {
srcDir: 'scss'
},
css: {
srcDir: 'stylesheets/development/',
prodDir: 'public/stylesheets/release/',
src: '',
dest: ''
},
js: {
srcFile: '',
buildFile: '',
minifiedFile: '',
testFile: ''
}
};
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
globalConfig: globalConfig,
jshint: {
files: [
'Gruntfile.js'
],
},
watch: {
compass: {
files: [globalConfig.sass.srcDir + '/**/*.scss'],
tasks: ['compass:development']
}
},
cssmin: {
singleFile: {
files: {
'<%= globalConfig.css.dest %>': '<%= globalConfig.css.src %>'
}
}
},
compass: {
development: {
options: {
config: 'config.rb'
},
files: [{
expand: true,
cwd: globalConfig.sass.srcDir + '/',
src: ['**/*.scss'],
dest: globalConfig.css.prodDir,
ext: '.css'
}]
}
}
});
// Load all npm tasks using matchdep
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
var browserifyPagesRE = new RegExp(globalConfig.srcDir + '\/pages\/');
var jsTestFileRE = new RegExp(globalConfig.testDir);
/*
* On the watch event, we check to see if we are changing a browserify js
* file. If so, we update the globalConfig object which is what the
* browserify and uglify tasks are using to build their respective files.
*/
grunt.event.on('watch', function (action, filepath, target) {
if ((action === 'changed' || action === 'added') &&
(browserifyPagesRE.test(filepath) ||
jsTestFileRE.test(filepath))) {
globalConfig.js.srcFile = filepath;
globalConfig.js.buildFile = filepath.replace('/src/', '/build/');
globalConfig.js.minifiedFile = globalConfig.js.buildFile.replace('.js', '.min.js');
}
});
/*
* This task is called from the command line when a page-specific CSS file is
* generated by Compass so we can have minified version of the compiled file.
*/
grunt.registerTask('compass:minify', function () {
var filepath = grunt.option('file');
globalConfig.css.src = filepath;
globalConfig.css.dest = filepath.replace('.css', '.min.css').replace(globalConfig.css.srcDir, globalConfig.css.prodDir);
grunt.task.run('cssmin:singleFile');
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', ['jshint']);
};