Fixed production asset management

This commit is contained in:
buddha87 2016-08-23 22:29:34 +02:00
parent 600d587cc8
commit 926a14baa9
12 changed files with 132 additions and 253 deletions

View File

@ -2,12 +2,11 @@ module.exports = function (grunt) {
var uglifyAssetcfg = {};
uglifyAssetcfg[grunt.option('to')] = grunt.option('from');
var cssMinAssetcfg = {};
cssMinAssetcfg[grunt.option('to')] = [grunt.option('from')];
grunt.log.write(grunt.option('from'));
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
@ -35,6 +34,14 @@ module.exports = function (grunt) {
}
},
assets: {
options: {
preserveComments: /^!|@preserve|@license|@cc_on/i,
//preserveComments: 'all',
// ASCIIOnly: true,
/*beautify: {
"ascii_only": true
},*/
},
files: uglifyAssetcfg
}
},
@ -51,14 +58,13 @@ module.exports = function (grunt) {
}
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('default', ['watch']);
grunt.registerTask('build', ['concat', 'uglify', 'clean']);
};

View File

@ -4,28 +4,27 @@
*/
humhub.initModule('client', function (module, require, $) {
var object = require('util').object;
var init = function() {
var init = function () {
/*$.ajaxPrefilter('html', function(options, originalOptions, jqXHR) {
debugger;
console.log(options);
var pjaxHandler = options.success;
options.success = function(result, textStatus, xhr) {
console.log(result);
pjaxHandler(result, textStatus, xhr);
};
options.error = function(err) {
debugger;
};
});
///TEESSS
$.pjax.defaults.maxCacheLength = 0;
$('a.dashboard').on('click', function(evt) {
debugger;
evt.preventDefault();
$.pjax({url:$(this).attr('href'), container: '#main-content', maxCacheLength:0, timeout:2000});
});*/
debugger;
console.log(options);
var pjaxHandler = options.success;
options.success = function(result, textStatus, xhr) {
console.log(result);
pjaxHandler(result, textStatus, xhr);
};
options.error = function(err) {
debugger;
};
});
$.pjax.defaults.maxCacheLength = 0;
$('a.dashboard').on('click', function(evt) {
debugger;
evt.preventDefault();
$.pjax({url:$(this).attr('href'), container: '#main-content', maxCacheLength:0, timeout:2000});
});*/
}
/**
* Response Wrapper Object for easily accessing common data
@ -51,19 +50,19 @@ humhub.initModule('client', function (module, require, $) {
Response.prototype.isError = function () {
return this.getStatus() > 0 || this.getErrors().length;
};
Response.prototype.getStatus = function () {
return (this.status) ? this.status : -1;
};
Response.prototype.getFirstError = function() {
Response.prototype.getStatus = function () {
return (this.status) ? this.status : -1;
};
Response.prototype.getFirstError = function () {
var errors = this.getErrors();
if(errors.length) {
if (errors.length) {
return errors[0];
}
};
Response.prototype.setAjaxError = function(xhr, errorThrown, textStatus,data , status) {
Response.prototype.setAjaxError = function (xhr, errorThrown, textStatus, data, status) {
this.xhr = xhr;
this.textStatus = textStatus;
this.status = status || xhr.status;
@ -92,7 +91,7 @@ humhub.initModule('client', function (module, require, $) {
ajax($form.attr('action'), cfg);
};
var post = function(path, cfg) {
var post = function (path, cfg) {
var cfg = cfg || {};
cfg.type = 'POST';
cfg.method = 'POST';
@ -100,9 +99,9 @@ humhub.initModule('client', function (module, require, $) {
};
var ajax = function (path, cfg) {
return new Promise(function(resolve, reject) {
var promise = new Promise(function (resolve, reject) {
cfg = cfg || {};
//Wrap the actual error handler with our own and call
var errorHandler = cfg.error;
var error = function (xhr, textStatus, errorThrown, data, status) {
@ -119,25 +118,35 @@ humhub.initModule('client', function (module, require, $) {
var success = function (json, textStatus, xhr) {
var response = new Response(json);
if (response.isError()) { //Application errors
return error(xhr, "application", response.getErrors(), json, response.getStatus() );
return error(xhr, "application", response.getErrors(), json, response.getStatus());
} else if (successHandler) {
response.textStatus = textStatus;
response.xhr = xhr;
successHandler(response);
}
resolve(response);
promise.then(function() {
// If content with <link> tags are inserted in resolve, the ajaxComplete handler in yii.js
// makes shure redundant stylesheets are removed.
$(document).trigger('ajaxComplete');
});
};
//Overwriting the handler with our wrapper handler
cfg.success = success;
cfg.error = error;
cfg.url = path;
//Setting some default values
cfg.dataType = cfg.dataType || "json";
$.ajax(cfg);
});
return promise;
};
module.export({
@ -150,24 +159,24 @@ humhub.initModule('client', function (module, require, $) {
/**
*
var handleResponse = function (json, callback) {
var response = new Response(json);
if (json.content) {
response.$content = $('<div>' + json.content + '</div>');
//Find all remote scripts and remove them from the partial
var scriptSrcArr = [];
response.$content.find('script[src]').each(function () {
scriptSrcArr.push($(this).attr('src'));
$(this).remove();
});
//Load the remote scripts synchronously only if they are not already loaded.
scripts.loadOnceSync(scriptSrcArr, function () {
callback(response);
});
} else {
callback(response);
}
};
var handleResponse = function (json, callback) {
var response = new Response(json);
if (json.content) {
response.$content = $('<div>' + json.content + '</div>');
//Find all remote scripts and remove them from the partial
var scriptSrcArr = [];
response.$content.find('script[src]').each(function () {
scriptSrcArr.push($(this).attr('src'));
$(this).remove();
});
//Load the remote scripts synchronously only if they are not already loaded.
scripts.loadOnceSync(scriptSrcArr, function () {
callback(response);
});
} else {
callback(response);
}
};
*/

View File

@ -8,90 +8,91 @@
* @param {type} param1
* @param {type} param2
*/
humhub.initModule('scripts', function(module, require, $) {
humhub.initModule('scripts', function (module, require, $) {
var _scripts = [];
$(document).ready(function() {
$('script[src]').each(function() {
var init = function () {
$('script[src]').each(function () {
addScript(cutTimestamp($(this).attr('src')));
});
});
var cutTimestamp = function(url) {
};
var cutTimestamp = function (url) {
return url.split('?')[0];
};
var loadOnce = function(urls) {
var loadOnce = function (urls) {
urls = $.isArray(urls) ? urls : [urls];
var promises = [];
$.each(urls, function(index, scriptUrl) {
if(!containsScript(scriptUrl)) {
$.each(urls, function (index, scriptUrl) {
if (!containsScript(scriptUrl)) {
addScript(scriptUrl);
promises.push($.getScript(scriptUrl));
}
});
promises.push($.Deferred(function( deferred ){
$( deferred.resolve );
promises.push($.Deferred(function (deferred) {
$(deferred.resolve);
}));
return $.when.apply(null, promises);
};
var loadOnceSync = function(urls, callback) {
var loadOnceSync = function (urls, callback) {
var deferred = new $.Deferred();
var promise = deferred.promise();
$.each(urls, function(index, scriptUrl) {
if(!containsScript(scriptUrl)) {
$.each(urls, function (index, scriptUrl) {
if (!containsScript(scriptUrl)) {
// we need an immediately invoked function expression to capture
// the current value of the iteration
(function(url) {
(function (url) {
// chaining the promises,
// by assigning the new promise to the variable
// and returning a promise from the callback
promise = promise.then(function() {
promise = promise.then(function () {
addScript(url);
return $.getScript(url).done(function(){});
return $.getScript(url).done(function () {});
});
}(scriptUrl));
}
});
promise.done(function() {
}
});
promise.done(function () {
callback.apply();
});
promise.fail(function(arg) {
console.error('Failed loading scripts for: '+arg);
//Call callback anyway
callback.apply();
promise.fail(function (arg) {
console.error('Failed loading scripts for: ' + arg);
//Call callback anyway
callback.apply();
});
deferred.resolve();
};
var containsScript = function(url) {
var containsScript = function (url) {
var result = false;
url = cutTimestamp(url);
$.each(_scripts, function(index, scriptUrl) {
if(scriptUrl === url) {
$.each(_scripts, function (index, scriptUrl) {
if (scriptUrl === url) {
result = true;
return false; //leave each
}
});
return result;
};
var addScript = function(url) {
var addScript = function (url) {
url = cutTimestamp(url);
_scripts.push(url);
};
module.export({
loadOnce: loadOnce,
loadOnceSync: loadOnceSync,
containsScript: containsScript,
addScript:addScript
addScript: addScript,
init: init
});
});

View File

@ -1,4 +1,4 @@
/* jquery.nicescroll 3.6.6 InuYaksa*2015 MIT http://nicescroll.areaaperta.com */(function(e){"function"===typeof define&&define.amd?define(["jquery"],e):"object"===typeof exports?module.exports=e(require("jquery")):e(jQuery)})(function(e){var A=!1,E=!1,O=0,P=2E3,z=0,I=["webkit","ms","moz","o"],u=window.requestAnimationFrame||!1,v=window.cancelAnimationFrame||!1;if(!u)for(var Q in I){var F=I[Q];u||(u=window[F+"RequestAnimationFrame"]);v||(v=window[F+"CancelAnimationFrame"]||window[F+"CancelRequestAnimationFrame"])}var x=window.MutationObserver||window.WebKitMutationObserver||
/*! jquery.nicescroll 3.6.6 InuYaksa*2015 MIT http://nicescroll.areaaperta.com */(function(e){"function"===typeof define&&define.amd?define(["jquery"],e):"object"===typeof exports?module.exports=e(require("jquery")):e(jQuery)})(function(e){var A=!1,E=!1,O=0,P=2E3,z=0,I=["webkit","ms","moz","o"],u=window.requestAnimationFrame||!1,v=window.cancelAnimationFrame||!1;if(!u)for(var Q in I){var F=I[Q];u||(u=window[F+"RequestAnimationFrame"]);v||(v=window[F+"CancelAnimationFrame"]||window[F+"CancelRequestAnimationFrame"])}var x=window.MutationObserver||window.WebKitMutationObserver||
!1,J={zindex:"auto",cursoropacitymin:0,cursoropacitymax:1,cursorcolor:"#424242",cursorwidth:"5px",cursorborder:"1px solid #fff",cursorborderradius:"5px",scrollspeed:60,mousescrollstep:24,touchbehavior:!1,hwacceleration:!0,usetransition:!0,boxzoom:!1,dblclickzoom:!0,gesturezoom:!0,grabcursorenabled:!0,autohidemode:!0,background:"",iframeautoresize:!0,cursorminheight:32,preservenativescrolling:!0,railoffset:!1,railhoffset:!1,bouncescroll:!0,spacebarenabled:!0,railpadding:{top:0,right:0,left:0,bottom:0},
disableoutline:!0,horizrailenabled:!0,railalign:"right",railvalign:"bottom",enabletranslate3d:!0,enablemousewheel:!0,enablekeyboard:!0,smoothscroll:!0,sensitiverail:!0,enablemouselockapi:!0,cursorfixedheight:!1,directionlockdeadzone:6,hidecursordelay:400,nativeparentscrolling:!0,enablescrollonselection:!0,overflowx:!0,overflowy:!0,cursordragspeed:.3,rtlmode:"auto",cursordragontouch:!1,oneaxismousemode:"auto",scriptpath:function(){var e=document.getElementsByTagName("script"),e=e.length?e[e.length-
1].src.split("?")[0]:"";return 0<e.split("/").length?e.split("/").slice(0,-1).join("/")+"/":""}(),preventmultitouchscrolling:!0},G=!1,R=function(){if(G)return G;var e=document.createElement("DIV"),c=e.style,h=navigator.userAgent,n=navigator.platform,d={haspointerlock:"pointerLockElement"in document||"webkitPointerLockElement"in document||"mozPointerLockElement"in document};d.isopera="opera"in window;d.isopera12=d.isopera&&"getUserMedia"in navigator;d.isoperamini="[object OperaMini]"===Object.prototype.toString.call(window.operamini);

View File

@ -2,6 +2,7 @@
"name": "humhub",
"devDependencies": {
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-copy": "*",
"grunt-contrib-concat": "^1.0.0",
"grunt-contrib-uglify": "^1.0.1",
"grunt-contrib-watch": "^1.0.0",

View File

@ -33,9 +33,10 @@ class AppAsset extends AssetBundle
//'js/bootstrap3-wysihtml5.js',
'js/desktop-notify-min.js',
'js/desktop-notify-config.js',
'js/jquery.nicescroll.min.js',
'resources/file/fileuploader.js',
'resources/user/userpicker.js',
'js/jquery.nicescroll.min.js',
];
public $depends = [

View File

@ -45,6 +45,7 @@ class CoreApiAsset extends AssetBundle
'js/humhub/legacy/app.js',
'js/humhub/humhub.core.js',
'js/humhub/humhub.util.js',
//'js/humhub/humhub.scripts.js',
'js/humhub/humhub.additions.js',
'js/humhub/humhub.client.js',
'js/humhub/humhub.ui.js',

View File

@ -26,7 +26,7 @@ class JqueryPjaxAsset extends AssetBundle
/**
* @inheritdoc
*/
public $js = ['jquery.pjax.min.js'];
public $js = ['jquery.pjax.js'];
/**
* @inheritdoc

View File

@ -1,7 +0,0 @@
<?php
/**
* This file is generated by the "yii asset" command.
* DO NOT MODIFY THIS FILE DIRECTLY.
* @version 2016-08-20 20:22:58
*/
return [];

View File

@ -1,138 +0,0 @@
<?php
/**
* This file is generated by the "yii asset" command.
* DO NOT MODIFY THIS FILE DIRECTLY.
* @version 2016-08-20 20:43:34
*/
return [
'all' => [
'class' => 'yii\\web\\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => [
'js/all-79ed2e2e2a9df9d9577d0964f06869e9.js',
],
'css' => [
'css/all-3df06579f2945d9873aa4ec9736097a2.css',
],
],
'yii\\web\\JqueryAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'yii\\web\\YiiAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'yii\\web\\JqueryAsset',
'all',
],
],
'yii\\bootstrap\\BootstrapAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'yii\\bootstrap\\BootstrapPluginAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'yii\\web\\JqueryAsset',
'yii\\bootstrap\\BootstrapAsset',
'all',
],
],
'humhub\\assets\\BluebirdAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'humhub\\assets\\JqueryTimeAgoAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'humhub\\assets\\JqueryWidgetAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'humhub\\assets\\JqueryColorAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'humhub\\assets\\JqueryPlaceholderAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'humhub\\assets\\FontAwesomeAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'humhub\\assets\\BlueimpFileUploadAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'humhub\\assets\\JqueryWidgetAsset',
'all',
],
],
'humhub\\assets\\JqueryHighlightAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'all',
],
],
'humhub\\assets\\AppAsset' => [
'sourcePath' => null,
'js' => [],
'css' => [],
'depends' => [
'yii\\web\\YiiAsset',
'yii\\bootstrap\\BootstrapAsset',
'yii\\bootstrap\\BootstrapPluginAsset',
'humhub\\assets\\BluebirdAsset',
'humhub\\assets\\JqueryTimeAgoAsset',
'humhub\\assets\\JqueryWidgetAsset',
'humhub\\assets\\JqueryColorAsset',
'humhub\\assets\\JqueryPlaceholderAsset',
'humhub\\assets\\FontAwesomeAsset',
'humhub\\assets\\BlueimpFileUploadAsset',
'humhub\\assets\\JqueryHighlightAsset',
'all',
],
],
];

View File

@ -4,12 +4,12 @@
*/
// In the console environment, some path aliases may not exist. Please define these:
Yii::setAlias('@webroot', __DIR__ . '/..');
Yii::setAlias('@webroot', __DIR__ . '/../../../');
Yii::setAlias('@web', '/');
return [
// Adjust command/callback for JavaScript files compressing:
'jsCompressor' => 'grunt uglify:assets --from={from} --to={to} --mangle --compress',
'jsCompressor' => 'grunt uglify:assets --from={from} --to={to} -d',
// Adjust command/callback for CSS files compressing:
'cssCompressor' => 'grunt cssmin --from={from} --to={to}',
// The list of asset bundles to compress:
@ -30,5 +30,10 @@ return [
'assetManager' => [
'basePath' => '@webroot/assets',
'baseUrl' => '@web/assets',
'bundles' => [
'yii\bootstrap\BootstrapPluginAsset' => [
'js' => ['js/bootstrap.min.js']
],
]
],
];

View File

@ -10,7 +10,7 @@ Build
## Assets
- Yii asset management http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#combining-compressing-assets
- php yii asset asset.php humhub/config/assets-prod.php
- php yii asset humhub/config/assets.php humhub/config/assets-prod.php