-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (100 loc) · 3.3 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
var $gulp = require('gulp'),
$lint = require('gulp-tslint'),
$del = require('del'),
$smap = require('gulp-sourcemaps'),
$tsc = require('gulp-typescript'),
$replace = require('gulp-replace'),
$insert = require('gulp-insert'),
$browserify = require('browserify'),
$source = require('vinyl-source-stream'),
$buffer = require('vinyl-buffer'),
$uglify = require('gulp-uglify'),
pkg = require('./package.json');
$gulp.task('lint', function () {
return $gulp.src('lib/**/*.ts')
.pipe($lint())
.pipe($lint.report('prose'));
});
$gulp.task('clear', function () {
$del([
'var/build/*.*.*.js',
'var/build/*.*.*.min.js*'
]);
});
$gulp.task('dist', function () {
var ts = $gulp.src('lib/Bigine.ts')
.pipe($smap.init())
.pipe($tsc($tsc.createProject('tsconfig.json', {
outFile: pkg.name + '.js'
})));
return ts.js
.pipe($replace(/\$\{BIGINE_VERSION\}/, pkg.version))
.pipe($insert.prepend('var __Bigine_Util = require("bigine.util");\n' +
'var __Bigine_C2D = require("bigine.c2d");\n'
)).pipe($insert.append('module.exports = Bigine;'))
.pipe($smap.write('.'))
.pipe($gulp.dest('var/build'));
});
$gulp.task('tsd', ['lint'], function () {
var ts = $gulp.src('lib/Bigine.ts')
.pipe($tsc($tsc.createProject('tsconfig.json', {
declaration: true,
removeComments: true
})));
return ts.dts
.pipe($replace(/\/{3} <reference path=".+\.d\.ts" \/>\n/g, ''))
.pipe($replace('\n', '\n '))
.pipe($replace(' import Util = __Bigine_Util;\n', ''))
.pipe($replace(' import G = __Bigine_C2D;\n', ''))
.pipe($replace('declare ', ''))
.pipe($insert.prepend('declare namespace __Bigine {\n' +
' import Util = __Bigine_Util;\n' +
' import G = __Bigine_C2D;\n' +
' '
)).pipe($insert.append('}\n' +
'\n' +
'declare module "bigine" {\n' +
' export = __Bigine.Bigine;\n' +
'}\n'
)).pipe($replace(/(\n {4}\}){2}\n/, '\n }\n}\n'))
.pipe($gulp.dest('.'));
});
$gulp.task('bundle', ['dist'], function () {
return $browserify({
detectGlobals: false
})
.require('bigine.util')
.require('bigine.c2d')
.require('./var/build/' + pkg.name, {
expose: 'bigine'
})
.exclude('./xhr')
.bundle()
.pipe($source(pkg.version + '.js'))
.pipe($gulp.dest('var/build'));
});
$gulp.task('minify', ['dist'], function () {
return $browserify({
debug: true,
detectGlobals: false
})
.require('bigine.util')
.require('bigine.c2d')
.require('./var/build/' + pkg.name, {
expose: 'bigine'
})
.exclude('./xhr')
.bundle()
.pipe($source(pkg.version + '.min.js'))
.pipe($buffer())
.pipe($smap.init({
loadMaps: true
}))
.pipe($uglify())
.pipe($smap.write('.'))
.pipe($gulp.dest('var/build'));
});
$gulp.task('watch', function () {
return $gulp.watch('lib/**/*.ts', ['tsd', 'dist']);
});
$gulp.task('default', ['tsd', 'minify']);