This repository has been archived by the owner on Dec 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 513
/
gulpfile.js
126 lines (114 loc) · 4.21 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
'use strict';
var gulp = require('gulp'),
gutil = require('gulp-util'),
clean = require('gulp-clean'),
gulpSequence = require('gulp-sequence'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
imagemin = require('gulp-imagemin'),
minifyCss = require('gulp-minify-css'),
minifyHtml = require('gulp-minify-html'),
ngTemplate = require('gulp-ng-template'),
uglify = require('gulp-uglify'),
rev = require('gulp-rev'),
replace = require('gulp-replace'),
usemin = require('gulp-usemin'),
merge2 = require('merge2'),
version = 'v' + require('./package.json').version,
cdnHost = require('./package.json').cdnHost;
gulp.task('clean', function () {
return gulp.src(['static/dist/*', 'static/cdn/*', 'static/src/js/templates.js'])
.pipe(clean({force: true}));
});
gulp.task('jshint', function () {
return gulp.src(['*.js', 'api/*.js', 'dao/*.js', 'lib/*.js', 'patch/*.js', 'static/src/js/*.js'])
.pipe(jshint())
.pipe(jshint.reporter());
});
gulp.task('css', function () {
return gulp.src([
'static/bower_components/pure/pure.css',
'static/bower_components/toastr/toastr.css',
'static/bower_components/font-awesome/css/font-awesome.css',
'static/src/css/prettify.css',
'static/src/css/main.css'
])
.pipe(concat('app.css'))
.pipe(replace('VERSION', version))
.pipe(gulp.dest('static/dist/css/'));
});
gulp.task('js-lib', function () {
return gulp.src([
'static/bower_components/jquery/dist/jquery.js',
'static/bower_components/angular/angular.js',
'static/bower_components/angular-animate/angular-animate.js',
'static/bower_components/angular-cookies/angular-cookies.js',
'static/bower_components/angular-resource/angular-resource.js',
'static/bower_components/angular-route/angular-route.js',
'static/bower_components/angular-i18n/angular-locale_zh-cn.js',
'static/bower_components/angular-ui-utils/validate.js',
'static/bower_components/angular-file-upload/angular-file-upload.js',
'static/bower_components/google-code-prettify/src/prettify.js',
'static/bower_components/marked/lib/marked.js',
'static/bower_components/toastr/toastr.js',
'static/bower_components/crypto-js/build/rollups/hmac-sha256.js',
'static/bower_components/utf8/utf8.js',
'static/bower_components/store2/dist/store2.js',
'static/bower_components/jsonkit/jsonkit.js',
'static/src/js/lib/bootstrap.js',
'static/src/js/lib/Markdown.Editor.js',
'static/src/js/lib/sanitize.js'
])
.pipe(concat('lib.js'))
.pipe(gulp.dest('static/dist/js/'));
});
gulp.task('js-app', function () {
return merge2(
gulp.src([
'static/src/js/app.js',
'static/src/js/locale_zh-cn.js',
'static/src/js/router.js',
'static/src/js/tools.js',
'static/src/js/services.js',
'static/src/js/filters.js',
'static/src/js/directives.js',
'static/src/js/controllers.js'
]),
gulp.src('static/src/tpl/*.html')
.pipe(minifyHtml({empty: true, quotes: true}))
.pipe(ngTemplate({
moduleName: 'genTemplates',
standalone: true,
filePath: 'templates.js'
})
)
)
.pipe(concat('app.js'))
.pipe(gulp.dest('static/dist/js/'));
});
gulp.task('files', function () {
return gulp.src(['static/src/{md,img}/*', 'static/src/*.*'])
.pipe(gulp.dest('static/dist'));
});
gulp.task('font', function () {
return gulp.src('static/bower_components/font-awesome/fonts/*')
.pipe(gulp.dest('static/dist/fonts/'));
});
gulp.task('cdn', function () {
return gulp.src(['static/dist/**/*', '!static/dist/js/*', '!static/dist/css/*'])
.pipe(gulp.dest('static/cdn/'));
});
gulp.task('usemin', function () {
return gulp.src('static/dist/index.html')
.pipe(replace('VERSION', version))
.pipe(replace(/\/static\/(js|css)/g, '$1'))
.pipe(usemin({
css: [minifyCss({keepSpecialComments: 0}), rev()],
// html: [minifyHtml({empty: true})],
js: [uglify(), rev()]
}))
.pipe(replace('../cdn', cdnHost))
.pipe(gulp.dest('static/cdn/'));
});
gulp.task('default', gulpSequence('clean', 'jshint', ['css', 'font', 'js-lib', 'js-app', 'files']));
gulp.task('build', gulpSequence('default', 'cdn', 'usemin'));