This repository has been archived by the owner on Jan 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
99 lines (84 loc) · 2.94 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
/**
* Gulp tasks for openslides.org
*
* Run $ ./node_modules/.bin/gulp
*
*/
// TODO: Remove the next line when support for Node 0.10.x is dropped.
// See https://github.com/postcss/postcss#nodejs-010-and-the-promise-api
require('es6-promise').polyfill();
var gulp = require('gulp'),
concat = require('gulp-concat'),
cssnano = require('gulp-cssnano'),
gettext = require('gulp-angular-gettext'),
jshint = require('gulp-jshint'),
mainBowerFiles = require('main-bower-files'),
nodemon = require('gulp-nodemon'),
path = require('path'),
uglify = require('gulp-uglify');
// Directory where the results go to
var output_directory = path.join('public', 'static');
/**
* Default tasks to be run before start.
*/
// Catches all JavaScript files from all bower components and concats and uglify
// them to js/openslides-libs.js.
gulp.task('js-libs', function () {
return gulp.src(mainBowerFiles({
filter: /\.js$/
}))
.pipe(concat('openslides-libs.js'))
.pipe(uglify())
.pipe(gulp.dest(path.join(output_directory, 'libs', 'js')));
});
// Catches all CSS files from all bower components and concats and uglify
// them to css/openslides-libs.css.
gulp.task('css-libs', function () {
return gulp.src(mainBowerFiles({
filter: /\.css$/
}))
.pipe(concat('openslides-libs.css'))
.pipe(cssnano({discardUnused: false}))
.pipe(gulp.dest(path.join(output_directory, 'libs', 'css')));
});
// Catches all font files from all bower components.
gulp.task('fonts-libs', function() {
return gulp.src(mainBowerFiles({
filter: /\.(eot)|(svg)|(ttf)|(woff)|(woff2)$/
}))
.pipe(gulp.dest(path.join(output_directory, 'libs', 'fonts')));
});
// Compiles translation files (*.po) to *.json and saves them in the directory i18n.
gulp.task('translations', function () {
return gulp.src(path.join('locale', '*.po'))
.pipe(gettext.compile({
format: 'json'
}))
.pipe(gulp.dest(path.join(output_directory, 'i18n')));
});
// Gulp default task. Runs all other tasks before.
gulp.task('default', ['js-libs', 'css-libs', 'fonts-libs', 'translations'], function () {});
/**
* Extra tasks that have to be called manually.
*/
// Extracts translatable strings using angular-gettext and saves them in file
// locale/template-en.pot.
gulp.task('pot', function () {
return gulp.src(['public/index.html',
'public/static/views/*.html',
'public/static/js/*.js'])
.pipe(gettext.extract('template-en.pot', {}))
.pipe(gulp.dest('locale'));
});
// Checks JavaScript using JSHint
gulp.task('jshint', function () {
return gulp.src([ 'gulpfile.js', path.join('public', 'static', 'js', '*.js' ) ])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Run http express server
gulp.task('serve', function () {
nodemon({
script: 'server.js'
});
});