2015-05-07 15:40:12 +00:00
( function ( ) {
2015-08-20 19:54:42 +00:00
var Promise , capitano , form , mkdirp , patterns , resin ;
2015-05-07 15:40:12 +00:00
Promise = require ( 'bluebird' ) ;
capitano = Promise . promisifyAll ( require ( 'capitano' ) ) ;
2015-08-27 14:01:33 +00:00
mkdirp = Promise . promisify ( require ( 'mkdirp' ) ) ;
2015-05-07 15:40:12 +00:00
resin = require ( 'resin-sdk' ) ;
form = require ( 'resin-cli-form' ) ;
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' ,
root : true ,
permission : 'user' ,
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-08-20 19:54:42 +00:00
return patterns . selectApplication ( ) . tap ( function ( applicationName ) {
2015-08-27 14:01:33 +00:00
return capitano . runAsync ( "app create " + applicationName ) ;
} ) . 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 ) ;
} ) . tap ( function ( ) {
return console . log ( 'Your device is ready, lets start pushing some code!' ) ;
2015-08-20 19:54:42 +00:00
} ) . then ( patterns . selectProjectDirectory ) . tap ( mkdirp ) . tap ( process . chdir ) . then ( function ( ) {
2015-08-27 14:01:33 +00:00
return capitano . runAsync ( "app associate " + params . name ) ;
} ) . then ( function ( remoteUrl ) {
console . log ( "Resin git remote added: " + remoteUrl ) ;
return console . log ( "Please type:\n\n $ cd " + ( process . cwd ( ) ) + " && git push resin master\n\nTo push your project to resin.io." ) ;
} ) . nodeify ( done ) ;
2015-05-07 15:40:12 +00:00
}
} ;
} ) . call ( this ) ;