|
280 | 280 |
|
281 | 281 | var term; |
282 | 282 | var shell; |
| 283 | + var input; |
283 | 284 | var user_dir; |
284 | 285 | var cwd_abs; |
285 | 286 | var cwd; |
|
439 | 440 |
|
440 | 441 | install['https-server'] = async function(){ |
441 | 442 |
|
| 443 | + if(cwd===null){ |
| 444 | + log.red('can only install https-server relative to workdir'); |
| 445 | + return; |
| 446 | + } |
| 447 | + |
442 | 448 | log.green('installing https-server'); |
443 | 449 |
|
444 | 450 | var mod = await import('https://code.ext-code.com/nodejs/servers/https-server/create-archive.m.js'); |
|
454 | 460 |
|
455 | 461 | path = path.slice(base.length); |
456 | 462 | path = cwd+path; |
457 | | - console.log(path,file); |
458 | | - if(path){ |
| 463 | + console.log(path);//,file); |
| 464 | + if(path.length>cwd.length){ |
459 | 465 | if(file.dir){ |
460 | | - await webcontainer.fs.mkdir(path); |
| 466 | + await webcontainer.fs.mkdir(path,{recursive:true}); |
461 | 467 | }else{ |
462 | 468 | //console.log("File:",path,file); |
463 | 469 | //console.log("Content:", content); |
|
469 | 475 | }//for |
470 | 476 |
|
471 | 477 |
|
472 | | - await webcontainer.spawn('npm',['i'],{cwd}); |
| 478 | + var process = await webcontainer.spawn('npm',['i'],{cwd,output:true}); |
| 479 | + var stream = new WritableStream({write(data){term.write(data)}}); |
| 480 | + process.output.pipeTo(stream) |
| 481 | + var code = await process.exit; |
| 482 | + if(code!=0){ |
| 483 | + log.red('an error ocurred : '+code); |
| 484 | + }else{ |
| 485 | + log.green('done.'); |
| 486 | + } |
| 487 | + term.writeln('done.'); |
473 | 488 |
|
474 | | - log.green('done.'); |
| 489 | + //await input.write('\u0003'); // Sends Ctrl+C to clear any junk |
| 490 | + await input.write('\n'); // Sends Enter to get a clean prompt |
475 | 491 |
|
476 | 492 | }//https-server |
477 | 493 |
|
|
794 | 810 | }); |
795 | 811 | shell.output.pipeTo(output); |
796 | 812 |
|
797 | | - var input = shell.input.getWriter(); |
| 813 | + input = shell.input.getWriter(); |
798 | 814 | term.onData(data=>input.write(data)); |
799 | 815 |
|
800 | 816 | //term.resize(); |
|
803 | 819 | })(); |
804 | 820 |
|
805 | 821 |
|
806 | | - async function getShellCwd(shell){ |
807 | | - |
808 | | - return new Promise(resolve=>{ |
809 | | - |
810 | | - var decoder = new TextDecoder(); |
811 | | - var onData = data=>{ |
812 | | - |
813 | | - var text = decoder.decode(data); |
814 | | - var line = text.trim(); |
815 | | - if(line.startsWith('/')){ |
816 | | - shell.output.off('data',onData); |
817 | | - resolve(line); |
818 | | - } |
819 | | - |
820 | | - }; |
821 | | - |
822 | | - shell.output.on('data',onData); |
823 | | - shell.input.write('pwd\n'); |
824 | | - |
825 | | - }); |
826 | | - |
827 | | - }//getShellCwd |
828 | 822 |
|
829 | 823 |
|
830 | 824 |
|
|
0 commit comments