This repository has been archived by the owner on Aug 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
142 lines (129 loc) · 3.41 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
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
const gulp = require('gulp');
const zip = require('gulp-zip');
const imagemin = require('gulp-imagemin');
const run = require('gulp-run');
const change = require('gulp-change');
const rename = require('gulp-rename');
const del = require('del');
const { series } = gulp;
let dark = false;
function setDark() {
//returns promise so gulp won't complain
return new Promise(function(resolve, reject) {
dark = true;
resolve();
});
}
function setLight() {
//returns promise so gulp won't complain
return new Promise(function(resolve, reject) {
dark = false;
resolve();
});
}
function cleanWorkspace(cb) {
if (dark) {
return del('guideDark.pdf');
} else {
return del('guideLight.pdf');
}
}
function optimizeImages(cb) {
//using gulp-imagemin to compress images, will not compress image that already has been
return gulp
.src('src/res/images/*')
.pipe(imagemin())
.pipe(gulp.dest('src/res/images'));
}
function backup(cb) {
return gulp.src('src/guide.tex').pipe(gulp.dest('backup'));
}
function loadBackup(cb) {
return gulp.src('backup/guide.tex').pipe(gulp.dest('src'));
}
function packagePdf(cb) {
//creates the final output file including both the pdf file and the LICENSE file
if (dark) {
return gulp
.src('LICENSE')
.pipe(rename('LICENSE.txt'))
.pipe(gulp.src('guideDark.pdf'))
.pipe(zip('guideDarkPdf.zip'))
.pipe(gulp.dest('dist'));
} else {
return gulp
.src('LICENSE')
.pipe(rename('LICENSE.txt'))
.pipe(gulp.src('guideLight.pdf'))
.pipe(zip('guideLightPdf.zip'))
.pipe(gulp.dest('dist'));
}
}
function packageImages(cb) {
return gulp
.src('src/res/images/*')
.pipe(zip('guideImages.zip'))
.pipe(gulp.dest('dist'));
}
function replaceStr(content) {
let str = dark ? '%$DARK:' : '%$LIGHT:';
str = str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
return content.replace(new RegExp(str, 'g'), '');
}
function makeDarkTex(cb) {
//creates the guideDark.tex file using the guide.tex file and uncommenting all DARK marked lines
return gulp
.src('src/guide.tex')
.pipe(change(replaceStr))
.pipe(rename('guideDark.tex'))
.pipe(gulp.dest('src/'));
}
function makeLightTex(cb) {
//creates the guideLight.tex file using the guide.tex file and uncommenting all LIGHT marked lines
return gulp
.src('src/guide.tex')
.pipe(change(replaceStr))
.pipe(rename('guideLight.tex'))
.pipe(gulp.dest('src/'));
}
function buildGuide(cb) {
//using gulp-run and xelatex from your PATH, creates pdf file from either Light or Dark tex file
if (dark) {
return run(
'xelatex -interaction=nonstopmode -file-line-error -aux-directory=src -include-directory=src/res/sections/ src/guideDark.tex'
).exec();
} else {
return run(
'xelatex -interaction=nonstopmode -file-line-error -aux-directory=src -include-directory=src/res/sections/ src/guideLight.tex'
).exec();
}
}
//all commands available using gulp <command>, requires gulp cli
exports.buildDark = series(
setDark,
backup,
optimizeImages,
makeDarkTex,
buildGuide,
loadBackup,
packagePdf,
cleanWorkspace
);
exports.buildLight = series(
setLight,
backup,
optimizeImages,
makeLightTex,
buildGuide,
loadBackup,
packagePdf,
cleanWorkspace
);
exports.testLight = series(
setLight,
backup,
makeLightTex,
buildGuide,
loadBackup
);
exports.packageImages = series(optimizeImages, packageImages);