This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
gulpfile.js
180 lines (154 loc) · 4.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var gulp = require('gulp');
var fs = require('fs');
var $ = require('gulp-load-plugins')();
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var path = require('path');
var pkg = require('./package.json');
//var preprocessOpts = {context: { NODE_ENV: process.env.NODE_ENV || 'development', DEBUG: true}};
var dist = 'dist';
var src = 'src';
var glob = {
scripts: [src+'/vg.js', src+'/**/*.js'],
hexScripts: [src+'/vg.js', src+'/**/*.js', '!src/grids/Square.js', '!src/grids/SquareGrid.js'],
sqrScripts: [src+'/vg.js', src+'/**/*.js', '!src/grids/Hex.js', '!src/grids/HexGrid.js'],
editorScripts: ['editor/ui/**/*.js', 'editor/modules/**/*.js'],
styles: src+'/**/*.styl'
};
/*----------------------------------------------------------------------
MACRO
*/
gulp.task('default', ['clean'], function() {
runSequence(
['scripts']
);
});
gulp.task('clean', del.bind(null, [dist]));
gulp.task('dev', ['clean'], function() {
runSequence(
['scripts'],
['watch']
);
});
gulp.task('dev-ed', ['clean'], function() {
runSequence(
['scripts', 'scripts-editor'],
['serve-editor']
);
});
/*----------------------------------------------------------------------
SCRIPTS
*/
gulp.task('scripts', ['all', 'hex', 'sqr']);
gulp.task('all', function() {
return gulp.src(glob.scripts)
.pipe($.plumber({errorHandler: handleErrors}))
.pipe($.eslint({ fix: true }))
.pipe($.eslint.formatEach())
.pipe($.eslint.failOnError())
.pipe($.sourcemaps.init())
.pipe($.concat('von-grid.min.js'))
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dist))
.pipe(browserSync.stream());
});
gulp.task('hex', function() {
return gulp.src(glob.hexScripts)
.pipe($.plumber({errorHandler: handleErrors}))
.pipe($.sourcemaps.init())
.pipe($.concat('hex-grid.min.js'))
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dist))
.pipe(browserSync.stream());
});
gulp.task('sqr', function() {
return gulp.src(glob.sqrScripts)
.pipe($.plumber({errorHandler: handleErrors}))
.pipe($.sourcemaps.init())
.pipe($.concat('sqr-grid.min.js'))
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dist))
.pipe(browserSync.stream());
});
gulp.task('scripts-editor', function() {
return gulp.src(glob.editorScripts)
.pipe($.plumber({errorHandler: handleErrors}))
.pipe($.sortAmd())
//.pipe($.eslint({ fix: true }))
//.pipe($.eslint.formatEach())
//.pipe($.eslint.failOnError())
.pipe($.addSrc.prepend('./editor/lib/define.min.js'))
.pipe($.sourcemaps.init())
.pipe($.concat('app.js'))
//.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('editor'))
.pipe(browserSync.stream());
});
/*----------------------------------------------------------------------
CSS
*/
/*
gulp.task('styles', function() {
return gulp.src(glob.styles)
.pipe($.plumber({errorHandler: handleErrors}))
.pipe($.sourcemaps.init())
.pipe($.stylus({
compress: true
}))
.pipe($.autoprefixer())
.pipe($.concat('styles.css'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(dist))
});
*/
/*----------------------------------------------------------------------
SERVER
*/
// Defines the list of resources to watch for changes.
function watch() {
gulp.watch(glob.scripts, ['scripts', reload]);
//gulp.watch(glob.styles, ['styles', reload]);
}
function serve(dir) {
browserSync.init({
notify: false,
server: {
baseDir: ['./', './'+dir],
index: './'+dir+'/index.html'
}
});
browserSync.watch(dist+'/**/*.*').on('change', reload);
gulp.watch(glob.scripts, ['scripts']);
}
gulp.task('watch', function() {
watch();
});
gulp.task('serve-editor', function() {
gulp.watch(glob.editorScripts, ['scripts-editor', reload]);
serve('editor');
});
gulp.task('serve-examples', function() {
//gulp.watch(glob.editorScripts, ['scripts-editor', reload]);
browserSync.watch('examples/**/*.*').on('change', reload);
serve('examples');
});
/*----------------------------------------------------------------------
HELPERS
*/
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
// Send error to notification center with gulp-notify
$.notify.onError({
title: 'Build error',
message: '<%= error%>',
showStack: true
}).apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
}