-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
109 lines (94 loc) · 3.01 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
var gulp = require('gulp');
var livereload = require('gulp-livereload');
var nodemon = require('gulp-nodemon');
var gulpOpen = require('gulp-open');
var protractor = require('gulp-protractor').protractor;
var webdriver_update = require('gulp-protractor').webdriver_update;
var gulpNgConfig = require('gulp-ng-config');
var config = require('config');
var wiredep = require('wiredep').stream;
var inject = require('gulp-inject');
var watchLivereload = function () {
gulp.watch(['lib/public/**/*.*'], function (event) {
gulp.src(event.path, {read: false})
.pipe(livereload());
});
};
var child;
gulp.task('spawn', function () {
var spawn = require('child_process').spawn;
child = spawn('node', ['index']);
child.stdout.on('data', function(data) {
console.log('stdout: ' + data);
});
child.stderr.on('data', function(data) {
console.log('stdout: ' + data);
});
child.on('close', function(code) {
console.log('closing code: ' + code);
});
});
gulp.task('protractor', ['webdriver_update', 'spawn'], function () {
gulp.src(['./src/tests/*.js'])
.pipe(protractor({
configFile: 'protractor.conf.js',
args: ['--baseUrl', 'http://127.0.0.1:' + (process.env.PORT || 3000)]
}))
.on('error', function(e) {
throw e;
})
.on('end', function () {
child.kill('SIGKILL');
})
});
gulp.task('webdriver_update', webdriver_update );
gulp.task('kill-spawn', function () {
if(child){
child.kill('SIGKILL');
}
});
var publicConfig = function (enviroment) {
return gulp.src('lib/public/scripts/config/config.json')
.pipe(gulpNgConfig('awesomeSocialNetworkApp.config', {
environment: enviroment,
constants: {
socketServerUrl: 'http://localhost:' + config.socketPort + '/'
}
}))
.pipe(gulp.dest('lib/public/scripts/config/'));
};
gulp.task('public-config:development', function () {
return publicConfig('development');
});
gulp.task('public-config:production', function () {
return publicConfig('production');
});
gulp.task('serve', function () {
nodemon({
script: 'index.js',
ignore: ['lib/public/**', 'test/**']
}).on('start', function () {
livereload.reload();
livereload.listen();
watchLivereload();
});
});
gulp.task('open', function () {
gulp.src('')
.pipe(gulpOpen({
uri: 'http://localhost:3000/',
app: 'chrome'
}));
});
gulp.task('default', ['public-config:development', 'injectScripts', 'serve', 'open']);
gulp.task('test:integration', ['protractor']);
gulp.task('injectScripts', function () {
var target = gulp.src('lib/public/index.html');
return target
.pipe(wiredep({
cwd: 'lib/public',
exclude: ['blueimp*']
}))
.pipe(inject(gulp.src(['lib/public/scripts/**/*.js'], {read: false}), {relative: true}))
.pipe(gulp.dest('./lib/public'));
});