-
Notifications
You must be signed in to change notification settings - Fork 56
/
gulpfile.js
92 lines (79 loc) · 2.48 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
const gulp = require(`gulp`);
const sass = require(`gulp-sass`)(require('node-sass'));
const sync = require(`browser-sync`).create();
const reload = sync.reload;
const colors = require(`colors/safe`);
const del = require(`del`);
const mustache = require(`gulp-mustache`);
const rename = require(`gulp-rename`);
const SERVER_ROOT = `build/`;
const translates = [
{
dest: SERVER_ROOT,
url: `./src/translate/ru.json`
},
{
dest: `${SERVER_ROOT}en/`,
url: `./src/translate/en.json`
}
];
// TEMPLATES
const tmplTasks = translates.map(({ dest, url }) => {
return (done) => {
gulp.src(`./src/index-src.html`)
.pipe(mustache(url))
.pipe(rename(`index.html`))
.pipe(gulp.dest(dest))
.pipe(reload({ stream: true }));
done();
};
});
gulp.task(`tmpl`, gulp.series(...tmplTasks));
// SCSS
gulp.task(`scss`, function () {
return gulp.src(`src/scss/**/styles.scss`)
.pipe(sass().on(`error`, sass.logError))
.pipe(gulp.dest(`${SERVER_ROOT}assets/css`))
.pipe(reload({ stream: true }));
});
// JS
gulp.task(`js`, function () {
return gulp.src(`src/js/**/*.js`)
.pipe(gulp.dest(`${SERVER_ROOT}assets/js`))
.pipe(reload({ stream: true }));
});
// WATCH FILES
function watchTasks () {
sync.init({
ui: false,
notify: false,
server: {
baseDir: SERVER_ROOT
}
});
gulp.watch([`src/scss/**/*.scss`], gulp.series(`scss`));
gulp.watch([`src/index-src.html`, `src/translate/**/*`], gulp.series(`tmpl`));
gulp.watch([`src/js/**/*`], gulp.series(`js`));
}
gulp.task(`serve`, gulp.series([`scss`, `js`, `tmpl`], watchTasks));
// CLEAN BUILD
gulp.task(`clean`, function (done) {
del([`${SERVER_ROOT}*`]).then(paths => {
console.log(`⬤ Deleted files and folders:\n`, paths.join(`\n`));
});
done();
});
// CLEAN BUILD & COPY FILES TO IT
gulp.task(`build`, gulp.series([`clean`], [`scss`, `js`, `tmpl`]));
gulp.task(`default`, function () {
console.log(colors.rainbow(`⬤ ================================ ⬤\n`));
console.log(` AVAILABLE COMMANDS:`);
console.log(` ` + colors.cyan(`-------------------\n`));
console.log(` ` + colors.yellow(`npm start`) +
` — run local server with watcher`);
console.log(` ` + colors.green(`npm run build`) +
` — make build of the project`);
console.log(` ` + colors.cyan(`npm run deploy`) +
` — make build and publish project to Github Pages`);
console.log(colors.rainbow(`\n⬤ ================================ ⬤`));
});