-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
46 lines (40 loc) · 1.26 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
var gulp = require('gulp');
var clean = require('gulp-clean');
var util = require('gulp-util');
var through2 = require('through2');
var watch = require("gulp-watch");
var fs = require('fs');
var path = require('path');
function mkdir(dir) {
if(!fs.existsSync(dir)) {
var parent = path.dirname(dir);
mkdir(parent);
fs.mkdirSync(dir);
}
}
gulp.task('clean-web', function() {
return gulp.src('./web/*')
.pipe(clean());
});
function cb(file, enc, cb) {
var target = file.path.replace(path.sep + 'src' + path.sep, path.sep + 'web' + path.sep);
util.log(path.relative(file.cwd, file.path), '->', path.relative(file.cwd, target));
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', gulp.series('clean-web', function() {
return gulp.src('./src/**/*.js')
.pipe(through2.obj(cb))
.pipe(gulp.dest('./web/'));
}));
gulp.task('watch', function() {
return watch('./src/**/*.js', function(file) {
var to = file.path.replace(path.sep + 'src' + path.sep, path.sep + 'web' + path.sep);
to = path.dirname(to);
gulp.src(file.path)
.pipe(through2.obj(cb))
.pipe(gulp.dest(to));
});
});