Minify Javascript and add automated syntax check on the CI

This commit is contained in:
Frederic Guillot 2017-01-02 19:21:15 -05:00
parent eee53dd589
commit bc503d49cd
13 changed files with 101 additions and 53 deletions

View File

@ -12,5 +12,7 @@ composer.json
composer.lock composer.lock
CONTRIBUTORS.md CONTRIBUTORS.md
docker-compose.yml docker-compose.yml
node_modules
package.json
Makefile Makefile
README.markdown README.markdown

1
.gitignore vendored
View File

@ -17,6 +17,7 @@ Thumbs.db
*.sublime-workspace *.sublime-workspace
.nbproject .nbproject
nbproject nbproject
node_modules
config.php config.php
!app/helpers/* !app/helpers/*
!app/models/* !app/models/*

View File

@ -20,8 +20,10 @@ install:
before_script: before_script:
- ./tests/ci/install.sh - ./tests/ci/install.sh
- npm install
script: script:
- ./node_modules/.bin/jshint assets/js/src/*.js
- ./vendor/bin/phpunit -c tests/phpunit.unit.sqlite.xml - ./vendor/bin/phpunit -c tests/phpunit.unit.sqlite.xml
- ./vendor/bin/phpunit -c tests/phpunit.unit.postgres.xml - ./vendor/bin/phpunit -c tests/phpunit.unit.postgres.xml
- ./vendor/bin/phpunit -c tests/phpunit.functional.sqlite.xml - ./vendor/bin/phpunit -c tests/phpunit.functional.sqlite.xml

View File

@ -18,6 +18,7 @@ Version 1.2.0 (unreleased)
* Add Docker compose file * Add Docker compose file
* Add functional tests (Json-RPC API and Fever API) * Add functional tests (Json-RPC API and Fever API)
* Add unit tests * Add unit tests
* Minify Javascript and add automated syntax check on the CI
Migration procedure from 1.1.x to 1.2.0: Migration procedure from 1.1.x to 1.2.0:

View File

@ -9,7 +9,7 @@
.PHONY: sync-locales .PHONY: sync-locales
.PHONY: find-locales .PHONY: find-locales
JS_FILE = assets/js/all.js JS_FILE = assets/js/app.min.js
CONTAINER = miniflux CONTAINER = miniflux
IMAGE = miniflux/miniflux IMAGE = miniflux/miniflux
TAG = latest TAG = latest
@ -28,13 +28,14 @@ docker-run:
js: $(JS_FILE) js: $(JS_FILE)
$(JS_FILE): assets/js/app.js \ $(JS_FILE): assets/js/src/app.js \
assets/js/feed.js \ assets/js/src/feed.js \
assets/js/item.js \ assets/js/src/item.js \
assets/js/event.js \ assets/js/src/event.js \
assets/js/nav.js assets/js/src/nav.js
@ echo "/* AUTO GENERATED FILE, DO NOT MODIFY THIS FILE, USE 'make js' */" > $@ @ yarn install || npm install
@ cat $^ >> $@ @ ./node_modules/.bin/jshint assets/js/src/*.js
@ cat $^ | node_modules/.bin/uglifyjs - > $@
@ echo "Miniflux.App.Run();" >> $@ @ echo "Miniflux.App.Run();" >> $@
# Build a new archive: make archive version=1.2.3 dst=/tmp # Build a new archive: make archive version=1.2.3 dst=/tmp

View File

@ -22,7 +22,7 @@
<link rel="apple-touch-icon" sizes="144x144" href="assets/img/touch-icon-ipad-retina.png"> <link rel="apple-touch-icon" sizes="144x144" href="assets/img/touch-icon-ipad-retina.png">
<link href="<?php echo Miniflux\Helper\css() ?>" rel="stylesheet" media="screen"> <link href="<?php echo Miniflux\Helper\css() ?>" rel="stylesheet" media="screen">
<script type="text/javascript" src="assets/js/all.js?<?php echo filemtime('assets/js/all.js') ?>" defer></script> <script type="text/javascript" src="assets/js/app.min.js?<?php echo filemtime('assets/js/app.min.js') ?>" defer></script>
</head> </head>
<body> <body>
<header> <header>

2
assets/js/app.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -22,10 +22,10 @@ Miniflux.App = (function() {
request.onload = function() { request.onload = function() {
var response = JSON.parse(this.responseText); var response = JSON.parse(this.responseText);
if (response['frontend_updatecheck_interval'] > 0) { if (response.frontend_updatecheck_interval > 0) {
Miniflux.App.Log('Frontend updatecheck interval in minutes: ' + response['frontend_updatecheck_interval']); Miniflux.App.Log('Frontend updatecheck interval in minutes: ' + response.frontend_updatecheck_interval);
Miniflux.Item.CheckForUpdates(); Miniflux.Item.CheckForUpdates();
setInterval(function(){ Miniflux.Item.CheckForUpdates(); }, response['frontend_updatecheck_interval']*60*1000); setInterval(function(){ Miniflux.Item.CheckForUpdates(); }, response.frontend_updatecheck_interval * 60 * 1000);
} }
else { else {
Miniflux.App.Log('Frontend updatecheck disabled'); Miniflux.App.Log('Frontend updatecheck disabled');

View File

@ -10,7 +10,7 @@ Miniflux.Event = (function() {
// Do not handle events when there is a focus in form fields // Do not handle events when there is a focus in form fields
var target = e.target || e.srcElement; var target = e.target || e.srcElement;
return !!(target.tagName === 'INPUT' || target.tagName === 'TEXTAREA'); return target.tagName === 'INPUT' || target.tagName === 'TEXTAREA';
} }
return { return {
@ -58,22 +58,34 @@ Miniflux.Event = (function() {
Miniflux.Feed.UpdateAll(e.target.getAttribute("data-concurrent-requests")); Miniflux.Feed.UpdateAll(e.target.getAttribute("data-concurrent-requests"));
break; break;
case 'refresh-feed': case 'refresh-feed':
currentItem && Miniflux.Feed.Update(currentItem); if (currentItem) {
Miniflux.Feed.Update(currentItem);
}
break; break;
case 'mark-read': case 'mark-read':
currentItem && Miniflux.Item.MarkAsRead(currentItem); if (currentItem) {
Miniflux.Item.MarkAsRead(currentItem);
}
break; break;
case 'mark-unread': case 'mark-unread':
currentItem && Miniflux.Item.MarkAsUnread(currentItem); if (currentItem) {
Miniflux.Item.MarkAsUnread(currentItem);
}
break; break;
case 'mark-removed': case 'mark-removed':
currentItem && Miniflux.Item.MarkAsRemoved(currentItem); if (currentItem) {
Miniflux.Item.MarkAsRemoved(currentItem);
}
break; break;
case 'bookmark': case 'bookmark':
currentItem && Miniflux.Item.SwitchBookmark(currentItem); if (currentItem) {
Miniflux.Item.SwitchBookmark(currentItem);
}
break; break;
case 'download-item': case 'download-item':
currentItem && Miniflux.Item.DownloadContent(currentItem); if (currentItem) {
Miniflux.Item.DownloadContent(currentItem);
}
break; break;
case 'mark-feed-read': case 'mark-feed-read':
var feed_id = document.getElementById('listing').getAttribute('data-feed-id'); var feed_id = document.getElementById('listing').getAttribute('data-feed-id');
@ -150,7 +162,9 @@ Miniflux.Event = (function() {
switch (e.key || e.which) { switch (e.key || e.which) {
case 'd': case 'd':
case 100: case 100:
currentItem && Miniflux.Item.DownloadContent(currentItem); if (currentItem) {
Miniflux.Item.DownloadContent(currentItem);
}
break; break;
case 'p': case 'p':
case 112: case 112:
@ -166,19 +180,27 @@ Miniflux.Event = (function() {
break; break;
case 'v': case 'v':
case 118: case 118:
currentItem && Miniflux.Item.OpenOriginal(currentItem); if (currentItem) {
Miniflux.Item.OpenOriginal(currentItem);
}
break; break;
case 'o': case 'o':
case 111: case 111:
currentItem && Miniflux.Item.Show(currentItem); if (currentItem) {
Miniflux.Item.Show(currentItem);
}
break; break;
case 'm': case 'm':
case 109: case 109:
currentItem && Miniflux.Item.SwitchStatus(currentItem); if (currentItem) {
Miniflux.Item.SwitchStatus(currentItem);
}
break; break;
case 'f': case 'f':
case 102: case 102:
currentItem && Miniflux.Item.SwitchBookmark(currentItem); if (currentItem) {
Miniflux.Item.SwitchBookmark(currentItem);
}
break; break;
case 'h': case 'h':
case 104: case 104:
@ -261,8 +283,10 @@ Miniflux.Event = (function() {
ListenTouchEvents: function() { ListenTouchEvents: function() {
var touches = null; var touches = null;
var resetTouch = function () { var resetTouch = function () {
touches && touches.element && (touches.element.style.opacity = 1); if (touches && touches.element) {
touches && touches.element && (touches.element.style.transform = ""); touches.element.style.opacity = 1;
touches.element.style.transform = "";
}
touches = { touches = {
"touchstart": {"x":-1, "y":-1}, "touchstart": {"x":-1, "y":-1},
"touchmove" : {"x":-1, "y":-1}, "touchmove" : {"x":-1, "y":-1},
@ -274,7 +298,7 @@ Miniflux.Event = (function() {
}; };
var horizontalSwipe = function () { var horizontalSwipe = function () {
if((touches.touchstart.x > -1 && touches.touchmove.x > -1 && if((touches.touchstart.x > -1 && touches.touchmove.x > -1 &&
((touches.touchmove.x - touches.touchstart.x) > 30 | touches.swipestarted) && ((touches.touchmove.x - touches.touchstart.x) > 30 || touches.swipestarted) &&
Math.abs(touches.touchmove.y - touches.touchstart.y) < 75)) { Math.abs(touches.touchmove.y - touches.touchstart.y) < 75)) {
touches.swipestarted = true; touches.swipestarted = true;
return touches.touchmove.x - touches.touchstart.x; return touches.touchmove.x - touches.touchstart.x;
@ -334,7 +358,9 @@ Miniflux.Event = (function() {
element = getTouchElement(); element = getTouchElement();
swipedistance = horizontalSwipe(); swipedistance = horizontalSwipe();
if(swipedistance > 75) { if(swipedistance > 75) {
element && Miniflux.Item.MarkAsRead(element); if (element) {
Miniflux.Item.MarkAsRead(element);
}
if(!element.getAttribute("data-hide")){ if(!element.getAttribute("data-hide")){
resetTouch(); resetTouch();
} }

View File

@ -6,6 +6,8 @@ Miniflux.Feed = (function() {
// Number of concurrent requests when updating all feeds // Number of concurrent requests when updating all feeds
var queue_length = 5; var queue_length = 5;
var updateInterval = null;
return { return {
Update: function(feed, callback) { Update: function(feed, callback) {
var itemsCounter = feed.querySelector("span.items-count"); var itemsCounter = feed.querySelector("span.items-count");
@ -25,8 +27,8 @@ Miniflux.Feed = (function() {
if (lastChecked) lastChecked.innerHTML = lastChecked.getAttribute("data-after-update"); if (lastChecked) lastChecked.innerHTML = lastChecked.getAttribute("data-after-update");
var response = JSON.parse(this.responseText); var response = JSON.parse(this.responseText);
if (response['result']) { if (response.result) {
itemsCounter.innerHTML = response['items_count']['items_unread'] + "/" + response['items_count']['items_total']; itemsCounter.innerHTML = response.items_count.items_unread + "/" + response.items_count.items_total;
} else { } else {
feed.setAttribute("data-feed-error", "1"); feed.setAttribute("data-feed-error", "1");
} }
@ -50,22 +52,22 @@ Miniflux.Feed = (function() {
queue_length = nb_concurrent_requests; queue_length = nb_concurrent_requests;
} }
var interval = setInterval(function() { updateInterval = setInterval(function() {
while (feeds.length > 0 && queue.length < queue_length) { while (feeds.length > 0 && queue.length < queue_length) {
var feed = feeds.shift(); var feed = feeds.shift();
queue.push(parseInt(feed.getAttribute('data-feed-id'), 10)); queue.push(parseInt(feed.getAttribute('data-feed-id'), 10));
Miniflux.Feed.Update(feed, Miniflux.Feed.OnFeedUpdated);
Miniflux.Feed.Update(feed, function(response) { }
var index = queue.indexOf(response['feed_id']); }, 100);
},
OnFeedUpdated: function(response) {
var index = queue.indexOf(response.feed_id);
if (index >= 0) queue.splice(index, 1); if (index >= 0) queue.splice(index, 1);
if (feeds.length === 0 && queue.length === 0) { if (feeds.length === 0 && queue.length === 0) {
clearInterval(interval); clearInterval(updateInterval);
Miniflux.Item.CheckForUpdates(); Miniflux.Item.CheckForUpdates();
} }
});
}
}, 100);
} }
}; };
})(); })();

View File

@ -284,7 +284,9 @@ Miniflux.Item = (function() {
}, },
OpenOriginal: function(item) { OpenOriginal: function(item) {
var link = item.querySelector("a.original"); var link = item.querySelector("a.original");
if (link) simulateMouseClick(link) if (link) {
simulateMouseClick(link);
}
}, },
DownloadContent: function(item) { DownloadContent: function(item) {
var container = document.getElementById("download-item"); var container = document.getElementById("download-item");
@ -299,9 +301,9 @@ Miniflux.Item = (function() {
var response = JSON.parse(request.responseText); var response = JSON.parse(request.responseText);
container.className = ""; container.className = "";
if (response['result']) { if (response.result) {
var content = document.getElementById("item-content"); var content = document.getElementById("item-content");
if (content) content.innerHTML = response['content']; if (content) content.innerHTML = response.content;
container.innerHTML = container.getAttribute("data-after-message"); container.innerHTML = container.getAttribute("data-after-message");
} }
@ -344,7 +346,7 @@ Miniflux.Item = (function() {
var tag = document.querySelector(tags[i]); var tag = document.querySelector(tags[i]);
if (tag) { if (tag) {
tag.dir = tag.dir == "" ? "rtl" : ""; tag.dir = tag.dir === "" ? "rtl" : "";
} }
} }
}, },
@ -359,10 +361,10 @@ Miniflux.Item = (function() {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.onload = function() { request.onload = function() {
var first_run = (latest_feeds_items.length === 0); var first_run = latest_feeds_items.length === 0;
var current_unread = false; var current_unread = false;
var response = JSON.parse(this.responseText); var response = JSON.parse(this.responseText);
var last_items_timestamps = response['last_items_timestamps']; var last_items_timestamps = response.last_items_timestamps;
for (var i = 0; i < last_items_timestamps.length; i++) { for (var i = 0; i < last_items_timestamps.length; i++) {
var current_feed = last_items_timestamps[i]; var current_feed = last_items_timestamps[i];
@ -374,12 +376,12 @@ Miniflux.Item = (function() {
} }
} }
Miniflux.App.Log('first_run: ' + first_run + ', current_unread: ' + current_unread + ', response.nbUnread: ' + response['nbUnread'] + ', nbUnreadItems: ' + nbUnreadItems); Miniflux.App.Log('first_run: ' + first_run + ', current_unread: ' + current_unread + ', response.nbUnread: ' + response.nbUnread + ', nbUnreadItems: ' + nbUnreadItems);
if (! document.hidden && (response['nb_unread_items'] !== nbUnreadItems || unreadItems)) { if (! document.hidden && (response.nb_unread_items !== nbUnreadItems || unreadItems)) {
Miniflux.App.Log('Counter changed! Updating unread counter.'); Miniflux.App.Log('Counter changed! Updating unread counter.');
unreadItems = false; unreadItems = false;
nbUnreadItems = response['nb_unread_items']; nbUnreadItems = response.nb_unread_items;
updateCounters(); updateCounters();
} }
else if (document.hidden && ! first_run && current_unread) { else if (document.hidden && ! first_run && current_unread) {

View File

@ -114,9 +114,12 @@ Miniflux.Nav = (function() {
}, },
ToggleMenuMore: function () { ToggleMenuMore: function () {
var menu = document.getElementById("menu-more"); var menu = document.getElementById("menu-more");
menu.hasAttribute("class")
? menu.removeAttribute("class") if (menu.hasAttribute("class")) {
: menu.setAttribute("class", "hide"); menu.removeAttribute("class");
} else {
menu.setAttribute("class", "hide");
}
}, },
IsListing: isListing IsListing: isListing
}; };

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": {
"jshint": "^2.9.4",
"uglify-js": "^2.7.5"
}
}