forked from blacchole/styrkur-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
163 lines (151 loc) · 5.28 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
module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerMultiTask('template-define-name', 'Add name to define function', function() {
var _ = require('lodash');
var lf = grunt.util.linefeed;
var options = this.options({
rootPath: 'www/js/',
separator: ';' + lf,
templateSettings: {}
});
var cutRootPath = function(path){
if(path.indexOf(options.rootPath) === 0){
return path.substring(options.rootPath.length);
}
return path;
}
this.files.forEach(function(f){
var output = f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
grunt.log.write('Source file "' + filepath + '" accepted.');
return true;
}
})
//Go through each file
.map(function(filepath){
var src = grunt.file.read(filepath),
compiled;
try {
compiled = _.template(src).source;
} catch (e) {
grunt.log.error(e);
grunt.fail.warn('JST "' + filepath + '" failed to compile.');
}
if (options.amd) {
return 'define("' + cutRootPath(filepath) + '", function(){ return ' + compiled + '})';
}
});
if (output.length < 1) {
grunt.log.warn('Destination not written because compiled files were empty.');
} else {
grunt.file.write(f.dest, output.join(grunt.util.normalizelf(options.separator)));
grunt.log.writeln('File "' + f.dest + '" created.');
}
});
});
/* We already have a build file in the js folder, lets reuse that one! */
var buildOptionsFile = grunt.file.read( 'www/js/app.build.js' );
var buildOptions = eval( buildOptionsFile );
/* Fix the pats */
buildOptions.baseUrl = 'www/js';
buildOptions.out = 'www/js/main_app.js';
grunt.initConfig({
'template-define-name': {
compile: {
options: {
templateSettings: {
interpolate : /\{\{(.+?)\}\}/g
},
amd: true,
rootPath: 'www/js/'
},
files: {
"www/js/templates/templates.js": [
"www/js/templates/**/*.html"
]
}
}
},
jshint: {
options: {
laxcomma: true,
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
},
},
all: ['www/js/**/*.js', '!www/js/templates/**/*']
},
requirejs: {
compile: {
options: buildOptions
}
},
uglify: {
options: {
compress: {}
},
my_target: {
files: {
'www/js/main_app.min.js': ['www/js/main_app.js']
}
}
},
csslint: {
strict: {
options: {
import: 2,
ids: false,
important: false,
"fallback-colors": false
},
src: ['www/css/style.css']
}
},
concat: { /* CSS TODO: minify! */
options: {
separator: '\n',
},
dist: {
src: [
'www/css/bootstrap.css',
'www/css/app-optimize.css',
'www/css/cards.css',
'www/css/mfglabs_iconset.css',
'www/css/toastr.css',
'www/css/style.css',
'www/css/transitions.css',
'www/css/chartist.min.css'
],
dest: 'www/css/main.css'
}
},
copy: {
main: {
src: [ /* Files we want to use in the mobile app */
'www/mobile.html',
'www/css/main.css',
'www/fonts/*',
'www/libs/almond/almond.js',
'www/libs/date/date.js',
'www/js/main_app.js'
],
dest: 'mobile/',
filter: 'isFile'
}
}
});
grunt.registerTask('default', ['template','optimize']);
grunt.registerTask('css', ['concat']);
grunt.registerTask('optimize', ['requirejs','uglify']);
grunt.registerTask('template', ['template-define-name']);
grunt.registerTask('build', ['template','optimize', 'css',]);
grunt.registerTask('mobile', ['template','optimize','css', 'copy']);
};