@@ -12,15 +12,6 @@ import { getFiles } from './util';
1212
1313const fs = vscode . workspace . fs ;
1414
15- type ACTIONS = {
16- [ id : string ] : {
17- baseBundle : string ,
18- before : string [ ] ,
19- run : string [ ] ,
20- debug : string [ ]
21- }
22- } ;
23-
2415export interface AsmResult {
2516 message ?: string ,
2617 error ?: number ,
@@ -65,20 +56,14 @@ export async function activate(context: vscode.ExtensionContext) {
6556 await emptyFolder ( assemblyToolsFolder . fsPath ) ;
6657 await emptyFolder ( seperateSpaceFolder . fsPath ) ;
6758
68- const actions : ACTIONS | undefined = extConfig . get ( 'ASM.actions' ) ;
69- if ( actions === undefined ) {
70- throw new Error ( "configurate `masmtasm.ASM.actions` first" ) ;
71- }
72- const action = actions [ conf . extConf . asmType ] ;
73-
7459 const doc = await vscode . workspace . openTextDocument ( _uri ) ;
7560 if ( doc . isDirty && extConfig . get ( 'ASM.savefirst' ) ) {
7661 await doc . save ( ) ;
7762 }
7863
7964 const bundlePath = vscode . Uri . joinPath (
8065 context . extensionUri ,
81- action [ "baseBundle" ] . replace ( '<built-in>/' , "resources/" )
66+ conf . extConf . action [ "baseBundle" ] . replace ( '<built-in>/' , "resources/" )
8267 ) ;
8368 const bundle = await fs . readFile ( bundlePath ) ;
8469
@@ -95,9 +80,12 @@ export async function activate(context: vscode.ExtensionContext) {
9580 const autoexec = [
9681 `mount c "${ assemblyToolsFolder . fsPath } ""` ,
9782 `mount d "${ folder . fsPath } ""` ,
98- 'd:' ,
99- ...action . before
83+ 'd:'
10084 ] ;
85+ const before = conf . extConf . action . before ;
86+ if ( before ) {
87+ autoexec . push ( ...before ) ;
88+ }
10189 const logUri = vscode . Uri . joinPath ( assemblyToolsFolder , logFilename ) ;
10290 if ( nodefs . existsSync ( logUri . fsPath ) ) {
10391 await fs . delete ( logUri ) ;
@@ -112,10 +100,10 @@ export async function activate(context: vscode.ExtensionContext) {
112100 return r + " >>C:\\" + logFilename ;
113101 }
114102 if ( act === conf . actionType . run ) {
115- autoexec . push ( ...action . run . map ( cb ) ) ;
103+ autoexec . push ( ...conf . extConf . action . run . map ( cb ) ) ;
116104 }
117105 if ( act === conf . actionType . debug ) {
118- autoexec . push ( ...action . debug . map ( cb ) ) ;
106+ autoexec . push ( ...conf . extConf . action . debug . map ( cb ) ) ;
119107 }
120108
121109 const box = conf . extConf . emulator === conf . DosEmulatorType . dosboxX ? api . dosboxX : api . dosbox ;
@@ -189,9 +177,12 @@ export async function activate(context: vscode.ExtensionContext) {
189177 const autoexec = [
190178 `mount c .` ,
191179 `mount d ./code` ,
192- 'd:' ,
193- ...action . before
180+ 'd:'
194181 ] ;
182+ const before = conf . extConf . action . before ;
183+ if ( before ) {
184+ autoexec . push ( ...before ) ;
185+ }
195186 function cb ( val : string ) {
196187 const r = val
197188 . replace ( "${file}" , fileInfo . base )
@@ -202,10 +193,10 @@ export async function activate(context: vscode.ExtensionContext) {
202193 return r ;
203194 }
204195 if ( act === conf . actionType . run ) {
205- autoexec . push ( ...action . run . map ( cb ) ) ;
196+ autoexec . push ( ...conf . extConf . action . run . map ( cb ) ) ;
206197 }
207198 if ( act === conf . actionType . debug ) {
208- autoexec . push ( ...action . debug . map ( cb ) ) ;
199+ autoexec . push ( ...conf . extConf . action . debug . map ( cb ) ) ;
209200 }
210201 api . jsdos . updateAutoexec ( autoexec ) ;
211202 const webview = await api . jsdos . runInWebview ( ) ;
@@ -227,11 +218,15 @@ export async function activate(context: vscode.ExtensionContext) {
227218
228219 terminal . show ( ) ;
229220 api . dosbox . fromBundle ( bundle , assemblyToolsFolder ) ;
230- action . before . forEach (
231- val => {
232- ( terminal as vscode . Terminal ) . sendText ( val . replace ( 'C:' , assemblyToolsFolder . fsPath ) ) ;
233- }
234- ) ;
221+ const { before, run, debug } = conf . extConf . action ;
222+ if ( before ) {
223+ before . forEach (
224+ val => {
225+ ( terminal as vscode . Terminal ) . sendText ( val . replace ( 'C:' , assemblyToolsFolder . fsPath ) ) ;
226+ }
227+ ) ;
228+ }
229+
235230 if ( act === conf . actionType . open ) {
236231 terminal . sendText ( `cd "${ vscode . Uri . joinPath ( _uri , '..' ) . fsPath } "` ) ;
237232 }
@@ -248,10 +243,10 @@ export async function activate(context: vscode.ExtensionContext) {
248243 }
249244 }
250245 if ( act === conf . actionType . run ) {
251- action . run . map ( cb ) . forEach ( val => ( terminal as vscode . Terminal ) . sendText ( val ) ) ;
246+ run . map ( cb ) . forEach ( val => ( terminal as vscode . Terminal ) . sendText ( val ) ) ;
252247 }
253248 if ( act === conf . actionType . debug ) {
254- action . debug . map ( cb ) . forEach ( val => ( terminal as vscode . Terminal ) . sendText ( val ) ) ;
249+ debug . map ( cb ) . forEach ( val => ( terminal as vscode . Terminal ) . sendText ( val ) ) ;
255250 }
256251 const logUri = vscode . Uri . joinPath ( folder , logFilename ) ;
257252 const [ hook , promise ] = messageCollector ( ) ;
@@ -298,11 +293,7 @@ export async function activate(context: vscode.ExtensionContext) {
298293
299294 emptyFolder ( assemblyToolsFolder . fsPath ) ;
300295
301- const actions : ACTIONS | undefined = extConfig . get ( 'ASM.actions' ) ;
302- if ( actions === undefined ) {
303- throw new Error ( "configurate `masmtasm.ASM.actions` first" ) ;
304- }
305- const action = actions [ conf . extConf . asmType ] ;
296+ const action = conf . extConf . action ;
306297
307298 const doc = await vscode . workspace . openTextDocument ( _uri ) ;
308299 if ( doc . isDirty && extConfig . get ( 'ASM.savefirst' ) ) {
@@ -335,9 +326,11 @@ export async function activate(context: vscode.ExtensionContext) {
335326 `mount c "${ assemblyToolsFolder . fsPath } ""` ,
336327 `mount d "${ workspaceFolder . uri . fsPath } ""` ,
337328 'd:' ,
338- `cd ${ fileInfo . dir } ` ,
339- ...action . before
329+ `cd ${ fileInfo . dir } `
340330 ] ;
331+ if ( action . before ) {
332+ autoexec . push ( ...action . before ) ;
333+ }
341334 const logUri = vscode . Uri . joinPath ( assemblyToolsFolder , logFilename ) ;
342335 if ( nodefs . existsSync ( logUri . fsPath ) ) {
343336 await fs . delete ( logUri ) ;
@@ -435,9 +428,11 @@ export async function activate(context: vscode.ExtensionContext) {
435428 `mount c .` ,
436429 `mount d ./code` ,
437430 'd:' ,
438- `cd ${ fileInfo . dir } ` ,
439- ...action . before
431+ `cd ${ fileInfo . dir } `
440432 ] ;
433+ if ( action . before ) {
434+ autoexec . push ( ...action . before ) ;
435+ }
441436 function cb ( val : string ) {
442437 const r = val
443438 . replace ( "${file}" , fileInfo . base )
@@ -473,7 +468,7 @@ export async function activate(context: vscode.ExtensionContext) {
473468
474469 terminal . show ( ) ;
475470 api . dosbox . fromBundle ( bundle , assemblyToolsFolder ) ;
476- action . before . forEach (
471+ action . before ? .forEach (
477472 val => {
478473 ( terminal as vscode . Terminal ) . sendText ( val . replace ( 'C:' , assemblyToolsFolder . fsPath ) ) ;
479474 }
0 commit comments