forked from unconed/mathbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
156 lines (130 loc) · 3.53 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
154
155
156
var gulp = require('gulp');
var gutil = require('gulp-util');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require("gulp-rename");
var karma = require('gulp-karma');
var sequence = require('run-sequence');
var browserify = require('gulp-browserify');
var watch = require('gulp-watch');
var shell = require('gulp-shell');
var jsify = require('./vendor/gulp-jsify');
var plumber = require('gulp-plumber');
var batch = require('gulp-batch');
var KarmaServer = require('karma').Server;
var builds = {
core: 'build/mathbox-core.js',
bundle: 'build/mathbox-bundle.js',
css: 'build/mathbox.css',
};
var products = [
builds.core,
builds.bundle
];
var vendor = [
'vendor/three.js',
'vendor/threestrap/build/threestrap.js',
'vendor/threestrap/vendor/renderers/VRRenderer.js',
'vendor/threestrap/vendor/controls/VRControls.js',
'vendor/threestrap/vendor/controls/OrbitControls.js',
'vendor/threestrap/vendor/controls/DeviceOrientationControls.js',
'vendor/threestrap/vendor/controls/TrackBallControls.js',
];
var css = [
'vendor/shadergraph/build/*.css',
'src/**/*.css',
];
var core = [
'.tmp/index.js',
];
var glsls = [
'src/shaders/glsl/**/*.glsl'
];
var coffees = [
'src/**/*.coffee'
];
var source = coffees.concat(glsls).concat(vendor).concat(css);
var bundle = vendor.concat(core);
var test = bundle.concat([
'test/**/*.spec.coffee',
]).filter(function (path) { return !path.match(/fix\.js/); });
gulp.task('glsl', function () {
return gulp.src(glsls)
.pipe(jsify("shaders.js", "module.exports"))
.pipe(gulp.dest('./build/'))
});
gulp.task('browserify', function () {
return gulp.src('src/index.coffee', { read: false })
.pipe(browserify({
debug: false,
//detectGlobals: false,
bare: true,
transform: ['coffeeify'],
extensions: ['.coffee'],
}))
.pipe(rename({
extname: ".js",
}))
.pipe(gulp.dest('.tmp/'))
});
gulp.task('css', function () {
return gulp.src(css)
.pipe(concat(builds.css))
.pipe(gulp.dest(''));
});
gulp.task('core', function () {
return gulp.src(core)
.pipe(concat(builds.core))
.pipe(gulp.dest(''));
});
gulp.task('bundle', function () {
return gulp.src(bundle)
.pipe(concat(builds.bundle))
.pipe(gulp.dest(''));
});
gulp.task('uglify-js', function () {
return gulp.src(products)
.pipe(uglify())
.pipe(rename({
extname: ".min.js",
}))
.pipe(gulp.dest('build'));
});
gulp.task('karma', function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
files: test,
singleRun: true,
}, done).start();
});
gulp.task('watch-karma', function() {
return gulp.src(test)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch',
}));
});
gulp.task('watch-build-watch', function () {
watch(source, function () {
return gulp.start('build');
});
});
// Main tasks
gulp.task('build', function (callback) {
sequence('glsl', 'browserify', ['core', 'bundle', 'css'], callback);
})
gulp.task('default', function (callback) {
sequence('build', 'uglify-js', callback);
});
gulp.task('docs', shell.task([
'coffee src/docs/generate.coffee > docs/primitives.md',
]));
gulp.task('test', function (callback) {
sequence('build', 'karma', callback);
});
gulp.task('watch-build', function (callback) {
sequence('build', 'watch-build-watch', callback);
})
gulp.task('watch', function (callback) {
sequence('watch-build', 'watch-karma', callback);
});