Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (42 sloc) 1.46 KB
const gulp = require('gulp')
const fsp = require('fs-promise')
const $ = require('gulp-load-plugins')()
const runSequence = require('run-sequence')
const templates = require('./templates')
const template = process.env.template || 'px'
let staticDir = `.`
let paths = {
src : `${staticDir}/src`,
dist: `${staticDir}/dist`
}
gulp.task('icons:sprite', async () => {
let dirs = await fsp.readdir(paths.src)
dirs = dirs.filter((item) => item[0] !== '.')
dirs.unshift('')
let fns = dirs.map((dir) => {
return new Promise((resolve, reject) => {
let name = dir === '' ? '_' : dir
let src = name !== '_' ? `${paths.src}/${dir}/*.+(gif|png|jpg)` : `${paths.src}/*.+(gif|png|jpg)`
gulp.src(src)
.pipe($.spritesmith({
padding: 15,
imgName: `${name}.png`,
cssName: `${name}-${template}.scss`,
cssTemplate(sprite){
return templates[template](name, sprite)
}
}))
.pipe(gulp.dest(paths.dist))
.on('end', resolve)
})
})
return await Promise.all(fns)
})
gulp.task('icons:css', ['icons:sprite'], () => {
return gulp.src(`${paths.dist}/*.scss`)
.pipe($.sass().on('error', $.sass.logError))
.pipe(gulp.dest(paths.dist))
})
gulp.task('default', () => {
gulp.start('icons:css')
})