Comparing version 0.1.5 to 0.1.6
@@ -18,5 +18,9 @@ 'use strict'; | ||
if(response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve(JSON.parse(body)); | ||
try { | ||
deferred.resolve(JSON.parse(body)); | ||
} catch (error) { | ||
deferred.reject(body); | ||
} | ||
} else { | ||
deferred.reject(body); | ||
deferred.reject(body); | ||
} | ||
@@ -39,12 +43,16 @@ } | ||
if(response.statusCode >= 200 && response.statusCode <= 299) { | ||
var queries = JSON.parse(body).public; | ||
var results = []; | ||
queries.forEach(function(query){ | ||
results[query.href.substring('/v1/_queries/'.length)] = { | ||
lastModified: new Date(query.lastModified).toISOString() | ||
}; | ||
}); | ||
deferred.resolve(results); | ||
try { | ||
var queries = JSON.parse(body).public; | ||
var results = []; | ||
queries.forEach(function(query){ | ||
results[query.href.substring('/v1/_queries/'.length)] = { | ||
lastModified: new Date(query.lastModified).toISOString() | ||
}; | ||
}); | ||
deferred.resolve(results); | ||
} catch(error) { | ||
deferred.reject(body); | ||
} | ||
} else { | ||
deferred.reject(body); | ||
deferred.reject(body); | ||
} | ||
@@ -63,12 +71,16 @@ }); | ||
if(response.statusCode >= 200 && response.statusCode <= 299) { | ||
var queries = JSON.parse(body).private; | ||
var results = []; | ||
queries.forEach(function(query){ | ||
results[query.href.substring('/v1/_queries/'.length)] = { | ||
lastModified: new Date(query.lastModified).toISOString() | ||
}; | ||
}); | ||
deferred.resolve(results); | ||
try { | ||
var queries = JSON.parse(body).private; | ||
var results = []; | ||
queries.forEach(function(query){ | ||
results[query.href.substring('/v1/_queries/'.length)] = { | ||
lastModified: new Date(query.lastModified).toISOString() | ||
}; | ||
}); | ||
deferred.resolve(results); | ||
} catch(error) { | ||
deferred.reject(body); | ||
} | ||
} else { | ||
deferred.reject(body); | ||
deferred.reject(body); | ||
} | ||
@@ -97,3 +109,3 @@ }); | ||
} else { | ||
deferred.reject(body); | ||
deferred.reject(body); | ||
} | ||
@@ -119,6 +131,6 @@ }); | ||
} else { | ||
deferred.reject(body); | ||
deferred.reject(body); | ||
} | ||
}); | ||
return deferred.promise; | ||
return deferred.promise; | ||
}; | ||
@@ -137,7 +149,7 @@ | ||
} else { | ||
deferred.reject(body); | ||
deferred.reject(body); | ||
} | ||
}); | ||
return deferred.promise; | ||
} | ||
return deferred.promise; | ||
}; | ||
@@ -155,3 +167,3 @@ this.getFile = function(path){ | ||
} else { | ||
deferred.reject(body); | ||
deferred.reject(body); | ||
} | ||
@@ -162,5 +174,3 @@ }); | ||
this.listFiles = function(){ | ||
var deferred = Q.defer(); | ||
var files = []; | ||
this.listFiles = function(){ | ||
var promises = []; | ||
@@ -178,8 +188,3 @@ var promise; | ||
Q.all(promises) | ||
.then(function(list){ | ||
deferred.resolve(list); | ||
}); | ||
return deferred.promise; | ||
return Q.all(promises); | ||
}; | ||
@@ -196,2 +201,3 @@ }; | ||
}; | ||
module.exports = API; |
@@ -63,9 +63,8 @@ 'use strict'; | ||
{ | ||
prompt: 'Overwrite : <' + toFile.origin + '>/' + toFile.path | ||
+ ' (' + toFile.lastModified + ') with <' + fromFile.path + '>/' | ||
+ fromFile.path | ||
+ ' (' + fromFile.lastModified + ')? Y/[N]', | ||
'default': 'N' | ||
} | ||
, | ||
prompt: 'Overwrite : <' + toFile.origin + '>/' + toFile.path + | ||
' (' + toFile.lastModified + ') with <' + fromFile.path + '>/' + | ||
fromFile.path + | ||
' (' + fromFile.lastModified + ')? Y/[N]', | ||
'default': 'N' | ||
}, | ||
function(er, value) { | ||
@@ -81,4 +80,3 @@ if(er) { | ||
result.action = ( | ||
new Date(fromFile.lastModified).getTime() | ||
> | ||
new Date(fromFile.lastModified).getTime() > | ||
new Date(toFile.lastModified).getTime() | ||
@@ -107,3 +105,3 @@ ); | ||
var toFile = { | ||
path: file, | ||
path: file, | ||
exists: to[file] !== undefined, | ||
@@ -121,6 +119,4 @@ lastModified: to[file] ? to[file].lastModified : undefined, | ||
( | ||
fromOrigin === 'remote' | ||
? | ||
writeToLocalFile(project, result.fromFile.path) | ||
: | ||
fromOrigin === 'remote' ? | ||
writeToLocalFile(project, result.fromFile.path) : | ||
writeToRemoteFile(project, result.fromFile.path) | ||
@@ -153,7 +149,5 @@ ) | ||
if(!simulate) { | ||
( | ||
fromOrigin === 'remote' | ||
? | ||
deleteLocalFile(file) | ||
: | ||
( | ||
fromOrigin === 'remote' ? | ||
deleteLocalFile(file) : | ||
deleteRemoteFile(project, file) | ||
@@ -178,3 +172,3 @@ ) | ||
}; | ||
this.upload = function(project, remote, local, overwrite, deleteOrphaned, simulate){ | ||
@@ -186,5 +180,5 @@ return sync(project, local, remote, overwrite, deleteOrphaned, simulate, 'local', 'remote'); | ||
return sync(project, remote, local, overwrite, deleteOrphaned, simulate, 'remote', 'local'); | ||
} | ||
}; | ||
}; | ||
module.exports = new Client(); |
@@ -18,6 +18,6 @@ 'use strict'; | ||
function objectConcat(o1, o2) { | ||
for (var key in o2) { | ||
o1[key] = o2[key]; | ||
} | ||
return o1; | ||
for (var key in o2) { | ||
o1[key] = o2[key]; | ||
} | ||
return o1; | ||
} | ||
@@ -52,6 +52,8 @@ | ||
var apiSettings = { | ||
API_URL: PROJECT_PROTOCOL + '://' + PROJECT_NAME + '.' + PROJECT_DOMAIN, | ||
API_VERSION: 'v1', | ||
DOMAIN: PROJECT_DOMAIN, | ||
getProjectAPI: function(name) { return PROJECT_PROTOCOL + '://' + name + '.' + PROJECT_DOMAIN + '/' + this.API_VERSION; } | ||
API_URL: PROJECT_PROTOCOL + '://' + PROJECT_NAME + '.' + PROJECT_DOMAIN, | ||
API_VERSION: 'v1', | ||
DOMAIN: PROJECT_DOMAIN, | ||
getProjectAPI: function(name) { | ||
return PROJECT_PROTOCOL + '://' + name + '.' + PROJECT_DOMAIN + '/' + this.API_VERSION; | ||
} | ||
}; | ||
@@ -76,3 +78,3 @@ | ||
}) | ||
.catch(function(error){ | ||
.catch(function(error){ | ||
deferred.reject(error); | ||
@@ -85,8 +87,9 @@ }); | ||
//Login Command | ||
var loginCmd = cli | ||
cli | ||
.command('login <email>') | ||
.description('Sign-in into 28.io.') | ||
.action(function(email) { | ||
if(!email) { | ||
console.log("Need email to authenticate: 28 -h for more infos"); | ||
console.log('Need email to authenticate: 28 -h for more infos'); | ||
return; | ||
@@ -102,7 +105,7 @@ } | ||
updateSettings(settings, session); | ||
console.log("Success! API tokens have been saved."); | ||
console.log('Success! API tokens have been saved.'); | ||
}) | ||
.catch(function(error){ | ||
console.error('Authentication failed. Server replied:') | ||
console.error(error); | ||
console.error('Authentication failed. Server replied:'); | ||
console.error(error); | ||
}); | ||
@@ -113,3 +116,3 @@ }); | ||
//List Projects | ||
var projectsCmd = cli | ||
cli | ||
.command('projects') | ||
@@ -126,4 +129,4 @@ .description('List of 28.io projects.') | ||
}) | ||
.catch(function(error){ | ||
console.log("Failed to authenticate. Please run: 28 login <your email>"); | ||
.catch(function(error){ | ||
console.log('Failed to authenticate. Please run: 28 login <your email>'); | ||
console.error('Server replied with:'); | ||
@@ -151,3 +154,3 @@ console.error(error); | ||
return undefined; | ||
} | ||
} | ||
} | ||
@@ -168,8 +171,5 @@ ) | ||
Q.all([ | ||
project.listFiles() | ||
, | ||
ffs.readdirRecursive('lib', true, 'lib') | ||
, | ||
ffs.readdirRecursive('public', true, 'public') | ||
, | ||
project.listFiles(), | ||
ffs.readdirRecursive('lib', true, 'lib'), | ||
ffs.readdirRecursive('public', true, 'public'), | ||
ffs.readdirRecursive('private', true, 'private') | ||
@@ -197,4 +197,4 @@ ]) | ||
project, remote, local, | ||
dlCmd.overwrite === undefined ? Client.OVERWRITE_ASK : dlCmd.overwrite, | ||
dlCmd.deleteOrphaned ? true : false, | ||
dlCmd.overwrite === undefined ? Client.OVERWRITE_ASK : dlCmd.overwrite, | ||
dlCmd.deleteOrphaned ? true : false, | ||
dlCmd.simulate ? true : false | ||
@@ -216,3 +216,3 @@ ) | ||
}).catch(function(error){ | ||
console.error(error); | ||
console.error(error); | ||
}); | ||
@@ -238,3 +238,3 @@ }); | ||
return undefined; | ||
} | ||
} | ||
} | ||
@@ -255,8 +255,5 @@ ) | ||
Q.all([ | ||
project.listFiles() | ||
, | ||
ffs.readdirRecursive('lib', true, 'lib') | ||
, | ||
ffs.readdirRecursive('public', true, 'public') | ||
, | ||
project.listFiles(), | ||
ffs.readdirRecursive('lib', true, 'lib'), | ||
ffs.readdirRecursive('public', true, 'public'), | ||
ffs.readdirRecursive('private', true, 'private') | ||
@@ -284,4 +281,4 @@ ]) | ||
project, remote, local, | ||
upCmd.overwrite === undefined ? Client.OVERWRITE_ASK : upCmd.overwrite, | ||
upCmd.deleteOrphaned ? true : false, | ||
upCmd.overwrite === undefined ? Client.OVERWRITE_ASK : upCmd.overwrite, | ||
upCmd.deleteOrphaned ? true : false, | ||
upCmd.simulate ? true : false | ||
@@ -303,3 +300,3 @@ ) | ||
}).catch(function(error){ | ||
console.error(error); | ||
console.error(error); | ||
}); | ||
@@ -311,2 +308,4 @@ }); | ||
.parse(process.argv); | ||
if (!cli.args.length) cli.help(); | ||
if (!cli.args.length) { | ||
cli.help(); | ||
} |
@@ -5,5 +5,8 @@ { | ||
"description": "Command line utility to download and upload 28.io queries.", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"keywords": [ | ||
"jsoniq", "xquery", "dev", "cloud" | ||
"jsoniq", | ||
"xquery", | ||
"dev", | ||
"cloud" | ||
], | ||
@@ -30,2 +33,5 @@ "homepage": "https://28.io", | ||
"devDependencies": { | ||
"grunt": "~0.4.2", | ||
"grunt-contrib-jshint": "~0.6.3", | ||
"matchdep": "~0.3.0" | ||
}, | ||
@@ -38,7 +44,7 @@ "optionalDependencies": {}, | ||
"contributors": [ | ||
{ | ||
"name": "William Candillon", | ||
"email": "w@28.io" | ||
} | ||
{ | ||
"name": "William Candillon", | ||
"email": "w@28.io" | ||
} | ||
] | ||
} |
26941
9
626
3