11import { ChildProcess , spawn } from 'child_process' ;
2- import { commands , ExtensionContext , Uri , WebviewView , WebviewViewProvider , WebviewViewResolveContext , window , workspace } from 'vscode' ;
2+ import { commands , ExtensionContext , Uri , WebviewView , WebviewViewProvider , WebviewViewResolveContext , window , workspace } from 'vscode' ;
33import { state } from './extension' ;
44import { dirname } from 'path' ;
55import * as treeKill from 'tree-kill' ;
@@ -11,7 +11,7 @@ export default function setupConsole(context: ExtensionContext) {
1111
1212 const register = window . registerWebviewViewProvider ( 'processingConsoleView' , provider ) ;
1313
14- const startSketch = commands . registerCommand ( 'processing.sketch.run' , ( resource : Uri ) => {
14+ const startSketch = commands . registerCommand ( 'processing.sketch.run' , ( resource : Uri , extraArguments : string [ ] ) => {
1515 const autosave = workspace
1616 . getConfiguration ( 'processing' )
1717 . get < boolean > ( 'autosave' ) ;
@@ -25,22 +25,22 @@ export default function setupConsole(context: ExtensionContext) {
2525 resource = editor . document . uri ;
2626 }
2727 }
28-
28+
2929 if ( ! resource ) {
3030 return ;
3131 }
3232 commands . executeCommand ( 'processingConsoleView.focus' ) ;
3333 commands . executeCommand ( 'processing.sketch.stop' ) ;
34-
34+
3535 const proc = spawn (
3636 state . selectedVersion . path ,
37- [ 'cli' , `--sketch=${ dirname ( resource . fsPath ) } ` , '--run' ] ,
37+ [ 'cli' , `--sketch=${ dirname ( resource . fsPath ) } ` , ... extraArguments , '--run' ] ,
3838 {
3939 shell : false ,
4040 }
4141 ) ;
4242 proc . stdout . on ( "data" , ( data ) => {
43- if ( proc != sketchProcesses [ 0 ] ) {
43+ if ( proc != sketchProcesses [ 0 ] ) {
4444 // If this is not the most recent process, ignore its output
4545 return ;
4646 }
@@ -60,7 +60,7 @@ export default function setupConsole(context: ExtensionContext) {
6060 commands . executeCommand ( 'setContext' , 'processing.sketch.running' , sketchProcesses . length > 0 ) ;
6161 } ) ;
6262 provider . webview ?. show ?.( true ) ;
63- provider . webview ?. webview . postMessage ( { type : 'clear' } ) ;
63+ provider . webview ?. webview . postMessage ( { type : 'clear' } ) ;
6464 sketchProcesses . unshift ( proc ) ;
6565 commands . executeCommand ( 'setContext' , 'processing.sketch.running' , true ) ;
6666 } ) ;
@@ -75,11 +75,17 @@ export default function setupConsole(context: ExtensionContext) {
7575 }
7676 } ) ;
7777
78+ const buildSketch = commands . registerCommand ( 'processing.sketch.export' , ( ) => {
79+ commands . executeCommand ( 'processing.sketch.run' , undefined , [ '--export' ] ) ;
80+ } ) ;
81+
82+
7883 context . subscriptions . push (
7984 register ,
8085 startSketch ,
8186 restartSketch ,
82- stopSketch
87+ stopSketch ,
88+ buildSketch
8389 ) ;
8490}
8591
0 commit comments