1- var fs = require ( 'fs' ) ;
2- var path = require ( 'path' ) ;
1+ //@ts -check
32
4- var RELEASE_DIR = path . join ( __dirname , '..' , 'build' , 'Release' ) ;
5- var BUILD_FILES = [
3+ const fs = require ( 'fs' ) ;
4+ const os = require ( 'os' ) ;
5+ const path = require ( 'path' ) ;
6+
7+ const RELEASE_DIR = path . join ( __dirname , '../build/Release' ) ;
8+ const BUILD_FILES = [
69 path . join ( RELEASE_DIR , 'conpty.node' ) ,
710 path . join ( RELEASE_DIR , 'conpty.pdb' ) ,
811 path . join ( RELEASE_DIR , 'conpty_console_list.node' ) ,
@@ -15,14 +18,18 @@ var BUILD_FILES = [
1518 path . join ( RELEASE_DIR , 'winpty.dll' ) ,
1619 path . join ( RELEASE_DIR , 'winpty.pdb' )
1720] ;
21+ const CONPTY_DIR = path . join ( __dirname , '../third_party/conpty' ) ;
22+ const CONPTY_SUPPORTED_ARCH = [ 'x64' , 'arm64' ] ;
23+
24+ console . log ( '\x1b[32m> Cleaning release folder...\x1b[0m' ) ;
1825
19- cleanFolderRecursive = function ( folder ) {
26+ function cleanFolderRecursive ( folder ) {
2027 var files = [ ] ;
21- if ( fs . existsSync ( folder ) ) {
28+ if ( fs . existsSync ( folder ) ) {
2229 files = fs . readdirSync ( folder ) ;
2330 files . forEach ( function ( file , index ) {
2431 var curPath = path . join ( folder , file ) ;
25- if ( fs . lstatSync ( curPath ) . isDirectory ( ) ) { // recurse
32+ if ( fs . lstatSync ( curPath ) . isDirectory ( ) ) { // recurse
2633 cleanFolderRecursive ( curPath ) ;
2734 fs . rmdirSync ( curPath ) ;
2835 } else if ( BUILD_FILES . indexOf ( curPath ) < 0 ) { // delete file
3643 cleanFolderRecursive ( RELEASE_DIR ) ;
3744} catch ( e ) {
3845 console . log ( e ) ;
39- //process.exit(1);
40- } finally {
41- process . exit ( 0 ) ;
46+ process . exit ( 1 ) ;
47+ }
48+
49+ console . log ( `\x1b[32m> Moving conpty.dll...\x1b[0m` ) ;
50+ if ( os . platform ( ) !== 'win32' ) {
51+ console . log ( ' SKIPPED (not Windows)' ) ;
52+ } else {
53+ const windowsArch = os . arch ( ) ;
54+ if ( ! CONPTY_SUPPORTED_ARCH . includes ( windowsArch ) ) {
55+ console . log ( ` SKIPPED (unsupported architecture ${ windowsArch } )` ) ;
56+ } else {
57+ const versionFolder = fs . readdirSync ( CONPTY_DIR ) [ 0 ] ;
58+ console . log ( ` Found version ${ versionFolder } ` ) ;
59+ const sourceFolder = path . join ( CONPTY_DIR , versionFolder , `win10-${ windowsArch } ` ) ;
60+ const destFolder = path . join ( RELEASE_DIR , 'conpty' ) ;
61+ fs . mkdirSync ( destFolder , { recursive : true } ) ;
62+ for ( const file of [ 'conpty.dll' , 'OpenConsole.exe' ] ) {
63+ const sourceFile = path . join ( sourceFolder , file ) ;
64+ const destFile = path . join ( destFolder , file ) ;
65+ console . log ( ` Copying ${ sourceFile } -> ${ destFile } ` ) ;
66+ fs . copyFileSync ( sourceFile , destFile ) ;
67+ }
68+ }
4269}
70+
71+ process . exit ( 0 ) ;
0 commit comments