-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
312 lines (255 loc) · 11 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
FOR USING IN OTHER PROJECTS ====================================================
release/
FOR TESTING ====================================================================
build/
audiobus.min.js
audiobus.js
audiobus.js.map
polyfills.js
examples/example.html
examples/assets/
dist/
audiobus.min.js
audiobus.js
polyfills.js
Readme
license
*/
// Load in tasks and modifiers
var
config = require('./config'),
gulp = require('gulp'),
gulpif = require('gulp-if'),
ts = require('gulp-typescript'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
sourcemap = require('gulp-sourcemaps');
// Settings
var debug = true;
var sourcemaps = true;
// EXAMPLES ====================================================================
////////////////////////////////////////////////////////////////////////////////
// Verbose logging just to ensure that everything fits accordingly
////////////////////////////////////////////////////////////////////////////////
gulp.task('test', function(){
console.log("Testing Configuration...");
console.log(config);
// check paths exist...
});
////////////////////////////////////////////////////////////////////////////////
// Copy example midi files from the source folder to the destination midi folder
////////////////////////////////////////////////////////////////////////////////
gulp.task('examples-midi', function(){
return gulp.src( config.source.midi )
.pipe(gulp.dest( config.destination.midi ));
})
////////////////////////////////////////////////////////////////////////////////
// Compile our styles.
// There are two sets of styles, one set is always loaded in
// the other set are only loaded per project
////////////////////////////////////////////////////////////////////////////////
gulp.task('examples-styles', function () {
var postcss = require('gulp-postcss');
var less = require('gulp-less');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var processors = [
autoprefixer( {browsers: ['last 1 version']} ),
cssnano(),
];
return gulp.src( config.source.style )
.pipe( gulpif( sourcemaps, sourcemap.init() ) )
.pipe( less().on('error', function(err){
// catch errors without breaking watch streams
console.log(err);
this.emit('end');
}) )
.pipe( postcss(processors) )
.pipe( gulpif( sourcemaps, sourcemap.write( config.destination.style ) ) )
.pipe( gulp.dest( config.destination.style ) );
});
////////////////////////////////////////////////////////////////////////////////
// This compiles down all code in the typescript/examples folder
////////////////////////////////////////////////////////////////////////////////
gulp.task('examples-code', function () {
var tsResult = gulp.src([
// definitions
'./typings/audiobus.d.ts',
"./typings/index.d.ts",
// example source files
'./src/typescript/examples/**/**.ts'
])
.pipe( gulpif( sourcemaps, sourcemap.init() )) // This means sourcemaps will be generated
.pipe( ts() );
return tsResult.js
//.pipe(concat('output.js')) // You can use other plugins that also support gulp-sourcemaps
// Now the sourcemaps are added to the .js file
.pipe( gulpif( sourcemaps,sourcemap.write() ))
.pipe( gulp.dest( config.destination.scripts ));
});
////////////////////////////////////////////////////////////////////////////////
// Straight copy of markup html to
////////////////////////////////////////////////////////////////////////////////
gulp.task('examples-markup', function(){
return gulp.src( config.source.markup )
.pipe(gulp.dest( config.destination.examples ));
});
////////////////////////////////////////////////////////////////////////////////
// Do all of the example files together
////////////////////////////////////////////////////////////////////////////////
gulp.task('examples', ['examples-code','examples-markup', 'examples-midi','examples-styles'], function(cb){
cb();
});
// static files simple copy to destination
// .htaccess
// https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess
gulp.task('static', function(){
return gulp.src( config.source.static )
.pipe(gulp.dest( config.destination.build ));
});
// TYPESCRIPT ========================
////////////////////////////////////////////////////////////////////////////////
// TASK : LINT
// Ensure that the code is good and proper
////////////////////////////////////////////////////////////////////////////////
gulp.task('lint', function () {
var tslint = require('gulp-tslint');
return gulp.src( config.source.typescript )
.pipe( tslint({
formatter: "verbose"
//formatter: "prose"
}) )
.pipe( tslint.report( {
emitError: false,
summarizeFailureOutput: true,
reportLimit: 20
} ));
});
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
gulp.task('polyfills', function(){
// Now add polyfilla
return gulp.src( config.source.polyfills )
.pipe( uglify() )
.pipe( concat( config.names.polyfills + '.js' ) )
.pipe( gulp.dest( config.destination.build ) )
.pipe( gulp.dest( config.destination.release ) );
//.pipe( gulp.dest(destination.distribute) );
});
////////////////////////////////////////////////////////////////////////////////
// save typed definitions locally...
////////////////////////////////////////////////////////////////////////////////
gulp.task('compile-definition', function () {
var tsProject = ts.createProject( 'tsconfig.json', {
declaration : true,
declarationFiles : true
});
var tsResult = gulp.src( config.source.typescript ).pipe( tsProject() );
return tsResult.dts.pipe( gulp.dest( config.typings ) );
});
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
gulp.task('compile-file', function () {
// if this lives outside of this closure then you can incrementally compile :)
var tsProject = ts.createProject( 'tsconfig.json', {
outFile: config.names.library + '.js',
//declarationFiles : true,
allowJs : true,
removeComments : !debug
});
var tsResult = tsProject.src(['./typings/**/**.ts','./src/typescript/audiobus/**/**.ts'])
.pipe( gulpif( sourcemaps,sourcemap.init() ) ) // This means sourcemaps will be generated
.pipe( tsProject() );
// save .d.ts file definitions
//tsResult.dts.pipe(gulp.dest(config.typings ));
// save big file
return tsResult.js
//.pipe( concat("audiobus.js")) // You can use other plugins that also support gulp-sourcemaps
.pipe( gulpif( sourcemaps,sourcemap.write('.')) ) // Now the sourcemaps are added to the .js file
.pipe( gulp.dest(config.destination.build));
//.pipe( gulp.dest(destination.distribute));
});
// RELEASE =====================================================================
gulp.task('compile-release', function () {
var tsProject = ts.createProject( 'tsconfig.json', {
outFile : config.names.library + '.js',
declarationFiles : true,
allowJs : true,
removeComments : true
});
var tsResult = tsProject.src( config.source.typescript ).pipe( ts(tsProject) );
// save big file
return tsResult.js.pipe( gulp.dest( config.destination.release ));
});
// Compresss all of the javascript files and uglify
gulp.task('minify', ['compile-release'], function(){
return gulp.src( config.destination.release+'/'+config.names.library + '.js')
.pipe( uglify() )
.pipe( rename(config.names.library + 'min.js') )
.pipe( gulp.dest( config.destination.release ) );
});
// This creates a folder of individual libs - not one long javascript
gulp.task('compile-folder', function () {
var tsProject = ts.createProject( 'tsconfig.json', {} );
var tsResult = tsProject.src( config.source.typescript )
.pipe( gulpif( sourcemaps,sourcemap.init() ) ) // This means sourcemaps will be generated
.pipe( ts(tsProject) );
return tsResult.js
//.pipe( concat("audiobus.js")) // You can use other plugins that also support gulp-sourcemaps
.pipe( gulpif( sourcemaps,sourcemap.write( config.destination.build )) ) // Now the sourcemaps are added to the .js file
.pipe( gulp.dest( config.destination.build ) );
});
////////////////////////////////////////////////////////////////////////////////
// TASK : Serve
// Create a local server and open it in our browser
////////////////////////////////////////////////////////////////////////////////
gulp.task('serve', ['lint','compile-file'], function () {
gulp.watch([config.source.typescript], ['compile-file']);
gulp.watch([config.source.style], ['examples-styles']);
gulp.watch(['src/typescript/examples/**/**.ts'], ['examples-code']);
var browserSync = require('browser-sync').create();
browserSync.init({
server: {
// Serve up our build folder
baseDir: destination.build,
directory: true,
index: "test.html",
logPrefix: "AudioBus::",
ghostMode: {
clicks: false,
forms: false,
scroll: false
},
//files: [ '**/*.js', '**/*.css', '**/*.html'],
files: [ '**/*.js', '**/*.css','**/*.html'],
injectChanges: true,
logFileChanges: false,
//logLevel: 'silent',
notify: true,
reloadDelay: 0,
browser: "google chrome"
}
});
});
// FOLDER_RELEASE ==============================================================
// 1. Compiles AudioBus to individual files
// 2. Copies minified audiobus.js
// 3. Copies License and Readme
// 4. Copies examples folder
var callback = function (cb) { cb(); };
////////////////////////////////////////////////////////////////////////////////
// This creates all of our files for use during development :)
////////////////////////////////////////////////////////////////////////////////
gulp.task('build', ['lint','polyfills','compile-folder'], callback );
////////////////////////////////////////////////////////////////////////////////
// This creates all of our files for use in production :)
////////////////////////////////////////////////////////////////////////////////
gulp.task('release', ['lint','polyfills','minify'], callback );
////////////////////////////////////////////////////////////////////////////////
// DEFAULT TASK : Do the following sequence of events
////////////////////////////////////////////////////////////////////////////////
gulp.task('default', ['build','examples','serve'], callback );