-
Notifications
You must be signed in to change notification settings - Fork 81
/
gulpfile.js
115 lines (95 loc) · 3.36 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
var gulp = require('gulp');
var gulpTypescript = require('gulp-typescript');
var typescript = require('typescript');
var header = require('gulp-header');
var merge = require('merge2');
var pkg = require('./package.json');
var clean = require('gulp-clean');
var webpack = require('webpack');
var webpackStream = require('webpack-stream');
var path = require('path');
var headerTemplate = '// <%= pkg.name %> v<%= pkg.version %>\n';
var bundleTemplate = '// <%= pkg.name %> v<%= pkg.version %>\n';
gulp.task('default', ['watch']);
gulp.task('release', ['webpack-all']);
gulp.task('webpack-all', ['webpack','webpack-minify','webpack-noStyle','webpack-minify-noStyle'], tscTask);
gulp.task('webpack-minify-noStyle', ['tsc'], webpackTask.bind(null, true, false));
gulp.task('webpack-noStyle', ['tsc'], webpackTask.bind(null, false, false));
gulp.task('webpack-minify', ['tsc'], webpackTask.bind(null, true, true));
gulp.task('webpack', ['tsc'], webpackTask.bind(null, false, true));
gulp.task('webpack-dev', ['tsc-dev'], webpackTask.bind(null, false, true));
gulp.task('tsc', ['cleanDist'], tscTask);
gulp.task('tsc-dev', ['copy-from-ag-grid'], tscTask);
gulp.task('cleanDist', cleanDist);
gulp.task('watch', ['webpack-dev'], watchTask);
gulp.task('copy-from-ag-grid', copyFromAgGrid);
function cleanDist() {
return gulp
.src('dist', {read: false})
.pipe(clean());
}
function tscTask() {
var tsResult = gulp
.src('src/**/*.ts')
.pipe(gulpTypescript({
typescript: typescript,
module: 'commonjs',
experimentalDecorators: true,
emitDecoratorMetadata: true,
declarationFiles: true,
target: 'es5',
noImplicitAny: true
}));
return merge([
tsResult.dts
.pipe(header(headerTemplate, { pkg : pkg }))
.pipe(gulp.dest('dist/lib')),
tsResult.js
.pipe(header(headerTemplate, { pkg : pkg }))
.pipe(gulp.dest('dist/lib'))
])
}
function webpackTask(minify, styles) {
var plugins = [];
if (minify) {
plugins.push(new webpack.optimize.UglifyJsPlugin({compress: {warnings: false}}));
}
var mainFile = styles ? './webpack-with-styles.js' : './webpack.js';
var fileName = 'ag-grid-enterprise';
fileName += minify ? '.min' : '';
fileName += styles ? '' : '.noStyle';
fileName += '.js';
return gulp.src('src/entry.js')
.pipe(webpackStream({
entry: {
main: mainFile
},
output: {
path: path.join(__dirname, "dist"),
filename: fileName,
library: ["agGrid"],
libraryTarget: "umd"
},
//devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.css$/, loader: "style-loader!css-loader" }
]
},
plugins: plugins
}))
.pipe(header(bundleTemplate, { pkg : pkg }))
.pipe(gulp.dest('./dist/'));
}
function copyFromAgGrid() {
return gulp.src(['../ag-grid/*', '../ag-grid/dist/**/*'], {base: '../ag-grid'})
.pipe(gulp.dest('./node_modules/ag-grid'));
}
// 1. copy files -> webpack
// 2. webpack <- copy files
function watchTask() {
gulp.watch([
'../ag-grid/dist/ag-grid.js',
'./src/**/*'
], ['webpack-dev']);
}