-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
157 lines (140 loc) · 4.08 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
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Copy FontAwesome files to the fonts/ directory
copy: {
fonts: {
src: [
'bower_components/bootstrap/fonts/**'
],
dest: 'static/fonts/',
flatten: true,
expand: true
}
},
// Delete files before running a build
clean: {
css: ['static/fonts', 'static/client.css'],
js: ['static/*.js*', 'build/*.js']
},
// Compile LESS
less: {
client: {
options: {
cleancss: true
},
files: {
"static/client.css": "client/less/client.less"
}
}
},
// Compile Handlebars templates
handlebars: {
client: {
options: {
amd: ['handlebars', '../templates/helpers'],
processName: function(filePath) {
var pieces = filePath.split("/");
var filename = pieces[pieces.length - 1];
var name = filename.split('.')[0];
if(pieces[pieces.length - 2] !== 'templates') {
name = pieces[pieces.length - 2] + '.' + name;
}
return name;
}
},
files: {
"build/templates.js": "client/templates/**/*.hbs"
}
}
},
// Lint JavaScript
jshint: {
client: ['client/**/*.js'],
server: ['*.js']
},
// Build client bundle with r.js optimizer
requirejs: {
client: {
options: {
baseUrl: 'client/js',
mainConfigFile: 'client/js/config.js',
out: 'static/client.js',
optimize: 'uglify2',
include: ['config', 'main'],
name: '../../bower_components/almond/almond',
generateSourceMaps: true,
preserveLicenseComments: false
}
}
},
// Use Node Inspector, available at http://127.0.0.1:8080/debug?port=5858
'node-inspector': {
dev: {}
},
// Start the node server app and restart when app code changes
nodemon: {
dev: {
script: 'app.js',
options: {
env: grunt.file.readJSON('.env'),
nodeArgs: ['--debug'],
stdout: false,
watch: ['app.js', 'models.js', 'views/**/*.hbs', '.env'],
callback: function (nodemon) {
// Don't log to the console
nodemon.on('log', function() {});
// Trigger a refresh on restart
nodemon.on('restart', function () {
setTimeout(function() {
require('fs').writeFileSync('.rebooted', 'rebooted');
}, 1000);
});
}
}
}
},
// Watch client-side code for changes and re-build as needed
watch: {
js: {
files: ['client/**/*.js', 'client/templates/**/*.hbs'],
tasks: ['build:js']
},
less: {
files: ['client/**/*.less'],
tasks: ['build:css']
},
// Only livereload when restart/build is complete
livereload: {
files: ['.rebooted', 'static/*.css', 'static/*.js'],
options: {
livereload: true
}
}
},
// Run server, client dev tasks concurrently
concurrent: {
options: {
logConcurrentOutput: true
},
dev: ['watch', 'nodemon', 'node-inspector']
}
});
// Load plugins
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-handlebars');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-node-inspector');
// Tasks
grunt.registerTask('build:js', ['jshint:client', 'clean:js', 'handlebars', 'requirejs']);
grunt.registerTask('build:css', ['clean:css', 'copy', 'less']);
grunt.registerTask('build', ['build:js', 'build:css']);
grunt.registerTask('default', ['build', 'concurrent']);
};