Skip to content

Commit 61fa762

Browse files
committed
deploy and new_app
1 parent c05cafa commit 61fa762

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

lib/commands/deploy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const Syncano = require('syncano')
55
, walkSync = require('walk-sync')
66
, clui = require('clui')
77
, Spinner = clui.Spinner
8+
, request = require('request')
89
;
910

1011
module.exports = function(FASTACK) {
@@ -23,7 +24,7 @@ module.exports = function(FASTACK) {
2324
resolve(appId);
2425
}
2526
else {
26-
reject(new Error(name + ' is not an app on Fastack'));
27+
throw new Error('App doesn\'t exist!');
2728
}
2829
}).catch((e) => {
2930
reject(e);

lib/commands/new_app.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Syncano = require('syncano')
22
, fs = require('fs')
3+
, request = require('request')
34
;
45

56
module.exports = function(FASTACK) {
@@ -8,18 +9,30 @@ module.exports = function(FASTACK) {
89

910
var fastack = new Syncano({instance: 'fastack', apiKey: FASTACK.apiKey, userKey: FASTACK.userKey});
1011

11-
var object = {
12-
name: args.app_name
13-
};
14-
15-
fastack.class('apps').dataobject().add(object, function(err, res){
16-
if (err) {
17-
console.log(err);
18-
}
19-
console.log(res.name + " successfully created");
20-
callback();
21-
} );
22-
12+
var createAppEndpoint = 'http://api.fastack.io/create-app';
13+
var userId;
14+
var appName = args['app_name'];
15+
16+
FASTACK.getUserId()
17+
.then((id) => new Promise((resolve, reject) => {
18+
userId = id;
19+
request.post(createAppEndpoint, (error, response) => {
20+
if (error) reject(error);
21+
resolve(response.headers['location']);
22+
})
23+
}))
24+
.then((redirected) => new Promise((resolve, reject) => {
25+
request.post(redirected, {
26+
json: true,
27+
body: {userId, appName}
28+
}, (error, response, body) => {
29+
if (error) reject(error);
30+
else resolve(body);
31+
})
32+
}))
33+
.finally(() => {
34+
callback();
35+
})
2336

2437
}
2538

lib/fastack.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ vorpal
194194
.action(require('./commands/deploy.js')(FASTACK));
195195

196196

197-
//vorpal
198-
// .command('new_app [app_name]', 'create a new fastack app')
199-
// .action(require('./commands/new_app.js')(FASTACK));
197+
vorpal
198+
.command('new_app <app_name>', 'create a new fastack app')
199+
.action(require('./commands/new_app.js')(FASTACK));
200200

201201

202202

lib/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const shell = require('shelljs')
44
, Path = require('path')
55
, fs = require('fs-extra')
66
, walkSync = require('walk-sync')
7+
, Syncano = require('syncano')
78
;
89

910
shell.log = function() {
@@ -96,6 +97,12 @@ module.exports = function(FASTACK) {
9697
})
9798
};
9899

100+
FASTACK.getUserId = () => new Promise((resolve, reject) => {
101+
var fastack = new Syncano({instance: 'fastack', apiKey: FASTACK.apiKey, userKey: FASTACK.userKey});
102+
fastack.class('user_profile').dataobject().list()
103+
.then((u) => resolve(u.objects[0].owner))
104+
});
105+
99106

100107
return new Promise(function(resolve, reject) {
101108
resolve();

0 commit comments

Comments
 (0)