forked from PrismJS/prism-themes
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
72 lines (59 loc) · 1.84 KB
/
gulpfile.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
const { src, dest, series } = require('gulp');
const cleanCSS = require('gulp-clean-css');
const CleanCSS = require('clean-css');
const header = require('gulp-header');
const fs = require('fs');
const lightDark = require('./light-dark.json');
function minify() {
return src(['themes/*.css', '!themes/base.css'])
.pipe(header(fs.readFileSync('./themes/base.css', 'utf8')))
.pipe(cleanCSS())
.pipe(dest('dist/'));
}
function mergeLightDark() {
const minify = (theme) => {
const cleaned = theme.replace(
/(pre|code)\[class\*='language-'\]::-moz[^\{]+\{[^\}]+\}/s,
'',
);
return new CleanCSS().minify(cleaned).styles;
};
const nestAndMinify = (theme) => {
const temp = theme
.replace(/(\n)([^\s\}@\/])/g, '$1.TEMP__NEST $2')
.replace(/\:root/g, '');
return minify(temp).replace(/\.TEMP__NEST/g, '&');
};
const base = minify(fs.readFileSync('./themes/base.css', 'utf8'));
const items = lightDark;
const partials = [];
items.forEach((data) => {
partials.push(`
<div>
<div class="stack">
<img src="${data.light.replace('.css', '.png')}">
<img src="${data.dark.replace('.css', '.png')}">
</div>
<span>
${data.name}<br>
<span class="has-text-grey-dark">
Light / Dark
</span>
</span>
</div>
`);
});
const html = partials.join('');
fs.writeFileSync('light-dark-gallery.html', html);
items.forEach((data) => {
const light = minify(fs.readFileSync(`./themes/${data.light}`, 'utf8'));
const nestedDark = nestAndMinify(
fs.readFileSync(`./themes/${data.dark}`, 'utf8'),
);
const name = data.name.replace(/\s/g, '-').toLowerCase();
const combo = `${base}${light}html[class*="-dark"],html[class*="dark-"],.dark{${nestedDark}}`;
fs.writeFileSync(`./dist/prism-${name}.light-dark.css`, combo);
});
return Promise.resolve();
}
exports.build = series(minify, mergeLightDark);