This repository has been archived by the owner on Dec 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (62 loc) · 1.62 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict'
const del = require('del')
const gulp = require('gulp')
const gulpFilter = require('gulp-filter')
const gulpRename = require('gulp-rename')
const gulpReplace = require('gulp-replace')
const gulpVinylZip = require('gulp-vinyl-zip')
const binaryDefault = [
'eot',
'gif',
'jpg',
'png',
'psd',
'swf',
'ttf',
'woff',
'woff2',
'xap',
'xcf'
]
const tasks = ({
root = 'core',
src = 'src',
binary = [],
version = null,
archive = null
}) => {
if (!version) throw new Error('Missing version config')
if (!archive) throw new Error('Missing archive config')
const nonBinary = [...binaryDefault, ...binary].map(str => `!**/*.${str}`)
const cleanTask = () => del(src)
const extractTask = () => (
gulpVinylZip.src(`${archive}${version}.zip`)
.pipe(gulpFilter(['**/*', '!**/*/Thumbs.db']))
.pipe(gulpRename(path => {
path.dirname = path.dirname.replace(new RegExp(`^${root}`), '')
return path
}))
.pipe(gulp.dest(src))
)
const processTask = () => {
const phpFilter = gulpFilter('**/*.php', {restore: true})
return gulp.src(['src/**/*'].concat(nonBinary))
.pipe(gulpReplace('\r\n', '\n'))
.pipe(gulpReplace('\r', '\n'))
.pipe(phpFilter)
.pipe(gulpReplace('\t', ' '))
.pipe(phpFilter.restore)
.pipe(gulpReplace('\t', ' '))
.pipe(gulpReplace(/ +$/gm, ''))
.pipe(gulpReplace(/([^\n])$/, '$1\n'))
.pipe(gulp.dest(src))
}
return [
{name: 'clean', task: cleanTask},
{name: 'extract', task: extractTask},
{name: 'process', task: processTask}
]
}
module.exports = {
default: tasks
}