-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
98 lines (83 loc) · 2.33 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
const gulp = require("gulp");
const gutil = require("gulp-util");
const babel = require("gulp-babel");
const rename = require("gulp-rename");
const nodemon = require("gulp-nodemon");
const shell = require("gulp-shell");
const livereload = require("gulp-livereload");
const FileCache = require("gulp-file-cache");
const resolve = require("path").resolve;
const webpack = require("webpack");
const webpackConfig = require("./webpack.config");
const webpackCallback = function(cb) {
var done = false;
return function(err, stats) {
if (err) {
throw new gutil.PluginError("[webpack]", err);
}
gutil.log("[webpack]", stats.toString({
colors: gutil.colors.supportsColor
}));
livereload.reload();
if (!done) {
done = true;
cb();
}
};
};
const cache = new FileCache();
const globs = {
server: [
"./src/{server,lib}/**/*.js",
"./src/server.js"
],
extension: "./extension/pages/**/*.html"
};
gulp.task("build:extension", function(cb) {
webpack(webpackConfig, webpackCallback(cb));
});
gulp.task("build:server", function() {
return gulp.src(globs.server)
.pipe(cache.filter())
.pipe(babel())
.pipe(cache.cache())
.pipe(gulp.dest("./server/dist"));
});
gulp.task("watch:extension", function(cb) {
const config = Object.assign({}, webpackConfig, {
watch: true
});
webpack(config, webpackCallback(cb));
});
gulp.task("watch:server", function() {
gulp.watch(globs.server.src, ["build:server"]);
});
gulp.task("build", ["build:server", "build:extension"]);
gulp.task("watch", ["watch:extension"], function() {
livereload.listen();
});
gulp.task("serve", ["build:server"], function() {
nodemon({
script: "./server/server.js",
watch: [
"./src/server/", "./src/lib/",
"./src/server.js"
].map(function(path) {
return resolve(__dirname, path);
}),
tasks: ["build:server"]
});
});
gulp.task("serve2", shell.task([
"concurrently \"gulp serve\" \"python controller/controller.py\""
]));
gulp.task("config", function() {
return gulp.src("./{server,controller,extension}/*.sample.{json,ini}")
.pipe(rename(function(path) {
const suffix = ".sample";
const index = path.basename.length - suffix.length;
path.basename = path.basename.substr(0, index);
}))
.pipe(gulp.dest("."));
});
gulp.task("default", ["build"]);