-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
54 lines (49 loc) · 1.53 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
var gulp = require('gulp');
var rimraf = require('gulp-rimraf');
var util = require('gulp-util');
var through2 = require('through2');
var jsdc = require('jsdc');
var path = require('path');
gulp.task('clean-bulid', function() {
return gulp.src('./build/*')
.pipe(rimraf());
});
gulp.task('clean-web', function() {
return gulp.src('./web/*')
.pipe(rimraf());
});
function cb(file, enc, cb) {
util.log(path.relative(file.cwd, file.path));
var content = file.contents.toString('utf-8');
jsdc.reset();
content = jsdc.parse(content);
file.contents = new Buffer(content);
cb(null, file);
}
function cb2(file, enc, cb) {
util.log(path.relative(file.cwd, file.path));
var content = file.contents.toString('utf-8');
content = 'define(function(require, exports, module){' + content + '});';
file.contents = new Buffer(content);
cb(null, file);
}
gulp.task('default', ['clean-bulid', 'clean-web'], function() {
gulp.src('./src/**/*.js')
.pipe(through2.obj(cb))
.pipe(gulp.dest('./build/'))
.pipe(through2.obj(cb2))
.pipe(gulp.dest('./web/'));
});
gulp.task('watch', function() {
gulp.watch('./src/**/*.js', function(file) {
var to = file.path.replace(path.sep + 'src' + path.sep, path.sep + 'build' + path.sep);
to = path.dirname(to);
var to2 = file.path.replace(path.sep + 'src' + path.sep, path.sep + 'web' + path.sep);
to2 = path.dirname(to2);
gulp.src(file.path)
.pipe(through2.obj(cb))
.pipe(gulp.dest(to))
.pipe(through2.obj(cb2))
.pipe(gulp.dest(to2));
});
});