-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
111 lines (98 loc) · 2.98 KB
/
Copy pathgulpfile.js
File metadata and controls
111 lines (98 loc) · 2.98 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
const gulp = require('gulp'),
xml = require('xml2js').parseString,
fs = require('fs'),
babel = require('gulp-babel'),
path = require('path'),
webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const WebpackDevServer = require("webpack-dev-server");
let webpackServer;//子进程
gulp.task('webpack', function(cb) {
//current api don't support refresh,so i start from cmdline
// const compiler = webpack(webpackConfig);
// const server = new WebpackDevServer(compiler, {
// contentBase: path.join(__dirname, "dest"),
// stats: {
// colors: true,
// },
// inline:false,
// hot:true
// });
// console.log(path.join(__dirname, "dest"))
// server.listen(8080, "127.0.0.1", function() {
// console.log("Starting server on http://localhost:8080");
// });
webpackServer = require('child_process').spawn('webpack-dev-server', ['--inline','--color']);
console.log(webpackServer.pid);
webpackServer.stdout.on('data', function (data) {
console.log(data.toString());
});
webpackServer.stderr.on('data', function (data) {
console.log(data.toString());
});
});
gulp.task('watch', function() {
gulp.watch(['*.html'],['html']);
})
gulp.task('html', function() {
//todo production env
// copy html move to dist
fs.readdir(__dirname,(err,files)=>{
if(err){
}else{
files.forEach((file)=>{
if(file.split('.').pop().toLowerCase() == 'html'){
gulp.src(file).pipe(gulp.dest("dest"))
}
})
}
})
});
gulp.task('default', ['html'], () => {
process.on('SIGINT', function() {
console.log('Got SIGINT. Press Control-D/Control-C to exit.');
//退出子进程
webpackServer.kill('SIGINT');
process.exit();
})
gulp.run(['webpack','watch']);
});
gulp.task('xml', function() {
// let str = fs.readFileSync('./haar.js');
let obj = require('./haarJSON.js');
function toNumber(str) {
str = str.toString()
if (str.indexOf('e') == -1) {
console.log(str)
str = str.split('');
str.pop();
return str.join();
}
console.log(str)
let tem = str.split('e');
tem[1][1] == 0 ? tem[1][1].replace('0', '') : undefined;
return tem[0] * Math.pow(10, tem[1]);
}
//对过滤器的修改
// obj.opencv_storage.cascade.stages._.forEach(function(e){
// e['weakClassifiers']['_'].forEach(function(ee){
// let tem = ee['internalNodes'].trim().split(' ');
// tem[tem.length-1] = toNumber(tem[tem.length-1]);
// ee['internalNodes'] = tem;
// ee['leafValues'] = ee['leafValues'].trim().split(' ').map(function(eee){
// return toNumber(eee);
// });
// })
// })
//对feature的修改
// obj.opencv_storage.cascade.features._.forEach(function(e){
// e.rects._ = e.rects._.map(function(e){
// let tem = e.trim().split(' ');
// let last = tem[tem.length-1].split('');
// last.pop();
// tem[tem.length-1] = last.join('');
// return tem;
// })
// })
fs.writeFileSync('./haarJson.js', JSON.stringify(obj));
})