22// The module 'vscode' contains the VS Code extensibility API
33// Import the module and reference it with the alias vscode in your code below
44import * as vscode from 'vscode' ;
5- const http = require ( 'axios' ) ;
5+ import http from 'axios' ;
66const fs = require ( "fs" ) ;
77
88// this method is called when your extension is activated
@@ -40,10 +40,12 @@ export function activate(context: vscode.ExtensionContext) {
4040 const content = result . getText ( ) ;
4141 let url : string ;
4242 let strictSSL : boolean ;
43+ let noProxy : boolean ;
4344 if ( content [ 0 ] === '{' ) {
4445 const configuration = JSON . parse ( content ) ;
4546 url = configuration . Generator . Connection ;
4647 strictSSL = configuration . Generator . VerifySsl ;
48+ noProxy = configuration . Generation . NoProxy ;
4749 }
4850 else {
4951 const start = content . indexOf ( '<Generator>' ) + 11 ;
@@ -65,17 +67,25 @@ export function activate(context: vscode.ExtensionContext) {
6567 const verifySslStart = generatorNode . indexOf ( '<VerifySsl>' ) + 11 ;
6668 const verifySslEnd = generatorNode . indexOf ( '</VerifySsl>' ) ;
6769 strictSSL = verifySslEnd === - 1 || generatorNode . substring ( verifySslStart , verifySslEnd ) . trim ( ) !== 'false' ;
70+ const noProxyStart = generatorNode . indexOf ( '<NoProxy>' ) ;
71+ const noProxyEnd = generatorNode . indexOf ( '</NoProxy>' ) ;
72+ const noProxyStandalone = generatorNode . includes ( '<NoProxy/>' ) || generatorNode . includes ( '<NoProxy />' ) ;
73+ noProxy = noProxyStandalone || noProxyStart >= 0 && generatorNode . substring ( noProxyStart + 9 , noProxyEnd ) . trim ( ) !== 'false' ;
6874 }
6975 if ( strictSSL === false ) {
7076 process . env [ 'NODE_TLS_REJECT_UNAUTHORIZED' ] = 0 ;
7177 }
7278 let id : string ;
73- http . post ( url + '/Create' , { configuration : content , } )
74- . then ( ( response : any ) => {
79+ const httpClient = http . create ( {
80+ baseURL : url ,
81+ proxy : noProxy ? false : undefined
82+ } ) ;
83+ httpClient . post ( '/Create' , { configuration : content } )
84+ . then ( response => {
7585 id = response . data ;
76- return http . get ( url + '/GetFiles/' + id ) ;
86+ return httpClient . get ( '/GetFiles/' + id ) ;
7787 } )
78- . then ( ( response : any ) => {
88+ . then ( response => {
7989 const data = response . data as string ;
8090 if ( ! data ) {
8191 vscode . window . showErrorMessage ( 'The generation is failed with an unkonw error #222d' ) ;
@@ -85,23 +95,29 @@ export function activate(context: vscode.ExtensionContext) {
8595 const promises : any [ ] = [ ] ;
8696 filePaths . forEach ( filePath => {
8797 const fullPath = currentDirectory . uri . fsPath + '\\' + filePath ;
88- const promise = http . get ( url + '/GetFile/' + id + '?path=' + filePath )
98+ const directory = fullPath . substring ( 0 , fullPath . lastIndexOf ( '\\' ) ) ;
99+ fs . mkdir ( directory ) ;
100+ const promise = httpClient . get ( '/GetFile/' + id + '?path=' + filePath )
89101 . then ( ( fileResponse : any ) => {
90102 const content = fileResponse . data as string ;
91103 fs . writeFile ( fullPath , content ) ;
92104 vscode . window . showInformationMessage ( fullPath + ' updated' ) ;
93105 } ) ;
94106 promises . push ( promise ) ;
95107 } ) ;
96- return Promise . all ( promises ) . then ( ( ) => filePaths . length ) ;
108+ return < any > Promise . all ( promises ) . then ( ( ) => filePaths . length ) ;
97109 } )
98110 . then ( ( count : number ) => {
99111 if ( count > 0 ) {
100112 vscode . window . showInformationMessage ( count + ' files generated' ) ;
101113 }
102114 } )
103115 . catch ( ( error : Error ) => {
104- vscode . window . showErrorMessage ( 'Can not reach the generator server #231d\r\n' + error ) ;
116+ let details = '' ;
117+ if ( error . message . includes ( 'SSL23_GET_SERVER_HELLO' ) ) {
118+ details = 'Try to disable proxy with <Generator><NoProxy />...\r\n\r\n' ;
119+ }
120+ vscode . window . showErrorMessage ( 'Can not reach the generator server #231d\r\n' + details + error ) ;
105121 } ) ;
106122 } ) ;
107123 } ) ;
0 commit comments