-
Notifications
You must be signed in to change notification settings - Fork 6
/
Gulpfile.js
79 lines (72 loc) · 1.7 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
'use strict';
/**
* Module Dependencies.
*/
var mkdirp = require('mkdirp');
var gulp = require('gulp');
var header = require('gulp-header');
var footer = require('gulp-footer');
var replace = require('gulp-replace');
var rename = require('gulp-rename');
var ugifyjs = require('gulp-uglify');
/**
* Package
*/
var pkg = require('./package.json');
var name = 'Jvent';
/**
* String
*/
var prefix = ['/*!',
' * <%= pkg.name %> - v<%= pkg.version %>',
' *',
' * Copyright (c) ' + new Date().getFullYear() + ', <%= pkg.author %>',
' * Released under the MIT license.',
' */',
'(function(window) {',
''].join('\n');
var postfix = '\n}(this));';
var umd = [
'// AMD',
'if (typeof window.define === \'function\' && window.define.amd !== undefined) {',
' window.define(\'' + name + '\', [], function () {',
' return ' + name + ';',
' });',
'// CommonJS',
'} else if (typeof module !== \'undefined\' && module.exports !== undefined) {',
' module.exports = ' + name + ';',
'// Browser',
'} else {',
' window.' + name + ' = ' + name + ';',
'};'
].join('\n');
/**
* Create directory
*/
mkdirp('./dist');
/**
* Build task
*/
gulp.task('build', function() {
mkdirp('./dist');
gulp.src('./index.js')
.pipe(header(prefix, { 'pkg' : pkg }))
.pipe(footer(postfix))
.pipe(replace('module.exports = ' + name + ';', umd))
.pipe(rename(pkg.name + '.js'))
.pipe(gulp.dest('./dist/'));
});
/**
* Min task
*/
gulp.task('min', function() {
gulp.src('./dist/' + pkg.name + '.js')
.pipe(ugifyjs())
.pipe(rename(pkg.name + '.min.js'))
.pipe(gulp.dest('./dist/'));
});
/**
* Register tasks
*/
gulp.task('default', ['build']);
gulp.task('dist', ['build', 'min']);