-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.mjs
116 lines (99 loc) · 3.13 KB
/
gulpfile.mjs
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
// /*
// * Backpack - Skyscanner's Design System
// *
// * Copyright 2016-2021 Skyscanner Ltd
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
import { deleteAsync } from 'del';
import gulp from 'gulp';
import chmod from 'gulp-chmod';
import clone from 'gulp-clone';
import rename from 'gulp-rename';
import ts from 'gulp-typescript';
import ordered from 'ordered-read-streams';
import createIconMapping from './tasks/metadata/iconMapping.mjs';
import metadata from './tasks/metadata/index.mjs';
import { iconsPlugins, spinnersPlugins } from './tasks/plugins.mjs';
import svgr from './tasks/svgr.mjs';
gulp.task('clean', () => deleteAsync(['dist']));
const iconReactComponents = (type, size) => {
let src;
let dest;
let plugins;
if (type === 'icons') {
src = `src/${type}/${size}/*.svg`;
dest = `dist/js/${type}/${size}`;
plugins = iconsPlugins;
}
if (type === 'spinners') {
src = `src/${type}/**/${size}.svg`;
dest = `dist/js/${type}`;
plugins = spinnersPlugins;
}
if (src === undefined || dest === undefined) {
throw new Error(`Unrecognised type: ${type}`);
}
const svgs = gulp.src(src).pipe(chmod(0o644));
const tsResult = svgs
.pipe(clone())
.pipe(svgr({ size, plugins }))
.pipe(rename({ extname: '.tsx' }))
.pipe(
ts({
noImplicitAny: true,
jsx: 'preserve',
target: 'es2020',
module: 'es2020',
declaration: true,
skipLibCheck: true,
allowSyntheticDefaultImports: true,
}),
);
return ordered([
tsResult.dts.pipe(gulp.dest(dest)),
tsResult.js.pipe(gulp.dest(dest)),
]);
};
gulp.task('spinners', () =>
ordered([
iconReactComponents('spinners', 'sm'),
iconReactComponents('spinners', 'lg'),
iconReactComponents('spinners', 'xl'),
]),
);
// /*
// ICONS
// */
gulp.task('icons', () =>
ordered([
iconReactComponents('icons', 'sm'),
iconReactComponents('icons', 'lg'),
]),
);
// copy-svgs ignores those in `xl` as we don't want to make them available to web consumers.
gulp.task('copy-svgs', () =>
ordered([
gulp
.src(['src/**/*.svg', '!src/icons/xl/*.svg'])
.pipe(gulp.dest('dist/svgs')),
gulp.src(['src/icons/icons.js']).pipe(gulp.dest('dist/svgs')),
]),
);
gulp.task('create-metadata', () =>
gulp.src('src/icons/lg/*.svg').pipe(metadata()).pipe(gulp.dest('dist')),
);
gulp.task('create-iconmapping', createIconMapping);
const allIcons = gulp.parallel('icons', 'copy-svgs');
const allSpinners = gulp.task('spinners');
gulp.task('default', gulp.series(gulp.parallel(allSpinners, allIcons, 'create-metadata'), 'create-iconmapping'));