-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGruntfile.js
More file actions
executable file
·167 lines (160 loc) · 4.69 KB
/
Gruntfile.js
File metadata and controls
executable file
·167 lines (160 loc) · 4.69 KB
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
'use strict';
module.exports = function (grunt) {
// load all grunt tasks without explicitly referecing them
require('load-grunt-tasks')(grunt);
var path = require('path');
var globalCfg = {
src: {
jsFiles: ['{app,starterKitSDK}/**/*.js', 'test/{unit,e2e}/**/*.js'],
staticMiscFiles: ['index.html', 'app/**/*.{html,json}', 'app/{img,img-static}/**', 'common/img/**'],
staticFontFiles: ['bower_components/bootstrap/dist/fonts/**']
},
distDir: 'dist'
};
//less config function for usemin
var lessCreateConfig = function (context, block) {
var cfg = { files: [] },
//the destination file is the one referenced in the html and it's to be placed in the context.outDir folder
outfile = path.join(context.outDir, block.dest),
filesDef = {};
filesDef.dest = outfile;
filesDef.src = [];
//we have to process each 'less' file referenced in the html, and they are in the 'inDir' folder
context.inFiles.forEach(function (inFile) {
filesDef.src.push(path.join(context.inDir, inFile));
});
cfg.files.push(filesDef);
context.outFiles = [block.dest];
return cfg;
};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
globalCfg: globalCfg,
jshint: {
all: '<%= globalCfg.src.jsFiles %>',
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
}
},
copy: {
main: {
files: [
{ expand: true, src: '<%= globalCfg.src.staticMiscFiles %>', dest: '<%= globalCfg.distDir %>', filter: 'isFile' },
{ expand: true, src: '<%= globalCfg.src.staticFontFiles %>', dest: '<%= globalCfg.distDir %>/app/fonts/', flatten: true, filter: 'isFile' }
],
},
},
useminPrepare: {
//html file that usemin is going to analyse to find the files to process
html: 'app/index.html',
options: {
//destination folder that usemin is going to use to output the processed files (for .js and .css for example)
dest: '<%= globalCfg.distDir %>/app/',
//this custom flow allows usemin to support less
flow: {
steps: {
'js': ['concat', 'uglify'],
'css': ['concat', 'cssmin'],
'less': [{
name: 'less',
createConfig: lessCreateConfig
}]
},
post: {}
},
}
},
less: {
options: {
plugins: [
//plugin that automatically prefixes the css rules with vendor prefixes when needed
new (require('less-plugin-autoprefix'))({ browsers: ['last 2 versions'] }),
//plugin that minifies the css
new (require('less-plugin-clean-css'))()
]
}
},
uglify: {
options: {
screwIE8: true
}
},
filerev: {
options: {
algorithm: 'md5',
length: 8
},
//we do not process the "img-static" folder because the files inside must keep a static path
images: { src: '<%= globalCfg.distDir %>/{app,common}/img/**/*' },
js: { src: '<%= globalCfg.distDir %>/{app,common}/js/**/*.js' },
css: { src: '<%= globalCfg.distDir %>/{app,common}/css/**/*.css' }
},
usemin: {
//html file within which usemin is going to replace the resource references
html: ['<%= globalCfg.distDir %>/app/**/*.html'],
js: ['<%= globalCfg.distDir %>/{app,common}/js/**/*.js'],
css: ['<%= globalCfg.distDir %>/{app,common}/css/**/*.css'],
options: {
//we add the css folders as an "asset dir" so that the ressources referenced in it can resolved
assetsDirs: [
'<%= globalCfg.distDir %>/app', '<%= globalCfg.distDir %>/common',
'<%= globalCfg.distDir %>/app/css', '<%= globalCfg.distDir %>/common/css'
],
blockReplacements: {
less: function (block) {
return '<link rel="stylesheet" href="' + block.dest + '">';
}
}
}
},
karma: {
options: {
configFile: 'karma.conf.js',
},
//continuous integration mode: run tests once in PhantomJS browser.
continuous: {
singleRun: true,
browsers: ['PhantomJS']
}
},
clean: {
public: [
'<%= globalCfg.distDir %>/**',
'.tmp'
]
},
'http-server': {
'dev': {
root: '<%= globalCfg.distDir %>',
port: 5001,
openBrowser: true
}
}
});
grunt.registerTask('buildinfo', 'generate buildinfo file', function () {
var pkg = grunt.file.readJSON('package.json');
var filePath = globalCfg.distDir + '/buildinfo.json';
var info = { 'name': pkg.name, 'version': pkg.version, 'build_date': grunt.template.today('yyyy-mm-dd') };
grunt.file.write(filePath, JSON.stringify(info));
grunt.log.ok(filePath + ' generated');
});
grunt.registerTask('test', [
'clean',
'jshint',
'karma:continuous',
]);
grunt.registerTask('build', [
'test',
'buildinfo',
'copy',
'useminPrepare',
'concat:generated',
'cssmin:generated',
'less:generated',
'uglify:generated',
'filerev',
'usemin'
]);
grunt.registerTask('web', ['http-server:dev']);
};