forked from yunalading/yuncms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·126 lines (110 loc) · 5.47 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');
var browserify = require('gulp-browserify');
var sourcemaps = require('gulp-sourcemaps');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var minify = require('gulp-minify-css');
var $ = require('gulp-load-plugins')();
var pkg = require('./package.json');
//项目配置文件
var config = {
AUTOPREFIXER_BROWSERS: [
'ie >= 8',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 2.3',
'bb >= 10'
]
};
var dateFormat = 'UTC:yyyy-mm-dd"T"HH:mm:ss Z';
var banner = [
'/*! <%= pkg.name %> v<%= pkg.version %><%=ver%>',
'by yunalading Team',
'<%= pkg.homepage %>',
'(c) ' + $.util.date(Date.now(), 'UTC:yyyy') + ' HTTGO, Inc.',
'<%= pkg.license.type %>',
$.util.date(Date.now(), dateFormat) + ' */ \n'
].join(' | ');
gulp.task('build:admin-js',function () {
gulp.src('./frontend/admin/js/admin.js').pipe(sourcemaps.init()).pipe(browserify()).pipe($.header(banner,{pkg:pkg,ver:''})).pipe($.plumber({errorHandler:function(err){
console.log(err);
this.emit('end');
}})).pipe(jshint()).pipe(gulp.dest('./public/static/admin/js')).pipe(uglify()).pipe($.rename({
'suffix': '.min',
'extname': '.js'
})).pipe(sourcemaps.write('./')).pipe(gulp.dest('./public/static/admin/js'));
});
gulp.task('build:admin-less',function () {
gulp.src('./frontend/admin/less/admin.less').pipe(sourcemaps.init()).pipe($.header(banner,{pkg:pkg,ver:''})).pipe($.plumber({errorHandler:function (err) {
console.log(err);
this.emit('end');
}})).pipe($.less()).pipe($.autoprefixer({browsers:config.AUTOPREFIXER_BROWSERS})).pipe(gulp.dest('./public/static/admin/css')).pipe(minify()).pipe($.rename({
'suffix': '.min',
'extname': '.css'
})).pipe(sourcemaps.write('./')).pipe(gulp.dest('./public/static/admin/css'));
});
gulp.task('build:home-js',function () {
gulp.src('./frontend/home/**/js/home.js').pipe(sourcemaps.init()).pipe(browserify()).pipe($.header(banner,{pkg:pkg,ver:''})).pipe($.plumber({errorHandler:function(err){
console.log(err);
this.emit('end');
}})).pipe(jshint()).pipe(gulp.dest('./public/static/home')).pipe(uglify()).pipe($.rename({
'suffix': '.min',
'extname': '.js'
})).pipe(sourcemaps.write('./')).pipe(gulp.dest('./public/static/home'));
});
gulp.task('build:home-less',function () {
gulp.src('./frontend/home/**/less/home.less').pipe(sourcemaps.init()).pipe($.header(banner,{pkg:pkg,ver:''})).pipe($.plumber({errorHandler:function (err) {
console.log(err);
this.emit('end');
}})).pipe($.less()).pipe($.autoprefixer({browsers:config.AUTOPREFIXER_BROWSERS})).pipe($.rename(function (path) {
path.dirname = path.dirname.replace('less','css');
})).pipe(gulp.dest('./public/static/home')).pipe(minify()).pipe($.rename({
'suffix': '.min',
'extname': '.css'
})).pipe(sourcemaps.write('./')).pipe(gulp.dest('./public/static/home'));
});
gulp.task('build:install-js',function () {
gulp.src('./frontend/install/js/install.js').pipe(sourcemaps.init()).pipe(browserify()).pipe($.header(banner,{pkg:pkg,ver:''})).pipe($.plumber({errorHandler:function(err){
console.log(err);
this.emit('end');
}})).pipe(jshint()).pipe(gulp.dest('./public/static/install/js')).pipe(uglify()).pipe($.rename({
'suffix': '.min',
'extname': '.js'
})).pipe(sourcemaps.write('./')).pipe(gulp.dest('./public/static/install/js'));
});
gulp.task('build:install-less',function () {
gulp.src('./frontend/install/less/install.less').pipe(sourcemaps.init()).pipe($.header(banner,{pkg:pkg,ver:''})).pipe($.plumber({errorHandler:function (err) {
console.log(err);
this.emit('end');
}})).pipe($.less()).pipe($.autoprefixer({browsers:config.AUTOPREFIXER_BROWSERS})).pipe(gulp.dest('./public/static/install/css')).pipe(minify()).pipe($.rename({
'suffix': '.min',
'extname': '.css'
})).pipe(sourcemaps.write('./')).pipe(gulp.dest('./public/static/install/css'));
});
gulp.task('copy:jquery',function () {
gulp.src('./node_modules/jquery/dist/**/*').pipe(gulp.dest('./public/static/common/jquery'));
});
gulp.task('copy:handlebars',function(){
gulp.src('./node_modules/handlebars/dist/**/*').pipe(gulp.dest('./public/static/common/handlebars'));
});
gulp.task('copy:amazeui',function () {
gulp.src('./node_modules/amazeui/dist/**/*').pipe(gulp.dest('./public/static/common/amazeui'));
});
gulp.task('copy:common',['copy:jquery','copy:handlebars','copy:amazeui']);
gulp.task('build',['build:admin-js','build:home-js','build:install-js','build:admin-less','build:home-less','build:install-less']);
gulp.task('watch',function(){
gulp.watch(['./frontend/admin/js/**/*.js'],['build:admin-js']);
gulp.watch(['./frontend/admin/less/**/*.less'],['build:admin-less']);
gulp.watch(['./frontend/home/**/js/**/*.js'],['build:home-js']);
gulp.watch(['./frontend/home/**/less/**/*.less'],['build:home-less']);
gulp.watch(['./frontend/install/js/**/*.js'],['build:install-js']);
gulp.watch(['./frontend/install/less/**/*.less'],['build:install-less']);
gulp.watch(['./frontend/common/js/**/*.js'],['build:install-js','build:admin-js','build:home-js']);
gulp.watch(['./frontend/common/less/**/*.less'],['build:install-less','build:admin-less','build:home-less']);
});
gulp.task('default',['copy:common','build','watch']);