forked from glenreesor/m3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
213 lines (187 loc) · 8.39 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* eslint no-var: 0 */
//-----------------------------------------------------------------------------
// Gulp plugins
//-----------------------------------------------------------------------------
var browserify = require('browserify');
var buffer = require('gulp-buffer');
var eslint = require('gulp-eslint');
var footer = require('gulp-footer');
var gulp = require('gulp');
var gutil = require('gulp-util');
var shell = require('gulp-shell');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
//-----------------------------------------------------------------------------
// Output folders
//-----------------------------------------------------------------------------
var debugDir = 'out/debug';
var productionDir = 'out/production';
//-----------------------------------------------------------------------------
// Fast things that don't need to be in parallel, and which will finish before
// everything else.
//
// If they are separate tasks, then output is polluted with all their start
// and stop messages.
//-----------------------------------------------------------------------------
gulp.task('fast', function() {
var result;
//--------------------------------------------------------------------------
// Deprecated appcache
//--------------------------------------------------------------------------
result = gulp.src('app/m3.appcache.template')
.pipe(footer('#Timestamp to force browser reload: ${timestamp}\n',
{timestamp: Date.now()}))
.pipe(gulp.dest(debugDir))
.pipe(gulp.dest(productionDir));
//--------------------------------------------------------------------------
// CSS
//--------------------------------------------------------------------------
result = gulp.src('app/src/*.css')
.pipe(gulp.dest(debugDir))
.pipe(gulp.dest(productionDir));
//--------------------------------------------------------------------------
// HTML
//--------------------------------------------------------------------------
result = gulp.src('app/src/*.html')
.pipe(gulp.dest(debugDir))
.pipe(gulp.dest(productionDir));
//--------------------------------------------------------------------------
// Images - Actions
//--------------------------------------------------------------------------
result = gulp.src('app/images/*')
.pipe(gulp.dest(debugDir + '/images'))
.pipe(gulp.dest(productionDir + '/images'));
//--------------------------------------------------------------------------
// Images - Icons
//--------------------------------------------------------------------------
result = gulp.src('app/images/icons/*')
.pipe(gulp.dest(debugDir + '/images/icons'))
.pipe(gulp.dest(productionDir + '/images/icons'));
//--------------------------------------------------------------------------
// Libs
//--------------------------------------------------------------------------
result = gulp.src('app/lib/*.js')
.pipe(gulp.dest(debugDir))
.pipe(gulp.dest(productionDir));
//--------------------------------------------------------------------------
// Webmanifest
//--------------------------------------------------------------------------
result = gulp.src('app/manifest.webmanifest')
.pipe(gulp.dest(debugDir))
.pipe(gulp.dest(productionDir));
//--------------------------------------------------------------------------
// php
//--------------------------------------------------------------------------
result = gulp.src('app/*.php')
.pipe(gulp.dest(debugDir))
.pipe(gulp.dest(productionDir));
//--------------------------------------------------------------------------
// Prod Pre-Loaded Maps
//--------------------------------------------------------------------------
result = gulp.src('app/maps/prod/*.mm')
.pipe(gulp.dest(debugDir + '/maps/prod'))
.pipe(gulp.dest(productionDir + '/maps/prod'));
//--------------------------------------------------------------------------
// License file
//--------------------------------------------------------------------------
result = gulp.src('LICENSE.txt')
.pipe(gulp.dest(debugDir))
.pipe(gulp.dest(productionDir));
//--------------------------------------------------------------------------
// embeddingSample Pre-Loaded Maps
//--------------------------------------------------------------------------
result = gulp.src('app/maps/embeddingSample/*.mm')
.pipe(gulp.dest(debugDir + '/maps/embeddingSample'))
.pipe(gulp.dest(productionDir + '/maps/embeddingSample'));
});
//-----------------------------------------------------------------------------
// JS Lint
//-----------------------------------------------------------------------------
gulp.task('js-lint', function() {
return gulp.src(['app/src/*.js'])
.pipe(eslint())
.pipe(eslint.format());
});
//-----------------------------------------------------------------------------
// Javascript Processing
// - Although the debugger uses sourcemaps to show proper original source,
// Firefox runtime errors do not use sourcemaps
// - Therefore we need separate non-uglified output for debugging
//-----------------------------------------------------------------------------
gulp.task('js-debug', function() {
// Set up the browserify instance on a task basis
var b = browserify({
entries: ['./app/src/main.js', './app/src/runMain.js'],
debug: true
});
return b.transform('babelify').bundle()
.pipe(source('m3.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(debugDir));
});
gulp.task('js-production', function() {
// Set up the browserify instance on a task basis
var b = browserify({
entries: ['./app/src/main.js', './app/src/runMain.js'],
debug: true
});
return b.transform('babelify').bundle()
.pipe(source('m3.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(productionDir));
});
//-----------------------------------------------------------------------------
// Test Linting
//-----------------------------------------------------------------------------
gulp.task('test-lint', function() {
return gulp.src(['test/unit/*.js'])
.pipe(eslint())
.pipe(eslint.format());
});
//-----------------------------------------------------------------------------
// Test Running
//-----------------------------------------------------------------------------
var cmd;
cmd = "./node_modules/babel-tape-runner/bin/babel-tape-runner " +
"test/unit/*.js|faucet";
gulp.task('test-run', shell.task(
[cmd]
));
//-----------------------------------------------------------------------------
// Tasks that are intended to be used from command line
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// dev (all tasks except test linting and running)
// Setup with dependencies on other tasks, so it's always the last one to
// print 'Finished'.
//-----------------------------------------------------------------------------
gulp.task('build', ['fast', 'js-lint', 'js-debug', 'js-production']);
//-----------------------------------------------------------------------------
// test (Run tests first, so linting output doesn't get lost)
//-----------------------------------------------------------------------------
gulp.task('test', ['test-run'], function() {
gulp.start('test-lint');
});
//-----------------------------------------------------------------------------
// All (all tasks)
//-----------------------------------------------------------------------------
gulp.task('all', ['build', 'test']);
//-----------------------------------------------------------------------------
// Default - Just provide options
//-----------------------------------------------------------------------------
gulp.task('default', shell.task(
[
"echo 'Gulp Targets'",
"echo ' all (All tasks)'",
"echo ' build (All tasks except test linting and running)'",
"echo ' test (Test linting and running)'"
]
));