-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
158 lines (139 loc) · 4.53 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* Project Name: ha-cunkute
* Description: Home Assistant with WebSocket by Keite Tran
* Creator: Tran Ngoc Anh - VietVbb Team (Keite)
* Email: [email protected]
* HomePage: https://facebook.com/mr.ngocanhtran
*/
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const runSequence = require('run-sequence');
const gulpIf = require('gulp-if');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const cssnano = require('gulp-cssnano');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const fileinclude = require('gulp-file-include');
const del = require('del');
const useref = require('gulp-useref');
const htmlmin = require('gulp-htmlmin');
const headerComment = require('gulp-header-comment');
// Copy required plugin file
gulp.task('copy-required-file', ['images', 'javascript'], function () {
// Copying CSS to /dist
gulp.src([
'node_modules/bootstrap/dist/css/bootstrap.min.css',
'node_modules/weathericons/css/weather-icons.min.css',
'node_modules/toastr/build/toastr.min.css',
'node_modules/sweetalert2/dist/sweetalert2.min.css',
]).pipe(concat('./plugin.min.css'))
.pipe(gulp.dest("dist/assets/css"));
// CSS map file
gulp.src([
'node_modules/bootstrap/dist/css/bootstrap.min.css.map',
]).pipe(gulp.dest("dist/assets/css/"));
// Copying Fonts to /dist
gulp.src([
'node_modules/weathericons/font/*'
]).pipe(gulp.dest("dist/assets/font"));
// Copying javascript to /dist
gulp.src([
'node_modules/jquery/dist/jquery.min.js',
'node_modules/popper.js/dist/umd/popper.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/feather-icons/dist/feather.min.js',
'node_modules/toastr/build/toastr.min.js',
'node_modules/chart.js/dist/Chart.min.js',
'node_modules/js-cookie/src/js.cookie.js',
'node_modules/chartjs-plugin-annotation/chartjs-plugin-annotation.min.js',
'node_modules/sweetalert2/dist/sweetalert2.min.js',
'node_modules/crypto-js/crypto-js.js',
'src/plugins/pulltorefresh.js',
'src/plugins/jquery.sparkline.min.js'
]).pipe(uglify()).pipe(concat('./plugin.min.js'))
.pipe(gulp.dest("dist/assets/js"));
});
// Compile SCSS into CSS
gulp.task('scss', function () {
return gulp.src(['src/scss/**/*.scss'])
.pipe(sass())
.pipe(postcss([
autoprefixer({
browsers: ['last 5 version']
})
])).pipe(cssnano())
.pipe(concat('./all.min.css'))
.pipe(gulp.dest('dist/assets/css'))
.pipe(browserSync.stream());
});
// Copying javascript to /dist
gulp.task('javascript', function () {
return gulp.src('src/js/**/*')
.pipe(uglify())
.pipe(concat('./core.min.js'))
.pipe(gulp.dest("dist/assets/js"));
});
// Copying images to /dist
gulp.task('images', function () {
// Images file
gulp.src(['src/img/*.png']).pipe(gulp.dest("./dist/assets/img/"));
// Icons file
gulp.src(['src/icons/*']).pipe(gulp.dest("./dist/"));
// SVG file
gulp.src(['src/svg/*']).pipe(gulp.dest("./dist/assets/svg/"));
});
// Compile Html file to /dist
gulp.task('html', function () {
return gulp.src(['src/*.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
})).pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
// Clean /dist folder
gulp.task('clean', function () {
return del.sync('dist');
});
// Static Server + watching scss/html/assets
gulp.task('default', function (callback) {
// Run task
runSequence('copy-required-file', 'scss', 'html', callback);
// Init server
browserSync.init({
server: ["./dist"],
files: ["./dist/assets/**/*"]
});
// watch file state change
gulp.watch(['src/scss/*'], ['scss']);
gulp.watch(['src/img/**/*'], ['images']);
gulp.watch(['src/js/**/*'], ['javascript']);
gulp.watch(['src/**/*.html'], ['html']);
// Push event reload to browser
gulp.on('change', browserSync.reload);
});
// Build project
gulp.task('build', function () {
runSequence('clean', ['copy-required-file', 'scss', 'html'], 'comments');
});
// Add header file comment
gulp.task('comments', function () {
var headerCommentTemp = `
Project Name: <%= pkg.name %>
Description: <%= pkg.description %>
Creator: <%= pkg.author %> - VietVbb Team (Keite)
Email: <%= pkg.email %>
HomePage: <%= pkg.homepage %>
`;
gulp.src('dist/**/*')
.pipe(gulpIf('*.js', headerComment(headerCommentTemp)))
.pipe(gulpIf('*.css', headerComment(headerCommentTemp)))
.pipe(gulpIf('*.html', headerComment(headerCommentTemp)))
.pipe(gulp.dest('dist/'));
});