forked from DanKottke/midas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
236 lines (218 loc) · 6.19 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
/**
* Gruntfile
*
* If you created your Sails app with `sails new foo --linker`,
* the following files will be automatically injected (in order)
* into the EJS and HTML files in your `views` and `assets` folders.
*
* At the top part of this file, you'll find a few of the most commonly
* configured options, but Sails' integration with Grunt is also fully
* customizable. If you'd like to work with your assets differently
* you can change this file to do anything you like!
*
* More information on using Grunt to work with static assets:
* http://gruntjs.com/configuring-tasks
*/
var fs = require('fs'),
path = require('path'),
exec = require('child_process').exec,
browserify = require('browserify'),
stringify = require('stringify');
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-jsonlint');
grunt.loadNpmTasks('grunt-browserify');
// Get path to core grunt dependencies from Sails
var depsPath = grunt.option('gdsrc') || 'node_modules/sails/node_modules';
grunt.loadTasks(depsPath + '/grunt-contrib-clean/tasks');
grunt.loadTasks(depsPath + '/grunt-contrib-copy/tasks');
grunt.loadTasks(depsPath + '/grunt-contrib-concat/tasks');
grunt.loadTasks(depsPath + '/grunt-contrib-watch/tasks');
grunt.initConfig({
browserify: {
prod: {
src: 'assets/js/backbone/app.js',
dest: 'assets/build/js/bundle.min.js',
options: {
browserifyOptions: { debug: false },
transform: ['stringify', ['uglifyify', { global: true }]],
require: ['./assets/js/vendor/jquery-shim.js:jquery'],
}
},
dev: {
src: 'assets/js/backbone/app.js',
dest: 'assets/build/js/bundle.js',
options: {
browserifyOptions: { debug: true },
transform: ['stringify'],
require: ['./assets/js/vendor/jquery-shim.js:jquery'],
}
}
},
cssmin: {
combine: {
files: {
'assets/build/css/midas.css': [
'node_modules/bootstrap/dist/css/bootstrap.css',
'assets/styles/font-awesome/css/font-awesome.min.css',
'assets/styles/font-custom/css/style.css',
'node_modules/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css',
'node_modules/timepicker/jquery.timepicker.css',
'node_modules/blueimp-file-upload/css/jquery.fileupload.css',
'node_modules/Select2/select2.css',
'assets/styles/application.css',
'assets/styles/theme.css'
]
},
options: {
report: 'min'
}
},
minify: {
expand: true,
cwd: 'assets/build/css/',
src: ['*.css', '!*.min.css'],
dest: 'assets/build/css/',
ext: '.min.css',
extDot: 'last',
options: {
report: 'min'
}
}
},
pkg: grunt.file.readJSON('package.json'),
copy: {
prod: {
files: [
{
expand: true,
cwd: './assets',
src: ['build/**/*', 'js/vendor/**/*', 'images/**/*','locales/**/*'],
dest: '.tmp/public'
}
]
},
font: {
files: [
{
expand: true,
flatten: true,
cwd: './assets',
src: ['styles/font-awesome/fonts/*'],
dest: 'assets/build/fonts'
},
{
expand: true,
flatten: true,
cwd: './assets',
src: ['styles/font-custom/fonts/*'],
dest: 'assets/build/fonts'
},
{
expand: true,
flatten: true,
cwd: './assets',
src: ['fonts/*'],
dest: 'assets/build/fonts'
}
]
},
csssupport: {
files: [
{
expand: true,
flatten: true,
cwd: './',
src: ['node_modules/Select2/*.png', 'node_modules/Select2/*.gif'],
dest: 'assets/build/css'
}
]
}
},
clean: {
prod: ['.tmp/public/**']
},
jsonlint : {
sample: {
src:['assets/locales/**/*.json']
}
},
watch: {
api: {
// API files to watch:
files: ['api/**/*']
},
assets: {
// Assets to watch:
files: ['assets/**/*'],
// When assets are changed:
tasks: [
'clean:prod',
// Check validity of JSON files.
'jsonlint',
// build js bundle
'browserify:dev',
// compile the css
'cssmin',
// copy fonts
'copy:font',
// copy css-support images (images that css expects to be in the css directory)
'copy:csssupport',
// copy assets
'copy:prod'
]
}
}
});
// When Sails is lifted:
grunt.registerTask('default', [
'build',
'watch'
]);
grunt.registerTask('build', [
'clean:prod',
// Check validity of JSON files.
'jsonlint',
// build js bundle
'browserify',
// compile the css
'cssmin',
// copy fonts
'copy:font',
// copy css-support images (images that css expects to be in the css directory)
'copy:csssupport',
// copy assets
'copy:prod'
]);
// When sails is lifted in production
// clean and only copy the production files
grunt.registerTask('prod', [
'clean:prod',
// copy fonts
'copy:font',
// copy css-support images (images that css expects to be in the css directory)
'copy:csssupport',
// copy assets
'copy:prod'
]);
grunt.registerTask('initTags', 'load tag data', function() {
var done = this.async();
var toolPath = "tools/tagtool";
fs.readdir(toolPath, function (err, files) {
if (err) {
throw err;
}
files.map(function (file) {
return path.join(toolPath, file);
}).filter(function (file) {
return fs.statSync(file).isFile() &&
path.extname(file) === ('.txt');
}).forEach(function (file) {
var cmd = 'node ' + toolPath + '/tagtool.js ' + path.basename(file, '.txt') + ' ' + file;
grunt.log.write('Adding tags from ' + file).ok();
exec(cmd);
});
done();
});
});
};