gulpfile.js
2.64 KB
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
/* 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 filter = require('gulp-filter');
var util = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var lazypipe = require('lazypipe');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var foreach = require('gulp-foreach');
var amdOptimize = require("amd-optimize");
var argv = require('yargs').argv;
// uglify
var compress = {
unsafe : true,
hoist_vars : true,
warnings : false,
pure_getters : true
};
var mangle = {
except: [ "define" ]
};
function renameModules(match) {
return match.replace(/['"]([\w\.\/]+)?['"]/g, '"$1.min"');
}
var uglify = lazypipe()
.pipe(logger, { after: 'uglify complete', extname: '.min.js', showChange: true })
.pipe(uglify, { compress, mangle, preserveComments: "license" })
.pipe(replace, /define\(.+?\]/g, renameModules)
.pipe(rename, { suffix: ".min" });
// AMD gathering
function gatherCustomAmd(stream, file) {
var moduleId = file.path.match(/kendo\.(.+)\.js/)[1];
console.log(moduleId);
return stream.pipe(amdOptimize(`kendo.${moduleId}`, {
baseUrl: "js",
exclude: [ 'jquery' ]
}));
}
var gatherCustom = lazypipe()
.pipe(foreach, gatherCustomAmd);
gulp.task("custom", function() {
var files = argv.c;
if (files.indexOf(",") == -1) {
throw new util.PluginError({
task: "custom",
plugin: "custom",
message: "please specify more than one component"
});
}
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 = [];
return gulp.src(`js/kendo.{${files}}.js`, { base: "js" })
.pipe(gatherCustom())
.pipe(filter(function(file) {
if (included.indexOf(file.path) === -1) {
included.push(file.path);
return true;
} else {
return false;
}
}))
.pipe(concat({path: 'js/kendo.custom.js', base: 'js'}))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(logger({after: 'source map complete!', extname: '.map', showChange: true}))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("dist/js"));
});