2015-05-07 15:40:12 +00:00
( function ( ) {
2015-10-21 14:03:48 +00:00
var Promise , capitano , patterns , resin ;
2015-05-07 15:40:12 +00:00
Promise = require ( 'bluebird' ) ;
capitano = Promise . promisifyAll ( require ( 'capitano' ) ) ;
resin = require ( 'resin-sdk' ) ;
2015-08-20 19:54:42 +00:00
patterns = require ( '../utils/patterns' ) ;
2015-08-27 14:01:33 +00:00
2015-05-07 15:40:12 +00:00
exports . wizard = {
signature : 'quickstart [name]' ,
description : 'getting started with resin.io' ,
help : 'Use this command to run a friendly wizard to get started with resin.io.\n\nThe wizard will guide you through:\n\n - Create an application.\n - Initialise an SDCard with the resin.io operating system.\n - Associate an existing project directory with your resin.io application.\n - Push your project to your devices.\n\nExamples:\n\n $ sudo resin quickstart\n $ sudo resin quickstart MyApp' ,
permission : 'user' ,
2015-10-01 14:39:36 +00:00
primary : true ,
2015-05-07 15:40:12 +00:00
action : function ( params , options , done ) {
2015-08-27 14:01:33 +00:00
return Promise [ "try" ] ( function ( ) {
if ( params . name != null ) {
return ;
2015-05-07 15:40:12 +00:00
}
2015-09-29 15:10:33 +00:00
return patterns . selectOrCreateApplication ( ) . tap ( function ( applicationName ) {
2015-09-11 15:30:30 +00:00
return resin . models . application . has ( applicationName ) . then ( function ( hasApplication ) {
if ( hasApplication ) {
return applicationName ;
}
return capitano . runAsync ( "app create " + applicationName ) ;
} ) ;
2015-08-27 14:01:33 +00:00
} ) . then ( function ( applicationName ) {
return params . name = applicationName ;
} ) ;
} ) . then ( function ( ) {
return capitano . runAsync ( "device init --application " + params . name ) ;
2015-08-20 19:54:42 +00:00
} ) . tap ( patterns . awaitDevice ) . then ( function ( uuid ) {
2015-08-27 14:01:33 +00:00
return capitano . runAsync ( "device " + uuid ) ;
2015-10-21 14:03:48 +00:00
} ) . then ( function ( ) {
return console . log ( 'Your device is ready, start pushing some code!' ) ;
2015-08-27 14:01:33 +00:00
} ) . nodeify ( done ) ;
2015-05-07 15:40:12 +00:00
}
} ;
} ) . call ( this ) ;