forked from telerik/kendo-ui-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
262 lines (211 loc) · 8.68 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* jshint browser:false, node:true, esnext: true */
var gulp = require('gulp');
var shell = require('gulp-shell');
var path = require('path');
var debug = require('gulp-debug'); // jshint ignore:line
var logger = require('gulp-logger');
var util = require('gulp-util');
var clone = require('gulp-clone');
var plumber = require('gulp-plumber');
var filter = require('gulp-filter');
var sourcemaps = require('gulp-sourcemaps');
var gulpIf = require('gulp-if');
var jshint = require("gulp-jshint");
var replace = require("gulp-replace");
var rename = require("gulp-rename");
var ignore = require('gulp-ignore');
var merge = require('merge2');
var concat = require('gulp-concat');
var lazypipe = require('lazypipe');
var browserSync = require('browser-sync').create();
var argv = require('yargs').argv;
var license = require('./build/gulp/license');
var cssUtils = require('./build/gulp/css');
var umdWrapToCore = require('./build/gulp/wrap-umd');
var gatherAmd = require('./build/gulp/gather-amd');
var uglify = require('./build/gulp/uglify');
var requireDir = require('require-dir');
var runSequence = require('run-sequence');
var webpack = require('webpack');
var webpackStream = require('webpack-stream');
var named = require('vinyl-named');
var kendoVersion = require("./build/gulp/kendo-version");
requireDir('./build/gulp/tasks');
var makeSourceMaps = !argv['skip-source-maps'];
gulp.task("css-assets", function() {
return gulp.src("styles/**/*.{less,woff,ttf,eot,png,gif,css,svg,txt}")
.pipe(gulpIf((file) => file.path.match(/.less$/), license() ))
.pipe(gulp.dest("dist/styles"));
});
gulp.task("build-skin", ["css-assets"], function() {
var resumeOnErrors = lazypipe()
.pipe(plumber, {
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
});
var mapLogger = logger({ after: 'source map complete!', extname: '.css.map', showChange: true });
var allFiles = "styles/**/*.less";
var filesToBuild = argv.s || 'styles/**/kendo.*.less';
return gulp.src(allFiles)
.pipe(resumeOnErrors())
.pipe(cssUtils.cacheLessDependencies())
.pipe(filter([
filesToBuild.replace(/(styles|mobile|web)/, "**")
]))
.pipe(sourcemaps.init())
.pipe(cssUtils.fromLess())
.pipe(mapLogger)
.pipe(sourcemaps.write("maps", { sourceRoot: "../../../../styles" }))
.pipe(gulp.dest('dist/styles'))
.pipe(browserSync.stream({ match: '**/*.css' }));
});
gulp.task("less",function() {
var css = gulp.src(`styles/${argv.styles || '**/kendo*.less'}`, { base: "styles" })
.pipe(license())
.pipe(cssUtils.fromLess());
var minCss = css.pipe(clone())
.pipe(gulpIf(makeSourceMaps, sourcemaps.init()))
.pipe(cssUtils.minify())
.pipe(gulpIf(makeSourceMaps, sourcemaps.write("./", {
mapSources: function(sourcePath) {
return sourcePath
.replace(/(styles|mobile|web)\//, "")
.replace(/\.css$/, ".min.css");
}
})));
return merge(css, minCss)
.pipe(gulp.dest('dist/styles'));
});
gulp.task("styles", [ "less", "css-assets" ]);
gulp.task("watch-styles", [ "build-skin", "css-assets" ], function() {
browserSync.init({ proxy: "localhost", open: false });
return gulp.watch("styles/**/*.less", [ "build-skin" ]);
});
// cloning those somehow fails, I think that it is due to the RTL symbols in the culture
function cultures() {
return gulp.src('src/cultures/kendo.culture.*.js', { base: 'src' })
.pipe(umdWrapToCore())
.pipe(license());
}
function messages() {
return gulp.src('src/messages/kendo.messages.*.js', { base: 'src' })
.pipe(umdWrapToCore())
.pipe(license());
}
var toDist = lazypipe().pipe(gulp.dest, "dist/js");
gulp.task("scripts", function() {
var skipMinify = argv['skip-min'];
var src = gulp.src(`src/${argv.scripts || 'kendo.*.js'}`, { base: "src" }).pipe(gatherAmd.gather()).pipe(license());
var thirdParty = gulp.src('src/{jquery,angular,pako,jszip}*.*');
var minSrc;
if (!skipMinify) {
var gatheredSrc = src.pipe(clone())
.pipe(ignore.include(["**/src/kendo.**.js"]));
var scriptsToUglify = argv['skip-cultures'] ? gatheredSrc : merge(cultures(), messages(), gatheredSrc);
minSrc = scriptsToUglify
.pipe(gulpIf(makeSourceMaps, sourcemaps.init()))
.pipe(uglify())
.pipe(gulpIf(makeSourceMaps, logger({after: 'source map complete!', extname: '.map', showChange: true})))
.pipe(gulpIf(makeSourceMaps, sourcemaps.write("./")));
}
// the duplication below is due to something strange with merge2 and concat
// resulting in "cannot switch to old mode now" error
var combinedSrc = merge(
cultures().pipe(toDist()),
messages().pipe(toDist()),
src.pipe(toDist()),
thirdParty.pipe(toDist())
);
return skipMinify ? combinedSrc : merge(combinedSrc, minSrc.pipe(toDist()));
});
gulp.task("custom", function() {
var files = argv.c;
if (!files) {
throw new util.PluginError({
task: "custom",
plugin: "custom",
message: "please provide a list of the components to be included in the build with -c, separated with ','"
});
}
if (files.indexOf(',') !== -1) {
files = `{${files}}`;
}
var included = [];
var src = gulp.src(`src/kendo.${files}.js`)
.pipe(gatherAmd.gatherCustom())
.pipe(filter(function(file) {
if (included.indexOf(file.path) === -1) {
included.push(file.path);
return true;
} else {
util.log("skipping ", file.path);
return false;
}
}))
.pipe(concat({path: 'src/kendo.custom.js', base: 'src'}))
.pipe(license());
var minSrc = src
.pipe(clone())
.pipe(gulpIf(makeSourceMaps, sourcemaps.init()))
.pipe(uglify())
.pipe(gulpIf(makeSourceMaps, logger({after: 'source map complete!', extname: '.map', showChange: true})))
.pipe(gulpIf(makeSourceMaps, sourcemaps.write("./")));
return merge(src.pipe(toDist()), minSrc.pipe(toDist()));
});
gulp.task("jshint", function() {
var packageJSON = require('./package');
return gulp.src(argv.files || packageJSON.jshintFiles)
.pipe(jshint(packageJSON.jshintConfig))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('build', [ 'scripts', 'styles' ]);
gulp.task('tests', [ 'karma-unit' ]);
gulp.task('ci', function(done) {
runSequence('build', 'karma-jenkins', done);
});
gulp.task('travis', function(done) {
runSequence('jshint', 'build', 'karma-travis', done);
});
gulp.task('cjs', function() {
return gulp.src('src/{kendo.*.js,*/*.js,*/**/*.js}')
.pipe(named(function(file) {
const thePath = file.path;
const relativeDir = path.relative(file.base, path.dirname(thePath));
const fileName = path.basename(thePath, path.extname(thePath));
return path.join(relativeDir, fileName);
}))
.pipe(webpackStream({
output: {
libraryTarget: 'commonjs2'
},
plugins: [ new webpack.ProvidePlugin({ 'jQuery': "jquery" }) ],
externals: ['jquery', /^\.\//, /^\.\.\// ]
}))
.pipe(gulp.dest('dist/cjs'));
});
gulp.task('mdspell', shell.task(
['cd docs && mdspell "**/*.md" -n -a --report']
));
[ 'pro', 'core' ].forEach(function(flavor) {
gulp.task('npm-' + flavor, [ 'cjs', 'styles' ] , function() {
var js = gulp.src('dist/cjs/**/*').pipe(gulp.dest('dist/npm/js'));
var styles = gulp.src('dist/styles/**/*').pipe(gulp.dest('dist/npm/css'));
var pkg = gulp.src('build/package-' + flavor + '.json')
.pipe(replace("$KENDO_VERSION", kendoVersion))
.pipe(rename('package.json'))
.pipe(gulp.dest('dist/npm'));
var license = gulp.src('resources/legal/npm/' + flavor + '.txt')
.pipe(replace("$YEAR", new Date().getFullYear()))
.pipe(rename('LICENSE'))
.pipe(gulp.dest('dist/npm'));
var readme = gulp.src('resources/npm/' + flavor + '-README.md')
.pipe(rename('README.md'))
.pipe(gulp.dest('dist/npm'));
return merge(js, styles, pkg, license, readme);
})
})
const taskListing = require('gulp-task-listing');
gulp.task('tasks', taskListing.withFilters(/:/));