-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
186 lines (155 loc) · 6.98 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
'use strict'
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var del = require('del');
var replace = require('gulp-replace');
var injectPartials = require('gulp-inject-partials');
var inject = require('gulp-inject');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var merge = require('merge-stream');
gulp.task('sass', function () {
return gulp.src('./scss/**/style.scss')
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./css'))
.pipe(browserSync.stream());
});
// Static Server + watching scss/html files
gulp.task('serve', gulp.series('sass', function() {
browserSync.init({
port: 3001,
server: "./",
ghostMode: false,
notify: false
});
gulp.watch('scss/**/*.scss', gulp.series('sass'));
gulp.watch('**/*.html').on('change', browserSync.reload);
gulp.watch('js/**/*.js').on('change', browserSync.reload);
}));
// Static Server without watching scss files
gulp.task('serve:lite', function() {
browserSync.init({
server: "./",
ghostMode: false,
notify: false
});
gulp.watch('**/*.css').on('change', browserSync.reload);
gulp.watch('**/*.html').on('change', browserSync.reload);
gulp.watch('js/**/*.js').on('change', browserSync.reload);
});
/* inject partials like sidebar and navbar */
gulp.task('injectPartial', function () {
return gulp.src("./**/*.html", { base: "./" })
.pipe(injectPartials())
.pipe(gulp.dest("."));
});
/* inject Js and CCS assets into HTML */
gulp.task('injectCommonAssets', function () {
return gulp.src('./**/*.html')
.pipe(inject(gulp.src([
'./vendors/mdi/css/materialdesignicons.min.css',
'./vendors/base/vendor.bundle.base.css',
'./vendors/base/vendor.bundle.base.js',
], {read: false}), {name: 'base', relative: true}))
.pipe(inject(gulp.src([
'./css/*.css',
'./js/template.js',
], {read: false}), {relative: true}))
.pipe(gulp.dest('.'));
});
/* inject Js and CCS assets into HTML */
gulp.task('injectLayoutStyles', function () {
return gulp.src('./**/*.html')
.pipe(inject(gulp.src([
'./css/style.css',
], {read: false}), {relative: true}))
.pipe(gulp.dest('.'));
});
/*replace image path and linking after injection*/
gulp.task('replacePath', function(){
var replacePath1 = gulp.src(['./pages/*/*.html'], { base: "./" })
.pipe(replace('="images/', '="../../images/'))
.pipe(replace('href="pages/', 'href="../../pages/'))
.pipe(replace('href="docs/', 'href="../../docs/'))
.pipe(replace('href="index.html"', 'href="../../index.html"'))
.pipe(gulp.dest('.'));
var replacePath2 = gulp.src(['./pages/*.html'], { base: "./" })
.pipe(replace('="images/', '="../images/'))
.pipe(replace('"pages/', '"../pages/'))
.pipe(replace('href="index.html"', 'href="../index.html"'))
.pipe(gulp.dest('.'));
var replacePath3 = gulp.src(['./index.html'], { base: "./" })
.pipe(replace('="images/', '="images/'))
.pipe(gulp.dest('.'));
return merge(replacePath1, replacePath2, replacePath3);
});
/*sequence for injecting partials and replacing paths*/
gulp.task('inject', gulp.series('injectPartial' , 'injectCommonAssets' , 'injectLayoutStyles', 'replacePath'));
gulp.task('clean:vendors', function () {
return del([
'vendors/**/*'
]);
});
/*Building vendor scripts needed for basic template rendering*/
gulp.task('buildBaseVendorScripts', function() {
return 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/perfect-scrollbar/dist/perfect-scrollbar.min.js'
])
.pipe(concat('vendor.bundle.base.js'))
.pipe(gulp.dest('./vendors/base'));
});
/*Building vendor styles needed for basic template rendering*/
gulp.task('buildBaseVendorStyles', function() {
return gulp.src(['./node_modules/perfect-scrollbar/css/perfect-scrollbar.css'])
.pipe(concat('vendor.bundle.base.css'))
.pipe(gulp.dest('./vendors/base'));
});
/*Scripts for addons*/
gulp.task('copyAddonsScripts', function() {
var aScript1 = gulp.src(['node_modules/chart.js/dist/Chart.min.js'])
.pipe(gulp.dest('./vendors/chart.js'));
var aScript2 = gulp.src(['node_modules/justgage/raphael-2.1.4.min.js'])
.pipe(gulp.dest('./vendors/justgage'));
var aScript3 = gulp.src(['node_modules/justgage/justgage.js'])
.pipe(gulp.dest('./vendors/justgage'));
var aScript4 = gulp.src(['node_modules/raphael/raphael.min.js'])
.pipe(gulp.dest('./vendors/raphael'));
var aScript13 = gulp.src(['node_modules/jvectormap/jquery-jvectormap.min.js'])
.pipe(gulp.dest('./vendors/jvectormap'));
var aScript14 = gulp.src(['node_modules/jvectormap/tests/assets/jquery-jvectormap-world-mill-en.js'])
.pipe(gulp.dest('./vendors/jvectormap'));
var aScript18 = gulp.src(['node_modules/chartjs-plugin-datalabels/dist/**/*'])
.pipe(gulp.dest('./vendors/chartjs-plugin-datalabels'));
var aScript19 = gulp.src(['node_modules/progressbar.js/dist/progressbar.min.js'])
.pipe(gulp.dest('./vendors/progressbar.js'));
var aScript20 = gulp.src(['node_modules/typeahead.js/dist/typeahead.bundle.min.js'])
.pipe(gulp.dest('./vendors/typeahead.js'));
var aScript21 = gulp.src(['node_modules/select2/dist/js/select2.min.js'])
.pipe(gulp.dest('./vendors/select2'));
return merge(aScript1, aScript2, aScript3, aScript4, aScript13, aScript14, aScript18, aScript19, aScript20, aScript21);
});
/*Styles for addons*/
gulp.task('copyAddonsStyles', function() {
var aStyle1 = gulp.src(['./node_modules/@mdi/font/css/materialdesignicons.min.css'])
.pipe(gulp.dest('./vendors/mdi/css'));
var aStyle2 = gulp.src(['./node_modules/@mdi/font/fonts/*'])
.pipe(gulp.dest('./vendors/mdi/fonts'));
var aStyle9 = gulp.src(['node_modules/jvectormap/jquery-jvectormap.css'])
.pipe(gulp.dest('./vendors/jvectormap'));
var aStyle10 = gulp.src(['node_modules/select2/dist/css/select2.min.css'])
.pipe(gulp.dest('./vendors/select2'));
var aStyle11 = gulp.src(['node_modules/select2-bootstrap-theme/dist/select2-bootstrap.min.css'])
.pipe(gulp.dest('./vendors/select2-bootstrap-theme'));
var aStyle12 = gulp.src(['node_modules/jquery-file-upload/css/uploadfile.css'])
.pipe(gulp.dest('./vendors/jquery-file-upload'));
return merge(aStyle1, aStyle2, aStyle9, aStyle10, aStyle11, aStyle12);
});
/*sequence for building vendor scripts and styles*/
gulp.task('bundleVendors', gulp.series('clean:vendors', 'buildBaseVendorStyles','buildBaseVendorScripts', 'copyAddonsStyles', 'copyAddonsScripts'));
gulp.task('default', gulp.series('serve'));