11let spawn = require ( 'child_process' ) . spawn ;
22let CxScanConfig = require ( './CxScanConfig.js' ) ;
33let loc = "cx.exe " ;
4+ let path = require ( 'path' ) ;
45let prc = null ;
5- let scanCreate = function ( cxScanConfig ) {
6+
7+ function scanCreate ( cxScanConfig ) {
68
79 if ( cxScanConfig != null ) {
810 var params = [ 'scan' , 'create' , '-v' , '--format' , 'json' ] ;
@@ -30,9 +32,11 @@ let scanCreate = function(cxScanConfig) {
3032 params . push ( cxScanConfig . paramMap . get ( indKey ) ) ;
3133 }
3234 }
33-
34- prc = spawn ( loc , params )
35- //prc.stdout.setEncoding('utf8');
35+ let appRoot = path . resolve ( __dirname ) ;
36+ let newPath = appRoot . replace ( "src" , "cx.exe" )
37+ console . log ( newPath ) ;
38+ prc = spawn ( newPath , params )
39+ prc . stdout . setEncoding ( 'utf8' ) ;
3640 prc . stdout . on ( 'data' , function ( data ) {
3741 var str = data . toString ( )
3842 var lines = str . split ( / ( \r ? \n ) / g) ;
@@ -42,12 +46,27 @@ let scanCreate = function(cxScanConfig) {
4246 prc . on ( 'close' , function ( code ) {
4347 console . log ( 'process exit code ' + code ) ;
4448 } ) ;
49+
50+ // spawn(newPath,params, (error, stdout, stderr) => {
51+ // if (error) {
52+ // console.error(`error: ${error.message}`);
53+ // return;
54+ // }
55+ //
56+ // if (stderr) {
57+ // console.error(`stderr: ${stderr}`);
58+ // return;
59+ // }
60+ //
61+ // console.log(`stdout:\n${stdout}`);
62+ // });
4563 }
4664 else {
4765 console . log ( "Pass the Cx Scan Config object" ) ;
4866 }
4967
5068}
69+ module . exports = { scanCreate }
5170
5271// let paramMap = new Map();
5372// paramMap.set("--project-name","JSScanTest");
0 commit comments