-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
146 lines (124 loc) · 4.16 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
var fs = require("fs");
var del = require("del");
var gulp = require("gulp");
var eslint = require("gulp-eslint");
var less = require("gulp-less");
var concat = require("gulp-concat-sourcemap");
var replace = require("gulp-replace-task");
var browserSync = require("browser-sync");
var proxy = require("proxy-middleware");
var url = require("url");
var args = require("yargs").argv;
var autoprefixer = require("gulp-autoprefixer");
var shell = require("gulp-shell");
var sourcePath = require("./config/paths/source-path");
var libPath = require("./config/paths/lib-path");
var libCssFiles = require("./config/paths/lib-css-list.js");
var appPath = libPath.concat(sourcePath);
var pkg = require("./package");
gulp.task("clean", function () {
return del.sync(["dev"]);
});
gulp.task("lint", function () {
gulp.src(sourcePath, ["config/**/*.js"])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task("concat-sources", function () {
var env = args.env || "dev";
var filename = env + ".json";
var settings = JSON.parse(fs.readFileSync("./config/" + filename, "utf8"));
gulp.src(appPath)
.pipe(replace({
patterns: [
{
match: "apiHost",
replacement: settings.apiHost
}
]
}))
.pipe(concat("sources.js"))
.pipe(gulp.dest("./dev/src"));
});
gulp.task("build-less", function () {
gulp.src("./src/style/app.less")
.pipe(less())
.pipe(gulp.dest("dev/src"));
});
gulp.task("copy-lib-css", function () {
gulp.src(libCssFiles)
.pipe(concat("bootstrap.css"))
.pipe(gulp.dest("./dev/src"));
});
gulp.task("autoprefixer", function () {
gulp.src("dev/src/app.css")
.pipe(autoprefixer({
cascade: false
}))
.pipe(gulp.dest("dev/src"))
});
gulp.task("copy-template", function () {
gulp.src("src/template/**/*")
.pipe(gulp.dest("dev/src/template/"));
});
gulp.task("copy-index", function () {
gulp.src("./index.html")
.pipe(gulp.dest("dev/src/"));
});
gulp.task("copy-assets", function () {
gulp.src("./assets/**")
.pipe(gulp.dest("./dev/src/assets/"));
});
gulp.task("copy", ["copy-index", "copy-template", "copy-assets"]);
gulp.task("browser-sync", function () {
browserSync.init(
["./dev/src/app.css", "./dev/src/sources.js"],
{
"server": {
"baseDir": "./dev/src",
"index": "index.html"
},
logConnections: true,
ghostMode: {
links: false,
forms: false,
scroll: false,
click: false
},
open: true
})
});
gulp.task("watch", function () {
gulp.watch("./src/js/**", ["concat-sources"]);
gulp.watch("./index.html", ["copy-index"]);
gulp.watch("./src/template/**/*", ["copy-template"]);
gulp.watch("./src/style/**/*.less", ["build-less"]);
});
gulp.task("dev-live", ["concat-sources", "build-less", "copy-lib-css", "copy", "autoprefixer", "browser-sync", "watch"]);
gulp.task("dist-test", ["lint", "concat-sources", "build-less", "copy-lib-css", "copy"]);
gulp.task("build", ["concat-sources", "build-less", "copy-lib-css", "copy", "autoprefixer"]);
gulp.task("docker", function () {
var email = process.env.DOCKER_EMAIL;
var username = process.env.DOCKER_USERNAME;
var password = process.env.DOCKER_PASSWORD;
var imageName = process.env.DOCKER_IMAGE_NAME || "gerritdashboard-web";
var version = pkg.version;
if (!email) {
throw new Error("DOCKER_EMAIL undefined!");
}
if (!username) {
throw new Error("DOCKER_USERNAME undefined!");
}
if (!password) {
throw new Error("DOCKER_PASSWORD undefined!");
}
return shell.task([
`docker build -t ${imageName}:${version} .`,
`docker tag ${imageName}:${version} ${imageName}:latest`,
`docker login -e="${email}" -u="${username}" -p="${password}"`,
`docker push ${imageName}:${version}`,
`docker push ${imageName}:latest`
])();
});
gulp.task("default", ["clean", "build"]);