forked from twang281314/frontEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
106 lines (81 loc) · 2.61 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
var gulp = require('gulp');
//var i5ting_toc = require('gulp-i5ting-toc');
var tocmd = require('./index');
var fs = require('fs')
var minimist = require('minimist');
var browserSync = require('browser-sync').create();
var pwd = process.cwd()
// var source_file_name = pwd + '/' + source_file
// var file_name = source_file_name.split('/').pop();;
// var _file_name = file_name.split('.')[0];
// var dest_file_path = pwd + '/preview/' + _file_name + '.html';
// console.log('pwd=' + pwd);
// console.log('source_file_name=' + source_file_name);
// console.log('dest_file_path=' + dest_file_path);
var knowOptions = {
string: 'f',
default: {
f: ''
}
}
var options = minimist(process.argv.slice(2), knowOptions);
var opt = {
source_file_name: 'useMarkdown.md',
is_open: true,
debug: false,
markd_config: {
debug: false
}
}
/**
* 将当前目录下的md文件生成html
*/
gulp.task('build', function() {
//默认将当前目录下面的所有md文件全部生成html
if (options.f === '') {
fs.readdir('.', function(err, data) {
data.forEach(function(name) {
if (name.lastIndexOf('.md') > 0) {
var tempName = name.replace('.md', '').trim();
//console.log(tempName);
tocmd(pwd, name, 'preview/' + tempName + '.html', false, opt)
}
});
});
} else {//将指定md文件生成html
var tempName = options.f.replace('.md','').trim();
tocmd(pwd,options.f,'preview/'+tempName+'.html',false,opt);
}
console.log('全部生成完毕!!!');
});
/**
* 监视文件变化 自动生成html
*/
gulp.task('watch', function() {
gulp.watch(['*.md'], function(event) {
//s=s.replace(/(.*/){0,}([^.]+).*/ig,"$2") ;//Page1.htm
var name = event.path.replace(/.*\\/, '').trim();
var tempName = name.replace('.md', '').trim();
tocmd(pwd, name, 'preview/' + tempName + '.html', false, opt)
console.log('文件:'+name+'已重新生成html');
});
});
/**
* 开发使用说明
* gulp build 将当前目录下所有md文件全部重新生成html
* gulp build --f api.md 将指定的md文件生成html
* gulp 将监视文件变化 实时生成html
*
*/
// 使用变量引用 `reload` 方法
var reload = browserSync.reload;
// 静态服务器
gulp.task('coding', function() {
browserSync.init({
server: {
baseDir: "code"
}
});
gulp.watch("code/menu/*.*").on("change", browserSync.reload);
});
gulp.task('default', ['watch']);