forked from telerik/kendo-ui-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
189 lines (153 loc) · 6.22 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
/* jshint browser:false, node:true, esnext: true */
var gulp = require('gulp');
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 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');
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("./")));
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 ','"
});
}
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(packageJSON.jshintFiles)
.pipe(jshint(packageJSON.jshintConfig))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('build', [ 'scripts', 'styles' ]);
gulp.task('ci', function(done) {
runSequence('build', 'karma-jenkins', done);
});
gulp.task('travis', function(done) {
runSequence('jshint', 'build', 'karma-travis', done);
});