-
Notifications
You must be signed in to change notification settings - Fork 405
/
gulpfile.js
109 lines (96 loc) · 2.36 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
var concat = require('gulp-concat')
var connect = require('gulp-connect')
var gulp = require('gulp')
var gutil = require('gulp-util')
var inject = require('gulp-inject')
var plumber = require('gulp-plumber')
var rimraf = require('rimraf')
var sass = require('gulp-sass')
var sourcemaps = require('gulp-sourcemaps')
var svgmin = require('gulp-svgmin')
var svgstore = require('gulp-svgstore')
var uglify = require('gulp-uglify')
//
// Variables
//
var srcDir = './lib';
var distDir = './build';
var isDebug = !gutil.env.prod;
//
// Default
//
gulp.task('default', ['build'], function() {
gulp.start('watch');
});
//
// Clean
//
gulp.task('clean', function(cb) {
rimraf(distDir, cb);
});
//
// Build
//
gulp.task('build', ['clean'], function() {
gulp.start('scripts', 'styles');
});
//
// Watch
//
gulp.task('watch', ['server'], function() {
gulp.watch(srcDir + '/js/**/*.js', ['scripts']);
gulp.watch(srcDir + '/css/**/*.scss', ['styles']);
});
//
// Server
//
gulp.task('server', function() {
connect.server({
root: './demo',
port: 2222,
livereload: false
});
});
//
// Javascript
//
gulp.task('scripts', function () {
var svgs = gulp.src(srcDir + '/icons/*.svg')
.pipe(svgmin())
.pipe(svgstore({inlineSvg: true}))
// .pipe(gulp.dest(distDir));
function fileContents (filePath, file) {
return file.contents.toString();
}
var files = [
srcDir + '/js/core/bootstrap.js',
srcDir + '/js/core/darkroom.js',
srcDir + '/js/core/*.js',
// srcDir + '/js/plugins/*.js',
srcDir + '/js/plugins/darkroom.history.js',
srcDir + '/js/plugins/darkroom.rotate.js',
srcDir + '/js/plugins/darkroom.crop.js',
srcDir + '/js/plugins/darkroom.save.js',
];
gulp.src(files)
.pipe(plumber())
.pipe(isDebug ? sourcemaps.init() : gutil.noop())
.pipe(concat('darkroom.js', {newLine: ';'}))
.pipe(inject(svgs, { transform: fileContents }))
.pipe(isDebug ? gutil.noop() : uglify({mangle: false}))
.pipe(isDebug ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest(distDir))
})
//
// Stylesheet
//
gulp.task('styles', function () {
gulp.src(srcDir + '/css/darkroom.scss')
.pipe(plumber())
.pipe(isDebug ? sourcemaps.init() : gutil.noop())
.pipe(sass({
outputStyle: isDebug ? 'nested' : 'compressed'
}))
.pipe(isDebug ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest(distDir))
})