forked from anvaka/npmgraph.an
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
117 lines (97 loc) · 3.28 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
var gulp = require('gulp'),
fs = require('fs'),
gutil = require('gulp-util'),
path = require('path'),
argv = require('yargs')
.alias('p', 'port')
.alias('s', 'server')
.argv;
var devServer = {
port: argv.port || Math.round(31337 + Math.random() * 1000),
server: argv.server || '0.0.0.0',
livereload: 35000 + Math.round((Math.random() * 1000)),
root: './dist'
};
gulp.task('default', ['build', 'startStaticServer', 'watchChanges']);
gulp.task('build', ['makeDist', 'runBrowserify', 'copyDist', 'compileLess']);
gulp.task('runBrowserify', runBrowserify);
gulp.task('compileLess', compileLess);
gulp.task('makeDist', makeDist);
gulp.task('copyDist', copyDist);
gulp.task('watchChanges', watchChanges);
gulp.task('startStaticServer', startStaticServer);
function runBrowserify() {
produceMainBundle();
produce3DBundle();
}
function produceMainBundle() {
var bundle = require('browserify')()
.exclude('renderer3d')
.add('./src/scripts/index.js');
bundle
.bundle()
.on('error', function (err) {
gutil.log(gutil.colors.red('Failed to browserify'), gutil.colors.yellow(err.message));
})
.pipe(fs.createWriteStream(path.join(__dirname + '/dist/bundle.js')));
}
function produce3DBundle() {
var bundle = require('browserify')()
.require('./src/scripts/viewer/3d/renderer3d.js', { expose: 'renderer3d' });
bundle
.bundle()
.on('error', function (err) {
gutil.log(gutil.colors.red('Failed to browserify render3d'), gutil.colors.yellow(err.message));
})
.pipe(fs.createWriteStream(path.join(__dirname + '/dist/renderer3d.js')));
}
function compileLess() {
var less = require('gulp-less')('src/styles');
less.on('error', function (err) {
gutil.log(gutil.colors.red('Failed to compile less: '), gutil.colors.yellow(err.message));
});
gulp.src('src/styles/main.less')
.pipe(less)
.pipe(gulp.dest('dist/styles'));
}
function makeDist() {
var fs = require('fs');
if (!fs.existsSync('./dist')) {
fs.mkdirSync('./dist');
}
}
function copyDist() {
var concat = require('gulp-concat');
gulp.src('./src/index.html').pipe(gulp.dest('./dist'));
gulp.src([
'./node_modules/angular/angular.min.js',
'./src/external/angular-route.js'
])
.pipe(concat('external.min.js'))
.pipe(gulp.dest('./dist'));
gulp.src([
'./node_modules/twitter-bootstrap-3.0.0/fonts/*'])
.pipe(gulp.dest('./dist/fonts/'));
}
function watchChanges() {
gulp.watch(['src/**/*.*', '!node_modules/**', '!src/*.html'], ['runBrowserify', 'copyDist']);
gulp.watch('src/styles/*.less', ['compileLess']);
gulp.watch(['src/*.html'], ['copyDist']);
gulp.watch(['dist/**', '!dist/**/node_modules/**']).on('change', notifyLivereload);
}
var lr;
function startStaticServer() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({port: devServer.livereload }));
app.use(express.static(devServer.root));
app.listen(devServer.port, devServer.server, function () {
gutil.log("opened server on http://" + devServer.server + ":" + devServer.port);
});
lr = require('tiny-lr')();
lr.listen(devServer.livereload);
}
function notifyLivereload(event) {
var fileName = require('path').relative(devServer.root, event.path);
lr.changed({ body: { files: [fileName] } });
}