summaryrefslogtreecommitdiff
path: root/gulpfile.js
blob: 4b9664a64f0d0d33c5e1ce85f0d03201a010a913 (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
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
/* eslint-env node */
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var csso = require('gulp-csso');
var size = require('gulp-size');
var uglify = require('gulp-uglify');
var webpack = require('webpack-stream');
var concat = require('gulp-concat');
var header = require('gulp-header');
var rename = require('gulp-rename');
var exec = require('child_process').exec;

gulp.task('style', function () {
    return gulp.src('./style/touch-imagelightbox.scss')
        .pipe(sass({
            outputStyle: 'compressed'
        }).on('error', sass.logError))
        .pipe(gulp.dest('./demo'));
});

var webpackOptions = {
    entry: {
        ActivityIndicator: './src/Plugins/ActivityIndicator.js',
        Overlay: './src/Plugins/Overlay.js',
        CloseButton: './src/Plugins/CloseButton.js',
        Captions: './src/Plugins/Captions.js',
        Navigation: './src/Plugins/Navigation.js',
        Core: './src/LightBox.js'
    },
    output: {
        filename: 'LightBox.[name].js',
        library: ['LightBox','[name]'],
        libraryTarget: "var"
    },
    module: {
        loaders: [
            {
                loader: 'babel',
                query: {
                    presets: ['es2015'],
                    plugins: ['add-module-exports']
                }
            }
        ]
    }
};

gulp.task('pack', function() {
    return gulp.src('')
        .pipe(webpack(webpackOptions))
        .pipe(gulp.dest('./demo'));
});

gulp.task('watch', function () {
    webpackOptions.watch = true;
    gulp.src('')
        .pipe(webpack(webpackOptions))
        .pipe(gulp.dest('./demo'));
});

gulp.task('lint', function() {
    return gulp.src('./src/**/*.js')
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

gulp.task('uglify', ['pack', 'clean'], function() {
    return gulp.src('./demo/LightBox.*.js')
        .pipe(uglify())
        .pipe(rename({suffix: ".min"}))
        .pipe(gulp.dest('dist'));
});

var bannerPlugins = ['/**',
  ' * Image LightBox Plugins - <%= pkg.description %>',
  ' * @version v<%= pkg.version %>',
  ' * @link <%= pkg.homepage %>',
  ' * @license <%= pkg.license %>',
  ' * @author <%= pkg.authors%>',
  ' */',
  ''].join('\n');

gulp.task('buildjs', ['uglify'], function() {
    return gulp.src(['./dist/LightBox.*.js', '!./dist/LightBox.Core.min.js', '!./dist/LightBox.Plugins.js'])
        .pipe(concat('LightBox.Plugins.js'))
        .pipe(rename({suffix: ".min"}))
        .pipe(header(bannerPlugins, { pkg : pkg }))
        .pipe(gulp.dest('./dist'));
});

var banner = ['/**',
  ' * Image LightBox - <%= pkg.description %>',
  ' * @version v<%= pkg.version %>',
  ' * @link <%= pkg.homepage %>',
  ' * @license <%= pkg.license %>',
  ' * @author <%= pkg.authors%>',
  ' */',
  ''].join('\n');

var pkg = require('./bower.json');
gulp.task('makecore', ['buildjs'], function() {
    gulp.src(['./dist/LightBox.Core.min.js'])
        .pipe(header(banner, { pkg : pkg }))
        .pipe(gulp.dest('./dist'));
});

gulp.task('csso', ['style'], function() {
    return gulp.src('./demo/touch-imagelightbox.css')
        .pipe(csso())
        .pipe(rename({suffix: ".min"}))
        .pipe(gulp.dest('./dist'));
});

gulp.task('clean', function() {
    exec('rm -r dist');
});

gulp.task('build', ['makecore','csso']);

gulp.task('default', ['pack']);