2017-07-27 11:07:05 +00:00
// Generated by CoffeeScript 1.12.7
2016-01-11 19:58:35 +00:00
/ *
2017-06-14 21:20:15 +00:00
Copyright 2016 - 2017 Resin . io
2016-01-11 19:58:35 +00:00
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 .
* /
2017-03-22 09:46:06 +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 $ resin quickstart\n $ resin quickstart MyApp' ,
primary : true ,
action : function ( params , options , done ) {
2017-03-27 09:14:55 +00:00
var Promise , capitanoRunAsync , patterns , resin ;
2017-03-22 09:46:06 +00:00
Promise = require ( 'bluebird' ) ;
2017-03-27 09:14:55 +00:00
capitanoRunAsync = Promise . promisify ( require ( 'capitano' ) . run ) ;
2017-03-22 09:46:06 +00:00
resin = require ( 'resin-sdk-preconfigured' ) ;
patterns = require ( '../utils/patterns' ) ;
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' ) ;
2017-03-27 09:14:55 +00:00
return capitanoRunAsync ( 'login' ) ;
2017-03-22 09:46:06 +00:00
} ) . then ( function ( ) {
if ( params . name != null ) {
return ;
}
return patterns . selectOrCreateApplication ( ) . tap ( function ( applicationName ) {
return resin . models . application . has ( applicationName ) . then ( function ( hasApplication ) {
if ( hasApplication ) {
return applicationName ;
}
2017-03-27 09:14:55 +00:00
return capitanoRunAsync ( "app create " + applicationName ) ;
2015-08-27 14:01:33 +00:00
} ) ;
2017-03-22 09:46:06 +00:00
} ) . then ( function ( applicationName ) {
return params . name = applicationName ;
} ) ;
} ) . then ( function ( ) {
2017-03-27 09:14:55 +00:00
return capitanoRunAsync ( "device init --application " + params . name ) ;
2017-03-22 09:46:06 +00:00
} ) . tap ( patterns . awaitDevice ) . then ( function ( uuid ) {
2017-03-27 09:14:55 +00:00
return capitanoRunAsync ( "device " + uuid ) ;
2017-03-22 09:46:06 +00:00
} ) . then ( function ( ) {
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" ) ;
} ) . nodeify ( done ) ;
}
} ;