1 Star 0 Fork 9

idealord/JRoll2

forked from BarZu/JRoll2 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gulpfile.js 4.29 KB
一键复制 编辑 原始数据 按行查看 历史
chjtx 提交于 2017-07-19 11:45 . JRoll-Infinite v2.2.0
'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:jlong@chjtx.com 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'
})
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/idealord/JRoll2.git
git@gitee.com:idealord/JRoll2.git
idealord
JRoll2
JRoll2
master

搜索帮助