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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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'),
|
2017-01-15 13:04:31 +01:00
|
|
|
inject = require('gulp-inject-string'),
|
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'),
|
2017-12-01 15:36:26 +01:00
|
|
|
rename = require('gulp-rename'),
|
|
|
|
sass = require('gulp-sass'),
|
2016-09-09 00:50:27 +02:00
|
|
|
sourcemaps = require('gulp-sourcemaps'),
|
|
|
|
templateCache = require('gulp-angular-templatecache'),
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-01-27 13:38:49 +01:00
|
|
|
// Catches all JavaScript files (excluded worker files) from all core apps and concats them to one
|
2016-09-09 00:50:27 +02:00
|
|
|
// file js/openslides.js. In production mode the file is uglified.
|
|
|
|
gulp.task('js', function () {
|
2017-01-27 13:38:49 +01:00
|
|
|
return gulp.src([
|
|
|
|
path.join('openslides', '*', 'static', 'js', '**', '*.js'),
|
|
|
|
'!' + path.join('openslides', 'core', 'static', 'js', 'core', 'pdf-worker.js'),
|
|
|
|
])
|
2016-09-09 00:50:27 +02:00
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(concat('openslides.js'))
|
|
|
|
.pipe(sourcemaps.write())
|
2016-10-04 14:08:07 +02:00
|
|
|
//TODO: Needs rework in all js files that uglified code works correctly.
|
|
|
|
//.pipe(gulpif(argv.production, uglify()))
|
2016-09-09 00:50:27 +02:00
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'js')));
|
|
|
|
});
|
|
|
|
|
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$/
|
|
|
|
}))
|
2016-09-09 00:50:27 +02:00
|
|
|
.pipe(sourcemaps.init())
|
2015-01-05 15:01:42 +01:00
|
|
|
.pipe(concat('openslides-libs.js'))
|
2016-09-09 00:50:27 +02:00
|
|
|
.pipe(sourcemaps.write())
|
2017-01-15 13:04:31 +01:00
|
|
|
.pipe(inject.prepend("/* set basepath of CKEditor */\n" +
|
|
|
|
"window.CKEDITOR_BASEPATH = '/static/ckeditor/';\n\n"))
|
2016-09-09 00:50:27 +02:00
|
|
|
.pipe(gulpif(argv.production, uglify()))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'js')));
|
|
|
|
});
|
|
|
|
|
2017-01-27 13:38:49 +01:00
|
|
|
// Catches all pdfmake files for pdf worker.
|
|
|
|
gulp.task('pdf-worker', function () {
|
|
|
|
return gulp.src([
|
|
|
|
path.join('openslides', 'core', 'static', 'js', 'core', 'pdf-worker.js'),
|
|
|
|
])
|
|
|
|
.pipe(gulpif(argv.production, uglify()))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'js', 'workers')));
|
|
|
|
});
|
|
|
|
// pdfmake files
|
|
|
|
gulp.task('pdf-worker-libs', function () {
|
|
|
|
return gulp.src([
|
|
|
|
path.join('bower_components', 'pdfmake', 'build', 'pdfmake.min.js'),
|
|
|
|
])
|
2018-01-30 16:12:02 +01:00
|
|
|
.pipe(gulpif(argv.production, uglify()))
|
|
|
|
.pipe(rename('pdf-worker-libs.js'))
|
2017-01-27 13:38:49 +01:00
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'js', 'workers')));
|
|
|
|
});
|
|
|
|
|
2016-09-09 00:50:27 +02:00
|
|
|
// Catches all template files from all core apps and concats them to one
|
|
|
|
// file js/openslides-templates.js. In production mode the file is uglified.
|
|
|
|
gulp.task('templates', function () {
|
|
|
|
return gulp.src(path.join('openslides', '*', 'static', 'templates', '**', '*.html'))
|
|
|
|
.pipe(templateCache('openslides-templates.js', {
|
|
|
|
module: 'OpenSlidesApp-templates',
|
|
|
|
standalone: true,
|
|
|
|
moduleSystem: 'IIFE',
|
|
|
|
transformUrl: function (url) {
|
|
|
|
var pathList = url.split(path.sep);
|
|
|
|
pathList.shift();
|
|
|
|
return pathList.join(path.sep);
|
|
|
|
},
|
|
|
|
}))
|
2015-01-05 15:01:42 +01:00
|
|
|
.pipe(gulpif(argv.production, uglify()))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'js')));
|
|
|
|
});
|
|
|
|
|
2017-12-01 15:36:26 +01:00
|
|
|
// Build the openslides-site.css file from the main file core/static/css/site.scss.
|
|
|
|
// Minimizes the outputfile if the production flag is given.
|
|
|
|
gulp.task('css-site', function () {
|
|
|
|
return gulp.src([
|
|
|
|
path.join('openslides', 'core', 'static', 'css', 'site.scss')
|
|
|
|
])
|
|
|
|
.pipe(sass().on('error', sass.logError))
|
|
|
|
.pipe(gulpif(argv.production, cssnano({safe: true})))
|
|
|
|
.pipe(rename('openslides-site.css'))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'css')));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build the openslides-projector.css file from the main file core/static/css/projector.scss.
|
|
|
|
// Minimizes the outputfile if the production flag is given.
|
|
|
|
gulp.task('css-projector', function () {
|
|
|
|
return gulp.src([
|
|
|
|
path.join('openslides', 'core', 'static', 'css', 'projector.scss')
|
|
|
|
])
|
|
|
|
.pipe(sass().on('error', sass.logError))
|
|
|
|
.pipe(gulpif(argv.production, cssnano({safe: true})))
|
|
|
|
.pipe(rename('openslides-projector.css'))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'css')));
|
|
|
|
});
|
|
|
|
|
2015-01-05 15:01:42 +01:00
|
|
|
// 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'))
|
2017-01-15 00:39:07 +01:00
|
|
|
.pipe(gulpif(argv.production, cssnano({safe: true})))
|
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({
|
2016-12-14 12:32:02 +01:00
|
|
|
filter: /\.(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-03-08 22:55:43 +01:00
|
|
|
// Catches image files for angular-chosen.
|
|
|
|
gulp.task('angular-chosen-img', function () {
|
|
|
|
return gulp.src(path.join('bower_components', 'chosen', '*.png'))
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'css')));
|
|
|
|
});
|
|
|
|
|
2016-12-16 21:02:12 +01:00
|
|
|
// CKEditor defaults
|
|
|
|
gulp.task('ckeditor-defaults', function () {
|
|
|
|
return gulp.src([
|
|
|
|
path.join('bower_components', 'ckeditor', 'styles.js'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'contents.css'),
|
|
|
|
])
|
2016-12-01 18:13:09 +01:00
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'ckeditor')));
|
2016-02-12 00:15:35 +01:00
|
|
|
});
|
|
|
|
|
2016-12-16 21:02:12 +01:00
|
|
|
// CKEditor skins
|
|
|
|
gulp.task('ckeditor-skins', function () {
|
2016-12-16 22:11:51 +01:00
|
|
|
return gulp.src(
|
|
|
|
[
|
|
|
|
path.join('bower_components', 'ckeditor', 'skins', 'moono-lisa', '**', '*'),
|
|
|
|
],
|
|
|
|
{
|
|
|
|
base: path.join('bower_components', 'ckeditor', 'skins')
|
|
|
|
}
|
|
|
|
)
|
2016-12-16 21:02:12 +01:00
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'ckeditor', 'skins')));
|
|
|
|
});
|
|
|
|
|
|
|
|
// CKEditor plugins
|
|
|
|
gulp.task('ckeditor-plugins', function () {
|
2016-12-16 22:11:51 +01:00
|
|
|
return gulp.src(
|
|
|
|
[
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'clipboard', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'colorbutton', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'dialog', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'find', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'image', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'justify', '**', '*'),
|
2017-01-06 11:08:32 +01:00
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'link', '**', '*'),
|
2016-12-16 22:11:51 +01:00
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'liststyle', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'magicline', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'pastefromword', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'panelbutton', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'showblocks', '**', '*'),
|
2017-01-06 11:08:32 +01:00
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'specialchar', '**', '*'),
|
2016-12-16 22:11:51 +01:00
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'sourcedialog', '**', '*'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'plugins', 'table', '**', '*'),
|
|
|
|
],
|
|
|
|
{
|
|
|
|
base: path.join('bower_components', 'ckeditor', 'plugins')
|
|
|
|
}
|
|
|
|
)
|
2016-12-16 21:02:12 +01:00
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'ckeditor', 'plugins')));
|
|
|
|
});
|
|
|
|
|
|
|
|
// CKEditor languages
|
|
|
|
gulp.task('ckeditor-lang', function () {
|
|
|
|
return gulp.src([
|
|
|
|
path.join('bower_components', 'ckeditor', 'lang', 'en.js'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'lang', 'de.js'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'lang', 'pt.js'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'lang', 'es.js'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'lang', 'fr.js'),
|
|
|
|
path.join('bower_components', 'ckeditor', 'lang', 'cs.js'),
|
2017-03-05 22:22:23 +01:00
|
|
|
path.join('bower_components', 'ckeditor', 'lang', 'ru.js'),
|
2016-12-16 21:02:12 +01:00
|
|
|
])
|
|
|
|
.pipe(gulp.dest(path.join(output_directory, 'ckeditor', 'lang')));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Combines all CKEditor related tasks.
|
|
|
|
gulp.task('ckeditor', ['ckeditor-defaults', 'ckeditor-skins', 'ckeditor-plugins', 'ckeditor-lang'], function () {});
|
2016-02-16 00:56:56 +01:00
|
|
|
|
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-12-16 21:02:12 +01:00
|
|
|
gulp.task('default', [
|
|
|
|
'js',
|
|
|
|
'js-libs',
|
2017-01-27 13:38:49 +01:00
|
|
|
'pdf-worker',
|
|
|
|
'pdf-worker-libs',
|
2016-12-16 21:02:12 +01:00
|
|
|
'templates',
|
2017-12-01 15:36:26 +01:00
|
|
|
'css-site',
|
|
|
|
'css-projector',
|
2016-12-16 21:02:12 +01:00
|
|
|
'css-libs',
|
|
|
|
'fonts-libs',
|
|
|
|
'ckeditor',
|
|
|
|
'angular-chosen-img',
|
|
|
|
'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
|
|
|
*/
|
|
|
|
|
2016-09-09 00:50:27 +02:00
|
|
|
// Watches changes in JavaScript and templates.
|
2017-12-01 15:36:26 +01:00
|
|
|
gulp.task('watch', ['js', 'templates', 'pdf-worker', 'css-site', 'css-projector'], function () {
|
2017-02-01 16:53:01 +01:00
|
|
|
gulp.watch([
|
|
|
|
path.join('openslides', '*', 'static', 'js', '**', '*.js'),
|
|
|
|
'!' + path.join('openslides', 'core', 'static', 'js', 'core', 'pdf-worker.js')
|
|
|
|
], ['js']);
|
2016-09-09 00:50:27 +02:00
|
|
|
gulp.watch(path.join('openslides', '*', 'static', 'templates', '**', '*.html'), ['templates']);
|
2017-02-01 16:53:01 +01:00
|
|
|
gulp.watch(path.join('openslides', 'core', 'static', 'js', 'core', 'pdf-worker.js'), ['pdf-worker']);
|
2017-12-01 15:36:26 +01:00
|
|
|
// We cannot differentiate between all scss files which belong to each realm. So if
|
|
|
|
// one scss file changes the site and projector css is rebuild.
|
|
|
|
gulp.watch(path.join('openslides', '*', 'static', 'css', '**', '*.scss'), ['css-site', 'css-projector']);
|
2016-09-09 00:50:27 +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',
|
2017-02-21 15:45:43 +01:00
|
|
|
'openslides/*/static/templates/**/*.html',
|
2016-01-27 22:44:42 +01:00
|
|
|
'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' ),
|
|
|
|
])
|
2015-10-21 22:44:07 +02:00
|
|
|
.pipe(jshint())
|
2016-03-02 16:51:40 +01:00
|
|
|
.pipe(jshint.reporter('default'))
|
|
|
|
.pipe(jshint.reporter('fail'));
|
2015-10-21 22:44:07 +02:00
|
|
|
});
|
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'),
|
2016-03-21 20:22:57 +01:00
|
|
|
path.join('bower_components', '*', 'package.json'),
|
2015-12-08 18:34:22 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|