forked from StarterSquad/ngseed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
170 lines (148 loc) · 4.74 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
var _ = require('underscore');
var autoprefix = require('gulp-autoprefixer');
var es = require('event-stream');
var gulp = require('gulp');
var karma = require('gulp-karma');
var livereload = require('gulp-livereload');
var lr = require('tiny-lr');
var protractor = require('gulp-protractor').protractor;
var replace = require('gulp-replace');
var rjs = require('gulp-requirejs');
var sass = require('gulp-ruby-sass');
var spawn = require('child_process').spawn;
var uglify = require('gulp-uglify');
var webdriver = require('gulp-protractor').webdriver;
var handleError = function (err) {
console.log(err.name, ' in ', err.plugin, ': ', err.message);
this.emit('end');
};
var server = lr();
// Bump version
gulp.task('bump-version', function () {
spawn('git', ['rev-parse', '--abbrev-ref', 'HEAD']).stdout.on('data', function (data) {
// Get current branch name
var branch = data.toString();
// Verify we're on a release branch
if (/^release\/.*/.test(branch)) {
var newVersion = branch.split('/')[1].trim();
// Update client index.html
gulp.src('./source/index.html')
.pipe(replace(/(bust=v)(\d*\.?)*/g, '$1' + newVersion))
.pipe(gulp.dest('./source'));
var updateJson = function (file) {
gulp.src(file)
.pipe(replace(/("version" *: *")([^"]*)(",)/g, '$1' + newVersion + '$3'))
.pipe(gulp.dest('./'));
};
updateJson('./bower.json');
updateJson('./package.json');
console.log('Successfully bumped to ' + newVersion);
} else {
console.error('This task should be executed on a release branch!');
}
});
});
// Copy
gulp.task('copy', ['sass'], function () {
return es.concat(
// update index.html to work when built
gulp.src(['source/index.html'])
.pipe(gulp.dest('build')),
// copy config-require
gulp.src(['source/js/config-require.js'])
.pipe(uglify().on('error', handleError))
.pipe(gulp.dest('build/js')),
// copy template files
gulp.src(['source/js/**/*.html'])
.pipe(gulp.dest('build/js')),
// copy vendor files
gulp.src(['source/vendor/**/*'])
.pipe(gulp.dest('build/vendor')),
// copy assets
gulp.src(['source/assets/**/*'])
.pipe(gulp.dest('build/assets')),
// minify requirejs
gulp.src(['build/vendor/requirejs/require.js'])
.pipe(uglify().on('error', handleError))
.pipe(gulp.dest('build/vendor/requirejs')),
// minify domReady
gulp.src(['build/vendor/requirejs-domready/domReady.js'])
.pipe(uglify().on('error', handleError))
.pipe(gulp.dest('build/vendor/requirejs-domready'))
);
});
// JavaScript
gulp.task('js', function () {
var configRequire = require('./source/js/config-require.js');
var configBuild = {
baseUrl: 'source/js',
insertRequire: ['main'],
name: 'main',
wrap: true
};
var config = _(configBuild).extend(configRequire);
return gulp.src(['source/js/main.js'])
.pipe(rjs(config).on('error', handleError))
.pipe(uglify().on('error', handleError))
.pipe(gulp.dest('build/js/'))
.pipe(livereload(server));
});
// Karma
gulp.task('karma', function () {
return gulp.src(['no need to supply files because everything is in config file'])
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}).on('error', handleError));
});
gulp.task('karma-ci', function () {
return gulp.src(['no need to supply files because everything is in config file'])
.pipe(karma({
configFile: 'karma-compiled.conf.js',
action: 'run'
}).on('error', handleError));
});
// Sass
gulp.task('sass', function () {
return gulp.src(['source/sass/*.scss', '!source/sass/_*.scss'])
.pipe(sass({
bundleExec: true,
require: [
'./source/sass/sass_extensions.rb',
'sass-globbing'
],
style: 'compressed'
}).on('error', handleError))
.pipe(autoprefix().on('error', handleError))
.pipe(gulp.dest('source/assets/css'))
.pipe(livereload(server));
});
// Protractor
gulp.task('protractor', function () {
return gulp.src('source/js/**/*.e2e.js')
.pipe(protractor({ configFile: 'p.conf.js' }));
});
gulp.task('protractor-ci', function () {
return gulp.src('source/js/**/*.e2e.js')
.pipe(protractor({ configFile: 'p-compiled.conf.js' }));
});
gulp.task('webdriver', webdriver);
// Watch
gulp.task('watch', ['sass', 'karma'], function () {
gulp.watch('source/sass/**/*.scss', function () {
gulp.run('sass');
});
// enable Livereload
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
gulp.watch([
'source/assets/*.css',
'source/index.html',
'source/js/**/*',
'!source/js/**/*.spec.js'
]);
});
});
gulp.task('default', ['js', 'copy', 'karma-ci', 'protractor-ci']);