-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gulpfile.js
executable file
·94 lines (82 loc) · 2.34 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
var gulp = require('gulp'),
//sass = require('gulp-ruby-sass'),
sass = require('gulp-sass'),
$ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'main-bower-files', 'event-stream'],
replaceString: /\bgulp[\-.]/
}),
folderSources = {
assetDir: './assets/',
publicDir: './public/',
bowerDir: './bower_components/'
},
//ES6 Stuff
//traceur = require('gulp-traceur'),//using babel not traceur (http://weblogs.asp.net/dwahlin/getting-started-with-es6-%E2%80%93-transpiling-es6-to-es5)
babel = require('gulp-babel'),
plumber = require('gulp-plumber');
//END ES6 Stuff
gulp.task('watch', function(){
$.livereload.listen();
gulp.watch(folderSources.assetDir + 'sass/*.scss', ['styles']);
gulp.watch(folderSources.assetDir + 'js/*.js', ['scripts', 'babel']);
});
gulp.task('sass', function () {
gulp.src(folderSources.assetDir + 'sass/*.scss')
.pipe(sass().on('error', function(err) {
console.error('Error!', err.message);
}))
.pipe(gulp.dest(folderSources.publicDir + 'stylesheets'))
.pipe($.livereload());
});
gulp.task('wsClientScript', function(){
compileScripts('ws-client.min.js');
});
gulp.task('scripts', [
'wsClientScript'
]);
gulp.task('default', [
'scripts',
'sass',
'watch'
]);
/***************
* Functions
**************/
//Script compiling
function compileScripts2(minFileName, filesArray) {
"use strict";
var filesToMove = [
'/assets/js/*.js'
];
gulp.task('move',['clean'], function(){
// the base option sets the relative root for the set of files,
// preserving the folder structure
gulp.src(filesToMove, { base: './' })
.pipe(gulp.dest('/public/script'));
});
}
function compileScripts(minFileName, filesArray) {
var concat = $.concat,
vendorFiles,
projectFiles;
vendorFiles = gulp.src($.mainBowerFiles())
.pipe($.filter('*.js'))
.pipe($.concat('vendor.js'));
if(typeof filesArray !== 'undefined') {
projectFiles = gulp.src(filesArray)
.pipe($.concat('app.js'))
//babel
.pipe(plumber())
.pipe(babel());
}
//projectFiles won't be avail if there is no filesArray sent in, so just use vendorFiles, which is bower stuff :)
$.eventStream.concat(vendorFiles, projectFiles || vendorFiles)
.pipe($.order([
'vendor.js',
'app.js'
]))
.pipe(concat(minFileName))
.pipe($.uglify())
.pipe(gulp.dest(folderSources.publicDir + 'scripts'))
.pipe($.livereload());
}