-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
181 lines (156 loc) · 5.88 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
/* eslint-env node */
const gulp = require('gulp');
const babel = require('gulp-babel');
const uglifyjs = require('uglify-es');
const composer = require('gulp-uglify/composer');
const concat = require('gulp-concat');
const autoprefixer = require('gulp-autoprefixer');
const plumber = require('gulp-plumber');
const sass = require('gulp-sass');
const imagemin = require('gulp-imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
const clean = require('gulp-clean');
const sourcemaps = require('gulp-sourcemaps');
const minifyCss = require('gulp-minify-css');
const browserSync = require('browser-sync').create();
const markdown = require('gulp-markdown');
const eslint = require('gulp-eslint');
const minify = composer(uglifyjs, console);
// SETTINGS
// Build paths
const BUILD_PATH = 'build';
const BUILT_MIN_CSS_PATH = 'build/min-css/'; // Automated task: Convert scss in to minified css here
const BUILD_IMG_PATH = 'build/img/'; // Automated task: Compress new photos from IMG_PATH
const BUILD_JS_PATH = 'build/js/'; // Automated task: Join all js files
// Source paths
const COPY_PATH = ['source/*.html','source/data/*'];
const CSS_PATH = 'source/css'; // Automated task: put here a copy of css files. For reading only purpose.
const SCRIPTS_FOLDER = 'source/js/'
const SCRIPTS_P_MARKET = SCRIPTS_FOLDER+'PageMarket/'
const SCRIPTS_P_VARIABILITY = SCRIPTS_FOLDER+'PageVariability/'
const SCSS_PATH = 'source/scss/**/*.scss';
const IMG_PATH = 'source/img/**/*';
// Order how js will be concatenated
const JS_ORDER_VARIABILITY = [SCRIPTS_P_VARIABILITY+'chart-settings-and-data.js', SCRIPTS_P_VARIABILITY+'/**/*.js', SCRIPTS_P_VARIABILITY+'draw-chart.js'];
const JS_ORDER_MARKET=[SCRIPTS_P_MARKET+'**/*.js']
// Picture quality 0 (worst) to 100 (perfect).
const QUALITY = 40;
// For changing readme.md in to html format
gulp.task('readme', () => gulp.src('README.md').pipe(markdown()).pipe(gulp.dest('build/')));
gulp.task('eslint', () => {
gulp.src(['source/js/PageVariability/**/*.js'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
// Photos
gulp.task('photo', () => gulp.src([IMG_PATH])
.pipe(imagemin([
imageminMozjpeg({
quality: QUALITY,
}),
]))
.pipe(gulp.dest(BUILD_IMG_PATH)));
gulp.task('delete-photos', () => gulp.src('BUILD_IMG_PATH', {
read: false, allowEmpty: true,
})
.pipe(clean({
allowEmpty: true,
})));
gulp.task('delete-build', () => gulp.src(BUILD_PATH, {
read: false, allowEmpty: true,
})
.pipe(clean()));
gulp.task('copy', () => gulp
.src(COPY_PATH)
.pipe(gulp.dest(BUILD_PATH)));
gulp.task('delete-jasmine-files', () => gulp.src(['build/js/SpecRunner.html', 'build/js/_spec.js'], {
read: false, allowEmpty: true,
})
.pipe(clean()));
gulp.task('copy-jasmine-files', () => gulp
.src('source/spec/**/*')
.pipe(gulp.dest('build/js/')));
// SCSS automation
gulp.task('styles', () => gulp.src(SCSS_PATH)
.pipe(plumber(function (err) {
console.log('Error: ');
console.log(err);
this.emit('end');
}))
.pipe(sourcemaps.init()) // how files was look like before
.pipe(autoprefixer())
// you can pass object into autoprefixer:
// for example { browser: ['last 2 versions', 'ie 8']
.pipe(sass(
// {outputStyle: 'compressed'}
))
.pipe(gulp.dest(CSS_PATH))
.pipe(minifyCss())
.pipe(sourcemaps.write()) // how files was look like after?
.pipe(gulp.dest(BUILT_MIN_CSS_PATH)));
// JS automationT
gulp.task('script', () => gulp.src(JS_ORDER_VARIABILITY)
.pipe(plumber(function (err) {
console.log('Java script errors:');
console.log(err);
this.emit('end');
}))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/env'],
}))
.pipe(minify())
.pipe(concat('variability.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(BUILD_JS_PATH)));
gulp.task('script2', () => gulp.src(JS_ORDER_MARKET)
.pipe(plumber(function (err) {
console.log('Java script errors:');
console.log(err);
this.emit('end');
}))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/env'],
}))
.pipe(minify())
.pipe(concat('market.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(BUILD_JS_PATH)));
// Reload the webpage
gulp.task('reload', () => {
console.log('Reloading page');
browserSync.reload();
});
// Static server
gulp.task('server', () => {
browserSync.init({
files: ['build/'],
server: {
baseDir: './build/',
},
});
gulp.watch('/*.md', gulp.series('readme'));
gulp.watch('source/spec/**/*.html', gulp.series('script', 'delete-jasmine-files' ,'copy-jasmine-files'));
gulp.watch('source/spec/**/*.js', gulp.series('script', 'delete-jasmine-files' ,'copy-jasmine-files'));
gulp.watch('source/js/PageVariability/**/*.js', gulp.series('script','delete-jasmine-files', 'copy-jasmine-files'));
gulp.watch('source/js/PageMarket/**/*.js', gulp.series('script2', 'delete-jasmine-files', 'copy-jasmine-files'));
gulp.watch(SCSS_PATH, gulp.series('styles'));
gulp.watch('source/img/**/*', gulp.series('delete-photos'));
gulp.watch('source/img/**/*', gulp.series('photo'));
gulp.watch('build/**/*.css').on('change', browserSync.reload);
gulp.watch('source/*.html', gulp.series('copy'));
gulp.watch('README.md', gulp.series('readme'));
gulp.watch('build/*.html').on('change', browserSync.reload);
gulp.watch('build/js/**/*').on('change', browserSync.reload);
});
// Rebuild whole project and run the server
gulp.task('default', gulp.series('delete-build', 'copy', 'copy-jasmine-files', 'script', 'script2', 'styles', 'photo', 'readme', 'server'), () => {
});