forked from ag-grid/ag-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
151 lines (134 loc) · 4.4 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var gulp = require('gulp');
var path = require('path');
var uglify = require('gulp-uglify');
var foreach = require('gulp-foreach');
var rename = require("gulp-rename");
var stylus = require('gulp-stylus');
var buffer = require('vinyl-buffer');
var nib = require('nib');
var gulpTypescript = require('gulp-typescript');
var typescript = require('typescript');
var sourcemaps = require('gulp-sourcemaps');
var header = require('gulp-header');
var merge = require('merge2');
var pkg = require('./package.json');
var tsd = require('gulp-tsd');
var headerTemplate = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
gulp.task('default', ['stylus', 'tsd', 'debug-build', 'watch']);
gulp.task('release', ['stylus', 'tsd', 'ts-release']);
// Build
gulp.task('debug-build', ['stylus', 'ts-debug']);
gulp.task('stylus', stylusTask);
gulp.task('ts-debug', tsDebugTask);
gulp.task('ts-release', tsReleaseTask);
// Watch
gulp.task('watch', watchTask);
gulp.task('tsd', function (callback) {
tsd({
command: 'reinstall',
config: './tsd.json'
}, callback);
});
gulp.task('es6', function (callback) {
var tsResult = gulp
.src('src/es6/**/*.ts')
.pipe(sourcemaps.init()) // for sourcemaps only
.pipe(gulpTypescript({
typescript: typescript,
noImplicitAny: true,
experimentalDecorators: true,
emitDecoratorMetadata: true,
target: 'es5',
module: 'commonjs'
}));
return tsResult.js
.pipe(sourcemaps.write()) // for sourcemaps only
.pipe(gulp.dest('./docs/dist'));
});
// does TS compiling, sourcemaps = yes, minification = no, distFolder = no
function tsDebugTask() {
var tsResult = gulp
.src('src/ts/**/*.ts')
.pipe(sourcemaps.init()) // for sourcemaps only
.pipe(gulpTypescript({
typescript: typescript,
noImplicitAny: true,
//experimentalDecorators: true,
//emitDecoratorMetadata: true,
target: 'es5',
//module: 'commonjs',
out: 'ag-grid.js'
}));
return tsResult.js
.pipe(sourcemaps.write()) // for sourcemaps only
.pipe(rename('ag-grid.js'))
.pipe(gulp.dest('./docs/dist'));
}
// does TS compiling, sourcemaps = no, minification = yes, distFolder = yes
function tsReleaseTask() {
var tsResult = gulp
.src('src/ts/**/*.ts')
.pipe(gulpTypescript({
typescript: typescript,
noImplicitAny: true,
//experimentalDecorators: true,
//emitDecoratorMetadata: true,
target: 'es5',
//module: 'commonjs',
declarationFiles: true,
out: 'ag-grid.js'
}));
return merge([
tsResult.dts.pipe(gulp.dest('dist')),
tsResult.js
.pipe(rename('ag-grid.js'))
.pipe(header(headerTemplate, { pkg : pkg }))
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./docs/dist'))
.pipe(buffer())
.pipe(uglify())
.pipe(rename('ag-grid.min.js'))
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./docs/dist'))
]);
}
function stylusTask() {
// Uncompressed
gulp.src('./src/styles/*.styl')
.pipe(foreach(function(stream, file) {
return stream
.pipe(stylus({
use: nib(),
compress: false
}))
.pipe(gulp.dest('./docs/dist/'))
.pipe(gulp.dest('./dist/'));
}));
// Compressed
return gulp.src('./src/styles/*.styl')
.pipe(foreach(function(stream, file) {
return stream
.pipe(stylus({
use: nib(),
compress: true
}))
.pipe(rename((function() {
var name = path.basename(file.path);
var dot = name.indexOf('.');
name = name.substring(0, dot) + '.min.css';
return name;
})()))
.pipe(gulp.dest('./dist/'))
.pipe(gulp.dest('./docs/dist/'));
}));
}
function watchTask() {
gulp.watch('./src/ts/**/*', ['ts-debug']);
gulp.watch('./src/styles/**/*', ['stylus']);
}