-
Notifications
You must be signed in to change notification settings - Fork 71
/
gulpfile.js
140 lines (118 loc) · 4.05 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
var path = require('path');
var del = require('del');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var less = require('gulp-less');
var preprocess = require('gulp-preprocess');
var zip = require('gulp-zip');
var rename = require('gulp-rename');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
var git = require('git-rev');
var htmlmin = require('gulp-htmlmin');
var templateCache = require('gulp-angular-templatecache');
var addStream = require('add-stream');
var pkg = require('./package.json');
var paths = {
scripts: ['./src/**/*.js'],
index_pages: ['./src/*.html'],
templates: ['./src/**/*.html', '!./src/*.html'],
statics: ['./src/**/*.svg', './src/**/*.png', './src/favicon.ico'],
styles: ['./src/**/*.less'],
dest: 'webapp',
release: 'dist'
};
gulp.task('default', ['clean', 'jshint', 'concat', 'copy', 'less', 'copy-index']);
gulp.task('clean', function () {
return del.sync([paths.dest + '/**/*.*']);
});
gulp.task('clean-release', function () {
return del.sync([paths.release]);
});
gulp.task('jshint', function () {
return gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('concat', function (cb) {
git.long(function (rev) {
var stream = gulp.src(paths.scripts)
.pipe(addStream.obj(prepareTemplates()))
.pipe(sourcemaps.init())
.pipe(ngAnnotate())
.pipe(concat(pkg.name + '.js'))
.pipe(preprocess({
context: { VERSION: pkg.version, COMMIT_HASH: rev }
}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(path.join(paths.dest, 'scripts')))
.on('end', cb);
});
});
gulp.task('copy', function () {
return gulp.src(paths.statics, {base: './src'})
.pipe(gulp.dest(paths.dest));
});
function prepareTemplates() {
return gulp.src(paths.templates)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(templateCache({module: 'monitorrent'}));
}
gulp.task('templateCache', function () {
return prepareTemplates()
.pipe(gulp.dest(paths.dest));
});
gulp.task('less', function () {
return gulp.src(paths.styles)
.pipe(less())
.pipe(concat(pkg.name + '.css'))
.pipe(gulp.dest(path.join(paths.dest, 'styles')));
});
gulp.task('copy-index', ['copy-index-html', 'copy-login-html']);
function preprocessIndexHtmlTpl(mode, rev) {
return gulp.src(['./src/index.html'])
.pipe(preprocess({
context: { VERSION: pkg.version, MODE: mode, COMMIT_HASH: rev }
}))
.pipe(rename(mode + '.html'))
.pipe(gulp.dest(paths.dest));
}
gulp.task('copy-index-html', function (cb) {
git.long(function (rev) {
var stream = preprocessIndexHtmlTpl('index', rev);
stream.on('end', cb);
});
});
gulp.task('copy-login-html', function (cb) {
git.long(function (rev) {
var stream = preprocessIndexHtmlTpl('login', rev);
stream.on('end', cb);
});
});
gulp.task('watch', ['default'], function () {
gulp.watch(paths.statics, ['copy']);
gulp.watch(paths.scripts.concat(paths.templates), ['concat']);
gulp.watch(paths.styles, ['less']);
gulp.watch(paths.index_pages, ['copy-index']);
});
gulp.task('release', ['dist'], function () {
return gulp.src([paths.release + '/**/*.*'])
.pipe(zip(pkg.name + '-' + pkg.version + '.zip'))
.pipe(gulp.dest('.'));
});
gulp.task('dist', ['clean-release', 'copy-python', 'copy-webapp', 'copy-desc']);
gulp.task('copy-python', function () {
return gulp.src(['./**/*.py', '!./tests*/**/*.*', '!./venv/**/*.*', '!./' + paths.release + '/**/*.py', '!./MonitorrentInstaller/**/*.*'])
.pipe(gulp.dest(paths.release));
});
gulp.task('copy-webapp', ['default'], function () {
return gulp.src([path.join(paths.dest, '**/*.*'), '!./**/*.map'])
.pipe(gulp.dest(path.join(paths.release, paths.dest)));
});
gulp.task('copy-desc', function () {
return gulp.src(['./package.json', './README.md', './requirements.txt'])
.pipe(gulp.dest(paths.release));
})