Skip to content

Commit

Permalink
Merge pull request #327 from nextcloud/cleanup/js_minifying
Browse files Browse the repository at this point in the history
Bundle and minify vendor files
  • Loading branch information
georgehrke authored Feb 12, 2017
2 parents 2631e42 + b34e0a1 commit 9112285
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 79 deletions.
22 changes: 10 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,18 @@ appstore:
"l10n" \
"templates" \
"timezones" \
"css/public/app.css" \
"css/public/app.min.css" \
"css/public/app.min.css.map" \
"css/public/vendor.css" \
"css/public/vendor.min.css" \
"css/public/vendor.min.css.map" \
"js/public/app.js" \
"js/public/app.min.js" \
"js/vendor/fullcalendar/dist/fullcalendar.css" \
"js/vendor/jquery-timepicker/jquery.ui.timepicker.css" \
"js/vendor/jquery-timepicker/jquery.ui.timepicker.js" \
"js/vendor/ical.js/build/ical.js" \
"js/vendor/jstzdetect/jstz.js" \
"js/vendor/angular/angular.js" \
"js/vendor/angular-bootstrap/ui-bootstrap.js" \
"js/vendor/angular-bootstrap/ui-bootstrap-tpls.js" \
"js/vendor/fullcalendar/dist/fullcalendar.js" \
"js/vendor/fullcalendar/dist/locale-all.js" \
"js/vendor/davclient.js/lib/client.js" \
"js/vendor/hsl_rgb_converter/converter.js" \
"js/public/app.min.js.map" \
"js/public/vendor.js" \
"js/public/vendor.min.js" \
"js/public/vendor.min.js.map" \
"js/vendor/autosize/dist/autosize.js" \
"COPYING" \
"CHANGELOG.md" \
Expand Down
1 change: 0 additions & 1 deletion js/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"jquery-timepicker": "883bb2cd94",
"jstzdetect": "1.0.6",
"ical.js": "1.2.2",
"davclient.js": "evert/davclient.js",
"fullcalendar": "3.1.0",
"hsl_rgb_converter": "https://github.com/kayellpeee/hsl_rgb_converter.git",
"autosize": "^3.0.20"
Expand Down
95 changes: 82 additions & 13 deletions js/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ const gulp = require('gulp'),
KarmaServer = require('karma').Server,
concat = require('gulp-concat'),
wrap = require('gulp-wrap'),
strip = require('gulp-strip-banner'),
strip = require('gulp-strip-comments'),
stripCSS = require('gulp-strip-css-comments'),
babel = require('gulp-babel'),
stylelint = require('gulp-stylelint'),
sourcemaps = require('gulp-sourcemaps');
const gulpsync = require('gulp-sync')(gulp);

