-
Notifications
You must be signed in to change notification settings - Fork 34
/
gulpfile.babel.js
130 lines (112 loc) · 3.69 KB
/
gulpfile.babel.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import fs from 'fs'
import _ from 'lodash'
import gulp from 'gulp'
import twig from 'gulp-twig'
import all from 'gulp-all'
import rename from 'gulp-rename'
import sass from 'gulp-sass'
import autoprefixer from 'gulp-autoprefixer'
import concat from 'gulp-concat'
import header from 'gulp-header'
import cleanCss from 'gulp-clean-css'
import ghPages from 'gulp-gh-pages'
gulp.task('default', ['sass'])
gulp.task('gh-build', ['gh:copy-assets', 'gh:twig-other', 'gh:twig-library'])
/* font */
gulp.task('sass', function () {
let subtasks = [];
let versions = getVersions()
let latest = _.head(versions)
let license = "/*!\n* XEIcon <%= version %> by @NAVER - http://xpressengine.github.io/XEIcon/ - @XEIcon\n* License - http://xpressengine.github.io/XEIcon/license.html (Font: SIL OFL 1.1, CSS: MIT License)\n*/\n\n"
return gulp.src(['./src/versions/' + latest + '/style.css', './src/sass/xeicon.scss'])
.pipe(sass({outputStyle: 'expanded'}))
.pipe(autoprefixer())
.pipe(concat('xeicon.css'))
.pipe(header(license, {version : latest }))
.pipe(gulp.dest('./'))
.pipe(rename({suffix: '.min'}))
.pipe(cleanCss({
compatibility: 'ie9'
}))
.pipe(gulp.dest('./'))
});
gulp.task('gh:deploy', function() {
return gulp.src('./dist/**/*')
.pipe(ghPages());
});
/* gh-pages */
gulp.task('gh:copy-assets', function() {
return gulp.src('./src/template/assets/**/*')
.pipe(gulp.dest('./dist/assets'))
})
gulp.task('gh:twig-other', function () {
'use strict';
let versions = getVersions()
return gulp.src(['./src/template/*.twig', '!**/library.twig'])
.pipe(twig({
data: {
title: 'XEIcon, 문자를 그리다',
versions: versions
}
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('gh:twig-library', function () {
'use strict';
let versions = getVersions()
let subtasks = versions.map(function(version){
let selection = getIcons(version)
return gulp.src('./src/template/library.twig')
.pipe(twig({
data: {
title: 'XEIcon, 문자를 그리다',
versions: versions,
version: selection.version,
categories: selection.categories,
icons: selection.icons
}
}))
.pipe(rename({
suffix: "-" + version
}))
.pipe(gulp.dest('./dist'));
})
return all(subtasks)
});
function getIcons(version) {
let icons = []
let result = {
"version": null,
"categories": [],
"icons": null
}
let selection = JSON.parse(fs.readFileSync('./src/versions/' + version + '/selection.json').toString()).icons
// icon을 카테고리별로 분류
selection.map(function(item, idx) {
let icon = {}
let name = _.map(item.properties.name.split(','), _.trim)
// 필요한 데이터만 선별, 정리
icon.name = _.head(name)
icon.alias = _.slice(name, 1)
icon.category = _.head(item.icon.tags)
icon.order = item.iconIdx
icon.code = item.properties.code
icon.hex = item.properties.code.toString(16)
icon.keyword = _.uniq(_.concat(name, _.slice(item.icon.tags, 1)))
icons.push(icon);
})
result.version = version
result.icons = _.groupBy(icons, 'category')
result.categories = _.keys(result.icons)
return result;
}
function getVersions() {
let dirs = fs.readdirSync('./src/versions');
let versions = [];
dirs.map(function(ver) {
if(fs.existsSync('./src/versions/' + ver + '/selection.json')) {
versions.push(ver)
}
})
return _.reverse(versions)
}