-
Notifications
You must be signed in to change notification settings - Fork 33
/
gulpfile.js
104 lines (97 loc) · 2.73 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
var gulp = require("gulp"),
clean = require("gulp-clean"),
concat = require("gulp-concat"),
rename = require("gulp-rename"),
replace = require("gulp-replace"),
terser = require("gulp-terser-js"),
minifyCss = require("gulp-minify-css"),
zip = require("gulp-zip");
/**
* Remove dist directory
*/
gulp.task("clean", function () {
return gulp.src("dist", {read: false}).pipe(clean());
});
/**
* concat and minimy js
*/
gulp.task("js", function () {
return gulp
.src(["js/vendor/**/*", "!js/vendor/jquery.min.js", "js/src/*"])
.pipe(concat("main.js"))
.pipe(terser())
.pipe(gulp.dest("tmp/js/"));
});
/**
* generate plugin.min.js
*/
gulp.task("plugin", function () {
return gulp
.src("plugin.js")
.pipe(terser())
.pipe(rename("plugin.min.js"))
.pipe(gulp.dest("tmp/"));
});
/**
* Concat and minify CSS
*/
gulp.task("css", function () {
return gulp
.src(["css/bootstrap.min.css", "css/bootstrap-theme.min.css", "css/youtube.css"])
.pipe(concat("styles.css"))
.pipe(minifyCss())
.pipe(gulp.dest("tmp/css/"));
});
/**
* html file: replace css and js by minified files
*/
gulp.task("html", function () {
return gulp
.src("youtube.html")
// remove css
.pipe(replace(/(\r\n|\n|\r)\s*<link href[^>]*>/ig, function () {
return "";
}))
.pipe(replace(/<\/title>(\r\n|\n|\r)/i, function (match) {
return match + ' <link href="./css/styles.css" rel="stylesheet">\r\n'
}))
// remove js
.pipe(replace(/(\r\n|\n|\r)\s*<script\ssrc="\.(.*)"><\/script>/ig, function (match, file) {
if (file.match("jquery.min.js")) {
return match; // don't modify this include
} else {
return "";
}
}))
// add concat js file
.pipe(replace("</head>", ' <script src="./js/main.js"></script>\r\n</head>'))
.pipe(gulp.dest("tmp/"));
});
/**
* Build distribuable package
**/
gulp.task("dist", ["clean", "html", "css", "js", "plugin"], function () {
return gulp
.src([
"img/**/*",
"view/**/*",
"langs/**/*",
"js/main.js",
"tmp/**/*",
"js/vendor/jquery.min.js",
"LICENCE",
"plugin.js",
"README.md"
], {base: "."})
.pipe(rename(function (path) {
path.dirname = "youtube/" + path.dirname.replace(/^tmp\/*/, "");
}))
.pipe(zip("youtube.zip"))
.pipe(gulp.dest("dist/"))
});
/**
* Build and remove temps
*/
gulp.task("default", ["dist"], function () {
return gulp.src("tmp", {read: false}).pipe(clean());
});