-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
97 lines (86 loc) · 2.87 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
// Dependencies
var config = require("./config.js");
var pathManager = require("./server/pathManager.js");
var gulp = require("gulp");
var del = require("del");
var jshint = require("gulp-jshint");
var shell = require("gulp-shell");
var preprocess = require("gulp-preprocess");
var nodemon = require("gulp-nodemon");
var mocha = require("gulp-mocha");
// Clean
gulp.task("clean", function (cb) {
del([pathManager.PUBLIC_BUILD], cb);
});
// Copy to build directory
gulp.task("copy", ["clean"], function () {
gulp.src([pathManager.PUBLIC_ASSETS + "/**/*.*"]).pipe(gulp.dest(pathManager.PUBLIC_BUILD + "/assets"));
gulp.src([pathManager.PUBLIC_CSS + "/**/*.*"]).pipe(gulp.dest(pathManager.PUBLIC_BUILD + "/css"));
if (config.env != "production") {
gulp.src([pathManager.PUBLIC_LIB + "/**/*.*"]).pipe(gulp.dest(pathManager.PUBLIC_BUILD + "/lib"));
gulp.src([pathManager.PUBLIC_SCRIPTS + "/**/*.js"]).pipe(gulp.dest(pathManager.PUBLIC_BUILD + "/scripts"));
} else {
gulp.src([pathManager.PUBLIC_LIB + "/requirejs/require.js"]).pipe(gulp.dest(pathManager.PUBLIC_BUILD + "/lib/requirejs"));
}
});
// Runs the r.js command
gulp.task("scripts", ["clean"], shell.task(config.requirejsCommand + " -o public/scripts/build.js"));
// HTML preprocessor
gulp.task("html", ["clean"], function () {
gulp.src(pathManager.PUBLIC + "/index.html")
.pipe(preprocess({ context: { NODE_ENV: config.env } }))
.pipe(gulp.dest(pathManager.PUBLIC_BUILD));
});
// Starts node server
gulp.task("server", function () {
nodemon({
script: pathManager.BASE + "/server.js",
watch: [
pathManager.BASE + "/*.js",
pathManager.SERVER + "/*.js"
],
ignore: [
pathManager.PUBLIC + "/**/*.*",
pathManager.TEST + "/**/*.js"
]
});
});
// Watch
gulp.task("watch", function () {
// Public side
gulp.watch([
pathManager.TEST + "/public/**/*.js",
pathManager.PUBLIC + "/**/*.*",
"!" + pathManager.PUBLIC_BUILD + "/**/*.*"
], ["copy", "html", "lint", "test"]);
// Server side
gulp.watch([
pathManager.BASE + "/*.js",
pathManager.SERVER + "/*.js",
pathManager.TEST + "/server/**/*.js"
], ["server", "lint", "test"]);
});
// Lint
gulp.task("lint", function () {
return gulp.src([
pathManager.BASE + "/*.js",
pathManager.SERVER + "/*.js",
pathManager.PUBLIC_SCRIPTS + "/**/*.js",
"!" + pathManager.PUBLIC_SCRIPTS + "/build.js",
"!" + pathManager.PUBLIC_BUILD + "/main-built.js",
])
.pipe(jshint())
.pipe(jshint.reporter("default"));
});
// Tests with mocha
gulp.task("test", function () {
gulp.src(pathManager.TEST + "/**/*.js")
.pipe(mocha())
.on("error", function(err){
console.log(err.toString());
});
});
// Environment tasks
gulp.task("development", ["watch", "copy", "html", "lint", "test", "server"]);
gulp.task("production", ["copy", "scripts", "html"]);
gulp.task("default", [config.env]);