-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
207 lines (197 loc) · 5.22 KB
/
gulpfile.js
File metadata and controls
207 lines (197 loc) · 5.22 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
const gulp = require('gulp');
const path = require('path');
const { rimraf } = require('rimraf');
/** When fixed, need to update build command with:
* "build": "NODE_ENV=production gulp && npx rollup -c --bundleConfigAsCjs",
*/
// Define library configurations
const NODE_DIST = path.join(__dirname, 'node_modules');
const LIB_DIST = 'assets/lib';
const libraries = [
{
name: 'bootstrap',
files: [
{
src: 'bootstrap/dist/js/bootstrap*.js',
dest: '',
},
{
src: 'bootstrap/dist/css/bootstrap*.css',
dest: '',
}
]
},
{
name: 'clipboard',
files: [
{
src: 'clipboard/dist/js/*.js',
dest: '',
}
]
},
{
name: 'dayjs',
files: [
{
src: 'dayjs/dayjs.min.js',
dest: '',
},
{
src: 'dayjs/locale/*.js',
dest: 'locale',
},
{
src: 'dayjs/plugin/*.js',
dest: 'plugin',
}
]
},
{
name: 'fontawesome-free',
files: [
{
src: '@fortawesome/fontawesome-free/css/*.css',
dest: 'css',
},
{
src: '@fontawesome/fontawesome-free/webfonts/*.{ttf,woff,woff2}',
dest: 'webfonts',
},
]
},
{
name: 'jquery',
files: [
{
src: 'jquery/dist/*.{js,map}',
dest: '',
}
]
},
{
name: 'magnific-popup',
files: [
{
src: 'magnific-popup/jquery*.js',
dest: '',
},
{
src: 'magnific-popup/magnific-*.css',
dest: '',
},
]
},
{
name: 'mathjax',
files: [
{
src: 'mathjax/es5/*.js',
dest: ''
},
{
src: 'mathjax/es5/a11y/*.js',
dest: 'a11y'
},
{
src: 'mathjax/es5/adaptors/*.js',
dest: 'adaptors'
},
{
src: 'mathjax/es5/input/*.js',
dest: 'input'
},
{
src: 'mathjax/es5/input/mml/*.js',
dest: 'input/mml'
},
{
src: 'mathjax/es5/input/tex/extensions/*.js',
dest: 'input/tex/extensions'
},
{
src: 'mathjax/es5/output/*.js',
dest: 'output'
},
{
src: 'mathjax/es5/output/svg/fonts/*.js',
dest: 'output/svg/fonts'
},
{
src: 'mathjax/es5/output/chtml/fonts/*.js',
dest: 'output/chtml/fonts'
},
{
src: 'mathjax/es5/output/chtml/fonts/woff-v2/*.woff',
dest: 'output/chtml/fonts/woff-v2'
},
{
src: 'mathjax/es5/sre/*.js',
dest: 'sre'
},
{
src: 'mathjax/es5/sre/mathmaps/*.js',
dest: 'sre/mathmaps'
},
{
src: 'mathjax/es5/ui/*.js',
dest: 'ui'
},
]
},
{
name: 'mermaid',
files: [
{
src: 'mermaid/dist/mermaid.min.js',
dest: '',
},
]
},
{
name: 'simple-jekyll-search',
files: [
{
src: 'simple-jekyll-search/dest/simple-jekyll-search*.js',
dest: '',
},
]
}
];
// Task to clear LIB_DIST
function cleanLibDist() {
const libDistPath = path.join(__dirname, LIB_DIST);
const libraryPaths = libraries.map(library => path.join(libDistPath, library.name));
// Similarly to the above, except now we will use libraryPaths to remove each library directory
return new Promise((resolve, reject) => {
// Use rimraf for recursive directory removal
rimraf(libraryPaths)
.then(() => {
resolve();
})
.catch(error => {
reject(error);
});
});
}
// Task to copy library assets
function copyLibraryAssets(library) {
const { name, files } = library;
const dest = path.join(LIB_DIST, name);
return gulp.parallel(
...files.map(file => {
const srcPath = path.join(NODE_DIST, file.src);
const destPath = path.join(dest, file.dest);
return () => gulp.src(srcPath).pipe(gulp.dest(destPath));
})
);
}
// Create tasks for each library
libraries.forEach(library => {
const taskName = `copy-${ library.name }`;
gulp.task(taskName, copyLibraryAssets(library));
});
// Task to run all library copy tasks
gulp.task('copy-libraries', gulp.series(...libraries.map(library => `copy-${ library.name }`)));
// Default task
gulp.task('default', gulp.series(cleanLibDist, 'copy-libraries'));