Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
54 lines (48 loc) · 1.84 KB
/
Copy pathgulpfile.js
File metadata and controls
54 lines (48 loc) · 1.84 KB
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
import gulp from 'gulp';
import sass from 'gulp-sass';
import sassCompiler from 'sass';
import babel from 'gulp-babel';
import uglify from 'gulp-uglify';
import pug from 'gulp-pug';
import plumber from 'gulp-plumber';
import fs from "fs";
import path from "path";
import {fileURLToPath} from "url";
const sassTask = sass(sassCompiler);
const __filename = fileURLToPath(import.meta.url);
const __dirnamePath = path.dirname(__filename);
const users = JSON.parse(fs.readFileSync(path.join(__dirnamePath, "data/users.json"), "utf8"));
const title = "title";
const allNews = JSON.parse(fs.readFileSync(path.join(__dirnamePath, "data/news.json"), "utf8"));
const friendsNews = allNews.filter(n => users[0].friends && users[0].friends.includes(n.author_id));
const userNews = allNews.filter(n => n.author_id === users[0].id);
const combinedNews = [...userNews, ...friendsNews];
combinedNews.sort((a, b) => new Date(b.date) - new Date(a.date));
export const styles = () => {
return gulp.src('./styles/styles.scss')
.pipe(sassTask().on('error', sassTask.logError))
.pipe(gulp.dest('public/css'));
};
export const scripts = () => {
return gulp.src('./js/*.js')
.pipe(plumber())
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('dist/gulp'));
}
export const views = () => {
return gulp.src('./pages/*.pug')
.pipe(pug({locals: {users: users, user: users[0], title: title,
friends: users.filter(u => users[0].friends.includes(u.id)),
news:combinedNews}}))
.pipe(gulp.dest('dist/gulp'));
}
export const defaultTask = gulp.series(
gulp.parallel(styles, scripts, views),
() => {
gulp.watch('public/scss/**/*.scss', styles);
gulp.watch('public/js/**/*.js', scripts);
gulp.watch(['views/**/*.pug', 'data/**/*.json'], views);
}
);
export default defaultTask;