-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
89 lines (73 loc) · 2.44 KB
/
gulpfile.js
File metadata and controls
89 lines (73 loc) · 2.44 KB
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
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
es6ify = require('es6ify'),
fs = require('fs'),
path = require('path'),
merge = require('merge-stream');
var componentsPath = "components";
//Default
gulp.task('default', ['build', 'connect'], function () {
gulp.watch(['components/**/**.*'], ['build']);
gulp.watch(['index.html', 'components/**/**.*', 'css/**/**.*', 'js/**/**.*', 'images/**/**.*'], function (event) {
return gulp.src(event.path)
.pipe($.connect.reload());
});
});
//Connect
gulp.task('connect', function () {
$.connect.server({
root: [__dirname],
port: 8002,
livereload: {port: 2983}
});
});
//Build
gulp.task('build', ['js', 'html', 'css', 'vulcanize']);
//JS
gulp.task('js', function () {
var folders = getFolders(componentsPath);
var tasks = folders.map(function(folder) {
return gulp.src('components/' + folder + '/src/*.js')
.pipe($.concat(folder + '.js'))
.pipe($.traceur())
.pipe(gulp.dest('components/' + folder + '/dist'));
});
return merge(tasks);
});
//HTML
gulp.task('html', function () {
var folders = getFolders(componentsPath);
var tasks = folders.map(function(folder) {
return gulp.src('components/' + folder + '/src/' + folder + '.html')
.pipe($.rename(folder + '.local.html'))
.pipe(gulp.dest('components/' + folder + '/dist'));
});
return merge(tasks);
});
//CSS
gulp.task('css', function () {
var folders = getFolders(componentsPath);
var tasks = folders.map(function(folder) {
return gulp.src('components/' + folder + '/src/' + folder + '.css')
.pipe(gulp.dest('components/' + folder + '/dist'));
});
return merge(tasks);
});
//Vulcanize
gulp.task('vulcanize', ['html', 'css'], function () {
var folders = getFolders(componentsPath);
var tasks = folders.map(function(folder) {
return gulp.src('components/' + folder + '/dist/' + folder + '.local.html')
.pipe($.vulcanize({dest: 'components/' + folder + '/dist', inline: true}))
.pipe($.rename(folder + '.html'))
.pipe(gulp.dest('components/' + folder + '/dist'));
});
return merge(tasks);
});
//Gets component folders
function getFolders(dir) {
return fs.readdirSync(dir)
.filter(function(file) {
return fs.statSync(path.join(dir, file)).isDirectory();
});
}