File tree Expand file tree Collapse file tree 4 files changed +37
-16
lines changed Expand file tree Collapse file tree 4 files changed +37
-16
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const Syncano = require('syncano')
5
5
, walkSync = require ( 'walk-sync' )
6
6
, clui = require ( 'clui' )
7
7
, Spinner = clui . Spinner
8
+ , request = require ( 'request' )
8
9
;
9
10
10
11
module . exports = function ( FASTACK ) {
@@ -23,7 +24,7 @@ module.exports = function(FASTACK) {
23
24
resolve ( appId ) ;
24
25
}
25
26
else {
26
- reject ( new Error ( name + ' is not an app on Fastack' ) ) ;
27
+ throw new Error ( 'App doesn\'t exist!' ) ;
27
28
}
28
29
} ) . catch ( ( e ) => {
29
30
reject ( e ) ;
Original file line number Diff line number Diff line change 1
1
const Syncano = require ( 'syncano' )
2
2
, fs = require ( 'fs' )
3
+ , request = require ( 'request' )
3
4
;
4
5
5
6
module . exports = function ( FASTACK ) {
@@ -8,18 +9,30 @@ module.exports = function(FASTACK) {
8
9
9
10
var fastack = new Syncano ( { instance : 'fastack' , apiKey : FASTACK . apiKey , userKey : FASTACK . userKey } ) ;
10
11
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
+ } )
23
36
24
37
}
25
38
Original file line number Diff line number Diff line change @@ -194,9 +194,9 @@ vorpal
194
194
. action ( require ( './commands/deploy.js' ) ( FASTACK ) ) ;
195
195
196
196
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 ) ) ;
200
200
201
201
202
202
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const shell = require('shelljs')
4
4
, Path = require ( 'path' )
5
5
, fs = require ( 'fs-extra' )
6
6
, walkSync = require ( 'walk-sync' )
7
+ , Syncano = require ( 'syncano' )
7
8
;
8
9
9
10
shell . log = function ( ) {
@@ -96,6 +97,12 @@ module.exports = function(FASTACK) {
96
97
} )
97
98
} ;
98
99
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
+
99
106
100
107
return new Promise ( function ( resolve , reject ) {
101
108
resolve ( ) ;
You can’t perform that action at this time.
0 commit comments