-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgulpfile.js
More file actions
239 lines (203 loc) · 7.73 KB
/
gulpfile.js
File metadata and controls
239 lines (203 loc) · 7.73 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
(function () {
"use strict";
var gulp = require("gulp");
var gutil = require("gulp-util");
var html2string = require("gulp-html2string");
var html2js = require("gulp-html2js");
var path = require("path");
var rename = require("gulp-rename");
var concat = require("gulp-concat");
var bump = require("gulp-bump");
var fs = require("fs");
var runSequence = require("run-sequence");
var es = require("event-stream");
var jshint = require("gulp-jshint");
var uglify = require("gulp-uglify");
var factory = require("widget-tester").gulpTaskFactory;
var bower = require("gulp-bower");
var del = require("del");
var colors = require("colors");
var deploy = require('gulp-gh-pages');
var argv = require('minimist')(process.argv.slice(2));
var subcomponents = fs.readdirSync("src")
.filter(function(file) {
return file[0] !== "_" && //exclude folders prefixed with "_"
fs.statSync(path.join("src", file)).isDirectory();
});
var views = fs.readdirSync("src/_angular")
.filter(function(file) {
return fs.statSync(path.join("src/_angular", file)).isDirectory();
});
gulp.task("clean-bower", function(cb){
del(["./components/**"], cb);
});
gulp.task("clean-dist", function (cb) {
del(['./dist/**'], cb);
});
gulp.task("clean-tmp", function (cb) {
del(['./tmp/**'], cb);
});
gulp.task("clean", ["clean-dist", "clean-tmp"]);
gulp.task("config", function() {
var env = process.env.NODE_ENV || "dev";
gutil.log("Environment is", env);
return gulp.src(["./src/_config/" + env + ".js"])
.pipe(rename("config.js"))
.pipe(gulp.dest("./src/_config"));
});
gulp.task("bump", function(){
return gulp.src(["./package.json", "./bower.json"])
.pipe(bump({type:"patch"}))
.pipe(gulp.dest("./"));
});
gulp.task("html2js-subcomponents", function () {
var tasks = subcomponents.map(function(folder) {
return gulp.src(path.join("src", folder, "**/*.html"))
.pipe(html2string({ createObj: true, base: path.join(__dirname, "src", folder), objName: "TEMPLATES" }))
.pipe(rename({extname: ".js"}))
.pipe(gulp.dest(path.join("tmp", "templates", folder)));
});
return es.concat.apply(null, tasks);
});
gulp.task("lint", function() {
return gulp.src('src/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter("jshint-stylish"))
.pipe(jshint.reporter("fail"));
});
gulp.task('js-concat-subcomponents', ["html2js-subcomponents", "lint"], function () {
var tasks = subcomponents.map(function(folder) {
return gulp.src([
path.join("tmp", "templates", folder, "**/*.js"), //template js files
path.join("src", folder, "**/*.js"),
"src/_config/config.js"
])
.pipe(concat(folder + ".js"))
.pipe(gulp.dest("dist/js"));
});
return es.concat.apply(null, tasks);
});
gulp.task("js-concat", ["js-concat-subcomponents"], function () {
return gulp.src("dist/js/*.js")
.pipe(concat("widget-settings-ui-components.js"))
.pipe(gulp.dest("dist/js"));
});
gulp.task("html2js-angular", function() {
var tasks = views.map(function(folder) {
return gulp.src(path.join("src/_angular", folder, "**/*.html"))
.pipe(html2js({
outputModuleName: "risevision.widget.common." + folder,
useStrict: true,
base: "src"
}))
.pipe(rename({extname: ".js"}))
.pipe(gulp.dest(path.join("tmp/ng-templates/", folder)));
});
return es.concat.apply(null, tasks);
});
gulp.task("angular", ["html2js-angular"], function () { //copy angular files
var tasks = views.map(function(folder) {
return gulp.src([
path.join("src/_angular", folder, "**/*.js"),
path.join("tmp/ng-templates/", folder, "**/*.js")
])
.pipe(concat(folder + ".js"))
.pipe(gulp.dest("dist/js/angular"));
});
return es.concat.apply(null, tasks);
});
gulp.task("js-uglify", ["angular", "js-concat"], function () {
gulp.src("dist/js/**/*.js")
.pipe(uglify())
.pipe(rename(function (path) {
path.basename += ".min";
}))
.pipe(gulp.dest("dist/js"));
});
gulp.task("webdriver_update", factory.webdriveUpdate());
// ***** e2e Testing ***** //
gulp.task("e2e:server", ["config"], factory.testServer());
gulp.task("e2e:server-close", factory.testServerClose());
gulp.task("e2e:test", factory.testE2E());
gulp.task("e2e:test-ng", ["webdriver_update"], factory.testE2EAngular({
src: ["test/e2e/angular/*test-ng.js"]
}));
// ***** Primary Tasks ***** //
gulp.task("bower-clean-install", ["clean-bower"], function(cb){
return bower().on("error", function(err) {
console.log(err);
cb();
});
});
// ****** Unit Testing ***** //
gulp.task("test:unit", factory.testUnitAngular(
{testFiles: [
"components/angular/angular.js",
"components/angular-mocks/angular-mocks.js",
"components/angular-sanitize/angular-sanitize.js",
"components/angular-bootstrap/ui-bootstrap-tpls.js",
"components/jquery/dist/jquery.js",
"components/angular-translate/angular-translate.js",
"components/angular-translate-loader-static-files/angular-translate-loader-static-files.js",
"components/common-header/dist/js/components/i18n.js",
"node_modules/widget-tester/mocks/i18n-config.js",
"components/component-storage-selector/dist/storage-selector.js",
"components/common-header/dist/js/components/subscription-status.js",
"dist/js/angular/tooltip.js",
"dist/js/angular/url-field.js",
"dist/js/angular/file-selector.js",
"test/mock/subscription-svc-http-mock.js",
"test/unit/**/*spec.js"]}
));
gulp.task("test", function(cb) {
runSequence("build", "test:unit", "e2e:server", "e2e:test", "e2e:test-ng", "e2e:server-close", cb);
});
gulp.task("build", function (cb) {
runSequence(["clean", "config"], ["js-uglify"], cb);
});
gulp.task("demo:server", ["build-demo"], factory.testServer({
rootPath: "./dist-demos"
}));
gulp.task("build-demo", function (cb) {
runSequence("copy-pages-to-demo-dist", "copy-dist-to-demo-dist", "copy-components-to-demo-dist", "copy-mocks-to-demo-dist", cb);
});
gulp.task("copy-pages-to-demo-dist", function() {
return gulp.src(["./demos/*.html"])
.pipe(gulp.dest("./dist-demos"));
});
gulp.task("copy-dist-to-demo-dist", function() {
return gulp.src(["./dist/**"])
.pipe(gulp.dest("./dist-demos/dist"));
});
gulp.task("copy-components-to-demo-dist", function() {
return gulp.src(["./components/**"])
.pipe(gulp.dest("./dist-demos/components"));
});
gulp.task("copy-mocks-to-demo-dist", function() {
return gulp.src(["./demos/mocks/**"])
.pipe(gulp.dest("./dist-demos/mocks"));
});
/**
* Deploy to gh-pages
*/
gulp.task("deploy-demo", function () {
// Remove temp folder created by gulp-gh-pages
if (argv.clean) {
var os = require('os');
var path = require('path');
var repoPath = path.join(os.tmpdir(), 'tmpRepo');
gutil.log('Delete ' + gutil.colors.magenta(repoPath));
del.sync(repoPath, {force: true});
}
return gulp.src("./dist-demos/**/*")
.pipe(deploy("https://github.com/Rise-Vision/widget-settings-ui-components.git"));
});
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 tests".yellow);
console.log(" gulp build: build distribution versions of all components".yellow);
console.log("********************************************************************".yellow);
return true;
});
})();