@connectedcars/device-modules
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -9,14 +9,14 @@ /// <reference types="node" /> | ||
*/ | ||
export declare function run(cmdToRun: string, totalTimeout: number, isSudo?: boolean, env?: NodeJS.ProcessEnv): Promise<string>; | ||
export declare function run(cmdToRun: string, totalTimeout: number, isSudo?: boolean, outputCallback?: (chunk: string) => void, env?: NodeJS.ProcessEnv): Promise<string>; | ||
/** | ||
* Wait for output | ||
*/ | ||
export declare function runWaitFor(cmd: string, waitFor: RegExp, totalTimeout: number, isSudo?: boolean, env?: NodeJS.ProcessEnv): Promise<string>; | ||
export declare function runWaitFor(cmd: string, waitFor: RegExp, totalTimeout: number, isSudo?: boolean, outputCallback?: (chunk: string) => void, env?: NodeJS.ProcessEnv): Promise<string>; | ||
/** | ||
* Run a command "amountRuns" times | ||
*/ | ||
export declare function runExpectRepeat(cmdToRun: string, expect: RegExp, timeoutPerRun: number, pauseEveryRun: number, amountRuns: number, isSudo?: boolean, env?: NodeJS.ProcessEnv): Promise<string>; | ||
export declare function runExpectRepeat(cmdToRun: string, expect: RegExp, timeoutPerRun: number, pauseEveryRun: number, amountRuns: number, isSudo?: boolean, outputCallback?: (chunk: string) => void, env?: NodeJS.ProcessEnv): Promise<string>; | ||
/** | ||
* Runs a background process, also writes the output to a file. You have to stop it manually later. (kill) | ||
*/ | ||
export declare function backgroundProcess(cmd: string, outputFilePath: string, isSudo?: boolean, secondsToWaitBeforeStart?: number, env?: NodeJS.ProcessEnv): Promise<RunProcess>; | ||
export declare function backgroundProcess(cmd: string, outputFilePath: string, isSudo?: boolean, secondsToWaitBeforeStart?: number, outputCallback?: (chunk: string) => void, env?: NodeJS.ProcessEnv): Promise<RunProcess>; |
@@ -66,3 +66,4 @@ "use strict"; | ||
let isSudo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
let env = arguments.length > 3 ? arguments[3] : undefined; | ||
let outputCallback = arguments.length > 3 ? arguments[3] : undefined; | ||
let env = arguments.length > 4 ? arguments[4] : undefined; | ||
let output = ''; | ||
@@ -86,3 +87,8 @@ let runProcess; // Fix for commandEmulation or we won't have the right PATH and get (spawn shittySleepHello ENOENT) or env['PATH'] = process.env['PATH'] | ||
function addToOutput(chunk) { | ||
output += chunk.toString('utf8'); | ||
const chunkStr = chunk.toString('utf8'); | ||
output += chunkStr; | ||
if (outputCallback !== undefined) { | ||
outputCallback(chunkStr); | ||
} | ||
} | ||
@@ -116,3 +122,4 @@ | ||
let isSudo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
let env = arguments.length > 4 ? arguments[4] : undefined; | ||
let outputCallback = arguments.length > 4 ? arguments[4] : undefined; | ||
let env = arguments.length > 5 ? arguments[5] : undefined; | ||
let output = ''; | ||
@@ -136,3 +143,8 @@ let runProcess; // Fix for commandEmulation or we won't have the right PATH and get (spawn shittySleepHello ENOENT) or env['PATH'] = process.env['PATH'] | ||
function addToOutput(chunk) { | ||
output += chunk.toString('utf8'); | ||
const chunkStr = chunk.toString('utf8'); | ||
output += chunkStr; | ||
if (outputCallback !== undefined) { | ||
outputCallback(chunkStr); | ||
} | ||
} | ||
@@ -161,3 +173,4 @@ | ||
let isSudo = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; | ||
let env = arguments.length > 6 ? arguments[6] : undefined; | ||
let outputCallback = arguments.length > 6 ? arguments[6] : undefined; | ||
let env = arguments.length > 7 ? arguments[7] : undefined; | ||
let output = ''; // Fix for commandEmulation or we won't have the right PATH and get (spawn shittySleepHello ENOENT) or env['PATH'] = process.env['PATH'] | ||
@@ -171,3 +184,3 @@ | ||
try { | ||
const cmdOut = await run(cmdToRun, timeoutPerRun, isSudo, env); | ||
const cmdOut = await run(cmdToRun, timeoutPerRun, isSudo, outputCallback, env); | ||
output += `\n---START RUN ${i}---\n${cmdOut}---END OF RUN ${i}---\n`; | ||
@@ -201,3 +214,4 @@ } catch (err) { | ||
let secondsToWaitBeforeStart = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2; | ||
let env = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; | ||
let outputCallback = arguments.length > 4 ? arguments[4] : undefined; | ||
let env = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; | ||
let runProcess; // Fix for commandEmulation or we won't have the right PATH and get (spawn shittySleepHello ENOENT) or env['PATH'] = process.env['PATH'] | ||
@@ -220,3 +234,8 @@ | ||
function addToOutput(chunk) { | ||
const chunkStr = chunk.toString('utf8'); | ||
(0, _file.writeToOutputFile)(chunk.toString('utf8'), outputFilePath); | ||
if (outputCallback !== undefined) { | ||
outputCallback(chunkStr); | ||
} | ||
} | ||
@@ -223,0 +242,0 @@ |
export declare const SSH_OPTIONS = "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR"; | ||
export declare const RSYNC_SSH_OPTIONS: string; | ||
export declare function run(command: string, userName: string, ip: string, timeout: number, useSudo: boolean): Promise<string>; | ||
@@ -3,0 +4,0 @@ export declare function runWaitFor(command: string, waitFor: RegExp, userName: string, ip: string, timeout: number, useSudo: boolean): Promise<string>; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.SSH_OPTIONS = void 0; | ||
exports.SSH_OPTIONS = exports.RSYNC_SSH_OPTIONS = void 0; | ||
exports.checkFileExists = checkFileExists; | ||
@@ -30,2 +30,4 @@ exports.checkSshAlive = checkSshAlive; | ||
exports.SSH_OPTIONS = SSH_OPTIONS; | ||
const RSYNC_SSH_OPTIONS = `-e "ssh ${SSH_OPTIONS}"`; | ||
exports.RSYNC_SSH_OPTIONS = RSYNC_SSH_OPTIONS; | ||
@@ -100,3 +102,3 @@ function getSshBase(command, userName, ip, useSudo) { | ||
const recursiveStr = recursive === true ? `-r ` : ``; | ||
return cmd.run(`rsync ${recursiveStr}${source} ${userName}@${ip}:${destination}`, timeout); | ||
return cmd.run(`rsync ${RSYNC_SSH_OPTIONS} ${recursiveStr}${source} ${userName}@${ip}:${destination}`, timeout); | ||
} | ||
@@ -106,3 +108,3 @@ | ||
const recursiveStr = recursive === true ? `-r ` : ``; | ||
return cmd.run(`rsync ${recursiveStr}${userName}@${ip}:${source} ${destination}`, timeout); | ||
return cmd.run(`rsync ${RSYNC_SSH_OPTIONS} ${recursiveStr}${userName}@${ip}:${source} ${destination}`, timeout); | ||
} | ||
@@ -109,0 +111,0 @@ |
{ | ||
"name": "@connectedcars/device-modules", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/dist/src/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109538
990