-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
136 lines (120 loc) · 3.78 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
/* jshint esversion: 6 */
const gulp = require('gulp');
const browserSync = require('browser-sync');
const sass = require('gulp-sass');
const del = require('del');
const concat = require('gulp-concat');
const concatCss = require('gulp-concat-css');
const uglify = require('gulp-uglify-es').default;
const argv = require('yargs').argv;
const DESTINATION = 'wwwdccn/static';
const SOURCE = 'frontend';
const CSS_BUNDLE_NAME = 'dccn-ui.css';
const JS_BUNDLE_NAME = 'dccn-ui.js';
const paths = {
styles: {
source: `${SOURCE}/scss/**/*.scss`,
destination: `${DESTINATION}/css`
},
scripts: {
source: `${SOURCE}/**/*.js`,
destination: `${DESTINATION}/scripts`
},
html: {
source: `${SOURCE}/**/*.html`
// destination: `${DESTINATION}/`
},
images: {
source: `${SOURCE}/images/*`,
destination: `${DESTINATION}/images`
},
externalScripts: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/popper.js/dist/popper.min.js',
'node_modules/bootstrap/dist/js/bootstrap.bundle.js',
'node_modules/sweetalert2/dist/sweetalert2.min.js',
'node_modules/mathjs/dist/math.js',
'node_modules/chart.js/dist/Chart.bundle.min.js',
'node_modules/requirejs/require.js',
'node_modules/bootbox/dist/bootbox.min.js',
],
externalStyles: [
'node_modules/sweetalert2/dist/sweetalert2.min.css',
],
codeMirror: 'node_modules/codemirror',
};
function fonts() {
return gulp.src('node_modules/@fortawesome/fontawesome-free/webfonts/*')
.pipe(gulp.dest(`${DESTINATION}/webfonts`));
}
function styles() {
return gulp.src(paths.styles.source)
.pipe(sass()).on("error", sass.logError)
.pipe(concatCss(CSS_BUNDLE_NAME))
.pipe(gulp.dest(paths.styles.destination))
.pipe(browserSync.stream());
}
function scripts() {
return gulp.src(paths.scripts.source)
.pipe(concat(JS_BUNDLE_NAME))
.pipe(uglify())
.pipe(gulp.dest(paths.scripts.destination))
.pipe(browserSync.stream());
}
function copyExternalScripts() {
return gulp.src(paths.externalScripts)
.pipe(gulp.dest(paths.scripts.destination));
}
function copyNodeModules() {
return gulp.src([
`node_modules/codemirror/**`,
], {
base: 'node_modules/'
}).pipe(gulp.dest(DESTINATION));
}
function copyAssets() {
return gulp.src([
`${SOURCE}/assets/**`,
], {
base: SOURCE
}).pipe(gulp.dest(DESTINATION))
}
function copyExternalStyles() {
return gulp.src(paths.externalStyles)
.pipe(gulp.dest(paths.styles.destination));
}
function html(cb) {
if (!argv.production) {
return gulp.src(paths.html.source)
// .pipe(gulp.dest(paths.html.destination))
.pipe(browserSync.stream());
}
cb();
}
function images() {
return gulp.src(paths.images.source)
.pipe(gulp.dest(paths.images.destination))
.pipe(browserSync.stream());
}
function clean(cb) {
del([`${paths.styles.destination}`]);
del([`${paths.scripts.destination}`]);
del([`${paths.images.destination}`]);
del([`${DESTINATION}/webfonts`]);
// Remove modules:
del([`${DESTINATION}/codemirror`]);
cb();
}
function serve() {
browserSync.init({server: [`${DESTINATION}`, `${SOURCE}/samples`]});
gulp.watch(paths.styles.source, styles);
gulp.watch(paths.scripts.source, scripts);
gulp.watch(paths.html.source, html);
gulp.watch(paths.images.source, images);
}
const copyExternals = gulp.parallel(copyExternalScripts, copyExternalStyles, copyNodeModules, copyAssets);
const build = gulp.parallel(styles, scripts, images, fonts, copyExternals);
exports.build = build;
exports.clean = clean;
exports.serve = serve;
exports.default = gulp.series(clean, build, serve);