-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
112 lines (98 loc) · 3.04 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var gulp = require('gulp');
var less = require('gulp-less');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var notify = require('gulp-notify');
var minifycss = require('gulp-minify-css');
var plumber = require('gulp-plumber');
var del = require('del');
var rename = require('gulp-rename');
var ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var flatten = require('gulp-flatten');
var merge = require('merge-stream');
var bom = require('gulp-bom');
var webserver = require('gulp-webserver');
var onError = function(err) {
//notify.onError({
// title: "Gulp",
// subtitle: "Failure!",
// message: "Error: <%= error.message %>",
// sound: "Beep"
//})(err);
this.emit('end');
};
gulp.task('clean', function(cb) {
del(['website/molvwr'], cb)
});
gulp.task('styles', function() {
return gulp.src(['**/*.less'], { cwd: 'demo website', base : '.' })
.pipe(plumber({errorHandler: onError}))
.pipe(less())
.pipe(bom())
.pipe(gulp.dest(''));
});
var tsMolvwrProject = ts.createProject({
declarationFiles: true,
noExternalResolve: true,
target: 'ES5',
noEmitOnError: false
});
gulp.task('copylib', function () {
gulp.src(['lib/**/*'])
.pipe(gulp.dest("dist"))
.pipe(gulp.dest("demo website/lib"));
});
gulp.task('package', ['compile-molvwr'], function () {
gulp.src(['dist/molvwr.js', 'lib/babylon.js', 'lib/hand.js'], { base: '.' })
.pipe(concat('molvwr-bundle.js'))
.pipe(gulp.dest("dist"))
.pipe(gulp.dest("demo website/lib"));
});
gulp.task('compile-molvwr', function () {
var tsResult = gulp.src([
'src/**/*.ts',
], { base: '.' })
.pipe(plumber({ errorHandler: onError }))
//.pipe(sourcemaps.init())
.pipe(ts(tsMolvwrProject));
return merge([
tsResult.dts.pipe(flatten()).pipe(concat('molvwr.d.ts')).pipe(bom()).pipe(gulp.dest('dist')),
tsResult.js
.pipe(concat('molvwr.js'))
//.pipe(sourcemaps.write(".",{
// sourceRoot: function (file) {
// var sources = [];
// file.sourceMap.sources.forEach(function (s) {
// var filename = s.substr(s.lastIndexOf('/') + 1);
// //console.log(filename)
// sources.push("../../src/" + [filename]);
// });
// file.sourceMap.sources = sources;
// return ' ';
// }
//}))
.pipe(bom())
.pipe(gulp.dest('dist'))
.pipe(gulp.dest('demo website/lib'))
]);
});
gulp.task('webserver', function() {
gulp.src('demo website')
.pipe(webserver({
livereload: true,
open: 'http://localhost:1339/index.html',
port: 1339,
fallback: 'index.html'
}));
});
gulp.task('build', ['clean', 'package', 'copylib'], function () {
});
gulp.task('watch', function() {
gulp.start('webserver');
gulp.watch(['demo website/**/*.less'], ['styles']);
gulp.watch(['src/**/*.ts'], ['package']);
});
gulp.task('default', ['build'], function() {
});