aboutsummaryrefslogtreecommitdiff
path: root/gulpfile.js
blob: 0bb7f86f35d9a5f36f977e28fc6e99c6b2e724a6 (plain)
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
'use strict';

var gulp = require('gulp');
var browserSync = require('browser-sync');
var uglify = require('gulp-uglify');
var zip = require('gulp-vinyl-zip').zip;
var size = require('gulp-size');
var runSequence = require('run-sequence');
let rollup = require('rollup-stream');

var source = require('vinyl-source-stream');
var libs = ['./node_modules/kontra/kontra.min.js', './node_modules/tinymusic/dist/TinyMusic.min.js'];
var devLibs = ['./node_modules/jsfxr/jsfxr.js'];
var libFolder = 'libs/';
var outputTemp = 'temp/';

gulp.task('serve', ['copylibs', 'copylibsDev', 'uglyfy_copy'], function () {
    browserSync.init({
        server: {
            baseDir: "./"
        }
    });

    gulp.watch("src/js/**/*.js", { cwd: './' }, ['uglyfy_copy', 'reload'])
    gulp.watch("./**/*.html", { cwd: './' }).on('change', browserSync.reload);

    browserSync.watch()

});

gulp.task('reload', function () {
    browserSync.reload();
});


gulp.task('uglyfy_copy', function () {
    return rollup({
        "format": "iife",
        input: './src/js/main.js'
    })
    .pipe(source('main.js'))
        .pipe(gulp.dest('public/js'));

});


gulp.task('copylibs', function () {
    return gulp
        .src(libs)
        .pipe(gulp.dest(libFolder))
});

gulp.task('copylibsDev', function () {
    return gulp
        .src(devLibs)
        .pipe(uglify())
        .pipe(gulp.dest(libFolder))
});

gulp.task('zipFiles', function () {
    return gulp.src('temp/**/*.*')
        .pipe(zip('archive.zip'))
        .pipe(gulp.dest('dist'))
        .pipe(size({
            title: '### Final Archive Size => '
        }))

});

gulp.task('prepare_dist_folder', function () {
    return gulp
        .src(['libs/*', 'public/**/*.*', 'index.html'], { base: './' })
        .pipe(gulp.dest(outputTemp))
});

gulp.task('release', function () {
    runSequence('copylibs', 'copylibsDev', 'uglyfy_copy', 'prepare_dist_folder', 'zipFiles');
});