generated from GeN-w-DeJA/lazyXimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
150 lines (119 loc) · 4 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
"use strict";
var gulp = require("gulp");
var util = require("gulp-util");
var data = require("gulp-data");
var noop = require("gulp-noop");
var rename = require("gulp-rename");
var header = require("gulp-header");
var jshint = require("gulp-jshint");
var uglify = require("gulp-uglify");
var concat = require("gulp-concat-util");
var pkg = require("./package.json");
var nl = require("os").EOL;
/*
** CONFIG & PATHS
*/
var config = {
header : "/*! jQuery & Zepto Lazy <%= info %> - <%= pkg.homepage %> - MIT&GPL-2.0 license - Copyright 2012-<%= year %> <%= pkg.author.name %> */",
main : pkg.main,
plugins : [
"plugins/jquery.lazy.*.js",
"!plugins/jquery.lazy.*.min.js"
]
};
/*
** PIPES
*/
var pipes = {};
// check files with jshint
pipes.validateFiles = function(files) {
return gulp.src(files, {base: "./"})
.pipe(jshint())
.pipe(jshint.reporter("jshint-stylish"));
};
// check all files
pipes.validate = function() {
return pipes.validateFiles([config.main].concat(config.plugins));
};
// build main project file
pipes.buildMain = function() {
return pipes.validateFiles(config.main)
.pipe(uglify())
.pipe(header(config.header + nl, {
pkg : pkg,
info : "v" + pkg.version,
year : new Date().getFullYear()
}))
.pipe(rename(function(path) {
path.extname = ".min" + path.extname;
}))
.pipe(gulp.dest("./"));
};
// build plugin files
pipes.buildPlugins = function() {
return pipes.validateFiles(config.plugins)
.pipe(data(function(file) {
var string = String(file.contents).split("\n")[1];
var matches = string.match(/\s-\s([a-z ]+)\s-\sv([0-9.]+)/i);
return {
info: "- " + matches[1] + " v" + matches[2]
};
}))
.pipe(uglify())
.pipe(header(config.header + nl, {
pkg : pkg,
year : new Date().getFullYear()
}))
.pipe(rename(function(path) {
path.extname = ".min" + path.extname;
}))
.pipe(gulp.dest("./"));
};
// concat plugin files
pipes.concatPlugins = function() {
return gulp.src(config.plugins)
.pipe(concat(config.main.replace(".js", ".plugins.js"), {
sep: nl + nl
}))
.pipe(gulp.dest("./"))
.pipe(uglify())
.pipe(header(config.header + nl, {
pkg : pkg,
info : "- All Plugins v" + pkg.version,
year : new Date().getFullYear()
}))
.pipe(rename(function(path) {
path.extname = ".min" + path.extname;
}))
.pipe(gulp.dest("./"));
};
/*
** TASKS
*/
// check & build everything
gulp.task("build", ["build-main", "build-plugins", "concat-plugins"]);
// check & build main project file
gulp.task("build-main", pipes.buildMain);
// check & build single plugin files
gulp.task("build-plugins", pipes.buildPlugins);
// build concatenated plugins file
gulp.task("concat-plugins", pipes.concatPlugins);
// check all files
gulp.task("validate", pipes.validate);
// check, build & watch live changes
gulp.task("watch", ["build"], function() {
// watch main file
gulp.watch(config.main, function() {
var task = pipes.buildMain();
util.log("updated", "'" + util.colors.red("main file") + "'");
return task;
});
// watch plugins
gulp.watch(config.plugins, function() {
var task = pipes.buildPlugins();
util.log("updated", "'" + util.colors.red("plugins") + "'");
pipes.concatPlugins();
util.log("updated", "'" + util.colors.red("concatenated plugins file") + "'");
return task;
});
});