-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (30 loc) · 1.16 KB
/
index.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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require("gulp-rename");
function _safeCheck(filesToCopy) {
filesToCopy = typeof filesToCopy === 'string' ? [filesToCopy] : filesToCopy;
if (!Array.isArray(filesToCopy) && typeof filesToCopy !== 'object') {
throw new gutil.PluginError('gulp-copy-rex', '`filesToCopy` should be a string, array or object.');
}
return filesToCopy;
}
function _setFilename(filename) {
if (filename) {
filename = filename.indexOf('.min.js') >= 0 ? filename : filename + '.min.js';
}
return filename || 'app.min.js';
}
module.exports = function (filesToCopy, destination, opts) {
filesToCopy = _safeCheck(filesToCopy);
opts = opts || {min: false, concat: false};
var filename = _setFilename(opts.filename);
return gulp
.src(filesToCopy)
.pipe(opts.concat ? concat(filename) : gutil.noop())
.pipe(opts.min ? uglify() : gutil.noop())
.pipe(opts.filename && !opts.concat ? rename(filename) : gutil.noop())
.pipe(gulp.dest(destination));
};