ardoq-local-plugins
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "ardoq-local-plugins", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Script that allows for local development of plugins.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -75,2 +75,3 @@ var fs = require('fs'), | ||
console.warn('Couldn\'t get existing plugins', response.statusCode); | ||
process.exit(); | ||
} | ||
@@ -112,3 +113,6 @@ }); | ||
} | ||
that.mergePluginData(remotePluginData); | ||
}); | ||
} else { | ||
that.mergePluginData(remotePluginData); | ||
} | ||
@@ -118,29 +122,7 @@ } catch (e) { | ||
fs.writeFile(that.pluginPath, remotePluginData.script, 'utf8'); | ||
that.mergePluginData(remotePluginData); | ||
} | ||
var mergedPluginData = {}, | ||
changes = 0; | ||
_.each(remotePluginData, function (remoteVal, key) { | ||
if (API_GENERATED_FIELDS.indexOf(key) !== -1) { | ||
return; | ||
} else if (!that.pluginData[key]) { | ||
mergedPluginData[key] = remoteVal; | ||
} else if (that.pluginData[key] !== remoteVal) { | ||
changes++; | ||
mergedPluginData[key] = remoteVal; | ||
} else { | ||
mergedPluginData[key] = remoteVal; | ||
} | ||
}); | ||
that.pluginData = mergedPluginData; | ||
that.writeLocalPluginData(); | ||
console.log('Synced local plugin data from remote:'); | ||
if (changes === 0) { | ||
console.log('All up-to-date.') | ||
} else { | ||
console.log('Forced updates to ' + that.pluginDataPath); | ||
} | ||
console.log('Waiting for changes...'); | ||
} else { | ||
console.warn('Couldn\'t get remote plugin', response.statusCode); | ||
process.exit(); | ||
} | ||
@@ -150,2 +132,29 @@ }); | ||
mergePluginData (remotePluginData) { | ||
var mergedPluginData = {}, | ||
that = this, | ||
changes = 0; | ||
_.each(remotePluginData, function (remoteVal, key) { | ||
if (API_GENERATED_FIELDS.indexOf(key) !== -1) { | ||
return; | ||
} else if (!that.pluginData[key]) { | ||
mergedPluginData[key] = remoteVal; | ||
} else if (that.pluginData[key] !== remoteVal) { | ||
changes++; | ||
mergedPluginData[key] = remoteVal; | ||
} else { | ||
mergedPluginData[key] = remoteVal; | ||
} | ||
}); | ||
this.pluginData = mergedPluginData; | ||
this.writeLocalPluginData(); | ||
console.log('Synced local plugin data from remote:'); | ||
if (changes === 0) { | ||
console.log('All up-to-date.') | ||
} else { | ||
console.log('Forced updates to ' + this.pluginDataPath); | ||
} | ||
console.log('Waiting for changes...'); | ||
} | ||
writeLocalPluginData () { | ||
@@ -167,8 +176,10 @@ fs.writeFile(this.pluginDataPath, JSON.stringify(this.pluginData, null, 4), 'utf8'); | ||
that.writeLocalPluginData(); | ||
console.log('Waiting for changes...'); | ||
} else if (response.statusCode === 409) { | ||
console.warn('Local version differs from remote version', response.statusCode); | ||
console.warn('Local version differs from remote version, trying to merge...'); | ||
that.updatePluginData(); | ||
} else { | ||
console.warn('Couldn\'t update the plugin', response.statusCode); | ||
process.exit(); | ||
} | ||
console.log('Waiting for changes...'); | ||
}); | ||
@@ -175,0 +186,0 @@ } |
@@ -15,3 +15,3 @@ # ardoq-local-plugins | ||
3. Create a config file "config.json": | ||
```json | ||
```javascript | ||
{ | ||
@@ -18,0 +18,0 @@ "api": "https://app.ardoq.com/api/", |
16416
383