forked from atomiqio/json-schema-builder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
119 lines (99 loc) · 2.72 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
113
114
115
116
117
118
var gulp = require('gulp');
//var gutil = require('gulp-util');
var mocha = require('gulp-mocha');
var babel = require("gulp-babel");
var sourcemaps = require('gulp-sourcemaps');
var path = require('path');
var del = require('del');
//ts
var ts = require("gulp-typescript");
//var gulpFilter = require('gulp-filter');
//var ext_replace = require('gulp-ext-replace');
var rename = require("gulp-rename");
var merge = require('merge2');
//
//var concat = require('gulp-concat');
var webpack = require('gulp-webpack');
var paths = {
sourceRoot: path.join(__dirname, 'src'),
src: ['src/**/*.js', 'src/**/*.ts'],
watch: ['src/**/*.js', 'src/**/*.ts', 'src/**/*.json'],
dist: 'dist',
test: 'dist/test/test.js',
dest: {
pack: 'pack'
}
};
var webpackOptions = {
output: {
filename: '[name].bundle.js',
libraryTarget: 'umd'
}
//,
//externals: {
// Backbone: {
// root: 'Backbone',
// amd: 'Backbone'
// }
//},
//module: {
// loaders: [
// { test: /\.hbs$/, loader: "handlebars-loader" }
// ]
//}
};
gulp.task('default', ['test', 'watch']);
gulp.task('clean', function(cb) {
return del(paths.dist, cb);
});
gulp.task('babel', ['clean'], function () {
var tsProject = ts.createProject("tsconfig.json");
var tsResult = gulp.src('src/**/*.ts')
.pipe(sourcemaps.init())
.pipe(ts(tsProject));
var babelResult = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.', { sourceRoot: paths.sourceRoot }));
return merge([
tsResult.dts
.pipe(rename(function(pth) {
if(pth.dirname === 'lib') {
pth.dirname = '';
}
else {
pth.dirname = pth.dirname.replace('lib' + path.sep, '');
}
return pth;
}))
.pipe(gulp.dest('dist/definitions')),
tsResult.js
.pipe(babel())
.pipe(sourcemaps.write('.', { sourceRoot: paths.sourceRoot }))
.pipe(gulp.dest(paths.dist)),
babelResult
.pipe(gulp.dest(paths.dist))
]);
});
gulp.task('dist', ['babel'], function() {
return gulp.src(['src/**/*', '!**/*.js', '!**/*.ts'], {base: 'src'})
.pipe(gulp.dest(paths.dist));
});
gulp.task('pack', ['dist'], function () {
return gulp.src(paths.dist + '/lib' + '/index.js')
.pipe(webpack(webpackOptions))
.pipe(gulp.dest(paths.dest.pack));
});
gulp.task('test', ['pack'], function() {
//gulp.task('test', function() {
return gulp.src(paths.test, {read: false})
.pipe(mocha({ reporter: 'dot' }));
; //.on('error', gutil.log);
});
gulp.task('watch', function () {
gulp.watch(paths.watch, ['test']);
});
gulp.task('generate-testsuite', ['dist'], function() {
var testSuite = require('./dist/test/testsuite');
testSuite.generate('./src/test/testsuite');
});