-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (60 loc) · 2.08 KB
/
gulpfile.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
/**
* @file gulpfile
* @author ludafa <leonlu@outlook.com>
*/
const gulp = require('gulp');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const svgToJsx = require('./tools/svg-to-component');
const svgRename = require('./tools/svg-rename');
const through = require('through2');
const gutil = require('gulp-util');
const path = require('path');
const fs = require('fs');
gulp.task('svg', () => (
gulp
.src('node_modules/material-design-icons/**/svg/production/*_24px.svg')
.pipe(svgToJsx({
passProps: true
}))
.pipe(rename(path => {
path.dirname = path.dirname
.replace('node_modules/material-design-icons', '')
.replace(/[^/]+\/svg\/production/, '');
path.extname = '.js';
path.basename = svgRename(path.basename);
}))
.pipe(gulp.dest('components'))
));
gulp.task('index', ['svg'], () => {
let files = [];
let stream = gulp
.src('components/*.js')
.pipe(
through.obj((file, encoding, callback) => {
files.push(file.path);
callback(null, file);
})
);
stream.on('end', () => {
let content = files
.map(file => {
let componentName = path.basename(file, '.js');
return `export {default as ${componentName}} from './${componentName}';`
})
.join('\n');
let icons = files.map(file => path.basename(file, '.js'));
fs.writeFileSync(`${__dirname}/components/index.js`, content, 'utf-8');
fs.writeFileSync(`${__dirname}/components/icons.json`, JSON.stringify(icons, 0, 4), 'utf8');
});
return stream;
});
gulp.task('babel', ['index'], () => (
gulp
.src(['components/*.js'])
.pipe(babel())
.pipe(gulp.dest('lib'))
));
gulp.task('icons', ['index'], () => gulp.src('components/icons.json').pipe(gulp.dest('lib')));
gulp.task('pkg', () => gulp.src('package.json').pipe(gulp.dest('lib')));
gulp.task('default', ['babel', 'icons', 'pkg']);