forked from alexk111/SVG-Morpheus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
153 lines (137 loc) · 4.52 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 argv = require('minimist')(process.argv.slice(2)),
gulp = require('gulp'),
header = require('gulp-header'),
gutil = require('gulp-util'),
refresh = require('gulp-livereload'),
prefix = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
clean = require('gulp-rimraf'),
concat = require('gulp-concat-util'),
express = require('express'),
express_lr = require('connect-livereload'),
tinylr = require('tiny-lr'),
opn = require('opn'),
jshint = require('gulp-jshint'),
jshintStylish= require('jshint-stylish'),
pkg = require('./package.json'),
lr,
refresh_lr;
var today = new Date();
// Configuration
var Config = {
port: 9000,
livereloadPort: 35728,
indexPage: 'demos/object.html',
cache: (typeof argv.cache !== 'undefined' ? !!argv.cache : true),
paths: {
demos: 'demos',
source: {
root: 'source',
js: 'source/js'
},
compileUnminified: {
root: 'compile',
js: 'compile'
},
compileMinified: {
root: 'compile',
js: 'compile'
}
},
banners: {
unminified: '/*!\n' +
' * ' + pkg.prettyName + ' v' + pkg.version + '\n' +
' * ' + pkg.homepage + '\n' +
' *\n' +
' * Copyright (c) ' + (today.getFullYear()) + ' ' + pkg.author.name +'\n' +
' * License: ' + pkg.license + '\n' +
' *\n' +
' * Generated at ' + gutil.date(today, 'dddd, mmmm dS, yyyy, h:MM:ss TT') + '\n' +
' * forked from https://github.com/alexk111/SVG-Morpheus\n'+
'*/',
minified: '/*! ' + pkg.prettyName + ' v' + pkg.version + ' License: ' + pkg.license + ' forked from https://github.com/alexk111/SVG-Morpheus */'
}
};
// Tasks
// =====
// Compile Scripts
gulp.task('scripts', function(){
return gulp.src([
Config.paths.source.js + '/deps/raf.js',
Config.paths.source.js + '/deps/easings.js',
Config.paths.source.js + '/deps/helpers.js',
Config.paths.source.js + '/deps/snapsvglite.js',
Config.paths.source.js + '/svg-morpheus.js'
])
.pipe(concat('svg-morpheus.js', {
separator: '\n\n',
process: function(src) {
// Remove all 'use strict'; from the code and
// replaces all double blank lines with one
return src.replace(/\r\n/g, '\n')
.replace(/'use strict';\n+/g, '')
.replace(/\n\n\s*\n/g, '\n\n');
}
}))
.pipe(concat.header(Config.banners.unminified + '\n' +
'var SVGMorpheus=(function() {\n\'use strict\';\n\n'))
.pipe(concat.footer('\n}());\n\nif ( typeof module === "object" && module.exports ) {\n module.exports = SVGMorpheus;\n}\n'))
.pipe(gulp.dest(Config.paths.compileUnminified.js));
});
// Make a Distrib
gulp.task('dist:js:clean', function(){
return gulp.src([Config.paths.compileMinified.root + '/**/*'], { read: false })
.pipe(clean());
});
// gulp.task('dist:js', ['dist:js:clean', 'scripts'], function(){
// return gulp.src(Config.paths.compileUnminified.js + '/svg-morpheus.js')
// .pipe(uglify())
// .pipe(header(Config.banners.minified))
// .pipe(gulp.dest(Config.paths.compileMinified.js));
// });
// Server
gulp.task('server', function(){
express()
.use(express_lr())
.use(express.static('.'))
.listen(Config.port);
gutil.log('Server listening on port ' + Config.port);
});
// LiveReload
gulp.task('livereload', function(){
lr = tinylr();
lr.listen(Config.livereloadPort, function(err) {
if(err) {
gutil.log('Livereload error:', err);
}
});
refresh_lr=refresh(lr);
});
// Watches
gulp.task('watch', function(){
gulp.watch([Config.paths.source.js + '/**/*.js'], ['scripts']);
gulp.watch([
Config.paths.compileUnminified.js + '/**/*.js',
Config.paths.demos + '/**/*.*'
], function(evt){
refresh_lr.changed(evt.path);
});
});
// User commands
// =============
// Code linter
gulp.task('lint', function() {
return gulp.src(Config.paths.source.js + '/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter(jshintStylish));
});
// Build
gulp.task('build', ['dist:js:clean', 'scripts']);
// Start server and watch for changes
gulp.task('default', ['server', 'livereload', 'scripts', 'watch'], function(){
// use the -o arg to open the test page in the browser
if(argv.o) {
opn('http://localhost:' + Config.port+'/'+Config.indexPage);
}
});