-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
100 lines (86 loc) · 2.87 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
'use strict';
require('dotenv').config();
const gulp = require('gulp');
const watch = require('gulp-watch');
const gulpif = require('gulp-if');
const argv = require('yargs').argv;
const jshint = require('gulp-jshint');
const sass = require('gulp-sass');
const babel = require('gulp-babel');
const replace = require('gulp-replace');
const pug = require('gulp-pug');
const pugwatch = require('gulp-watch-pug');
const sourcemaps = require('gulp-sourcemaps');
const relativesourcemaps = require('gulp-relative-sourcemaps-source');
const browserify = require('gulp-browserify');
const mocha = require('gulp-mocha');
const babelregister = require('babel-register');
const paths = {
src: './src/**/*.js',
config: './src/**/*.json',
views: './src/**/*.pug',
models: './src/models/**/*.js',
migrations: './src/migrations/**/*.js',
dist: './dist',
clientjs: ['./dist/utils/transactionUtil.js']
}
const precompileViews = () => {
return gulp.src([paths.views])
.pipe(pug({client: true}))
.pipe(replace('function template(locals)', 'module.exports = function(locals, pug)'))
.pipe(gulp.dest(paths.dist))
};
const handleError = (err) => {
console.log(err.toString());
}
gulp.task('mocha', () => {
return gulp.src(['test/*.js'])
.pipe(mocha({compilers:babelregister}).on('error', handleError))
.once('end', () => { process.exit(0); });
});
gulp.task('jslint', () => {
// Excluding models & migrations folder due to being generated by ORM
return gulp.src([paths.src, '!' + paths.models, '!' + paths.migrations])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('sass', () => {
return gulp.src('./src/sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./public/css'));
});
gulp.task('babel', ['cleanDist'], () => {
return gulp.src([paths.src])
.pipe(gulpif(!argv.production, sourcemaps.init()))
.pipe(babel())
.pipe(gulpif(!argv.production, relativesourcemaps({dest: 'dist'})))
.pipe(gulpif(!argv.production, sourcemaps.write('.')))
.pipe(gulp.dest(paths.dist));
});
gulp.task('views', ['babel'], () => {
if (argv.production) {
return precompileViews();
} else {
return gulp.src([paths.views])
.pipe(gulp.dest(paths.dist));
}
});
gulp.task('config', ['babel'], () => {
return gulp.src([paths.config])
.pipe(gulp.dest(paths.dist))
});
gulp.task('cleanDist', function () {
var del = require('del');
return del(paths.dist);
});
// Browserify some clientjs
// only to be ran after babel task
// Possibly think about running seperate babel tasks with different presets for this task
gulp.task('clientjs', ['babel'], () => {
gulp.src(paths.clientjs)
.pipe(browserify({standalone: 'transactionUtil'}))
.pipe(gulp.dest('./public/js'));
});
gulp.task('build', ['cleanDist', 'babel', 'views', 'config', 'clientjs']);
gulp.task('lint', ['jslint']);