Skip to content

Commit

Permalink
Merge branch 'deploy'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanseidel committed Apr 7, 2017
2 parents 1203764 + 6993e68 commit 2b28587
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 16 deletions.
2 changes: 1 addition & 1 deletion controllers/AutoUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ exports.init = function init(window) {
}

exports.manualCheckUpdate = function () {
app.helpers.CheckUpdate(FEED_URL, function (err, update) {
app.helpers.CheckAppUpdate(FEED_URL, function (err, update) {
if (err) {
console.error(TAG, err)
app.controllers.MainWindow.notify('Update Error', 'Failed to check for updates');
Expand Down
57 changes: 52 additions & 5 deletions controllers/ExtensionManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
var TAG = _TAG('TournamenterModules');
var TAG = _TAG('ExtensionManager');
//
// Manages (extra) extensions for Tournamenter
//
Expand All @@ -12,11 +12,18 @@ var TAG = _TAG('TournamenterModules');
//
const fs = require('fs');
const path = require('path');
const async = require('async');
const fork = require('child_process').fork;
const readline = require('readline');

const emit = app.helpers.emit;

//
// Cache variables
//
exports._cachedUpdates = null
exports._cachedExtensions = null

//
// Initialize module
//
Expand Down Expand Up @@ -54,6 +61,9 @@ exports.init = function () {
ipc.on('ExtensionManager:executing', function (event, id) {
event.returnValue = exports.isExecuting();
})

// Delay check for updates a bit
setTimeout(exports.checkUpdates, 4000);
}


Expand Down Expand Up @@ -89,7 +99,6 @@ exports.getExtensionsPaths = function (extensions) {
//
// List packages with it's `package.js` information
//
exports._cachedExtensions = null
exports.list = function () {
const installPath = path.join(exports.getInstallPath(), 'node_modules');

Expand Down Expand Up @@ -142,7 +151,7 @@ exports.list = function () {
if(!('_requiredBy' in extension))
return true;

// It's a root dependency (installed by `npm install <dep>`)
// It's a root dependency (installed by `npm install <dep>`)
if(extension._requiredBy.indexOf('#USER') >= 0)
return true;

Expand All @@ -165,6 +174,12 @@ exports.list = function () {
])
})

// Set updates into objects
extensions = extensions.map((extension) => {
extension.update = exports.getUpdate(extension.name)
return extension
})

// Save cache
exports._cachedExtensions = extensions;

Expand Down Expand Up @@ -217,7 +232,8 @@ exports.install = function (extension, cb) {

// Bind stdout and stderr read events and pipes to ipc
app.helpers.bindProcessLogsToIPC(proc, 'ExtensionManager', {
error: /ERR!/g,
error: /ERR!/,
skip: /npm (verb|http|info)/
});
}

Expand All @@ -239,10 +255,35 @@ exports.remove = function (extension, cb){

// Bind stdout and stderr read events and pipes to ipc
app.helpers.bindProcessLogsToIPC(proc, 'ExtensionManager', {
error: /ERR!/g,
error: /ERR!/,
skip: /npm (verb|http|info)/
});
}

//
// Check for updates on all dependencies
//
exports.checkUpdates = function (next) {
let packages = exports.list()
async.mapLimit(packages, 2, app.helpers.CheckPackageUpdate, (err, updates) => {
// Join the 'names' with the versions, to create a map table from module name to version
let versions = _.zipObject(_.map(packages, 'name'), updates)
exports._cachedUpdates = versions

// Clear Extensions cache
exports._cachedExtensions = null

// Notify update
emit('ExtensionManager:update', true)
})
}

//
// Get an update for a given module name string. Returns null if up to date
//
exports.getUpdate = function (name) {
return exports._cachedUpdates && exports._cachedUpdates[name] || null
}

//
// Low level call for NPM
Expand Down Expand Up @@ -295,6 +336,12 @@ exports.runNpm = function (params, cb){
console.log(TAG, chalk.green(`npm run ${params[0]} ${params[1]}... finish: ${code}`));
emit('ExtensionManager:log', 'server', `Install finished. Code ${code}`);

// Clear extension update cache
exports._cachedUpdates = null

// Check for updates
exports.checkUpdates()

// Callback with error
cb && cb(failed ? errors && errors.join('\r\n') : null);
})
Expand Down
2 changes: 1 addition & 1 deletion helpers/CheckUpdate.js → helpers/CheckAppUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const request = require('request')
* Checks for update given the url.
* Returns the Update object with ''
*/
module.exports = function CheckUpdate(url, next) {
module.exports = function CheckAppUpdate(url, next) {
request({
url: url,
json: true,
Expand Down
33 changes: 33 additions & 0 deletions helpers/CheckPackageUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const semver = require('semver')
const request = require('request')

const NPM_BASE = 'http://registry.npmjs.org'

/*
* Checks for update for a specific package
* this will never send back errors. Only no-update available (null)
*/
module.exports = function CheckPackageUpdate(package, next) {
let {name, version} = package
let url = `${NPM_BASE}/${name}`

request({
url,
json: true,
}, function (error, response, body) {
if (error) {
return next && next(null, null)
}

if (response.statusCode != 200) {
return next && next(null, null)
}

// Check version
let newVersion = body['dist-tags'].latest
let hasUpdate = semver.gt(newVersion, version)

// Send back data
return next && next(null, hasUpdate ? newVersion : null)
})
}
5 changes: 4 additions & 1 deletion helpers/bindProcessLogsToIPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ module.exports = function bindProcessLogsToIPC(proc, namespace, regexs = {}){
if(!regexs.error || (regexs.error && regexs.error.test(line)))
return emit(`${namespace}:log`, 'error', line);

// Skip lines
if(regexs.skip && regexs.skip.test(line))
return;

// Emits a warning
emit(`${namespace}:log`, 'warn', line);

});

}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"homepage": "https://github.com/ivanseidel/TournamenterApp",
"repository": "https://github.com/ivanseidel/TournamenterApp",
"license": "MIT",
"version": "1.6.2",
"version": "1.6.4",
"README": "none",
"engines": {
"node": "6.9.1"
Expand Down Expand Up @@ -72,15 +72,16 @@
}
},
"dependencies": {
"async": "1.2.1",
"async": "^2.3.0",
"chalk": "^1.1.3",
"forever-monitor": "^1.7.0",
"ip": "^1.1.5",
"kerberos": "0.0.21",
"lodash": "^4.13.1",
"npm": "^3.10.5",
"request": "^2.81.0",
"tournamenter": "2.2.8"
"semver": "^5.3.0",
"tournamenter": "2.3.0"
},
"devDependencies": {
"bower": "latest",
Expand Down
2 changes: 1 addition & 1 deletion public/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ angular.module('App', [
$scope._loaded = false;
$scope.version = require('electron').remote.app.getVersion();
$scope.versionTournamenter = require('tournamenter/package.json').version;
$scope.newUpdate = require('electron').remote.require('./helpers/CheckUpdate.js').newUpdate;
$scope.newUpdate = require('electron').remote.require('./helpers/CheckAppUpdate.js').newUpdate;

$scope.openExternal = function openExternal(link){
const {shell} = require('electron');
Expand Down
6 changes: 3 additions & 3 deletions public/views/extensions.panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<md-list ng-cloak style="padding: 0;"
ng-class="{installing: executing}">

<md-list-item class="secondary-button-padding">
<md-list-item class="secondary-button-padding" style="padding: 0;">
<div flex style="line-height: 1.2; font-size: 14px; margin: 8px 16px;">
Installed: <small class="label" style="background-color: #999;">
{{ extensions.length }}
Expand All @@ -25,12 +25,12 @@
ng-repeat="extension in extensions track by extension.name">

<div flex style="line-height: 1.2; margin: 8px 8px 8px 0;">
<h5>{{ extension.name }}</h5>
<h5>{{ extension.name }} <small>{{ extension.update ? '(Update Available)' : ''}}</small></h5>
<div class="description">{{ extension.description }}</div>
</div>
<!-- <flex></flex> -->

<div style="font-size: 14px;">
<div class="label" style="font-size: 10px;">
v{{ extension.version }}
</div>

Expand Down
4 changes: 3 additions & 1 deletion public/views/extensions.window.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ <h3>{{ extension.name }}</h3>
</div>


<div layout="column">
<div layout="column" layout-align="start end">
<div class="version">
<span ng-if="extension.update">New Update: </span>
<md-icon md-font-icon="mdi mdi-layers"></md-icon>
<span>v{{ extension.version }}</span>
<span ng-if="extension.update"> -> v{{ extension.update }}</span>
</div>
<div flex></div>
<div layout="row">
Expand Down

0 comments on commit 2b28587

Please sign in to comment.