Skip to content

Instantly share code, notes, and snippets.

@MatheusR42
Created August 25, 2018 16:47
Show Gist options
  • Save MatheusR42/462bc4245fbf3377a892044dd5bf5482 to your computer and use it in GitHub Desktop.
Save MatheusR42/462bc4245fbf3377a892044dd5bf5482 to your computer and use it in GitHub Desktop.
This script runs on VTEX /admin/a. It opens all the subfolders from a selected folder and return it as a Set(very similar to array)

This script runs on VTEX /admin/a. It opens all the subfolders from a selected folder and return it as a Set(very similar to array). At the bottom of file I convert it to string to be copied to other uses.

How to use

  • set the selectedDirectory variable at the bottom of the script
  • set the websiteurl variable at the bottom of the script
  • Enter in /admin/a
  • open CMS folder
  • open Sites and channels folder
  • open selected website
  • open the root folder "/"
  • run the script in console
class GetAllDirectories {
constructor(diretoryName, siteUrl, delay){
this.diretoryName = diretoryName;
this.siteUrl = siteUrl || '';
this.delay = delay || 6000;
this.directories = new Set();
this.openFirstFolder()
}
openFirstFolder() {
const _self = this;
$('.directory').each(function() {
if ($(this).find('> a').text() === _self.diretoryName) {
$(this).find('> a').click();
setTimeout(() => {
_self.openSubFolders($(this));
}, _self.delay)
}
})
}
openSubFolders(folderElement){
const _self = this;
folderElement.addClass('getpages-folder');
_self.directories.add(_self.getFolderPath(folderElement));
folderElement.find('> ul > li.directory').each(function(index) {
const subFolder = $(this);
setTimeout(() => {
subFolder.find('> a').click();
console.log(subFolder.find('> a').text())
setTimeout(() => {
_self.openSubFolders(subFolder)
}, _self.delay);
}, _self.delay + (index * 2000))
})
}
getFolderPath(folderElement){
let paths = [];
//current folder path
paths.push(folderElement.find('> a').text());
//parent folders path
folderElement.parents('.getpages-folder').each(function(){
paths.push($(this).find('> a').text());
});
return this.siteUrl + '/' + paths.reverse().join('/')
}
}
/**
* set the selectedDirectory variable at the bottom of the script
* set the websiteurl variable at the bottom of the script
* Enter in /admin/a
* open CMS folder
* open Sites and channels folder
* open selected website
* open the root folder "/"
* run the script
*/
const selectedDirectory = 'tree';
const websiteurl = 'http://corebiz.com.br'; //do not add the end slash "/"
var a = new GetAllDirectories(selectedDirectory, websiteurl);
/**
* when it stops to run, all the subfolders of selectedDirectory
* will be in this Set (very similar to array)
*/
console.log(a.directories);
/**
* converting to array and print as string to copy
*/
JSON.stringify([...a.directories])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment