-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
153 lines (131 loc) · 3.49 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
var paths = require("./gulpfile-paths"),
gulp = require("gulp"),
compileLess = require("gulp-less"),
minifyCss = require("gulp-clean-css"),
uglify = require("gulp-uglify"),
rename = require("gulp-rename"),
runSequence = require("run-sequence"),
del = require("del"),
watch = require("gulp-watch"),
fileInclude = require("gulp-file-include"),
pyshell = require("python-shell"),
fs = require("fs");
// delete content of "dest" directory (except the directory itself)
gulp.task("clean-full", function (cb) {
return del(
[
paths.dest() + "/**",
"!" + paths.dest()
],
{
force: true
},
cb
);
});
// delete content of "dest" directory except vendor files
gulp.task("clean-fast", function (cb) {
return del(
[
paths.dest() + "/**",
"!" + paths.dest(),
"!" + paths.dest("vendor") + "**",
"!" + paths.dest("files") + "**"
],
{
force: true
},
cb
);
});
gulp.task("build:examples.html", function(){
return true;
// fixme: uncomment when Codepen allows automatic creation
// pyshell.run("codepen-parser/html_generator.py", {
// "pythonPath": "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5"
// }, function (err) {
// if (err) throw err;
// fs.createReadStream("codepen-parser/examples.html").pipe(fs.createWriteStream("src/examples.html"));
// });
});
// build HTML
gulp.task("build:html", function(){
// copy main HTML files
gulp.src(paths.src("html.pages"))
.pipe(fileInclude({
prefix: "@@",
basepath: "@file",
context: {
navActiveItem: ""
}
}))
.pipe(gulp.dest(paths.dest("html.pages")));
// copy the rest
return gulp.src(paths.src("html.yuidocs"))
.pipe(gulp.dest(paths.dest("html.yuidocs")));
});
// build LESS files into CSS
gulp.task("build:less", function(){
return gulp.src(paths.src("less"))
.pipe(compileLess())
.pipe(minifyCss())
.pipe(rename(paths.get("less.destFile")))
.pipe(gulp.dest(paths.dest("less")));
});
// build scripts
gulp.task("build:js", function(){
return gulp.src(paths.src("js"))
.pipe(gulp.dest(paths.dest("js")));
});
// bunble images
gulp.task("build:images", function(){
// todo: compress/optimize images
return gulp.src(paths.src("images"))
.pipe(gulp.dest(paths.dest("images")));
});
// build fonts
gulp.task("build:fonts", function(){
return gulp.src(paths.src("fonts"))
.pipe(gulp.dest(paths.dest("fonts")));
});
// bundle vendor files
gulp.task("build:vendor", function(){
return gulp.src(paths.src("vendor"))
.pipe(gulp.dest(paths.dest("vendor")));
});
// bundle zip files of NeXt
gulp.task("build:files", function(){
return gulp.src(paths.src("files"))
.pipe(gulp.dest(paths.dest("files")));
});
// full clean & build
gulp.task("build-full", function(){
return runSequence(
"clean-full",
["build:less", "build:js", "build:images", "build:fonts", "build:vendor", "build:examples.html", "build:files"],
"build:html"
);
});
// build CSS, JS and HTML only
gulp.task("build-fast", function(){
return runSequence(
"clean-fast",
["build:less", "build:js", "build:images", "build:fonts", "build:examples.html"],
"build:html"
);
});
// simple watcher that listens to any changes
gulp.task("simple-watch", function(){
// gulp.watch(paths.src(), ["build-fast"])
return watch([
paths.src(),
// "!" + paths.src() + "/examples.html"
], { ignoreInitial: true }, function(){
console.log("Change detected");
runSequence("build-fast");
});
});
gulp.task("default", function(){
console.log("Initial build & start watcher");
runSequence("build-full", "simple-watch");
});