forked from sAleksovski/scrum-board-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
178 lines (158 loc) · 5.13 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var gulp = require('gulp');
var concat = require('gulp-concat');
var templateCache = require('gulp-angular-templatecache');
var rev = require('gulp-rev-append');
var connect = require('gulp-connect');
var replace = require('gulp-replace');
var argv = require('yargs').argv;
var fs = require("fs");
var CSS_LIB = [
'bower_components/angular-xeditable/dist/css/xeditable.css',
'bower_components/angular-material/angular-material.css'
];
var CSS_APP = [
'css/main.css'
];
var JS_LIB = [
'bower_components/angular/angular.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.min.js',
'bower_components/angular-sanitize/angular-sanitize.min.js',
'bower_components/angular-translate/angular-translate.min.js',
'bower_components/angular-ui-router/release/angular-ui-router.min.js',
'bower_components/angular-xeditable/dist/js/xeditable.min.js',
'bower_components/momentjs/moment.js',
'bower_components/angular-aria/angular-aria.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-material/angular-material.js',
'bower_components/angular-drag-and-drop-lists/angular-drag-and-drop-lists.min.js',
'bower_components/sockjs/sockjs.js',
'bower_components/stomp-websocket/lib/stomp.js'
];
var JS_APP = [
'app/**/**.js'
];
/**
* The location of the resources for deploy
*/
var DESTINATION = 'dest/';
/**
* The single page initial html file. It will be altered
* by this script.
*/
var INDEX_FILE = 'index.html';
/**
* The name of the angular module
*/
var MODULE_NAME = 'scrum-board-frontend';
/**
* The URL of the back-end API
*/
var BACKEND = argv.backend || 'http://localhost:8080';
var API_URL = BACKEND + '/api';
var LOGIN_URL = BACKEND + '/auth';
/**
* Route to which the API calls will be mapped
*/
var API_ROUTE = '/api';
var LOGIN_ROUTE = '/auth';
/**
* Task for concatenation of the js libraries used
* in this project
*/
gulp.task('concat_js_lib', function () {
return gulp.src(JS_LIB) // which js files
.pipe(concat('lib.js')) // concatenate them in lib.js
.pipe(gulp.dest(DESTINATION)); // save lib.js in the DESTINATION folder
});
/**
* Task for concatenation of the css libraries used
* in this project
*/
gulp.task('concat_css_lib', function () {
return gulp.src(CSS_LIB) // which css files
.pipe(concat('lib.css')) // concat them in lib.css
.pipe(gulp.dest(DESTINATION)); // save lib.css in the DESTINATION folder
});
/**
* Task for concatenation of the js code defined
* in this project
*/
gulp.task('concat_js_app', function () {
return gulp.src(JS_APP)
.pipe(concat('src.js'))
.pipe(replace('$$BACKEND$$', BACKEND))
.pipe(gulp.dest(DESTINATION))
});
/**
* Task for concatenation of the css code defined
* in this project
*/
gulp.task('concat_css_app', function () {
return gulp.src(CSS_APP)
.pipe(concat('app.css'))
.pipe(gulp.dest(DESTINATION))
});
/**
* Task for concatenation of the html templates defined
* in this project
*/
gulp.task('templates', function () {
return gulp.src('views/**/**.html') // which html files
.pipe(
templateCache('templates.js', { // compile them as angular templates
module: MODULE_NAME, // from module MODULE_NAME
root: 'app' // of the app
}))
.pipe(gulp.dest(DESTINATION));
});
/**
* Task for adding the revision as parameter
* for cache braking
*/
gulp.task('cache-break', function () {
return gulp.src(INDEX_FILE) // use the INDEX_FILE as source
.pipe(rev()) // append the revision to all resources
.pipe(gulp.dest('.')) // save the modified file at the same destination
.pipe(connect.reload());// reload
});
var tasks = [
'concat_js_lib',
'concat_css_lib',
'concat_js_app',
'concat_css_app',
'templates'
];
gulp.task('build', tasks, function () {
gulp.start('cache-break');
});
gulp.task('watch', function () {
gulp.watch('app/**/**.js', ['concat_js_app', 'cache-break']);
gulp.watch('views/**/**.html', ['templates', 'cache-break']);
gulp.watch('css/**/**.css', ['concat_css_app', 'cache-break']);
});
gulp.task('serve', function () {
connect.server({
port: argv.port || 8000,
livereload: typeof argv.livereload === 'undefined' || argv.livereload === 'true',
middleware: function (connect, opt) {
return [
(function () {
var url = require('url');
var proxy = require('proxy-middleware');
var options = url.parse(API_URL);
options.route = API_ROUTE;
return proxy(options);
})(),
(function () {
var url = require('url');
var proxy = require('proxy-middleware');
var options = url.parse(LOGIN_URL);
options.route = LOGIN_ROUTE;
return proxy(options);
})()
];
}
});
});
gulp.task('default', ['build', 'serve', 'watch']);