-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
144 lines (113 loc) · 3.64 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
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var rimraf = require('rimraf');
var runSequence = require('run-sequence');
var gls = require('gulp-live-server');
var replace = require('gulp-replace');
var concat = require('gulp-concat');
var autoprefixer = require ('gulp-autoprefixer');
var browserify = require('browserify');
var babelify = require("babelify");
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var file = require('gulp-file');
var server;
var watchEvent;
// DEVELOPMENT TASKS
//================================================
/*
* 1. Setup a webserver with livereload using BrowserSync
* 2. JS and CSS get processed and served from the 'build' folder
* */
// ENV
gulp.task('env', function() {
process.env.APP_BASE_PATH = __dirname;
});
gulp.task('css', function() {
// Extract the CSS from the JS Files and place into a single style with autoprefixer
return gulp.src('src/app/components/**/*.js')
.pipe(replace(/(^[\s\S]*<style>|<\/style>[\s\S]*$)/gm, ''))
.pipe(concat('style.css'))
.pipe(autoprefixer({browsers: ['last 2 versions']}))
.pipe(gulp.dest('build/app'));
});
gulp.task('public',['public-css','public-lib','browserify'], function() {
return gulp.src('build/client/bundle.js')
.pipe(gulp.dest('public/build/client'));
});
gulp.task('public-css', ['css'], function() {
return gulp.src('build/app/**/*.css')
.pipe(gulp.dest('public/build/app'));
});
gulp.task('public-lib', function() {
return gulp.src('lib/**/*.js')
.pipe(gulp.dest('public/lib'));
});
// JS
gulp.task('browserify', ['js-client', 'js-server', 'js-app'], function() {
// Browserify
var b = browserify({
entries: './build/client/index.js',
debug: true,
transform: [babelify.configure({optional: ['runtime', 'es7.asyncFunctions']})],
fullPaths: true
});
return b.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(gulp.dest('build/client'));
});
gulp.task('js-server', function() {
return gulp.src('src/server/**/*.js')
.pipe(gulp.dest('build/server'));
});
gulp.task('js-client', function() {
return gulp.src('src/client/**/*.js')
.pipe(gulp.dest('build/client'));
});
gulp.task('js-app', function() {
return gulp.src('src/app/**/*.js')
// remove the styles (they were extracted)
.pipe(replace(/<style>[\s\S]*<\/style>/gm, ''))
.pipe(gulp.dest('build/app'));
})
// HTML
gulp.task('html', function() {
gulp.src(['./index.html'])
.pipe(gulp.dest('./build'));
});
// serve task
gulp.task('serve', ['html', 'public', 'env'] , function(cb) {
server = gls.new('app.js');
server.start();
gulp.watch(['./src/**/*.js'], function(event) {
watchEvent = event;
gulp.start('reload-server');
});
gulp.watch('app.js', server.start);
});
gulp.task('reload-server', ['public'], function() {
console.log("Reloading server!")
server.notify(watchEvent) ;
});
// Delete build Directory
gulp.task('delete-build', function() {
rimraf('./build', function(err) {
plugins.util.log(err);
});
});
// Task for generating the primus client
gulp.task('primus', function() {
var Primus = require('primus');
var Emitter = require('primus-emitter');
var primus = Primus.createServer(function connection(spark) {
}, { port: 3000, transformer: 'websockets' });
primus.use('emitter', Emitter);
var str = primus.library();
return file('primus.js', str, { src: true }).pipe(gulp.dest('lib'));
})
// Default
gulp.task('default', ['serve']);
// DISTRIBUTION TASKS (TODO)
//===============================================