@@ -5,14 +5,12 @@ const ParticleApi = require('./api');
55const  settings  =  require ( '../../settings' ) ; 
66const  createApiCache  =  require ( '../lib/api-cache' ) ; 
77const  ApiClient  =  require ( '../lib/api-client' ) ; 
8- const  temp  =  require ( 'temp' ) . track ( ) ; 
98const  os  =  require ( 'os' ) ; 
10- const  FlashCommand  =  require ( './flash' ) ; 
119const  CloudCommand  =  require ( './cloud' ) ; 
1210
1311const  DownloadManager  =  require ( '../lib/download-manager' ) ; 
1412const  path  =  require ( 'path' ) ; 
15- const  {  prepareFlashFiles ,   getTachyonInfo,  getEDLDevice,  handleFlashError,  promptOSSelection,  isFile,  readManifestFromLocalFile
13+ const  {  getTachyonInfo,  getEDLDevice,  handleFlashError,  promptOSSelection,  isFile,  readManifestFromLocalFile
1614}  =  require ( '../lib/tachyon-utils' ) ; 
1715const  {  workflows,  workflowRun }  =  require ( '../lib/tachyon/workflow' ) ; 
1816
@@ -85,6 +83,7 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
8583		await  fs . ensureFile ( this . outputLog ) ; 
8684		this . ui . write ( `${ os . EOL }  Starting Process. See logs at: ${ this . outputLog } ${ os . EOL }  ` ) ; 
8785		const  deviceInfo  =  await  this . _getDeviceInfo ( ) ; 
86+ 		deviceInfo . usbVersion  =  this . device . usbVersion . major ; 
8887		this . _printDeviceInfo ( deviceInfo ) ; 
8988		// check if there is a config file 
9089		// validate version if local then workflow will be inferred from the manifest 
@@ -96,13 +95,18 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
9695			ui : this . ui , 
9796			api : this . api , 
9897			deviceInfo : deviceInfo , 
98+ 			device : this . device , 
9999			log : { 
100+ 				file : this . outputLog , 
100101				info : ( msg )  =>  fs . appendFileSync ( this . outputLog ,  `info: ${ msg }   ${ os . EOL }  ` ) , 
101102				error : ( msg )  =>  fs . appendFileSync ( this . outputLog ,  `error: ${ msg }   ${ os . EOL }  ` ) , 
102103			} 
103104		} ; 
104105
105- 		await  workflowRun ( config . workflow ,  context ) ; 
106+ 		const  workflowContext  =  await  workflowRun ( config . workflow ,  context ) ; 
107+ 		if  ( workflowContext . saveConfig )  { 
108+ 			await  this . _saveConfig ( workflowContext ) ; 
109+ 		} 
106110	} 
107111
108112	async  _getDeviceInfo ( )  { 
@@ -270,6 +274,30 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
270274		) ; 
271275	} 
272276
277+ 	async  _saveConfig ( config )  { 
278+ 		const  configFields  =  [ 
279+ 			'region' , 
280+ 			'version' , 
281+ 			'variant' , 
282+ 			'skipCli' , 
283+ 			'systemPassword' , 
284+ 			'productId' , 
285+ 			'timezone' , 
286+ 			'wifi' , 
287+ 			'country' , 
288+ 		] ; 
289+ 		const  configData  =  {  ...config  } ; 
290+ 
291+ 		const  savedConfig  =  Object . fromEntries ( 
292+ 			configFields 
293+ 				. filter ( key  =>  key  in  configData  &&  configData [ key ]  !==  null  &&  configData [ key ]  !==  undefined ) 
294+ 				. map ( key  =>  [ key ,  configData [ key ] ] ) 
295+ 		) ; 
296+ 		savedConfig . workflow  =  config . workflow . value ; 
297+ 		await  fs . writeFile ( config . saveConfig ,  JSON . stringify ( savedConfig ,  null ,  2 ) ,  'utf-8' ) ; 
298+ 		this . ui . write ( `${ os . EOL }  Configuration file written here: ${ config . saveConfig } ${ os . EOL }  ` ) ; 
299+ 	} 
300+ 
273301	_particleApi ( )  { 
274302		const  auth  =  settings . access_token ; 
275303		const  api  =  new  ParticleApi ( settings . apiUrl ,  {  accessToken : auth  }  ) ; 
0 commit comments