# All files / dist/systemTools exec.js

19.37% Statements 37/191
1.94% Branches 2/103
0% Functions 0/36
21.15% Lines 33/156

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    3204x
    4x
    4x
    4x
    4x
    4x
    4x
    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x
     var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.executeTelnet=exports.openCommand=exports.commandExistsSync=exports.commandExists=exports.execCLI=exports.executeAsync=void 0;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
    var _path=_interopRequireDefault(require("path"));
    var _fs=_interopRequireWildcard(require("fs"));
    var _chalk=_interopRequireDefault(require("chalk"));
    var _execa=_interopRequireDefault(require("execa"));
    var _ora=_interopRequireDefault(require("ora"));
    var _client=_interopRequireDefault(require("netcat/client"));
    var _util=_interopRequireDefault(require("util"));

    var _common=require("../common");function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(source,true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}var _require=

    require('child_process'),exec=_require.exec,execSync=_require.execSync;

    var _execute=function _execute(c,command){var _c$program,_c$program2,_c$program3;var opts=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};
    var defaultOpts={
    stdio:'pipe',
    localDir:_path.default.resolve('./node_modules/.bin'),
    preferLocal:true,
    all:true,
    maxErrorLength:(_c$program=c.program)==null?void 0:_c$program.maxErrorLength,
    mono:(_c$program2=c.program)==null?void 0:_c$program2.mono};

    var mergedOpts=_objectSpread({},defaultOpts,{},opts);

    var cleanCommand=command;
    var interval;
    var intervalTimer=30000;
    var timer=intervalTimer;

    if(Array.isArray(command))cleanCommand=command.join(' ');

    var logMessage=cleanCommand;var
    privateParams=mergedOpts.privateParams;
    if(privateParams&&Array.isArray(privateParams)){
    logMessage=_util.default.format(command,Array.from(privateParams,function(){return'*******';}));
    cleanCommand=_util.default.format.apply(_util.default,[command].concat((0,_toConsumableArray2.default)(privateParams)));
    }

    (0,_common.logDebug)("_execute: "+logMessage);var
    silent=mergedOpts.silent,mono=mergedOpts.mono,maxErrorLength=mergedOpts.maxErrorLength,ignoreErrors=mergedOpts.ignoreErrors;
    var spinner=!silent&&!mono&&(0,_ora.default)({text:"Executing: "+logMessage}).start();

    if(mono){
    interval=setInterval(function(){
    console.log("Executing: "+logMessage+" - "+timer/1000+"s");
    timer+=intervalTimer;
    },intervalTimer);
    }

    var child=_execa.default.command(cleanCommand,mergedOpts);

    var MAX_OUTPUT_LENGTH=200;

    var printLastLine=function printLastLine(buffer){
    var text=Buffer.from(buffer).toString().trim();
    var lastLine=text.split('\n').pop();
    spinner.text=lastLine.substring(0,MAX_OUTPUT_LENGTH);
    if(lastLine.length===MAX_OUTPUT_LENGTH)spinner.text+='...';
    };

    if((_c$program3=c.program)==null?void 0:_c$program3.info){
    child.stdout.pipe(process.stdout);
    }else if(spinner){
    child.stdout.on('data',printLastLine);
    }

    return child.then(function(res){
    spinner&&child.stdout.off('data',printLastLine);
    !silent&&!mono&&spinner.succeed("Executing: "+logMessage);
    (0,_common.logDebug)(res.all);
    interval&&clearInterval(interval);

    return res.stdout;
    }).catch(function(err){
    spinner&&child.stdout.off('data',printLastLine);
    if(!silent&&!mono&&!ignoreErrors)spinner.fail("FAILED: "+logMessage);
    (0,_common.logDebug)(err.all);
    interval&&clearInterval(interval);

    if(ignoreErrors&&!silent&&!mono){
    spinner.succeed("Executing: "+logMessage);
    return true;
    }
    var errMessage=(0,_common.parseErrorMessage)(err.all,maxErrorLength)||err.stderr||err.message;
    return Promise.reject("FAILED: "+logMessage+" with ERROR: "+errMessage);
    });
    };

    var execCLI=function execCLI(c,cli,command){var opts=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};
    var p=c.cli[cli];

    if(!_fs.default.existsSync(p)){
    (0,_common.logDebug)('execCLI error',cli,command);
    return Promise.reject("Location of your cli "+_chalk.default.white(p)+" does not exists. check your "+_chalk.default.white(
    c.paths.globalConfigPath)+" file if you SDK path is correct");

    }

    return _execute(c,p+" "+command,_objectSpread({},opts,{shell:true}));
    };exports.execCLI=execCLI;

    var executeAsync=function executeAsync(c,cmd,opts){
    if(cmd.includes('npm')&&process.platform==='win32')cmd.replace('npm','npm.cmd');
    return _execute(c,cmd,opts);
    };exports.executeAsync=executeAsync;

    var executeTelnet=function executeTelnet(port,command){return new Promise(function(resolve){
    var nc2=new _client.default();
    (0,_common.logDebug)("execTelnet: "+port+" "+command);

    var output='';

    nc2.addr('127.0.0.1').
    port(parseInt(port,10)).
    connect().
    send(command+"\n");
    nc2.on('data',function(data){
    var resp=Buffer.from(data).toString();
    output+=resp;
    if(output.includes('OK'))nc2.close();
    });
    nc2.on('close',function(){return resolve(output);});
    });};exports.executeTelnet=executeTelnet;

    var isUsingWindows=process.platform==='win32';

    var fileNotExists=function fileNotExists(commandName,callback){
    (0,_fs.access)(commandName,_fs.constants.F_OK,
    function(err){
    callback(!err);
    });
    };

    var fileNotExistsSync=function fileNotExistsSync(commandName){
    try{
    (0,_fs.accessSync)(commandName,_fs.constants.F_OK);
    return false;
    }catch(e){
    return true;
    }
    };

    var localExecutable=function localExecutable(commandName,callback){
    (0,_fs.access)(commandName,_fs.constants.F_OK|_fs.constants.X_OK,
    function(err){
    callback(null,!err);
    });
    };

    var localExecutableSync=function localExecutableSync(commandName){
    try{
    (0,_fs.accessSync)(commandName,_fs.constants.F_OK|_fs.constants.X_OK);
    return true;
    }catch(e){
    return false;
    }
    };

    var commandExistsUnix=function commandExistsUnix(commandName,cleanedCommandName,callback){
    fileNotExists(commandName,function(isFile){
    if(!isFile){
    exec("command -v "+cleanedCommandName+" 2>/dev/null"+(" && { echo >&1 "+

    cleanedCommandName+"; exit 0; }"),
    function(error,stdout){
    callback(null,!!stdout);
    });
    return;
    }

    localExecutable(commandName,callback);
    });
    };

    var commandExistsWindows=function commandExistsWindows(commandName,cleanedCommandName,callback){
    if(/[\x00-\x1f<>:"\|\?\*]/.test(commandName)){
    callback(null,false);
    return;
    }
    exec("where "+cleanedCommandName,
    function(error){
    if(error!==null){
    callback(null,false);
    }else{
    callback(null,true);
    }
    });
    };

    var commandExistsUnixSync=function commandExistsUnixSync(commandName,cleanedCommandName){
    if(fileNotExistsSync(commandName)){
    try{
    var stdout=execSync("command -v "+cleanedCommandName+" 2>/dev/null"+(" && { echo >&1 "+

    cleanedCommandName+"; exit 0; }"));
    return!!stdout;
    }catch(error){
    return false;
    }
    }
    return localExecutableSync(commandName);
    };

    var commandExistsWindowsSync=function commandExistsWindowsSync(commandName,cleanedCommandName){
    if(/[\x00-\x1f<>:"\|\?\*]/.test(commandName)){
    return false;
    }
    try{
    var stdout=execSync("where "+cleanedCommandName,{stdio:[]});
    return!!stdout;
    }catch(error){
    return false;
    }
    };

    var cleanInput=function cleanInput(s){
    if(/[^A-Za-z0-9_\/:=-]/.test(s)){
    s="'"+s.replace(/'/g,"'\\''")+"'";
    s=s.replace(/^(?:'')+/g,'').
    replace(/\\'''/g,"\\'");
    }
    return s;
    };

    Iif(isUsingWindows){
    cleanInput=function cleanInput(s){
    var isPathName=/[\\]/.test(s);
    if(isPathName){
    var dirname="\""+_path.default.dirname(s)+"\"";
    var basename="\""+_path.default.basename(s)+"\"";
    return dirname+":"+basename;
    }
    return"\""+s+"\"";
    };
    }

    var commandExists=function commandExists(commandName,callback){
    var cleanedCommandName=cleanInput(commandName);
    if(!callback&&typeof Promise!=='undefined'){
    return new Promise(function(resolve,reject){
    commandExists(commandName,function(error,output){
    if(output){
    resolve(commandName);
    }else{
    reject(error);
    }
    });
    });
    }
    if(isUsingWindows){
    commandExistsWindows(commandName,cleanedCommandName,callback);
    }else{
    commandExistsUnix(commandName,cleanedCommandName,callback);
    }
    };exports.commandExists=commandExists;

    var commandExistsSync=function commandExistsSync(commandName){
    var cleanedCommandName=cleanInput(commandName);
    if(isUsingWindows){
    return commandExistsWindowsSync(commandName,cleanedCommandName);
    }
    return commandExistsUnixSync(commandName,cleanedCommandName);
    };exports.commandExistsSync=commandExistsSync;

    var openCommand=process.platform=='darwin'?'open':process.platform=='win32'?'start':'xdg-open';exports.openCommand=openCommand;var _default=

    {
    executeAsync:executeAsync,
    execCLI:execCLI,
    openCommand:openCommand,
    executeTelnet:executeTelnet};exports.default=_default;
    //# sourceMappingURL=exec.js.map