forked from sarcadass/granim.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (72 loc) · 2.47 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
'use strict';
var gulp = require('gulp'),
browserify = require('browserify'),
uglify = require('gulp-uglify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
rename = require('gulp-rename'),
gulpif = require('gulp-if'),
sass = require('gulp-sass'),
pug = require('gulp-pug'),
copy = require('gulp-copy'),
sourcemaps = require('gulp-sourcemaps'),
header = require('gulp-header'),
isSourcemaps = require('minimist')(process.argv.slice(2)).sourcemaps,
appVersion = require('./package.json').version;
// LIB
gulp.task('build', function() {
return browserify({ entries: 'standalone.js', debug: isSourcemaps }).bundle()
.pipe(source('./granim.js'))
.pipe(buffer())
.pipe(gulpif(!isSourcemaps, header('/*! Granim v' + appVersion + ' - https://sarcadass.github.io/granim.js */\n')))
.pipe(gulp.dest('./dist/'));
});
gulp.task('buildMin', ['build'], function() {
return gulp.src('./dist/granim.js')
.pipe(rename({ suffix: '.min' }))
.pipe(uglify({ preserveComments: 'license' }))
.pipe(gulp.dest('./dist/'));
});
gulp.task('docDist', ['buildMin'], function() {
return gulp.src('./dist/granim.min.js')
.pipe(copy('./docs/assets/js/vendor/', { prefix: 1 }));
});
// DOC
gulp.task('buildDoc:html', function() {
return gulp.src('./docs/assets/pug/*.pug')
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('./docs/'));
});
gulp.task('buildDoc:js', function() {
return browserify({ entries: './docs/assets/js/app/index.js', debug: isSourcemaps }).bundle()
.pipe(source('./index.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(rename('script.js'))
.pipe(gulp.dest('./docs/assets/js/'));
});
gulp.task('buildDoc:css', function() {
return gulp.src('./docs/assets/css/scss/index.scss')
.pipe(gulpif(isSourcemaps, sourcemaps.init({ loadMaps: true })))
.pipe(sass({ outputStyle: 'compressed' })
.on('error', sass.logError)
)
.pipe(gulpif(isSourcemaps, sourcemaps.write({ includeContent: true })))
.pipe(rename('style.css'))
.pipe(gulp.dest('./docs/assets/css/'))
});
// TASKS
// lib
gulp.task('default', ['build', 'buildMin', 'docDist']);
gulp.task('watch', ['default'], function() {
gulp.watch('./lib/**/*.js', ['default'])
});
// doc
gulp.task('buildDoc', ['buildDoc:html', 'buildDoc:js', 'buildDoc:css']);
gulp.task('watchDoc', ['buildDoc'], function() {
gulp.watch('./docs/assets/pug/**/*', ['buildDoc:html']);
gulp.watch('./docs/assets/js/app/**/*', ['buildDoc:js']);
gulp.watch('./docs/assets/css/scss/**/*', ['buildDoc:css']);
});