-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
125 lines (105 loc) · 4.3 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
(function (require) {
"use strict";
var gulp = require("gulp");
var concat = require("gulp-concat");
var sass = require("gulp-sass");
var watch = require("gulp-watch");
var gulpif = require("gulp-if");
var uglify = require("gulp-uglify");
var sourcemaps = require("gulp-sourcemaps");
var inline = require("gulp-inline");
var replace = require("gulp-replace");
var templateCache = require("gulp-angular-templatecache");
var minifyHTML = require("gulp-minify-html");
var del = require("del");
var runSequence = require("run-sequence");
var args = require("yargs").argv;
var isPublish = false;
var paths = {
app: "./app/",
appAllRecursive: "./app/**/*",
target: "./bundled/",
targetAllRecursive: "./bundled/**/*"
};
paths.indexHtml = paths.app + "index.html";
paths.allHtmlButIndex = [paths.appAllRecursive + ".html", "!" + paths.indexHtml];
var appDefinition = {
srcs: [
paths.app + "keyPearlApp.js",
paths.app + "config.js",
paths.app + "components/**/*.js",
paths.app + "types/*.js"
],
targetFile: "app.js"
};
var libDefinition = {
srcs: [
"./bower_components/angular/angular.js",
"./bower_components/angular-route/angular-route.js",
"./bower_components/angular-touch/angular-touch.js",
"./bower_components/angular-animate/angular-animate.js"
],
targetFile: "libs.js"
};
var concatAndCopyScripts = function (definition, targetFolder) {
// todo: consider using/passing an object for replacements (i.e. {serverApiBaseUrl: "http://localhost:61345"}
// otherwise use a default config object - for the moment it works the way it is, but there's room for
// improvement here
return gulp.src(definition.srcs)
.pipe(sourcemaps.init())
.pipe(replace("$build:serverApiBaseUrl$", args.serverApiBaseUrl || "http://localhost:61345/"))
.pipe(gulp.dest(targetFolder + "/temp1"))
.pipe(concat(definition.targetFile))
.pipe(gulp.dest(targetFolder + "/temp2"))
.pipe(gulpif(isPublish, uglify()))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(targetFolder));
};
gulp.task("clean", function () {
return del.sync(paths.targetAllRecursive);
});
gulp.task("scriptsApp", function () {
return concatAndCopyScripts(appDefinition, paths.target);
});
gulp.task("scriptsLib", function () {
return concatAndCopyScripts(libDefinition, paths.target);
});
gulp.task("scss", function () {
return gulp.src(paths.appAllRecursive + ".scss")
.pipe(sass({outputStyle: "compressed"}).on("error", sass.logError))
.pipe(concat("styles.css"))
.pipe(gulp.dest(paths.target));
});
gulp.task("index.html", function () {
return gulp.src(paths.indexHtml)
.pipe(gulpif(isPublish, minifyHTML({conditionals: true, spare: true})))
.pipe(gulp.dest(paths.target));
});
gulp.task("templates", function () {
return gulp.src(paths.allHtmlButIndex)
.pipe(gulpif(isPublish, minifyHTML({conditionals: true, spare: true})))
.pipe(templateCache({module: "keyPearl"}))
.pipe(gulp.dest(paths.target));
});
gulp.task("default", function (callback) {
return runSequence("clean", ["scss", "scriptsLib", "scriptsApp", "index.html", "templates"], callback);
});
gulp.task("publish", function (callback) {
isPublish = true;
return runSequence("default", "inline", "deleteInlined", callback);
});
gulp.task("inline", function () {
return gulp.src(paths.target + "index.html")
.pipe(inline({base: paths.target}))
.pipe(gulp.dest(paths.target));
});
gulp.task("deleteInlined", function () {
return del.sync([paths.target + "*.js", paths.target + "*.css"]);
});
gulp.task("watch", function () {
gulp.watch(paths.allHtmlButIndex, ["templates"]);
gulp.watch(paths.indexHtml, ["index.html"]);
gulp.watch(paths.appAllRecursive + ".scss", ["scss"]);
gulp.watch(paths.appAllRecursive + ".js", ["scriptsApp"]);
});
})(require);