This repository has been archived by the owner on Dec 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
107 lines (95 loc) · 3.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('autoprefixer');
const plumber = require("gulp-plumber");
const cleanCSS = require('gulp-clean-css');
const clean = require('gulp-clean');
const uglify = require('gulp-uglify');
const gulpSequence = require('gulp-sequence');
const path = require('path');
const rev = require('gulp-rev');
const revFormat = require('gulp-rev-format');
const revdel = require('gulp-rev-delete-original');
const postcss = require('gulp-postcss');
const image = require('gulp-image');
const override=require('gulp-rev-css-url');
const notify = require("gulp-notify");
const config = {
entry: path.join(__dirname, '/resources/assets/'),
output: path.join(__dirname, '/public/assets/'),
sassoptions: {
errLogToConsole: true,
outputStyle: 'expanded'
}
};
gulp.task('scss', function(){
return gulp.src(config.entry + "/scss/**/*.scss")
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
.pipe(sass(config.sassoptions).on('error', sass.logError))
.pipe(postcss([autoprefixer({browsers: ['last 1 version']})]))
.pipe(gulp.dest(config.output + "/css"));
});
gulp.task('js', function(){
return gulp.src(config.entry + "/js/**/*.js")
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
.pipe(gulp.dest(config.output + "/js"));
});
gulp.task('image', function () {
gulp.src(config.entry + "/images/**/*.*")
//.pipe(image())
.pipe(gulp.dest(config.output + "/images"));
});
gulp.task('fonts', function() {
return gulp.src(config.entry + "/fonts/**/*.*")
.pipe(gulp.dest(config.output + "/fonts"));
});
gulp.task('cleancss', function(){
return gulp.src(config.output + "\\css\\**\\*.css")
.pipe(cleanCSS())
.pipe(gulp.dest(config.output + "/css"));
});
gulp.task('cleanjs', function(){
return gulp.src(config.output + "/js/**/*.js")
.pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
.pipe(uglify())
.pipe(gulp.dest(config.output + "/js"));
});
gulp.task('clean', function() {
return gulp.src([
config.output + "/css/**/*.css",
config.output + "/js/**/*.js",
config.output + "/images/**/*.*",
config.output + "/fonts/**/*.*",
config.output + "/rev-manifest.json"
]).pipe(clean({force: true}));
});
gulp.task('revisioning', function() {
return gulp.src(config.output + "/**")
.pipe(gulp.dest(config.output))
.pipe(rev())
.pipe(revFormat({
suffix: '-' + randomString(5),
}))
.pipe(override())
.pipe(gulp.dest(config.output))
.pipe(revdel())
.pipe(rev.manifest())
.pipe(notify({
title : "Blog CI4",
subtitle: "Gulp task",
message : "All tasks have been compiled",
sound: false
}))
.pipe(gulp.dest(config.output));
});
gulp.task('build', gulpSequence('clean', ['scss', 'js', 'image', 'fonts'], ['cleancss', 'cleanjs'], 'revisioning'));
gulp.task('default', ['scss', 'js' ]);
function randomString(len, charSet) {
charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var randomString = '';
for (var i = 0; i < len; i++) {
var randomPoz = Math.floor(Math.random() * charSet.length);
randomString += charSet.substring(randomPoz,randomPoz+1);
}
return randomString;
}