@smartface/smartface.updater
Advanced tools
Comparing version 6.3.1 to 6.3.2
{ | ||
"name": "@smartface/smartface.updater", | ||
"version": "6.3.1", | ||
"description": "SmartfaceCloud Updater plugin", | ||
"main": "smf.updater.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/smartface/smartface.updater.git" | ||
}, | ||
"author": "Smartface", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/smartface/smartface.updater/issues" | ||
}, | ||
"homepage": "https://github.com/smartface/smartface.updater" | ||
} | ||
"name": "@smartface/smartface.updater", | ||
"version": "6.3.2", | ||
"description": "SmartfaceCloud Updater plugin", | ||
"main": "smf.updater.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/smartface/smartface.updater.git" | ||
}, | ||
"author": "Smartface", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/smartface/smartface.updater/issues" | ||
}, | ||
"homepage": "https://github.com/smartface/smartface.updater", | ||
"dependencies": { | ||
"compare-versions": "^3.0.1" | ||
} | ||
} |
define(function(require, exports, module) { | ||
main.consumes = [ | ||
'ui', 'commands', 'proc', 'c9', 'notification.bubble', 'dialog.error', | ||
'fs', 'Plugin', 'menus' | ||
"Plugin", "fs", "proc", "c9" | ||
]; | ||
@@ -10,21 +9,19 @@ main.provides = ["smf.updater"]; | ||
function main(options, imports, register) { | ||
var commands = imports.commands; | ||
var c9 = imports.c9; | ||
var proc = imports.proc; | ||
var menus = imports.menus; | ||
var ui = imports.ui; | ||
var Plugin = imports.Plugin; | ||
var showError = imports["dialog.error"].show; | ||
var bubble = imports["notification.bubble"]; | ||
var plugin = new Plugin("Smartface.io", main.consumes, { | ||
name: 'smf.updater' | ||
name: "smf.updater" | ||
}); | ||
var emit = plugin.getEmitter(); | ||
var fs = imports.fs; | ||
var proc = imports.proc; | ||
var c9 = imports.c9; | ||
var compareVersions = require("./node_modules/compare-versions/index.js"); | ||
var loaded = false; | ||
var checkUpdateExecuted = false; | ||
var updateMenu; | ||
// Don't forget to update here | ||
var versions = { | ||
"6.3.0": require("./6.3.0/index.js") | ||
}; | ||
plugin.on("load", load); | ||
plugin.on("unload", unload); | ||
c9.once('connect', checkUpdate); | ||
@@ -34,7 +31,2 @@ function load() { | ||
loaded = true; | ||
addCommand(); | ||
updateMenu = new ui.item({ | ||
command: "smf.Update" | ||
}); | ||
menus.addItemByPath("Tools/Update", updateMenu, 400, plugin); | ||
} | ||
@@ -45,9 +37,32 @@ | ||
loaded = false; | ||
drawn = false; | ||
checkUpdateExecuted = false; | ||
} | ||
/** | ||
* Must be tirggered right before openFile action being dispatched. | ||
* Updates all components if version of .pgx is outdated | ||
*/ | ||
function update(editorVersion, components) { | ||
var pgxVersion = components[0].version; | ||
if (pgxVersion === editorVersion) return; | ||
Object.keys(versions).map(function(version) { | ||
var isWorkspaceOlder = pgxVersion ? | ||
compareVersions(version, pgxVersion) === 1 : | ||
true; | ||
if (isWorkspaceOlder) { | ||
var updateComponents = versions[version].updateComponents; | ||
var updateWorkspace = versions[version].updateWorkspace; | ||
updateComponents && updateComponents(components); | ||
updateWorkspace && updateWorkspace({ | ||
fs: fs, | ||
proc: proc, | ||
c9: c9 | ||
}); | ||
} | ||
}); | ||
components[0].version = editorVersion; | ||
} | ||
plugin.freezePublicAPI({ | ||
draw: draw, | ||
show: show | ||
update: update | ||
}); | ||
@@ -58,264 +73,3 @@ | ||
}); | ||
function show() { | ||
draw(); | ||
} | ||
var drawn = false; | ||
function draw() { | ||
if (drawn) { | ||
return; | ||
} | ||
drawn = true; | ||
plugin.draw(); | ||
emit('draw'); | ||
} | ||
function closeDialog() { | ||
if (checkUpdateExecuted) { | ||
restartWorkspaceIfNeeded(function(restartNeeded) { | ||
if (!restartNeeded) { | ||
emit('smf.updater:finished'); | ||
updateMenu && (updateMenu.enable()); | ||
checkUpdateExecuted = false; | ||
} | ||
}); | ||
} | ||
} | ||
function foundNothingToUpdate() { | ||
closeDialog(); | ||
} | ||
function updateProcessFailedWithError(err) { | ||
closeDialog(); | ||
console.log(err); | ||
showError('Update failed. Please try again later after any pending operation (Tools > Update)'); | ||
} | ||
function checkIfInstallerIsInstalled(callback) { | ||
var cliArgs = ['list', '-g', '--json', '--depth', '0']; | ||
proc.execFile('npm', { | ||
args: cliArgs | ||
}, function(err, stdout, stderr) { | ||
if (err) { | ||
if (stderr.indexOf('npm ERR! max depth reached') === -1) { | ||
return updateProcessFailedWithError(err); | ||
} | ||
} | ||
stdout = stdout || ''; | ||
stderr = stderr || ''; | ||
if (stdout.trim() === '') { | ||
return runUpdaterNpmCommand(); | ||
} | ||
var json; | ||
try { | ||
var pos = stdout.indexOf('npm ERR!'); | ||
if (pos !== -1) { | ||
stdout = stdout.substr(0, pos).trim(); | ||
} | ||
json = JSON.parse(stdout); | ||
} | ||
catch (e) { | ||
return updateProcessFailedWithError(e); | ||
} | ||
if (json.dependencies && typeof json.dependencies['smartfacecloud-updater'] === 'undefined') { | ||
installUpdater(); | ||
} | ||
else { | ||
checkOutdated(); | ||
} | ||
}); | ||
} | ||
function checkUpdate(force) { | ||
emit('smf.updater:started'); | ||
updateMenu && (updateMenu.disable()); | ||
if ((!c9.isAdmin || window.location.search.indexOf('skipUpdate=1') > -1) && !force) { | ||
checkUpdateExecuted = true; | ||
return closeDialog(); | ||
} | ||
bubble.popup('<div class="notificationlabel__text">Update process ' + | ||
'started in the background. "Run on Device" and "Publish" will ' + | ||
'not be available until the process is completed.</div>'); | ||
if (checkUpdateExecuted) { | ||
return closeDialog(); | ||
} | ||
checkUpdateExecuted = true; | ||
showUpdater(); | ||
checkIfInstallerIsInstalled(); | ||
} | ||
function checkOutdated() { | ||
proc.execFile('npm', { | ||
args: ['outdated', 'smartfacecloud-updater', '-g', '--json'] | ||
}, function(err, stdout, stderr) { | ||
if (err) { | ||
return updateProcessFailedWithError(err); | ||
} | ||
if (stdout.trim() === '') { | ||
return runUpdaterNpmCommand(); | ||
} | ||
var json; | ||
try { | ||
json = JSON.parse(stdout); | ||
} | ||
catch (e) { | ||
return updateProcessFailedWithError(e); | ||
} | ||
if (typeof json['smartfacecloud-updater'] !== 'undefined') { | ||
installUpdater(); | ||
} | ||
else { | ||
runUpdaterNpmCommand(); | ||
} | ||
}); | ||
} | ||
function installUpdater() { | ||
var updaterPackageName = 'smartfacecloud-updater'; | ||
proc.execFile('npm', { | ||
args: ['install', updaterPackageName, '-g', '--json', '--silent', '--depth', '0'] | ||
}, function(err, stdout, stderr) { | ||
if (err) { | ||
return updateProcessFailedWithError(err); | ||
} | ||
if (stderr) { | ||
return updateProcessFailedWithError(stderr); | ||
} | ||
var pos = stdout.indexOf('['); | ||
stdout = stdout.substr(pos).trim(); | ||
if (stdout === '') { | ||
return foundNothingToUpdate(); | ||
} | ||
var json; | ||
try { | ||
json = JSON.parse(stdout); | ||
} | ||
catch (e) { | ||
return updateProcessFailedWithError(e); | ||
} | ||
// if (json && json instanceof Array && json.length === 1) { | ||
// if (json[0].name === updaterPackageName) { | ||
// runUpdaterNpmCommand(); | ||
// } | ||
// } else { | ||
// return updateProcessFailedWithError(json); | ||
// } | ||
// run updater in any case | ||
runUpdaterNpmCommand(); | ||
}); | ||
} | ||
function runUpdaterNpmCommand() { | ||
var updaterPackageName = 'smartfacecloud-updater'; | ||
proc.execFile(updaterPackageName, { | ||
args: ['--workspacePath', c9.workspaceDir], | ||
cwd: c9.workspaceDir | ||
}, function(err, stdout, stderr) { | ||
if (err) { | ||
return updateProcessFailedWithError(err); | ||
} | ||
if (stderr) { | ||
return updateProcessFailedWithError(stderr); | ||
} | ||
if (stdout.trim() === '') { | ||
return foundNothingToUpdate(); | ||
} | ||
var searchText = 'smartface-cloud-updater has finished processing packagesInstalled'; | ||
var endText = 'smartface-cloud-updater json was sent'; | ||
var pos = stdout.indexOf(searchText); | ||
if (pos === -1) { | ||
return updateProcessFailedWithError('failed to find searchText: ' + stdout); | ||
} | ||
var json_str = stdout.substr(pos + searchText.length); | ||
var end_pos = json_str.indexOf(endText); | ||
if (end_pos !== -1) { | ||
json_str = json_str.substr(0, end_pos); | ||
} | ||
var json; | ||
try { | ||
json = JSON.parse(json_str); | ||
} | ||
catch (e) { | ||
return updateProcessFailedWithError('failed to parse json: ' + json_str); | ||
} | ||
if (!json.packagesInstalled) { | ||
return updateProcessFailedWithError('failed to find json.packagesInstalled'); | ||
} | ||
dialogSuccess(json); | ||
}); | ||
} | ||
function dialogSuccess(json) { | ||
closeDialog(); | ||
if (json.packagesInstalled.length === 0) { | ||
return foundNothingToUpdate(); | ||
} | ||
json.packagesInstalled.each(function(item) { | ||
bubble.popup('<div class="notificationlabel__text">Updated: ' + item.name + '@' + item.version + '</div>'); | ||
}); | ||
} | ||
function addCommand() { | ||
commands.addCommand({ | ||
name: "smf.Update", | ||
isAvailable: function() { | ||
return !checkUpdateExecuted; | ||
}, | ||
exec: function() { | ||
checkUpdate(true); | ||
} | ||
}, plugin); | ||
} | ||
function showUpdater() { | ||
draw(); | ||
plugin.show(); | ||
} | ||
function restartWorkspace() { | ||
commands.exec("restartc9vm"); | ||
} | ||
function restartWorkspaceIfNeeded(callback) { | ||
proc.execFile('node', { | ||
args: ['-v'] | ||
}, function(err, stdout, stderr) { | ||
var restart = false; | ||
if (err || stderr) { | ||
restart = true; | ||
} | ||
if (stdout) { | ||
// stdout will be something like "v4.4.7" | ||
var nodeVersion = stdout.match(/^v(\d+\.\d+\.\d+)/); | ||
nodeVersion = nodeVersion ? nodeVersion[1] : null; | ||
if (nodeVersion) { | ||
nodeVersion = nodeVersion.split(".").map(function(v) { | ||
return parseInt(v, 10); | ||
}); | ||
if (nodeVersion[0] < 4) { | ||
restart = true; | ||
} | ||
else if (nodeVersion[0] == 4 && nodeVersion[1] < 4) { | ||
restart = true; | ||
} | ||
else if (nodeVersion[0] == 4 && nodeVersion[1] == 4 && nodeVersion[2] < 7) { | ||
restart = true; | ||
} | ||
} | ||
else { | ||
restart = true; | ||
} | ||
} | ||
restart && restartWorkspace(); | ||
callback(restart); | ||
}); | ||
} | ||
} | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
3816
1
4
101
1
+ Addedcompare-versions@^3.0.1
+ Addedcompare-versions@3.6.0(transitive)