@@ -395,6 +395,7 @@ var pioEnv = (file) =>
395395  promisify ( fs . readFile ) ( file ,  'utf8' ) 
396396  . then ( a => a . split ( / \r \n ? | \n / ) ) 
397397  . then ( a => a . map ( i => i . match ( / \[ e n v \: ( .* ) \] / ) ) . filter ( i => i ) . map ( i => i [ 1 ] ) ) 
398+ 
398399app . get ( '/version/:screen' ,  function  ( req ,  res )  { 
399400  res . set ( 'Content-Type' ,  'text/plain' ) ; 
400401    visitor . screenview ( { 
@@ -419,20 +420,15 @@ function pioRoot(){
419420  return  seek4File ( 'platformio.ini' ,  [ '' ,  'Marlin' ] ) 
420421} 
421422app . get ( '/pio/:env' ,  function  ( req ,  res )  { 
422-   params = [ 'run' ] ; 
423-   if  ( req . params . env != 'Default' ) 
424-     params . push ( '-e' , req . params . env ) ; 
425-   pioRoot ( ) 
426-   . then ( root => 
427-     pio . run ( params , res ) 
428-   ) ; 
423+   var  params  =  [ 'run' ] ; 
424+   if  ( req . params . env  !=  'Default' ) 
425+     params . push ( '-e' ,  req . params . env ) ; 
426+   pioRoot ( ) . then ( file  =>  pio . run ( params ,  res ,  path . dirname ( file ) ) ) ; 
429427} ) ; 
430- function  atob ( b64string ) { 
428+ function  atob ( b64string )   { 
431429  if  (  process . version < "v6.0.0"  ) 
432-     // Node 5.10+ 
433430    return  Buffer . from ( b64string ,  'base64' ) ; 
434431  else 
435-     // older Node versions 
436432    return  new  Buffer ( b64string ,  'base64' ) ; 
437433} 
438434
@@ -444,24 +440,17 @@ app.get('/pio/:env/:port', function (req, res) {
444440    params . push ( '-e' , req . params . env ) ; 
445441  if  ( close ) 
446442    params . push ( '--upload-port' , port ) 
447-   console . log ( params ) ;  //if removed - process hangs :) 
443+   console . log ( ) ;  //if removed - process hangs :) 
448444  ( close && serial_enabled ?serial . close ( port ) :Promise . resolve ( true ) ) 
449445  . then ( pioRoot ) 
450-   . then ( root => { 
451-     var  cmd = pio . run ( params , res ) ; 
446+   . then ( file   =>   { 
447+     var  cmd   =   pio . run ( params ,   res ,   path . dirname ( file ) ) ; 
452448    req . on ( 'close' , function ( ) { 
453449      cmd . kill ( 'SIGINT' ) ; 
454450      console . error ( 'flash killed' ) 
455451    } ) 
456452  } ) ; 
457453} ) ; 
458- app . get ( '/pio-flash' ,  function  ( req ,  res )  { 
459-   git . root ( ) 
460-   . then ( root => { 
461-     process . chdir ( path . join ( root , 'Marlin' ) ) 
462-     pio . run ( [ 'run' , '-t' , 'upload' ] , res ) ; 
463-   } ) ; 
464- } ) ; 
465454
466455/* SNIPPETS */ 
467456
0 commit comments