forked from techlab/jquery-smartwizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
137 lines (114 loc) · 3.09 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
// Include the required tools used on tasks
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
saveLicense = require('uglify-save-license'),
babel = require("gulp-babel"),
postcss = require('gulp-postcss'),
cleanCSS = require('gulp-clean-css'),
cssbeautify = require('gulp-cssbeautify'),
autoprefixer = require('autoprefixer'),
sass = require('gulp-sass'),
del = require('del');
sass.compiler = require('node-sass');
var Server = require('karma').Server;
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
// Specify the Source files
var SRC_JS = 'src/js/*.js';
var SRC_CSS = 'src/css/*.css';
var SRC_SCSS = 'src/scss/*.scss';
// Specify the Destination folders
var DEST_JS = 'dist/js';
var DEST_CSS = 'dist/css';
var DEST_SCSS = 'src/css';
// BUILD JS
function build_js(cb) {
gulp.src(SRC_JS)
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest(DEST_JS))
.pipe(uglify({
output: {
comments: saveLicense
}
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(DEST_JS));
cb();
}
// BUILD CSS
function build_css(cb) {
gulp.src(SRC_CSS)
.pipe(postcss( [autoprefixer()] ))
.pipe(cssbeautify({ autosemicolon: true }))
.pipe(gulp.dest(DEST_CSS))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(DEST_CSS));
cb();
}
// BUILD SCSS
function build_scss(cb) {
gulp.src(SRC_SCSS)
.pipe(sass({outputStyle:'expanded'}).on('error', sass.logError))
.pipe(gulp.dest(DEST_SCSS));
cb();
}
// LINT
function lint_js(cb) {
gulp.src(SRC_JS)
.pipe(jshint({ "esversion": 8 }))
.pipe(jshint.reporter('default'));
cb();
}
// CLEAN
function clean_js(cb) {
del.sync([DEST_JS]);
cb();
}
function clean_css(cb) {
del.sync([DEST_CSS]);
cb();
}
// WATCH
function watch(cb) {
gulp.watch(SRC_JS, build_js);
gulp.watch(SRC_CSS, build_css);
gulp.watch(SRC_SCSS, build_scss);
cb();
}
// SERVE
function serve(cb) {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: ["examples", "dist"],
index: "index.html"
}
});
gulp.watch(SRC_JS, build_js).on("change", reload);
gulp.watch(SRC_CSS, build_css).on("change", reload);
gulp.watch(SRC_SCSS, build_scss).on("change", reload);
cb();
}
// TEST
function test(cb) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
cb();
}
// EXPORT methods
exports.clean = gulp.parallel(clean_js, clean_css);
exports.build = gulp.parallel(gulp.series(clean_js, lint_js, build_js), gulp.series(build_scss, build_css, clean_css));
exports.lint = lint_js;
exports.watch = watch;
exports.test = test;
exports.serve = serve;
exports.default = serve;