vtex.colossus
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -17,2 +17,3 @@ // Generated by CoffeeScript 1.7.1 | ||
for (key in this.routes) { | ||
console.log(key); | ||
route = new Route(key); | ||
@@ -27,3 +28,4 @@ if (route.match(req.originalUrl)) { | ||
Controller.prototype.get = function(route, func) { | ||
return this.routes["/:accountName/:appName" + route] = func; | ||
console.log(route); | ||
return this.routes["/:accountName/colossus/:appName" + route] = func; | ||
}; | ||
@@ -30,0 +32,0 @@ |
@@ -30,3 +30,2 @@ // Generated by CoffeeScript 1.7.1 | ||
url: 'http://api.beta.vtex.com/' + accountName + '/workspaces/master/apps', | ||
proxy: 'http://localhost:8888', | ||
headers: { | ||
@@ -61,16 +60,66 @@ Authorization: 'token ' + token.authCookie.Value, | ||
Gallery.prototype.downloadFilesFromApp = function(appName) { | ||
Gallery.prototype.getFilesFromVersion = function(vendor, appName, token, version) { | ||
var options; | ||
options = { | ||
url: 'http://api.beta.vtex.com/' + vendor + '/apps/' + appName + '/' + version + '/files?i=colossus/&content=true', | ||
headers: { | ||
Authorization: 'token ' + token.authCookie.Value, | ||
Accept: 'application/vnd.vtex.gallery.v0+json' | ||
} | ||
}; | ||
return request.get(options); | ||
}; | ||
Gallery.prototype.getFiles = function(vendor, appName, token, version, sandbox) { | ||
if (version != null) { | ||
return this.getFilesFromVersion(vendor, appName, token, version); | ||
} else if (sandbox != null) { | ||
return this.getFilesFromSandbox(vendor, appName, token, sandbox); | ||
} else { | ||
throw new Error(); | ||
} | ||
}; | ||
Gallery.prototype.getFilesFromSandbox = function(vendor, appName, token, sandbox) { | ||
var options, sandBoxName; | ||
sandBoxName = sandbox.replace(':', '/').split('/')[1]; | ||
options = { | ||
url: 'http://api.beta.vtex.com/' + vendor + '/sandboxes/' + sandBoxName + '/' + appName + '/files?i=colossus/&content=true', | ||
headers: { | ||
Authorization: 'token ' + token.authCookie.Value, | ||
Accept: 'application/vnd.vtex.gallery.v0+json' | ||
} | ||
}; | ||
options.headers['x-vtex-sandbox'] = sandbox; | ||
return request.get(options); | ||
}; | ||
Gallery.prototype.downloadFilesFromDefaultApp = function(appName) { | ||
var name, promise, vendor; | ||
vendor = appName.split('.')[0]; | ||
name = appName.split('.')[1]; | ||
promise = this.getVersionMapFromApp(appName); | ||
return promise.then((function(_this) { | ||
return function(version) { | ||
return _this.downloadFilesFromCustomApp(appName, version); | ||
}; | ||
})(this)); | ||
}; | ||
Gallery.prototype.downloadFilesFromCustomApp = function(appName, version, sandbox) { | ||
var name, promise, saveFile, vendor; | ||
vendor = appName.split('.')[0]; | ||
name = appName.split('.')[1]; | ||
promise = this.getVersionMapFromApp(appName); | ||
saveFile = function(appName, version, key, content) { | ||
saveFile = function(appName, version, key, content, sandbox) { | ||
return Q.Promise(function(resolve, reject, notify) { | ||
var appPath, dir; | ||
appPath = './apps/' + appName + '/' + version + '/'; | ||
var appPath, dir, sandBoxName; | ||
if (!sandbox) { | ||
appPath = './apps/' + appName + '/' + version + '/'; | ||
} else { | ||
sandBoxName = sandbox.replace(':', '/').split('/')[1]; | ||
appPath = './apps/sandbox/' + sandBoxName + '/' + appName + '/'; | ||
} | ||
dir = path.dirname(appPath + key); | ||
console.log(version); | ||
return mkdirp(dir, function(err) { | ||
return fs.writeFile(appPath + key, content, function(err) { | ||
console.log(key); | ||
return resolve(appPath); | ||
@@ -81,14 +130,5 @@ }); | ||
}; | ||
promise = promise.then(function(version) { | ||
return vtexCredentials.getToken().then(function(token) { | ||
var options; | ||
options = { | ||
url: 'http://api.beta.vtex.com/' + vendor + '/apps/' + name + '/' + version + '/files?i=colossus/&content=true', | ||
proxy: 'http://localhost:8888', | ||
headers: { | ||
Authorization: 'token ' + token.authCookie.Value, | ||
Accept: 'application/vnd.vtex.gallery.v0+json' | ||
} | ||
}; | ||
return request.get(options).then(function(data) { | ||
promise = vtexCredentials.getToken().then((function(_this) { | ||
return function(token) { | ||
return _this.getFiles(vendor, name, token, version, sandbox).then(function(data) { | ||
var appContent, key, promisses, value; | ||
@@ -99,8 +139,8 @@ appContent = JSON.parse(data); | ||
value = appContent[key]; | ||
promisses.push(saveFile(appName, version, key, value.content)); | ||
promisses.push(saveFile(appName, version, key, value.content, sandbox)); | ||
} | ||
return Q.all(promisses); | ||
}); | ||
}); | ||
}); | ||
}; | ||
})(this)); | ||
return promise.then(function(paths) { | ||
@@ -107,0 +147,0 @@ return paths[0]; |
{ | ||
"name": "vtex.colossus", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20789
218