-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
88 lines (69 loc) · 2.4 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
var gulp = require('gulp');
var del = require('del');
var connect = require('gulp-connect');
var rename =require('gulp-rename');
let child_process = require('child_process');
gulp.task('clean',function(){
return del(['./page','./static/','./index.html','./mainfest.json','service-worker.js','asset-manifest.json']);
});
gulp.task('blog',['reactDemo'],function(){
gulp.src('./src/blog/dist/**/*.*').pipe(gulp.dest('./'));
console.log('finish blog');
});
gulp.task('reactDemoHtml',function(){
gulp.src('./src/reactDemo/build/index.html').pipe(rename('reactDemo.html')).pipe(gulp.dest('./page/'));
});
gulp.task('reactDemo',['reactDemoHtml'],function(){
gulp.src(['./src/reactDemo/build/**/*.*','!./src/reactDemo/build/index.html']).pipe(gulp.dest('./'));
});
gulp.task('watch',function(){
gulp.watch('./src/blog/*.*',['blog']);
gulp.watch('./src/reactDemo',['blog']);
})
gulp.task('connect',function(){
connect.server({
root:'../',
ip:'0.0.0.0',
livereload:true
})
})
gulp.task('default',['connect','watch'], function() {
return gulp.start('blog');
});
gulp.task('blogBuild',['clean'],function(cb){
try{
child_process.exec('cd src/blog && npm run build ', { shell: '/bin/sh' }, function (error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
}catch (e) {
console.log(e);
} finally {
console.log('----------------------------------------------------end build------------------------------------------------------');
cb();
}
});
gulp.task('reactDemoBuild',function(cb){
try{
child_process.exec('cd src/reactdemo && npm run build ', { shell: '/bin/sh' }, function (error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
}catch (e) {
console.log(e);
} finally {
console.log('----------------------------------------------------end build------------------------------------------------------');
cb();
}
});
gulp.task('build',['blogBuild','reactDemoBuild'],function(){
gulp.start('blog');
});