1 | const gulp = require('gulp');
|
2 | const path = require('path');
|
3 | const clean = require('gulp-clean');
|
4 | const rename = require("gulp-rename");
|
5 | const autoprefixer = require('autoprefixer');
|
6 | const gulpTypescript = require('gulp-typescript');
|
7 | const typescript = require('typescript');
|
8 | const header = require('gulp-header');
|
9 | const merge = require('merge2');
|
10 | const pkg = require('./package.json');
|
11 | const webpack = require('webpack');
|
12 | const webpackStream = require('webpack-stream');
|
13 | const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
14 | const filter = require('gulp-filter');
|
15 | const named = require('vinyl-named');
|
16 | const replace = require('gulp-replace');
|
17 |
|
18 | const bundleTemplate = '// <%= pkg.name %> v<%= pkg.version %>\n';
|
19 |
|
20 | const headerTemplate = ['/**',
|
21 | ' * <%= pkg.name %> - <%= pkg.description %>',
|
22 | ' * @version v<%= pkg.version %>',
|
23 | ' * @link <%= pkg.homepage %>',
|
24 | ' * @license <%= pkg.license %>',
|
25 | ' */',
|
26 | ''].join('\n');
|
27 |
|
28 | const dtsHeaderTemplate =
|
29 | '// Type definitions for <%= pkg.name %> v<%= pkg.version %>\n' +
|
30 | '// Project: <%= pkg.homepage %>\n' +
|
31 | '// Definitions by: Niall Crosby <https://github.com/ag-grid/>\n';
|
32 |
|
33 | gulp.task('default', ['webpack-all']);
|
34 | gulp.task('release', ['webpack-all']);
|
35 |
|
36 | gulp.task('webpack-all', ['webpack', 'webpack-minify', 'webpack-noStyle', 'webpack-minify-noStyle'], tscSrcTask);
|
37 |
|
38 | gulp.task('webpack-minify-noStyle', ['tsc', 'scss'], webpackTask.bind(null, true, false));
|
39 | gulp.task('webpack-noStyle', ['tsc', 'scss'], webpackTask.bind(null, false, false));
|
40 | gulp.task('webpack-minify', ['tsc', 'scss'], webpackTask.bind(null, true, true));
|
41 | gulp.task('webpack', ['tsc', 'scss'], webpackTask.bind(null, false, true));
|
42 |
|
43 | gulp.task('scss-watch', ['scss-no-clean'], scssWatch);
|
44 | gulp.task('scss-no-clean', scssTask);
|
45 |
|
46 | gulp.task('tsc', ['tsc-src'], tscMainTask);
|
47 | gulp.task('tsc-src', ['cleanDist'], tscSrcTask);
|
48 | gulp.task('tsc-main', ['cleanMain'], tscMainTask);
|
49 | gulp.task('scss', ['cleanDist'], scssTask);
|
50 |
|
51 | gulp.task('cleanDist', cleanDist);
|
52 | gulp.task('cleanMain', cleanMain);
|
53 |
|
54 | gulp.task('cleanForCI', ['cleanDist', 'cleanMain']);
|
55 |
|
56 | gulp.task('publishForCI', () => {
|
57 | return gulp.src("./ag-grid-*.tgz")
|
58 | .pipe(rename("ag-grid.tgz"))
|
59 | .pipe(gulp.dest("c:/ci/ag-grid/"));
|
60 |
|
61 | });
|
62 |
|
63 | function scssWatch() {
|
64 | gulp.watch('./src/styles/!**/!*', ['scss-no-clean']);
|
65 | }
|
66 |
|
67 | function cleanDist() {
|
68 | return gulp
|
69 | .src('dist', {read: false})
|
70 | .pipe(clean());
|
71 | }
|
72 |
|
73 | function cleanMain() {
|
74 | return gulp
|
75 | .src(['./main.d.ts', 'main.js'], {read: false})
|
76 | .pipe(clean());
|
77 | }
|
78 |
|
79 | function tscSrcTask() {
|
80 | const project = gulpTypescript.createProject('./tsconfig.json', {typescript: typescript});
|
81 |
|
82 | const tsResult = gulp
|
83 | .src('src/ts/**/*.ts')
|
84 | .pipe(gulpTypescript(project));
|
85 |
|
86 | return merge([
|
87 | tsResult.dts
|
88 | .pipe(header(dtsHeaderTemplate, {pkg: pkg}))
|
89 | .pipe(gulp.dest('dist/lib')),
|
90 | tsResult.js
|
91 | .pipe(header(headerTemplate, {pkg: pkg}))
|
92 | .pipe(gulp.dest('dist/lib'))
|
93 | ])
|
94 | }
|
95 |
|
96 | function tscMainTask() {
|
97 | const project = gulpTypescript.createProject('./tsconfig-main.json', {typescript: typescript});
|
98 |
|
99 | const tsResult = gulp
|
100 | .src('./src/ts/main.ts')
|
101 | .pipe(gulpTypescript(project));
|
102 |
|
103 | return merge([
|
104 | tsResult.dts
|
105 | .pipe(replace("\"./", "\"./dist/lib/"))
|
106 | .pipe(header(dtsHeaderTemplate, {pkg: pkg}))
|
107 | .pipe(rename("main.d.ts"))
|
108 | .pipe(gulp.dest('./')),
|
109 | tsResult.js
|
110 | .pipe(replace("require(\"./", "require(\"./dist/lib/"))
|
111 | .pipe(header(headerTemplate, {pkg: pkg}))
|
112 | .pipe(rename("main.js"))
|
113 | .pipe(gulp.dest('./'))
|
114 | ])
|
115 | }
|
116 |
|
117 | function webpackTask(minify, styles) {
|
118 |
|
119 | const plugins = [];
|
120 | if (minify) {
|
121 | plugins.push(new webpack.optimize.UglifyJsPlugin({compress: {warnings: false}}));
|
122 | }
|
123 | const mainFile = styles ? './main-with-styles.js' : './main.js';
|
124 |
|
125 | let fileName = 'ag-grid';
|
126 | fileName += minify ? '.min' : '';
|
127 | fileName += styles ? '' : '.noStyle';
|
128 | fileName += '.js';
|
129 |
|
130 | return gulp.src('src/entry.js')
|
131 | .pipe(webpackStream({
|
132 | entry: {
|
133 | main: mainFile
|
134 | },
|
135 | output: {
|
136 | path: path.join(__dirname, "dist"),
|
137 | filename: fileName,
|
138 | library: ["agGrid"],
|
139 | libraryTarget: "umd"
|
140 | },
|
141 |
|
142 | module: {
|
143 | loaders: [
|
144 | {test: /\.css$/, loader: "style-loader!css-loader"}
|
145 | ]
|
146 | },
|
147 | plugins: plugins
|
148 | }))
|
149 | .pipe(header(bundleTemplate, {pkg: pkg}))
|
150 | .pipe(gulp.dest('./dist/'));
|
151 | }
|
152 |
|
153 | function scssTask() {
|
154 | const svgMinOptions = {
|
155 | plugins: [
|
156 | {cleanupAttrs: true},
|
157 | {removeDoctype: true},
|
158 | {removeComments: true},
|
159 | {removeMetadata: true},
|
160 | {removeTitle: true},
|
161 | {removeDesc: true},
|
162 | {removeEditorsNSData: true},
|
163 | {removeUselessStrokeAndFill: true},
|
164 | {cleanupIDs: true},
|
165 | {collapseGroups: true},
|
166 | {convertShapeToPath: true}
|
167 | ]
|
168 | };
|
169 |
|
170 |
|
171 | return gulp.src(['src/styles/*.scss', '!src/styles/_*.scss'])
|
172 | .pipe(named())
|
173 | .pipe(webpackStream({
|
174 | module: {
|
175 | rules: [
|
176 | {
|
177 | test: /\.scss$/,
|
178 | use: ExtractTextPlugin.extract({
|
179 | fallback: 'style-loader',
|
180 |
|
181 | use: [
|
182 | {loader: 'css-loader', options: {minimize: false}},
|
183 | 'sass-loader',
|
184 | {
|
185 | loader: 'postcss-loader',
|
186 | options: {syntax: 'postcss-scss', plugins: [autoprefixer()]}
|
187 | },
|
188 | ]
|
189 | })
|
190 | },
|
191 | {
|
192 | test: /\.(svg)$/,
|
193 | use: [
|
194 | 'cache-loader',
|
195 | {
|
196 | loader: 'url-loader',
|
197 | options: {
|
198 | limit: 8192
|
199 | }
|
200 | },
|
201 | {
|
202 | loader: 'image-webpack-loader',
|
203 | options: {
|
204 | svgo: svgMinOptions
|
205 | }
|
206 | },
|
207 | {
|
208 | loader: 'svg-colorize-loader',
|
209 | options: {
|
210 | color1: "#000000",
|
211 | color2: "#FFFFFF"
|
212 | }
|
213 | }
|
214 | ]
|
215 | }
|
216 | ]
|
217 | },
|
218 | plugins: [
|
219 | new ExtractTextPlugin('[name].css')
|
220 | ]
|
221 | }))
|
222 | .pipe(filter("**/*.css"))
|
223 | .pipe(gulp.dest('dist/styles/'));
|
224 | }
|
225 |
|