-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
92 lines (81 loc) · 2.38 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 eslint = require('gulp-eslint');
const sass = require('gulp-sass');
const sassLint = require('gulp-sass-lint');
const util = require('gulp-util');
const watch = require('gulp-watch');
const del = require('del');
const fs = require('fs');
const notifier = require('node-notifier');
const through = require('through2');
const exec = require('child_process').exec;
function mergeCss() {
return through.obj(function(file, enc, cb) {
const cssFilePath = file.path.replace(/\.js$/, '.css');
const js = file._contents.toString(enc);
let css = null;
try {
css = fs.readFileSync(cssFilePath).toString(enc);
}
catch (e) {
css = '';
}
const output = js.replace(/{{ css }}/, `<style>${ css }</style>`);
this.push(new util.File({
base: file.base,
path: file.path,
contents: Buffer.from(output, enc)
}));
cb();
});
}
gulp.task('lint', () => {
return gulp.src(['src/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('clean:tmp', (done) => {
del.sync(['.tmp/**']);
done();
});
gulp.task('clean:dist', gulp.series('clean:tmp', (done) => {
del.sync(['dist/**']);
done();
}));
gulp.task('sass:global', gulp.series('clean:dist', () => {
return gulp.src(['src/styles/global/haiku.scss'])
.pipe(sassLint())
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('.tmp'));
}));
gulp.task('sass', gulp.series('sass:global', () => {
return gulp.src(['src/**/*.scss', '!src/styles/global/**/*.scss'])
.pipe(sassLint())
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('.tmp'));
}));
gulp.task('js', gulp.series('sass', 'lint', () => {
return gulp.src(['src/**/*.js'])
.pipe(gulp.dest('.tmp'));
}));
gulp.task('build', gulp.series('js', () => {
return gulp.src(['.tmp/**/*.js', '.tmp/haiku.css'])
.pipe(mergeCss())
.pipe(gulp.dest('dist'));
}));
gulp.task('watch', () => {
watch(['src/**/*'], {debounceDelay: 2000}, () => {
gulp.start('deploy');
});
});
gulp.task('deploy', gulp.series('build', (cb) => {
exec('sh ./tools/deploy/deploy.sh', () => {
notifier.notify({
title: 'Deployment Complete',
message: 'The updated compiled artifacts were pushed to the raspberrypi.'
});
cb();
});
}));
gulp.task('default', gulp.series('build'));