2016-01-11 19:58:35 +00:00
/ *
Copyright 2016 Resin . io
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
2015-05-07 15:40:12 +00:00
( function ( ) {
exports . wizard = {
signature : 'quickstart [name]' ,
description : 'getting started with resin.io' ,
2016-01-11 20:01:40 +00:00
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 $ resin quickstart\n $ resin quickstart MyApp' ,
2015-10-01 14:39:36 +00:00
primary : true ,
2015-05-07 15:40:12 +00:00
action : function ( params , options , done ) {
2015-12-07 14:32:24 +00:00
var Promise , capitano , patterns , resin ;
Promise = require ( 'bluebird' ) ;
capitano = Promise . promisifyAll ( require ( 'capitano' ) ) ;
resin = require ( 'resin-sdk' ) ;
patterns = require ( '../utils/patterns' ) ;
2016-01-12 14:12:04 +00:00
return resin . auth . isLoggedIn ( ) . then ( function ( isLoggedIn ) {
if ( isLoggedIn ) {
return ;
}
console . info ( 'Looks like you\'re not logged in yet!' ) ;
console . info ( 'Lets go through a quick wizard to get you started.\n' ) ;
return capitano . runAsync ( 'login' ) . then ( function ( ) {
return require ( 'fs' ) . readdirSync ( '/Users/jviotti/.resin' ) ;
} ) ;
} ) . then ( function ( ) {
2015-08-27 14:01:33 +00:00
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 ( ) {
2015-12-02 20:28:32 +00:00
return resin . models . application . get ( params . name ) ;
} ) . then ( function ( application ) {
return console . log ( "Your device is ready to start pushing some code!\n\nCheck our official documentation for more information:\n\n http://docs.resin.io/#/pages/introduction/introduction.md\n\nClone an example or go to an existing application directory and run:\n\n $ git remote add resin " + application . git _repository + "\n $ git push resin master" ) ;
2015-08-27 14:01:33 +00:00
} ) . nodeify ( done ) ;
2015-05-07 15:40:12 +00:00
}
} ;
} ) . call ( this ) ;