-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.ts
142 lines (118 loc) · 3.16 KB
/
gulpfile.ts
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
131
132
133
134
135
136
137
138
139
140
141
142
import gulp from 'gulp';
import json2cson from 'gulp-json2cson';
import plumber from 'gulp-plumber';
import TOML from '@iarna/toml';
import del from 'del';
import yaml from 'js-yaml';
import xmlBuilder from 'xmlbuilder';
import { flatten } from 'lodash';
import { createStream, getSource, IconInfo } from './lib/utils';
const { parallel, series } = gulp;
const filename = 'character-list';
const JSONSource = getSource();
export function cleanAssets() {
return del('character-list/*');
}
export function cleanTS() {
return del([`src/${filename}.ts`, 'dist/*']);
}
export const clean = parallel(cleanAssets, cleanTS);
export function buildCSON() {
return createStream(`${filename}.cson`, JSON.stringify(JSONSource))
.pipe(plumber())
.pipe(json2cson())
.pipe(gulp.dest('character-list'));
}
export function buildJSON() {
return createStream(`${filename}.json`, JSON.stringify(JSONSource, null, '\t'))
.pipe(plumber())
.pipe(gulp.dest('character-list'));
}
export function buildTOML() {
return createStream(`${filename}.toml`, TOML.stringify(JSONSource))
.pipe(plumber())
.pipe(gulp.dest('character-list'));
}
interface IconXML {
'@id': string;
'unicode': { '#text': string };
}
export function buildXML() {
let convertToXMLObj = (icon: IconInfo): IconXML => {
return {
'@id': icon.name,
'unicode': {
'#text': icon.unicode
}
};
};
let xmlObj = {
style: {
solid: {
icon: JSONSource.solid.map(convertToXMLObj)
},
regular: {
icon: JSONSource.regular.map(convertToXMLObj)
},
brands: {
icon: JSONSource.brands.map(convertToXMLObj)
}
}
};
let xmlStr = xmlBuilder.create(xmlObj, { version: '1.0', encoding: 'UTF-8' })
.end({
pretty: true,
indent: '\t'
});
return createStream(`${filename}.xml`, xmlStr)
.pipe(plumber())
.pipe(gulp.dest('character-list'));
}
export function buildYAML() {
let yamlStr = '---\n';
yamlStr += yaml.safeDump(JSONSource);
return createStream(`${filename}.yaml`, yamlStr)
.pipe(plumber())
.pipe(gulp.dest('character-list'));
}
export const generate = series(cleanTS, function generate() {
let JSONSourceStr = JSON.stringify(JSONSource, null, '\t');
// Replace quote
JSONSourceStr = JSONSourceStr
.replace(/"solid"/g, 'solid')
.replace(/"regular"/g, 'regular')
.replace(/"brands"/g, 'brands')
.replace(/"name"/g, 'name')
.replace(/"unicode"/g, 'unicode')
.replace(/"/g, "'");
let content = `export default ${JSONSourceStr};\n`;
return createStream(`${filename}.ts`, content)
.pipe(plumber())
.pipe(gulp.dest('src'));
});
export function countTest() {
let { solid, regular, brands } = JSONSource;
let countAll = (...args: IconInfo[][]): number => {
let allKeys = flatten(args.map(iconInfs => {
return iconInfs.map(iconInf => iconInf.name);
}));
return allKeys.length;
};
let iconCount = {
all: countAll(solid, regular, brands),
solid: solid.length,
regular: regular.length,
brands: brands.length
};
return createStream('icon-count.json', JSON.stringify(iconCount, null, '\t'))
.pipe(gulp.dest('test'));
}
export const build = parallel(
buildCSON,
buildJSON,
buildTOML,
buildXML,
buildYAML
);
build.displayName = 'build';
export default build;