-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
156 lines (134 loc) · 4.45 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
154
155
156
(function () {
"use strict";
var gulp = require("gulp");
var bump = require("gulp-bump");
var concat = require("gulp-concat");
var folders = require("gulp-folders");
var html2js = require("gulp-html2js");
var jshint = require("gulp-jshint");
var gutil = require("gulp-util");
var rename = require("gulp-rename");
var uglify = require("gulp-uglify");
var path = require("path");
var runSequence = require("run-sequence");
var factory = require("widget-tester").gulpTaskFactory;
var del = require("del");
var colors = require("colors");
var minifyCSS = require("gulp-minify-css");
var bower = require("gulp-bower");
var wct = require("web-component-tester").gulp.init(gulp);
gulp.task("clean", function (cb) {
del(["./dist/**"], cb);
});
gulp.task("clean-bower", function(cb){
del(["./components/**"], cb);
});
gulp.task("config", function() {
var env = process.env.NODE_ENV || "prod";
gutil.log("Environment is", env);
return gulp.src(["./src/config/" + env + ".js"])
.pipe(rename("config.js"))
.pipe(gulp.dest("./src/config"))
.pipe(gulp.dest("dist"));
});
gulp.task("bump", function(){
return gulp.src(["./package.json", "./bower.json"])
.pipe(bump({type:"patch"}))
.pipe(gulp.dest("./"));
});
gulp.task("lint", function() {
return gulp.src("src/**/*.js")
.pipe(jshint())
.pipe(jshint.reporter("jshint-stylish"))
.pipe(jshint.reporter("fail"));
});
gulp.task("css", function() {
return gulp.src("src/css/**/*.css")
.pipe(gulp.dest("dist/css"))
});
gulp.task("css-concat", ["css"], function () {
return gulp.src("dist/**/*.css")
.pipe(concat("all.css"))
.pipe(gulp.dest("dist/css"));
});
gulp.task("css-minify", ["css-concat"], function () {
gulp.src("dist/css/*.css")
.pipe(minifyCSS())
.pipe(rename(function (path) {
path.basename += ".min";
}))
.pipe(gulp.dest("dist/css"));
});
gulp.task("js", function (cb) {
return gulp.src("src/js/*.js")
.pipe(gulp.dest("dist"));
});
gulp.task("js-folder", folders("src/js", function(folder) {
return gulp.src(path.join("src/js", folder, "*.js"))
.pipe(concat(folder + ".js"))
.pipe(gulp.dest("dist"));
}));
gulp.task("js-concat", ["js", "js-folder"], function (cb) {
return gulp.src("dist/**/*.js")
.pipe(concat("all.js"))
.pipe(gulp.dest("dist"));
});
gulp.task("js-uglify", ["js-concat"], function () {
gulp.src("dist/*.js")
.pipe(uglify())
.pipe(rename(function (path) {
path.basename += ".min";
}))
.pipe(gulp.dest("dist"));
});
gulp.task("assets", function () {
gulp.src("src/assets/**/*")
.pipe(gulp.dest("dist/assets"))
});
// ****** Unit Testing ***** //
gulp.task("test:unit", factory.testUnitAngular(
{testFiles: [
"components/jquery/dist/jquery.min.js",
"components/compare-versions/index.js",
"test/date.js",
"test/data/financial.js",
"node_modules/widget-tester/mocks/gadget-mocks.js",
"node_modules/widget-tester/mocks/visualization-api-mock.js",
"test/mocks/ajax.js",
"src/config/test.js",
"src/js/store-auth.js",
"src/js/visualization.js",
"src/js/financial/*.js",
"src/js/background.js",
"src/js/common.js",
"src/js/rise-cache.js",
"src/js/logger.js",
"src/js/ws-client.js",
"test/unit/**/*spec.js"]}
));
// ***** Integration Testing ***** //
gulp.task("test:integration", function(cb) {
runSequence("test:local", cb);
});
// ***** Primary Tasks ***** //
gulp.task("bower-update", function (cb) {
return bower({ cmd: "update"}).on("error", function(err) {
console.log(err);
cb();
});
});
gulp.task("build", function (cb) {
runSequence(["clean", "config", "bower-update"], ["lint", "js-uglify", "css-minify", "assets"], cb);
});
gulp.task("test", function(cb) {
runSequence("test:unit", "test:integration", cb)
});
gulp.task("default", [], function() {
console.log("********************************************************************".yellow);
console.log(" gulp bower-clean-install: delete and re-install bower components".yellow);
console.log(" gulp test: run e2e and unit tests".yellow);
console.log(" gulp build: build a distribution version".yellow);
console.log("********************************************************************".yellow);
return true;
});
})();