forked from tuna/thuthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
126 lines (100 loc) · 3.08 KB
/
gulpfile.js
File metadata and controls
126 lines (100 loc) · 3.08 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
const argv = require('minimist')(process.argv.slice(2))
const path = require('path');
const gulp = require('gulp');
const log = require('fancy-log');
const color = require('ansi-colors');
const del = require('del');
const zip = require('gulp-zip');
const packageName = 'thuthesis';
const config = {
template: {
files: ['thuthesis.ins',
'thuthesis.dtx',
'tsinghua.pdf',
'thuthesis-numeric.bst',
'thuthesis-author-year.bst',
'thuthesis-bachelor.bst',
'Makefile',
'latexmkrc',
'README.md',
'thuthesis.pdf'],
// generated shold not be included for ctan archive
generated: ['thuthesis.cls']
},
example: {
files: ['main.tex',
'shuji.tex',
'main.pdf',
'shuji.pdf',
'thuthesis.sty',
'data/*.tex',
'figures/*.*',
'ref/*.bib']
},
dist: {
root: './dist',
files: [],
build: '',
zip: ''
},
};
function usage() {
log('Usage:');
log('\t make dist version=x.y.z');
}
function _default(callback) {
usage();
callback();
}
function bootstrap(callback) {
if (!argv.hasOwnProperty('version')) {
usage();
process.exit(1);
}
callback();
}
function cleanup(callback) {
del.sync([path.join(config.dist.root, config.dist.build)]);
log(color.green.bold(`🍺 ${config.dist.zip} generated`));
callback();
}
function copy(callback) {
const src = config.dist.files;
const dest = path.join(config.dist.root, config.dist.build);
return gulp.src(src, {
cwdbase: true
})
.pipe(gulp.dest(dest));
}
function compress(callback) {
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));
}
function init_self(callback) {
config.dist.files = [...config.template.files, ...config.example.files, ...config.template.generated];
config.dist.build = `${packageName}-v${argv.version}`;
config.dist.zip = `${config.dist.build}.zip`;
log(`Removing old ${config.dist.build}...`);
del.sync([path.join(config.dist.root, config.dist.build),
path.join(config.dist.root, config.dist.zip)]);
callback();
}
function init_ctan(callback) {
config.dist.files = [...config.template.files, ...config.example.files];
config.dist.build = `${packageName}`;
config.dist.zip = `${config.dist.build}.zip`;
log(`Removing old ${config.dist.build}...`);
del.sync([path.join(config.dist.root, config.dist.build),
path.join(config.dist.root, config.dist.zip)]);
callback();
}
const build_self = gulp.series(init_self, copy, compress, cleanup);
const build_ctan = gulp.series(init_ctan, copy, compress, cleanup);
const build = gulp.series(bootstrap, build_self, build_ctan);
exports.default = _default;
exports.build = build;