-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
49 lines (44 loc) · 1.83 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
var $gulp = require('gulp'),
$lint = require('gulp-tslint'),
$smap = require('gulp-sourcemaps'),
$tsc = require('gulp-typescript'),
$replace = require('gulp-replace'),
$insert = require('gulp-insert'),
pkg = require('./package.json'),
ns = 'C2D';
$gulp.task('lint', function () {
return $gulp.src('lib/**/*.ts')
.pipe($lint())
.pipe($lint.report('prose'));
});
$gulp.task('dist', function () {
var ts = $gulp.src('lib/@' + ns.toLowerCase() + '.ts')
.pipe($smap.init())
.pipe($tsc($tsc.createProject('tsconfig.json', {
outFile: pkg.name + '.js'
})));
return ts.js
.pipe($replace(/\$\{BIGINE_MODULE_VERSION\}/, pkg.version))
.pipe($insert.prepend('var __Bigine_Util = require("bigine.util");\n'))
.pipe($insert.append('module.exports = ' + ns + ';'))
.pipe($smap.write('.'))
.pipe($gulp.dest('var/build'));
});
$gulp.task('tsd', ['lint'], function () {
var ts = $gulp.src('lib/@' + ns.toLowerCase() + '.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(' import Util = __Bigine_Util;\n', ''))
.pipe($replace('}\ndeclare namespace ' + ns + ' {\n', ''))
.pipe($replace('declare namespace ' + ns + ' {\n', 'declare namespace __Bigine_' + ns + ' {\n import Util = __Bigine_Util;\n'))
.pipe($insert.append('\ndeclare module "bigine.' + ns.toLowerCase() + '" {\n export = __Bigine_' + ns + ';\n}\n'))
.pipe($gulp.dest('.'));
});
$gulp.task('watch', function () {
return $gulp.watch('lib/**/*.ts', ['tsd', 'dist']);
});
$gulp.task('default', ['tsd', 'dist']);