-
Notifications
You must be signed in to change notification settings - Fork 91
/
gulpfile.js
153 lines (129 loc) · 4.29 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
'use strict'
var fs = require('fs')
var gulp = require('gulp')
var rename = require('gulp-rename')
var uglify = require('gulp-uglify')
var replace = require('gulp-just-replace')
var license = require('gulp-header')
// 压缩/备份JRoll主文件
gulp.task('default', function () {
// 获取头部注释
fs.readFile('src/jroll.js', function (err, data) {
if (err) throw err
var head = /\/\*.+v(\d+\.\d+\.\d+).+\*\//.exec(data.toString())
var copyright = '/*! JRoll v2.0.0 ~ (c) 2015-2017 Author:jlong, Email:[email protected] Website:http://www.chjtx.com/JRoll/ */\n;'
var version = '2.0.0'
if (head) {
copyright = head[0] + '\n;' // 头部注释
version = head[1] // 版本号
}
gulp.src('src/jroll.js')
// 备份原文件
.pipe(rename({
basename: 'jroll',
extname: '.' + version + '.js'
}))
.pipe(gulp.dest('build/'))
// 压缩
.pipe(uglify())
// 加入头部注释
.pipe(license(copyright))
// 修改后缀
.pipe(rename({
basename: 'jroll',
extname: '.min.js'
}))
// 输出
.pipe(gulp.dest('build/'))
// 备份
.pipe(rename({
basename: 'jroll',
extname: '.' + version + '.min.js'
}))
.pipe(gulp.dest('build/'))
})
})
// 压缩、备份扩展组件等
function build (options) {
gulp.src(options.src)
// 备份原文件
.pipe(rename({
basename: options.basename,
extname: '.' + options.version + '.js'
}))
.pipe(license(options.copyright))
.pipe(replace([{
search: /\{\{version\}\}/g,
replacement: options.version
}]))
.pipe(gulp.dest(options.dest))
// 压缩
.pipe(uglify())
// 加入头部注释
.pipe(license(options.copyright))
.pipe(rename({
basename: options.basename,
extname: '.' + options.version + '.min.js'
}))
.pipe(gulp.dest(options.dest))
}
// JRollViewer 压缩、备份
gulp.task('viewer', function () {
let version = JSON.parse(fs.readFileSync('./package.json'))['version-viewer']
let copyright = `/*! JRollViewer v${version} ~ (c) 2016-2017 Author:BarZu Git:https://github.com/chjtx/JRoll/tree/master/plugins/jroll-viewer */\n`
build({
version: version,
copyright: copyright,
src: 'plugins/jroll-viewer/jroll-viewer.js',
dest: 'plugins/jroll-viewer/build/',
basename: 'jroll-viewer'
})
})
// jroll-fixedinput 压缩、备份
gulp.task('fixedinput', function () {
let version = JSON.parse(fs.readFileSync('./package.json'))['version-fixedinput']
let copyright = `/*! JRoll-FixedInput v${version} ~ (c) 2016-2017 Author:BarZu Git:https://github.com/chjtx/JRoll/tree/master/extends/jroll-fixedinput */\n`
build({
version: version,
copyright: copyright,
src: 'extends/jroll-fixedinput/jroll-fixedinput.js',
dest: 'extends/jroll-fixedinput/build/',
basename: 'jroll-fixedinput'
})
})
// jroll-infinite 压缩、备份
gulp.task('infinite', function () {
let version = JSON.parse(fs.readFileSync('./package.json'))['version-infinite']
let copyright = `/*! JRoll-Infinite v${version} ~ (c) 2016-2017 Author:BarZu Git:https://github.com/chjtx/JRoll/tree/master/extends/jroll-infinite */\n`
build({
version: version,
copyright: copyright,
src: 'extends/jroll-infinite/jroll-infinite.js',
dest: 'extends/jroll-infinite/build/',
basename: 'jroll-infinite'
})
})
// jroll-pulldown 压缩、备份
gulp.task('pulldown', function () {
let version = JSON.parse(fs.readFileSync('./package.json'))['version-pulldown']
let copyright = `/*! JRoll-Pulldown v${version} ~ (c) 2016-2017 Author:BarZu Git:https://github.com/chjtx/JRoll/tree/master/extends/jroll-pulldown */\n`
build({
version: version,
copyright: copyright,
src: 'extends/jroll-pulldown/jroll-pulldown.js',
dest: 'extends/jroll-pulldown/build/',
basename: 'jroll-pulldown'
})
})
// jroll-lite 压缩、备份
gulp.task('lite', function () {
let version = JSON.parse(fs.readFileSync('./package.json'))['version-lite']
let copyright = `/*! JRoll-Lite v${version} ~ (c) 2017 Author:BarZu Git:https://github.com/chjtx/JRoll/blob/master/README-LITE.md */\n`
build({
version: version,
copyright: copyright,
src: 'src/jroll-lite.js',
dest: 'build/',
basename: 'jroll-lite'
})
})