diff --git a/deploy/jN/lib/PluginUpdater.js b/deploy/jN/lib/PluginUpdater.js index b9f42b9..a471253 100644 --- a/deploy/jN/lib/PluginUpdater.js +++ b/deploy/jN/lib/PluginUpdater.js @@ -1,3 +1,4 @@ +require("fs"); (function (){ @@ -14,11 +15,88 @@ function (registryPath, localPath){ this.updatePlugin = function (name){ var plugins = this.getPluginsInTheRegistry(); - var plugin = plugins["name"]; + var plugin = plugins[name]; if (!plugin) throw new Error("Plugin not found"); + var tmpDir = createTempDir(); + downloadPlugin(plugin.url, tmpDir); + fs.renameSync(tmpDir, localPath+"\\"+name); + } + + function createTempDir(){ + var path = fs.mkdtempSync(process.env["TEMP"]+"\\"); + fs.mkdirSync(path); + return path; + } + + function downloadPlugin(packageUrl, destDir){ + var packageJson = fetch(packageUrl, asText()); + var packageObj = JSON.parse(packageJson); + + var files = Array.isArray(packageObj.files)?packageObj.files:[]; + var packagePath = packageUrl.replace(/[^\/]+$/, ""); + + for(var i=0; i