forked from yqlu/sliceformstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
138 lines (118 loc) · 4.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
var gulp = require('gulp');
var browserSync = require('browser-sync');
var rename = require("gulp-rename");
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var usemin = require('gulp-usemin');
var gulpSequence = require('gulp-sequence');
var imagemin = require('gulp-imagemin');
var gzip = require('gulp-gzip');
var pngquant = require('imagemin-pngquant');
var minifyHtml = require('gulp-minify-html');
var minifyCss = require('gulp-minify-css');
var harp = require('harp');
var spritesmith = require('gulp.spritesmith');
var merge = require('merge-stream');
var gm = require('gm');
var promise = require('es6-promise').polyfill();
var _ = require('lodash');
var less = require('gulp-less');
var sass = require('gulp-sass');
var path = require('path');
var flatten = require('gulp-flatten');
var projectPath = '.';
var projectDest = 'www';
var exec = require('child_process').exec;
gulp.task('serve', function() {
harp.server(projectPath, {
ip: '0.0.0.0',
port: 9000
}, function() {
return this.projectPath;
});
});
gulp.task('browser-sync', function() {
browserSync({
proxy: "localhost:9000",
open: false
});
});
gulp.task('jshint', function() {
return gulp.src(['public/_js/**/*.js', '!public/_js/2D.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('harp-compile', function (done) {
exec('mv ./public/bower ./public/_bower', function() {
harp.compile(projectPath, projectDest, function() {
exec('mv ./public/_bower ./public/bower', function() {
done();
});
});
});
});
gulp.task('compile', ['harp-compile'], function () {
return gulp.src('./public/slfm_files/**/*.slfm', {base: './public/slfm_files'})
.pipe(gulp.dest(projectDest + '/slfm_files'));
});
gulp.task('css-preprocess', ['compile'], function (done) {
return gulp.src('./public/css/*.less')
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(gulp.dest('./public/css/'));
});
gulp.task('scripts', ['compile', 'css-preprocess'], function() {
console.log(projectDest);
return gulp.src(projectDest + '/*.html')
.pipe(usemin({
assetsDir: 'public',
js: [uglify, 'concat'],
css: ['concat']
}))
.pipe(gulp.dest(projectDest))
.pipe(gzip())
.pipe(gulp.dest(projectDest));
});
gulp.task('sprite', ['compile'], function() {
var spriteFolders = ['gallery-thumbs', 'starter', 'index-steps', 'docs', 'tutorial'];
var streams = _.map(spriteFolders, function(folder) {
var spriteData =
gulp.src(['./public/images/' + folder + '/*.jpg'])
.pipe(spritesmith({
imgName: folder + '-sprite.jpg',
cssName: folder + '-sprite.less',
engine: 'gmsmith',
imgOpts: {quality: 90, background: [255, 255, 255, 255]},
padding: 2,
cssTemplate: "sprites.less.handlebars"
}));
var imgStream = spriteData.img.pipe(gulp.dest('./public/images/sprites')); // output path for the sprite
var cssStream = spriteData.css.pipe(gulp.dest('./public/css')); // output path for the CSS
return merge(imgStream, cssStream);
});
_.each(_.tail(streams), function(s) {
_.first(streams).add(s);
});
return _.first(streams);
});
gulp.task('images-bower', ['compile'], function () {
return gulp.src('./public/bower/lightbox2/dist/images/*', {base: './public/bower'})
.pipe(flatten())
.pipe(gulp.dest('./public/images'));
});
gulp.task('images', ['images-bower', 'sprite'], function() {
var img = './public/images';
return gulp.src([img + '/*.*', img + '/sprites/**/*.*', img + '/index/*', img + '/gallery/**/*', img + '/gallery-diagrams/*', img + '/tutorial/*', img + '/docs/*.gif'], {base: './public/images'})
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
optimizationLevel: 3,
use: [pngquant()]
}))
.pipe(gulp.dest(projectDest + '/images'));
});
gulp.task('post-build', ['scripts', 'images'], function(done) {
exec('rm ./public/css/*.css', done);
});
gulp.task('build', ['scripts', 'sprite', 'images', 'post-build']);