forked from tuna/thuthesis
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
118 lines (94 loc) · 2.91 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
const path = require('path');
const gulp = require('gulp');
const util = require('gulp-util');
const del = require('del');
const zip = require('gulp-zip');
const packageName = 'thuthesis';
const config = {
template: {
files: ['thuthesis.ins',
'thuthesis.dtx',
'tsinghua.pdf',
'tsinghua.eps',
'thuthesis-numeric.bst',
'thuthesis-author-year.bst',
'Makefile',
'latexmkrc',
'README.md',
'thuthesis.pdf'],
generated: ['thuthesis.cls',
'thuthesis.cfg']
},
example: {
files: ['main.tex',
'shuji.tex',
'main.pdf',
'shuji.pdf',
'thuthesis.sty',
'data/*.tex',
'figures/*.*',
'ref/*.bib']
},
dist: {
root: './dist',
build: '',
zip: ''
},
isCTAN: false
};
function usage() {
util.log('Usage:');
util.log('\t make dist version=[x.y.z | ctan]');
util.log('\t gulp build --version=[x.y.z | ctan]');
}
function check_notification() {
util.log(util.colors.yellow('⚠️ Double check versions and dates: `make check`, 3 in thuthesis.dtx and 1 in package.json.'));
util.log(util.colors.yellow('⚠️ Ensure all files are generated.'));
}
gulp.task('default', function(callback) {
usage();
callback();
});
gulp.task('bootstrap', function(callback) {
if (!util.env.hasOwnProperty('version')) {
usage();
process.exit(1);
}
const version = util.env.version.toString().toLowerCase();
config.isCTAN = version === 'ctan';
check_notification();
if (config.isCTAN) {
config.dist.build = `${packageName}`;
} else {
config.template.files.push(...config.template.generated);
config.dist.build = `${packageName}-v${version}`;
}
config.dist.zip = `${config.dist.build}.zip`;
util.log(`Removing ${config.dist.build}...`);
del.sync([path.join(config.dist.root, config.dist.build),
path.join(config.dist.root, config.dist.zip)]);
callback();
});
gulp.task('copy', ['bootstrap'], function() {
const src = [...config.template.files, ...config.example.files];
const dest = path.join(config.dist.root, config.dist.build);
return gulp.src(src, {
cwdbase: true
})
.pipe(gulp.dest(dest));
});
gulp.task('zip', ['copy'], function() {
const src = path.join(config.dist.build, '**/*');
return gulp.src(src, {
cwd: config.dist.root,
cwdbase: true
})
.pipe(zip(config.dist.zip))
.pipe(gulp.dest(config.dist.root));
});
gulp.task('build', ['zip'], function(callback) {
del.sync([path.join(config.dist.root, config.dist.build)]);
util.log(util.colors.green.bold('🍺 Build Succeeded.'));
check_notification();
callback();
});