forked from ChikuwaJB/vue-feather-icon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
70 lines (63 loc) · 2.23 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
const path = require('path')
const gulp = require('gulp')
const es = require('event-stream')
const rename = require('gulp-rename')
const concat = require('gulp-concat')
const flatten = require('gulp-flatten')
const gutil = require('gulp-util')
const wrap = function(inject) {
return es.map(function (file, cb) {
const contents = String(file.contents)
const filename = path.basename(file.path, '.svg')
try {
file.contents = new Buffer(inject(filename, contents))
} catch (err) {
return cb(new gutil.PluginError('void', err))
}
cb(null, file)
})
}
const upCamelize = (str, separator = '-') => {
return str.split(separator).map((item) => {
return item.charAt(0).toUpperCase() + item.slice(1)
}).join('')
}
gulp.task('pia', () => {
gulp.src('feather/dist/icons/**/*.svg')
.pipe(wrap((name, content) => {
return `exports.${upCamelize(name)} = require('./components/${name}.vue')`
}))
.pipe(concat('index.js'))
.pipe(wrap((filename, content) => `exports.install = require('./plugin.js')\n${content}`))
.pipe(gulp.dest('./'))
})
gulp.task('typescript', () => {
gulp.src('feather/dist/icons/**/*.svg')
.pipe(wrap((name, content) => {
return ` export class ${upCamelize(name)} {}`
}))
.pipe(concat('index.d.ts'))
.pipe(wrap((filename, content) => `import Vue from 'vue';\n\ndeclare module 'vue-feather-icon' {\n export function install(): void;\n${content}\n}`))
.pipe(gulp.dest('./'))
})
gulp.task('components', () => {
gulp.src('feather/dist/icons/**/*.svg')
.pipe(wrap((name, content) => {
return ` Vue.component('feather-${name}', require('./components/${name}.vue').default)`
}))
.pipe(concat('plugin.js'))
.pipe(wrap((filename, content) => `module.exports = function(Vue) {\n Vue.component('feather-icon', require('./components/index.vue').default)\n${content}\n}`))
.pipe(gulp.dest('./'))
})
gulp.task('component', () => {
gulp.src('feather/dist/icons/**/*.svg')
.pipe(wrap((name, content) => {
return `<template>\n${content}\n</template>`
}))
.pipe(rename({
extname: '.vue'
}))
.pipe(flatten())
.pipe(gulp.dest('./components'))
})
gulp.task('default', ['component', 'components', 'pia', 'typescript'])