This repository has been archived by the owner on Jan 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (45 loc) · 1.77 KB
/
index.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
var gulp = require("gulp"),
Elixir = require("laravel-elixir"),
Task = Elixir.Task,
config = Elixir.config,
iconFont = require('gulp-iconfont'),
iconFontCss = require('gulp-iconfont-css'),
_ = require('underscore');
Elixir.extend("icons", function (options) {
var defaultOptions = {
iconsPath: config.assetsPath + "/icons/",
sassPath: config.assetsPath + "/" + config.css.sass.folder + "/",
fontPath: config.publicPath + "/fonts/",
relativeCssDir: "/fonts/",
iconFontName: "icon-font",
template: __dirname + "/icon-font-template.scss",
sassFileName: null
};
options = _.extend(defaultOptions, options);
options.sassFileName = options.sassFileName ? options.sassFileName : '_' + options.iconFontName + '.scss';
// The icon font SASS file will be saved relative to the font path
// So we need to get to the project root => ../../../
function getRoot(path) {
var backPath = '',
depth = (path.match(/\//g) || []).length;
for (var i = 0; i < depth; i++) {
backPath += '../';
}
return backPath;
}
new Task('icons', function() {
return gulp.src([options.iconsPath + "*.svg"], {base: '.'})
.pipe(iconFontCss({
fontName: options.iconFontName,
path: options.template,
targetPath: getRoot(options.fontPath) + options.sassPath + options.sassFileName,
fontPath: options.relativeCssDir
}))
.pipe(iconFont({
fontName: options.iconFontName,
normalize: true
}))
.pipe(gulp.dest(options.fontPath));
})
.watch(options.iconsPath + "*.svg");
});