forked from xdan/jodit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (60 loc) · 1.55 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
const gulp = require('gulp');
const path = require('path');
const ts = require('gulp-typescript');
const less = require('gulp-less');
const imagemin = require('gulp-imagemin');
const tsProject = ts.createProject('tsconfig.json', {
target: 'es5',
module: 'es2015'
});
const make = require('./make.js');
const entries = require('./src/utils/create-entries');
const rootPath = path.resolve(process.cwd()) + path.sep;
const mergeStream = require('merge-stream');
const files = entries.resolve(make.paths);
function buildOneFile(file) {
console.log('Build file: ' + file);
const full = path.dirname(path.resolve(file)).replace(rootPath, '');
let pipe = gulp.src(path.resolve(file)).on('error', error => {
console.warn(error);
});
const ext = path.extname(path.resolve(file)).toLowerCase();
switch (ext) {
case '.ts':
pipe = pipe.pipe(tsProject(ts.reporter.defaultReporter())).js;
break;
case '.less':
pipe = pipe.pipe(less());
break;
case '.ico':
case '.svg':
case '.png':
case '.jpg':
case '.jpeg':
pipe = pipe.pipe(imagemin());
break;
default:
break;
}
return pipe.pipe(gulp.dest('build/' + full));
}
function build() {
if (!files.length) {
return gulp.src('.');
}
return mergeStream.apply(null, files.map(file => buildOneFile(file)));
}
exports.watch = function watch() {
if (!files.length) {
return gulp.src('.');
}
files.forEach(file => {
gulp.watch(
file,
{ ignoreInitial: false },
buildOneFile.bind(null, file)
);
});
};
exports.default = () => gulp.parallel('watch');
exports.build = build;