-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
86 lines (79 loc) · 2.85 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
var path = require('path');
var _ = require('lodash');
module.exports = function(grunt) {
/*var materialPath = './node_modules/material-design-icons/',
indexFile = grunt.file.read(materialPath + 'index.html'),
pattern = /<div><img\ssrc='(.*)'><br>(.*)<\/div>/ig,
result = indexFile.match(pattern),
mdiIcons = _.map(result, function(val) {
var svg = val.replace(pattern, '$1').replace(/^\.\//, '');
return {
name: path.basename(svg).replace(/_(26x)?24px.svg$/, ''),
svg: svg
};
}),
config = require('./icons.json'),
mdiConfig = {
fontName: config.fontName,
fontDest: config.fontDest,
cssDest: config.cssDest,
cssFontsPath: config.cssFontsPath,
root: materialPath,
icons: mdiIcons
};
grunt.initConfig({
json_generator: {
target: {
dest: "./mid-icons.json",
options: mdiConfig
}
}
});*/
grunt.registerTask('add_patch', function() {
var patchPath = './patch/',
srcPath = './node_modules/webfonts-generator/src/',
cssPatch = 'renderCss.js',
htmlPatch = 'renderHtml.js';
grunt.file.copy(patchPath + cssPatch, srcPath + cssPatch);
grunt.file.copy(patchPath + htmlPatch, srcPath + htmlPatch);
});
grunt.registerTask('generate_font', function() {
var done = this.async();
var webfontsGenerator = require('webfonts-generator');
var config = require('./icons.json');
var iconFiles = config.icons.map(function(icon) {
return config.root + icon.svg;
});
webfontsGenerator({
fontName: config.fontName,
files: iconFiles,
dest: config.fontDest,
types: ['svg', 'ttf', 'woff', 'eot'],
rename: function(iconPath) {
var fileName = path.basename(iconPath);
return _.result(_.find(config.icons, function(icon) {
return path.basename(icon.svg) === fileName;
}), 'name');
},
cssDest: config.cssDest,
cssFontsPath: config.cssFontsPath,
cssTemplate: './template/css.hbs',
templateOptions: {
classPrefix: 'biz-icon-',
baseClass: 'biz-icon'
},
html: true,
htmlDest: './preview.html',
htmlTemplate: './template/html.hbs'
}, function(error) {
if (error) {
console.error(error);
done(false);
} else {
done();
}
});
});
grunt.loadNpmTasks('grunt-json-generator');
grunt.registerTask('default', ['add_patch', 'generate_font']);
};