This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
gulpfile.js
72 lines (65 loc) · 2.34 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
'use strict';
const gulp = require('gulp');
const gulpConcatPo = require('gulp-concat-po');
const gulpXgettext = require('gulp-xgettext');
const gulpReplace = require('gulp-replace');
const gulpRename = require('gulp-rename');
const gulpSass = require('gulp-ruby-sass');
const gulpFilter = require('gulp-filter');
const gutil = require('gulp-util');
const exec = require('child_process').exec;
gulp.task('pot', pot);
gulp.task('update-po', updatePo);
// Prepare all /census/locale/*/LC_MESSAGES/*.po files to use with i18n-abide
gulp.task('compile-po', compilePo);
gulp.task('compile-styles', compileStyles);
function pot() {
const jsFilter = gulpFilter('**/controllers/*.js', {restore: true});
const htmlFilter = gulpFilter('**/*.html', {restore: true});
const excludedDirs = '!(views_old|static|migrations|locale|ui_app|public)';
return gulp.src(['census/' + excludedDirs + '/**/*.{html,js}'])
// Filter just the html files
.pipe(htmlFilter)
// jsxgettext hates 'or' in templates, so make these special exceptions.
// https://github.com/zaach/jsxgettext/issues/78
.pipe(gulpReplace(/or gettext/g, '|| gettext'))
.pipe(gulpReplace(/or false/g, '|| false'))
.pipe(gulpReplace(/or \'\'/g, '|| \'\''))
.pipe(gulpXgettext({
language: 'jinja',
bin: 'node_modules/.bin/jsxgettext'
}))
// Restore all the files...
.pipe(htmlFilter.restore)
// ... and now filter just the js files
.pipe(jsFilter)
.pipe(gulpXgettext({
bin: 'node_modules/.bin/jsxgettext'
}))
// Restore all the files...
.pipe(jsFilter.restore)
// Concat all into the 'messages.pot' file
.pipe(gulpConcatPo('messages.pot', {
headers: {
'POT-Creation-Date': new Date().toISOString(),
'Content-Transfer-Encoding': '8bit',
'Project-Id-Version': 'PACKAGE VERSION',
'Language-Team': 'LANGUAGE <[email protected]>',
'Content-Type': 'text/plain; charset=utf-8'
}}))
.on('error', gutil.log)
.pipe(gulp.dest('census/locale/templates/LC_MESSAGES'));
}
function updatePo() {
return exec('./node_modules/.bin/merge-po locale');
}
function compilePo() {
return exec(
'./node_modules/.bin/compile-json ./census/locale ./census/locale');
}
function compileStyles() {
return gulpSass(['census/static/scss/styles.scss'])
// .pipe(minifyCss({compatibility: 'ie8'}))
.pipe(gulpRename('styles.css'))
.pipe(gulp.dest('census/static/css'));
}