// configure
const buildTarget = 'app.min.js';
const cssBuildTarget = 'app.min.css';
const buildTarget = 'app.js';
const buildTargetMin = 'app.min.js';
const cssBuildTarget = 'app.css';
const cssBuildTargetMin = 'app.min.css';
const vendorTarget = 'vendor.js';
const vendorTargetMin = 'vendor.min.js';
const vendorCssTarget = 'vendor.css';
const vendorCssTargetMin = 'vendor.min.css';
const karmaConfig = __dirname + '/../tests/js/config/karma.js';
const destinationFolder = __dirname + '/public/';
const cssDestinationFolder = __dirname + '/../css/public/';
Expand All @@ -42,20 +50,40 @@ const jsSources = [
const cssSources = [
'../css/app/*.css'
];
const vendorSources = [
'vendor/angular/angular.js',
'vendor/angular-bootstrap/ui-bootstrap-tpls.js',
'vendor/fullcalendar/dist/fullcalendar.js',
'vendor/fullcalendar/dist/locale-all.js',
'licenses/hsl_rgb_converter.js',
'vendor/hsl_rgb_converter/converter.js',
'vendor/ical.js/build/ical.js',
'vendor/jquery-timepicker/jquery.ui.timepicker.js',
'vendor/jstzdetect/jstz.js',
];
const vendorCssSources = [
'vendor/fullcalendar/dist/fullcalendar.css',
'licenses/jquery.timepicker.css',
'vendor/jquery-timepicker/jquery.ui.timepicker.css'
];

const testSources = ['../tests/js/unit/**/*.js'];
const watchSources = jsSources.concat(testSources).concat(['*.js']);
const lintSources = watchSources;

// tasks
gulp.task('default', ['lint', 'csslint'], () => {
// build css
gulp.task('default', ['lint', 'csslint', 'buildS', 'vendor']);
gulp.task('build', ['lint', 'csslint', 'buildS']);

gulp.task('buildS', gulpsync.sync(['buildSources', 'minifySources']));
gulp.task('vendor', gulpsync.sync(['buildVendor', 'minifyVendor']));

gulp.task('buildSources', () => {
gulp.src(cssSources)
.pipe(strip())
.pipe(sourcemaps.init({identityMap: true}))
.pipe(stripCSS({
preserve: false
}))
.pipe(concat(cssBuildTarget))
.pipe(uglifyCSS())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(cssDestinationFolder));

return gulp.src(jsSources)
Expand All @@ -67,15 +95,56 @@ gulp.task('default', ['lint', 'csslint'], () => {
}))
.pipe(ngAnnotate())
.pipe(strip())
.pipe(sourcemaps.init({identityMap: true}))
.pipe(concat(buildTarget))
.pipe(wrap(`(function(angular, $, oc_requesttoken, undefined){
'use strict';
<%= contents %>
})(angular, jQuery, oc_requesttoken);`))
.pipe(gulp.dest(destinationFolder));
});

gulp.task('minifySources', () => {
gulp.src([cssDestinationFolder + cssBuildTarget])
.pipe(concat(cssBuildTargetMin))
.pipe(sourcemaps.init({identityMap: true, largeFile: true}))
.pipe(uglifyCSS())
.pipe(sourcemaps.write('./', {includeContent: false}))
.pipe(gulp.dest(cssDestinationFolder));

return gulp.src([destinationFolder + buildTarget])
.pipe(concat(buildTargetMin))
.pipe(sourcemaps.init({identityMap: true, largeFile: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./', {includeContent: false}))
.pipe(gulp.dest(destinationFolder));
});

gulp.task('buildVendor', () => {
gulp.src(vendorCssSources)
.pipe(concat(vendorCssTarget))
.pipe(gulp.dest(cssDestinationFolder));

return gulp.src(vendorSources)
.pipe(concat(vendorTarget))
.pipe(gulp.dest(destinationFolder));
});

gulp.task('minifyVendor', () => {
gulp.src([cssDestinationFolder + vendorCssTarget])
.pipe(concat(vendorCssTargetMin))
.pipe(sourcemaps.init({identityMap: true, largeFile: true}))
.pipe(stripCSS({
preserve: false
}))
.pipe(uglifyCSS())
.pipe(sourcemaps.write('./', {includeContent: false}))
.pipe(gulp.dest(cssDestinationFolder));

return gulp.src([destinationFolder + vendorTarget])
.pipe(concat(vendorTargetMin))
.pipe(sourcemaps.init({identityMap: true, largeFile: true}))
.pipe(strip())
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(sourcemaps.write('./', {includeContent: false}))
.pipe(gulp.dest(destinationFolder));
});

Expand Down
5 changes: 5 additions & 0 deletions js/licenses/hsl_rgb_converter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
HSL RGB Converter
author: Keenan Lidral-Porter
license: ISC
*/
9 changes: 9 additions & 0 deletions js/licenses/jquery.timepicker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* jQuery UI Timepicker
*
* Copyright 2010-2013, Francois Gelinas
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://fgelinas.com/code/timepicker
*/
4 changes: 3 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
"gulp-jshint": "^2.0.4",
"gulp-ng-annotate": "^2.0.0",
"gulp-sourcemaps": "^2.4.0",
"gulp-strip-banner": "0.0.2",
"gulp-strip-comments": "^2.4.3",
"gulp-strip-css-comments": "^1.2.0",
"gulp-stylelint": "^3.7.0",
"gulp-sync": "^0.1.4",
"gulp-uglify": "^2.0.0",
"gulp-uglifycss": "^1.0.6",
"gulp-wrap": "^0.13.0",
Expand Down
79 changes: 41 additions & 38 deletions js/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1051,17 +1051,13 @@ date-now@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"

dateformat@^1.0.6:
dateformat@^1.0.11, dateformat@^1.0.6:
version "1.0.12"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-1.0.12.tgz#9f124b67594c937ff706932e4a642cca8dbbfee9"
dependencies:
get-stdin "^4.0.1"
meow "^3.3.0"

dateformat@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-2.0.0.tgz#2743e3abb5c3fc2462e527dca445e04e9f4dee17"

[email protected]:
version "0.0.4"
resolved "https://registry.yarnpkg.com/debug-fabulous/-/debug-fabulous-0.0.4.tgz#fa071c5d87484685424807421ca4b16b0b1a0763"
Expand Down Expand Up @@ -1090,6 +1086,12 @@ decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"

decomment@^0.8.6:
version "0.8.7"
resolved "https://registry.yarnpkg.com/decomment/-/decomment-0.8.7.tgz#248f2116f6ce3a8e8dd1b63e5b35aba5ca054ca5"
dependencies:
esprima "3.1"

deep-extend@^0.4.1, deep-extend@~0.4.0:
version "0.4.1"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.1.tgz#efe4113d08085f4e6f9687759810f807469e2253"
Expand Down Expand Up @@ -1307,6 +1309,10 @@ [email protected], esprima@^2.6.0, esprima@^2.7.1:
version "2.7.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"

[email protected]:
version "3.1.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"

estraverse@^1.9.1:
version "1.9.3"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.9.3.tgz#af67f2dc922582415950926091a4005d29c9bb44"
Expand Down Expand Up @@ -1506,12 +1512,6 @@ form-data@~2.1.1:
combined-stream "^1.0.5"
mime-types "^2.1.12"

fs-access@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/fs-access/-/fs-access-1.0.1.tgz#d6a87f262271cefebec30c553407fb995da8777a"
dependencies:
null-check "^1.0.0"

fs-exists-sync@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add"
Expand Down Expand Up @@ -1824,13 +1824,21 @@ gulp-sourcemaps@^2.4.0:
through2 "2.X"
vinyl "1.X"

gulp-strip-[email protected]:
version "0.0.2"
resolved "https://registry.yarnpkg.com/gulp-strip-banner/-/gulp-strip-banner-0.0.2.tgz#8d3c046552c13d2d844692349f2db985c61c952b"
gulp-strip-comments@^2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/gulp-strip-comments/-/gulp-strip-comments-2.4.3.tgz#e219b7c7beac1aba6c36e0aff1db7c5ae2c1c1b0"
dependencies:
gulp-util "^3.0.1"
strip-comments "^0.3.2"
through2 "^0.6.1"
decomment "^0.8.6"
gulp-util "3.0.7"
through2 "^2.0.1"

gulp-strip-css-comments@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/gulp-strip-css-comments/-/gulp-strip-css-comments-1.2.0.tgz#fe79863ce32f50dd4cbe8d0db56f476c86cfb9b8"
dependencies:
gulp-util "^3.0.0"
strip-css-comments "^3.0.0"
through2 "^2.0.0"

gulp-stylelint@^3.7.0:
version "3.7.0"
Expand All @@ -1844,6 +1852,10 @@ gulp-stylelint@^3.7.0:
stylelint "^7.7.0"
through2 "^2.0.3"

gulp-sync@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/gulp-sync/-/gulp-sync-0.1.4.tgz#22eb9528f95737d4715c01272180a08f24133db5"

gulp-uglify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/gulp-uglify/-/gulp-uglify-2.0.0.tgz#cbe4aae4fe0b6bdd760335bc46f200fff699c4af"
Expand All @@ -1865,15 +1877,15 @@ gulp-uglifycss@^1.0.6:
through2 "~2.0.1"
uglifycss "~0.0.20"

gulp-util@^3.0.0, gulp-util@^3.0.1, gulp-util@^3.0.3, gulp-util@^3.0.7, gulp-util@~3.0.7:
version "3.0.8"
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.8.tgz#0054e1e744502e27c04c187c3ecc505dd54bbb4f"
[email protected].7, gulp-util@^3.0.0, gulp-util@^3.0.3, gulp-util@^3.0.7, gulp-util@~3.0.7:
version "3.0.7"
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.7.tgz#78925c4b8f8b49005ac01a011c557e6218941cbb"
dependencies:
array-differ "^1.0.0"
array-uniq "^1.0.2"
beeper "^1.0.0"
chalk "^1.0.0"
dateformat "^2.0.0"
dateformat "^1.0.11"
fancy-log "^1.1.0"
gulplog "^1.0.0"
has-gulplog "^0.1.0"
Expand Down Expand Up @@ -2420,13 +2432,6 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.3.6"

karma-chrome-launcher@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-2.0.0.tgz#c2790c5a32b15577d0fff5a4d5a2703b3b439c25"
dependencies:
fs-access "^1.0.0"
which "^1.2.1"

karma-coverage@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/karma-coverage/-/karma-coverage-1.1.1.tgz#5aff8b39cf6994dc22de4c84362c76001b637cf6"
Expand Down Expand Up @@ -2991,10 +2996,6 @@ npmlog@^4.0.1:
gauge "~2.7.1"
set-blocking "~2.0.0"

null-check@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/null-check/-/null-check-1.0.0.tgz#977dffd7176012b9ec30d2a39db5cf72a0439edd"

num2fraction@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/num2fraction/-/num2fraction-1.2.2.tgz#6f682b6a027a4e9ddfa4564cd2589d1d4e669ede"
Expand Down Expand Up @@ -3401,7 +3402,7 @@ read-pkg@^1.0.0:
normalize-package-data "^2.3.2"
path-type "^1.0.0"

[email protected], readable-stream@~1.1.9:
[email protected], readable-stream@^1.0.33, readable-stream@~1.1.9:
version "1.1.14"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9"
dependencies:
Expand All @@ -3410,7 +3411,7 @@ [email protected], readable-stream@~1.1.9:
isarray "0.0.1"
string_decoder "~0.10.x"

"readable-stream@>=1.0.33-1 <1.1.0-0", readable-stream@^1.0.33, readable-stream@~1.0.2:
"readable-stream@>=1.0.33-1 <1.1.0-0", readable-stream@~1.0.2:
version "1.0.34"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c"
dependencies:
Expand Down Expand Up @@ -3937,9 +3938,11 @@ strip-bom@^2.0.0:
dependencies:
is-utf8 "^0.2.0"

strip-comments@^0.3.2:
version "0.3.4"
resolved "https://registry.yarnpkg.com/strip-comments/-/strip-comments-0.3.4.tgz#e1cb91b86de432540d13db2da8e81ae0d4e2ecbf"
strip-css-comments@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-css-comments/-/strip-css-comments-3.0.0.tgz#7a5625eff8a2b226cf8947a11254da96e13dae89"
dependencies:
is-regexp "^1.0.0"

strip-indent@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -4327,7 +4330,7 @@ void-elements@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"

which@^1.1.1, which@^1.2.1, which@^1.2.12, which@~1.2.10:
which@^1.1.1, which@^1.2.12, which@~1.2.10:
version "1.2.12"
resolved "https://registry.yarnpkg.com/which/-/which-1.2.12.tgz#de67b5e450269f194909ef23ece4ebe416fa1192"
dependencies:
Expand Down
Loading

0 comments on commit 9112285

Please sign in to comment.