-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
125 lines (107 loc) · 3.47 KB
/
Copy pathgulpfile.babel.js
File metadata and controls
125 lines (107 loc) · 3.47 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
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
const gulp = require('gulp');
const babel = require('gulp-babel');
const csso = require('gulp-csso');
const sass = require('gulp-sass');
const imagemin = require('gulp-imagemin');
const mocha = require('gulp-mocha-co');
const eslint = require('gulp-eslint');
const nodemon = require('nodemon');
const webpack = require('webpack-stream');
const istanbul = require('gulp-istanbul');
const webpackConfig = require('./webpack.client.config.js');
const webpackServerConfig = require('./webpack.server.config.js');
const rootDir = './dist';
require('babel-register');
require('babel-polyfill');
/** lint task **/
gulp.task('lint', () =>
gulp.src(['./app/**/*.js', '!node_modules/**', '!./app/resources/**/*.js'])
.pipe(eslint())
.pipe(eslint.formatEach())
.pipe(eslint.failAfterError()),
);
gulp.task('pre-test', () => {
return gulp.src(['tests/*.test.js'])
.pipe(babel({
presets: ['es2015'],
}))
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
/** run test **/
gulp.task('test', ['pre-test'], () => {
process.env.TEST_DB_URI = 'mongodb://localhost:27017/fake-data';
gulp.src('tests/*.test.js')
.pipe(babel({
presets: ['es2015'],
}))
.pipe(mocha({
reporter: 'spec',
}))
.pipe(istanbul.writeReports({
dir: '.',
reporters: ['lcovonly'],
reportOpts: {
lcov: {dir: 'lcovonly', file: 'lcov.info'}
}
}));
});
/** steps db conversion **/
const activeStepsConverterFunction = require('./server/database/mongodbScripts/activeStepsConverterScript');
const fullStepsConverterFunction = require('./server/database/mongodbScripts/fullStepsConverterScript');
gulp.task('set-convert-dbs', () => {
process.env.SRC_DB_URI = 'mongodb://localhost:27017/steps-api-sanitised';
process.env.DEST_DB_URI = 'mongodb://localhost:27017/dev';
});
gulp.task('active-convert', ['set-convert-dbs'], activeStepsConverterFunction);
gulp.task('full-convert', ['set-convert-dbs'], fullStepsConverterFunction);
/** minimizing files and bundling **/
gulp.task('css', () =>
gulp.src('./app/resources/style/**/*.scss')
.pipe(
sass({
includePaths: ['./app/resources/style'],
errLogToConsole: true,
}))
.pipe(csso())
.pipe(gulp.dest(`${rootDir}/resources/style/`)),
);
gulp.task('html', () =>
gulp.src('./app/*.html')
.pipe(gulp.dest(rootDir)),
);
gulp.task('image', () =>
gulp.src('./app/resources/images/*.+(png|jpg|svg|ico)')
.pipe(imagemin())
.pipe(gulp.dest(`${rootDir}/resources/images/`)),
);
gulp.task('bundle', () =>
gulp.src('./app/main.js')
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(rootDir)),
);
gulp.task('fonts', () =>
gulp.src('./app/resources/fonts/*.+(otf|ttf|eof|ttc|woff)')
.pipe(gulp.dest(`${rootDir}/resources/fonts/`)),
);
/** watch file changes **/
gulp.task('watch', () => {
gulp.watch('./app/resources/style/**/*.scss', ['css']);
gulp.watch('./app/*.html', ['html']);
gulp.watch('./app/**/*.js', ['bundle']);
});
gulp.task('buildServer', () => {
process.env.MONGODB_URI = 'mongodb://localhost:27017/dev';
process.env.JWT_SECRET = 'temp';
gulp.src('./server/server.js')
.pipe(webpack(webpackServerConfig))
.pipe(gulp.dest('./server/'));
});
gulp.task('buildClient', ['css', 'html', 'image', 'bundle']);
/** run gulp task for development **/
gulp.task('default', ['watch', 'css', 'html', 'image', 'bundle', 'fonts', 'buildServer'], () => {
nodemon({
script: './server/server.bundle.js',
ignore: ['./dist/'],
});
});