|
|
|
@ -411,14 +411,32 @@ fileExplorer.prototype.toGist = function (id) { |
|
|
|
|
token: tokenAccess |
|
|
|
|
}) |
|
|
|
|
if (id) { |
|
|
|
|
const fileList = Object.keys(this.files.origGistFiles) |
|
|
|
|
const updatedFileList = Object.keys(packaged) |
|
|
|
|
// Telling the GIST API to remove files
|
|
|
|
|
const allItems = fileList |
|
|
|
|
.filter(fileName => updatedFileList.indexOf(fileName) === -1) |
|
|
|
|
.reduce((acc, deleteFileName) => ({ |
|
|
|
|
...acc, |
|
|
|
|
[deleteFileName]: null |
|
|
|
|
}), this.files.origGistFiles) |
|
|
|
|
// adding new files
|
|
|
|
|
updatedFileList.forEach(file => allItems[file] = packaged[file]) |
|
|
|
|
|
|
|
|
|
tooltip('Saving gist (' + id + ') ...') |
|
|
|
|
gists.edit({ |
|
|
|
|
description: description, |
|
|
|
|
public: true, |
|
|
|
|
files: packaged, |
|
|
|
|
files: allItems, |
|
|
|
|
id: id |
|
|
|
|
}, (error, result) => { |
|
|
|
|
proccedResult(error, result) |
|
|
|
|
if (!error) { |
|
|
|
|
for (const key in allItems) { |
|
|
|
|
if (allItems[key] === null) delete allItems[key] |
|
|
|
|
} |
|
|
|
|
this.files.origGistFiles = allItems |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
tooltip('Creating a new gist ...') |
|
|
|
@ -491,40 +509,10 @@ fileExplorer.prototype.copyFiles = function () { |
|
|
|
|
|
|
|
|
|
// ------------------ gist publish --------------
|
|
|
|
|
fileExplorer.prototype.updateGist = function () { |
|
|
|
|
let self = this |
|
|
|
|
var gistId = this.files.id |
|
|
|
|
var fileList = Object.keys(this.files.files) |
|
|
|
|
// fileList is an array of files in the github gist - not the updated one
|
|
|
|
|
var updatedFileList |
|
|
|
|
|
|
|
|
|
// loop through fileList and check if each element is in updatedFileList
|
|
|
|
|
|
|
|
|
|
// if one is not there in updated file list add it and make its content null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.packageFiles(self.files, (error, packaged) => { |
|
|
|
|
if (error) { |
|
|
|
|
console.log(error) |
|
|
|
|
} else { |
|
|
|
|
updatedFileList = Object.keys(packaged) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const gistId = this.files.id |
|
|
|
|
if (!gistId) { |
|
|
|
|
tooltip('no gist content is currently loaded.') |
|
|
|
|
} else { |
|
|
|
|
// check that the file list is still the same
|
|
|
|
|
// console.log('RS ' , this.files)
|
|
|
|
|
// make an array with just the names of the files
|
|
|
|
|
|
|
|
|
|
// self.packageFiles(self.files, (error, packaged) => {
|
|
|
|
|
// if (error) {
|
|
|
|
|
// console.log(error)
|
|
|
|
|
// } else {
|
|
|
|
|
// console.log('file list is: ', packaged)
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
this.toGist(gistId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|