-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
115 lines (98 loc) · 3.02 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
var fs = require('fs');
var gulp = require("gulp");
var gutil = require("gulp-util");
var rename = require('gulp-rename');
var git = require('gulp-git');
var ngConstant = require('gulp-ng-constant');
var rm = require('gulp-rimraf');
var KarmaServer = require('karma').Server;
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
var webpackConfig = require("./webpack.config.js");
var runner = require('protractor-webpack');
var minimist = require('minimist');
var knownOptions = {
string: 'buildNumber',
default: { buildNumber: 'LOCAL' }
};
var options = minimist(process.argv.slice(2), knownOptions);
var versionMajorMinor = fs.readFileSync(__dirname + '/VERSION');
var gitHash = '';
gulp.task("webpack-dev-server", function(callback) {
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
new WebpackDevServer(webpack(myConfig), {
contentBase: 'app/',
stats: {
colors: true
}
}).listen(9001, "localhost", function(err) {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://127.0.0.1:9001");
});
});
gulp.task('protractor', function(callback) {
var reqlib = require('app-root-path').require;
var launcher = reqlib('/node_modules/protractor/built/launcher');
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
new WebpackDevServer(webpack(myConfig), {
contentBase: 'app/',
stats: {
colors: true
}
}).listen(9001, "localhost", function(err) {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
launcher.init(__dirname + '/test/protractor.conf.js');
gutil.log("[webpack-dev-server]", "http://127.0.0.1:9001");
});
});
gulp.task('karma', function(done) {
var server = new KarmaServer({
configFile: __dirname + '/test/karma.conf.js',
singleRun: false
}, done);
server.start();
});
gulp.task("clean", function() {
return gulp.src('dist/*').pipe(rm());
});
gulp.task("package", ["clean", "version"], function(done) {
webpack(webpackConfig, function(err, stats) {
if (stats.compilation.errors.length) {
throw new gutil.PluginError('webpack', stats.compilation.errors.toString());
}
if (stats.compilation.warnings.length) {
gutil.log('[WARNING]', stats.compilation.warnings.toString())
}
done();
});
});
gulp.task("githash", function(done) {
git.exec({args: 'rev-parse --short HEAD'}, function(err, stdout) {
gitHash = stdout;
done();
});
});
gulp.task('version', ["githash"], function() {
return ngConstant({
name: 'version',
constants: {
versionNumber: {
version: versionMajorMinor + options.buildNumber,
gitHash: gitHash.trim()
}
},
wrap: 'commonjs',
stream: true
})
.pipe(rename({
basename: 'version-service',
extname: '.js'
}))
.pipe(gulp.dest('./app/services/'));
});
gulp.task("build", ["package"]);
gulp.task("serve", ["webpack-dev-server"]);