forked from raytaylorlin/hust-graduation-thesis-pandoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
84 lines (73 loc) · 2.17 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
var gulp = require('gulp');
var clean = require('gulp-clean');
var pandoc = require('gulp-pandoc');
var gutil = require('gulp-util');
var runSequence = require('run-sequence');
var childProcess = require('child_process');
var exec = childProcess.exec;
var execSync = childProcess.execSync;
var DIR_TEMP = 'temp/';
var DIR_DIST = 'dist/';
gulp.task('pandoc-parts', function() {
return gulp.src(['src/*.md', '!src/thesis.md'])
.pipe(pandoc({
from: 'markdown',
to: 'latex',
ext: '.tex',
args: ['--chapters']
}))
.pipe(gulp.dest(DIR_TEMP));
});
gulp.task('pandoc-thesis', function(cb) {
exec('pandoc -s --template=template/template.tex --chapters -o temp/thesis.tex src/thesis.md');
// 让gulp知道任务到此已完成
cb();
});
gulp.task('copy-template', function() {
return gulp.src([
'template/hustthesis.bst',
'template/hustthesis.cls',
'template/hust-title.eps',
'template/hust-title.pdf'
]).pipe(gulp.dest(DIR_TEMP));
});
gulp.task('copy-src', function() {
return gulp.src([
'src/*.tex',
'src/figures/**/*',
'src/ref.bib'
], {base: 'src/'}).pipe(gulp.dest(DIR_TEMP));
});
gulp.task('pdf', function(cb) {
process.chdir(DIR_TEMP);
gutil.log('Executing xelatex thesis...');
execSync('xelatex thesis');
gutil.log('Executing bibtex thesis...');
execSync('bibtex thesis');
gutil.log('Executing xelatex thesis...');
execSync('xelatex thesis');
gutil.log('Executing xelatex thesis...');
execSync('xelatex thesis');
process.chdir('../');
// 让gulp知道任务到此已完成
cb();
});
gulp.task('copy-pdf', function() {
return gulp.src('temp/thesis.pdf')
.pipe(gulp.dest(DIR_DIST));
});
gulp.task('clean', function() {
return gulp.src(DIR_TEMP, {read: false})
.pipe(clean());
});
gulp.task('default', function(cb) {
runSequence(
// 'clean',
'pandoc-parts',
'pandoc-thesis',
['copy-template', 'copy-src'],
'pdf',
'copy-pdf',
cb
);
});