2015-10-21 22:44:07 +02:00
|
|
|
/**
|
2015-01-05 15:01:42 +01:00
|
|
|
* Gulp tasks for development and production.
|
|
|
|
*
|
|
|
|
* Run
|
|
|
|
*
|
|
|
|
* $ ./node_modules/.bin/gulp
|
|
|
|
*
|
|
|
|
* for development and
|
|
|
|
*
|
|
|
|
* $ ./node_modules/.bin/gulp --production
|
|
|
|
*
|
|
|
|
* for production mode.
|
|
|
|
*/
|
|
|
|
|
2016-02-05 15:33:17 +01:00
|
|
|
// 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();
|
|
|
|
|
2015-01-05 15:01:42 +01:00
|
|
|
var argv = require('yargs').argv,
|
|
|
|
gulp = require('gulp'),
|
|
|
|
concat = require('gulp-concat'),
|
2016-02-05 15:33:17 +01:00
|
|
|
cssnano = require('gulp-cssnano'),
|
2015-01-05 15:01:42 +01:00
|
|
|
gulpif = require('gulp-if'),
|
2015-02-08 22:37:55 +01:00
|
|
|
gettext = require('gulp-angular-gettext'),
|
2015-10-21 22:44:07 +02:00
|
|
|
jshint = require('gulp-jshint'),
|
2015-01-05 15:01:42 +01:00
|
|
|
mainBowerFiles = require('main-bower-files'),
|
|
|
|
path = require('path'),
|
2016-02-12 00:15:35 +01:00
|
|
|
rename = require('gulp-rename'),
|
2015-12-08 18:34:22 +01:00
|
|
|
through = require('through2'),
|
|
|
|
uglify = require('gulp-uglify'),
|
|
|
|
vsprintf = require('sprintf-js').vsprintf;
|
2015-01-05 15:01:42 +01:00
|
|
|
|
2015-12-08 18:34:22 +01:00
|
|
|
// Directory where the results go to
|
2015-01-05 15:01:42 +01:00
|
|
|
var output_directory = path.join('openslides', 'static');
|
|
|
|
|
2015-10-21 22:44:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default tasks to be run before start.
|
|
|
|
*/
|
|
|
|
|
2015-01-05 15:01:42 +01:00
|
|
|
// Catches all JavaScript files from all bower components and concats them to
|
|
|
|
// one file js/openslides-libs.js. In production mode the file is uglified.
|
2015-10-28 22:16:10 +01:00
|
|
|
gulp.task('js-libs', function () {
|
2015-01-05 15:01:42 +01:00
|
|
|
return gulp.src(mainBowerFiles({
|
|
|
|
filter: /\.js$/
|
|
|
|
}))
|
|
|
|
.pipe(concat('openslides-libs.js'))
|
|
|
|
.pipe(gulpif(argv.production, uglify()))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'js')));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Catches all CSS files from all bower components and concats them to one file
|
|
|
|
// css/openslides-libs.css. In production mode the file is uglified.
|
2015-10-28 22:16:10 +01:00
|
|
|
gulp.task('css-libs', function () {
|
2015-01-05 15:01:42 +01:00
|
|
|
return gulp.src(mainBowerFiles({
|
|
|
|
filter: /\.css$/
|
|
|
|
}))
|
|
|
|
.pipe(concat('openslides-libs.css'))
|
2016-02-08 23:02:09 +01:00
|
|
|
.pipe(gulpif(argv.production, cssnano({discardUnused: false})))
|
2015-01-05 15:01:42 +01:00
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'css')));
|
|
|
|
});
|
|
|
|
|
2015-01-17 13:31:06 +01:00
|
|
|
// Catches all font files from all bower components.
|
2015-10-21 22:44:07 +02:00
|
|
|
gulp.task('fonts-libs', function() {
|
2015-01-05 15:01:42 +01:00
|
|
|
return gulp.src(mainBowerFiles({
|
2015-06-21 19:39:36 +02:00
|
|
|
filter: /\.(eot)|(svg)|(ttf)|(woff)|(woff2)$/
|
2015-01-05 15:01:42 +01:00
|
|
|
}))
|
2015-01-17 13:31:06 +01:00
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'fonts')));
|
2015-01-05 15:01:42 +01:00
|
|
|
});
|
|
|
|
|
2016-02-12 00:15:35 +01:00
|
|
|
// Catches all skins files for TinyMCE editor.
|
|
|
|
gulp.task('tinymce-skins', function () {
|
|
|
|
return gulp.src(path.join('bower_components', 'tinymce-dist', 'skins', '**'))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'tinymce', 'skins')));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Catches all required i18n files for TinyMCE editor.
|
|
|
|
gulp.task('tinymce-i18n', function () {
|
|
|
|
return gulp.src([
|
|
|
|
'bower_components/tinymce-i18n/langs/cs.js',
|
|
|
|
'bower_components/tinymce-i18n/langs/de.js',
|
|
|
|
'bower_components/tinymce-i18n/langs/es.js',
|
|
|
|
'bower_components/tinymce-i18n/langs/fr_FR.js',
|
|
|
|
'bower_components/tinymce-i18n/langs/pt_PT.js',
|
|
|
|
])
|
|
|
|
.pipe(rename(function (path) {
|
2016-02-16 00:56:56 +01:00
|
|
|
if (path.basename === 'fr_FR') {
|
|
|
|
path.basename = 'fr';
|
|
|
|
} else if (path.basename === 'pt_PT') {
|
|
|
|
path.basename = 'pt';
|
|
|
|
}
|
2016-02-12 00:15:35 +01:00
|
|
|
}))
|
|
|
|
.pipe(gulpif(argv.production, uglify()))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'tinymce', 'i18n')));
|
2015-10-28 22:16:10 +01:00
|
|
|
});
|
|
|
|
|
2016-02-16 00:56:56 +01:00
|
|
|
// Combines all TinyMCE related tasks.
|
|
|
|
gulp.task('tinymce', ['tinymce-skins', 'tinymce-i18n'], function () {});
|
|
|
|
|
2015-12-08 18:34:22 +01:00
|
|
|
// Compiles translation files (*.po) to *.json and saves them in the directory
|
|
|
|
// openslides/static/i18n/.
|
|
|
|
gulp.task('translations', function () {
|
|
|
|
return gulp.src(path.join('openslides', 'locale', 'angular-gettext', '*.po'))
|
|
|
|
.pipe(gettext.compile({
|
|
|
|
format: 'json'
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'i18n')));
|
|
|
|
});
|
|
|
|
|
2015-10-21 22:44:07 +02:00
|
|
|
// Gulp default task. Runs all other tasks before.
|
2016-02-16 00:56:56 +01:00
|
|
|
gulp.task('default', ['js-libs', 'css-libs', 'fonts-libs', 'tinymce', 'translations'], function () {});
|
2015-10-21 22:44:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-08 18:34:22 +01:00
|
|
|
* Extra tasks that have to be called manually. Useful for development.
|
2015-10-21 22:44:07 +02:00
|
|
|
*/
|
|
|
|
|
2015-02-08 22:37:55 +01:00
|
|
|
// Extracts translatable strings using angular-gettext and saves them in file
|
|
|
|
// openslides/locale/angular-gettext/template-en.pot.
|
|
|
|
gulp.task('pot', function () {
|
2016-01-27 22:44:42 +01:00
|
|
|
return gulp.src([
|
|
|
|
'openslides/core/static/templates/*.html',
|
|
|
|
'openslides/*/static/templates/*/*.html',
|
|
|
|
'openslides/*/static/js/*/*.js',
|
|
|
|
])
|
2015-02-08 22:37:55 +01:00
|
|
|
.pipe(gettext.extract('template-en.pot', {}))
|
|
|
|
.pipe(gulp.dest('openslides/locale/angular-gettext/'));
|
|
|
|
});
|
|
|
|
|
2015-10-21 22:44:07 +02:00
|
|
|
// Checks JavaScript using JSHint
|
2015-12-08 18:34:22 +01:00
|
|
|
gulp.task('jshint', function () {
|
2016-02-16 00:56:56 +01:00
|
|
|
return gulp.src([
|
|
|
|
'gulpfile.js',
|
|
|
|
path.join( 'openslides', '*', 'static', '**', '*.js' ),
|
|
|
|
'!' + path.join( 'openslides', 'users', 'static', 'js', 'users', 'site.js' ),
|
|
|
|
'!' + path.join( 'openslides', 'motions', 'static', 'js', 'motions', 'base.js' ),
|
|
|
|
'!' + path.join( 'openslides', 'motions', 'static', 'js', 'motions', 'site.js' ),
|
|
|
|
])
|
2015-10-21 22:44:07 +02:00
|
|
|
.pipe(jshint())
|
|
|
|
.pipe(jshint.reporter('default'));
|
|
|
|
});
|
2015-12-08 18:34:22 +01:00
|
|
|
|
|
|
|
// Extracts names, URLs and licensed of all uses bower components and prints
|
|
|
|
// it to the console. This is useful to update the README.rst during release
|
|
|
|
// process.
|
|
|
|
gulp.task('bower-components-for-readme', function () {
|
|
|
|
var files = [];
|
|
|
|
return gulp.src([
|
|
|
|
path.join('bower_components', '*', 'bower.json'),
|
|
|
|
path.join('bower_components', '*', 'component.json'),
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
through.obj(
|
|
|
|
function (chunk, encoding, callback) {
|
|
|
|
files.push(chunk);
|
|
|
|
callback();
|
|
|
|
},
|
|
|
|
function (callback) {
|
|
|
|
// Extract JSON from bower.json or components.json file.
|
|
|
|
var extracted = [];
|
|
|
|
for (var index = 0; index < files.length; index++) {
|
|
|
|
extracted.push(JSON.parse(files[index].contents.toString()));
|
|
|
|
}
|
|
|
|
// Sort files.
|
|
|
|
extracted.sort(function (a, b) {
|
|
|
|
return a.name < b.name ? -1 : 1;
|
|
|
|
});
|
|
|
|
// Print out line for README.rst.
|
|
|
|
for (var index2 = 0; index2 < extracted.length; index2++) {
|
|
|
|
var data = [
|
|
|
|
extracted[index2].name,
|
|
|
|
extracted[index2].homepage,
|
|
|
|
extracted[index2].license,
|
|
|
|
];
|
|
|
|
console.log(vsprintf(' * `%s <%s>`_, License: %s', data));
|
|
|
|
}
|
|
|
|
// End stream without further file processing.
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|