Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}: {
args: string[];
inputs: InteractiveInputs;
processOpts: Record;
opts: {
// Default interval between inputs in case there is no specific interval
defaultIntervalBetweenInputs: number;
verbose: boolean;
};
}) {
const processName = this.bitBin || 'bit';
opts.verbose = !!this.debugMode;
const { stdout } = await runInteractive({ processName, args, inputs, processOpts, opts });
if (this.debugMode) {
console.log(rightpad(chalk.green('output: \n'), 20, ' ')); // eslint-disable-line no-console
console.log(chalk.cyan(stdout)); // eslint-disable-line no-console
}
return stdout;
}
}
const getInputOutput = (input) => {
const timeout = input.waitInput || actualDefaultIntervalBetweenInputs;
const label = typeof input.value === 'string' ? input.value : input.value.label;
return `${label}(${timeout})`;
};
const getInputsOutput = (inputs) => {
const inputsOutput = inputs.map(getInputOutput).join(' ');
return `${chalk.yellow('inputs:')} ${inputsOutput}`;
};
const getEntryOutput = (entry) => {
const triggerOutput = getTriggerOutput(entry.triggerText);
const inputsOutput = getInputsOutput(entry.inputs);
return `${triggerOutput} ${inputsOutput}`;
};
const output = inputsToPrint.map(getEntryOutput).join('\n');
console.log(rightpad(chalk.green('inputs:\n'), 20, ''), output); // eslint-disable-line no-console
}
}
}: {
args: string[],
inputs: InteractiveInputs,
processOpts: Object,
opts: {
// Default interval between inputs in case there is no specific interval
defaultIntervalBetweenInputs: number,
verbose: boolean
}
}) {
const processName = this.bitBin || 'bit';
opts.verbose = !!this.debugMode;
const { stdout } = await runInteractive({ processName, args, inputs, processOpts, opts });
if (this.debugMode) {
console.log(rightpad(chalk.green('output: \n'), 20, ' ')); // eslint-disable-line no-console
console.log(chalk.cyan(stdout)); // eslint-disable-line no-console
}
return stdout;
}
}
watch(): Promise {
const cmd = `${this.helper.command.bitBin} watch --verbose`;
if (this.helper.debugMode) console.log(rightpad(chalk.green('command: '), 20, ' '), cmd); // eslint-disable-line
return new Promise((resolve, reject) => {
// this.watchProcess = childProcess.exec(cmd, { cwd: this.helper.scopes.localPath, detached: true });
this.watchProcess = childProcess.exec(cmd, { cwd: this.helper.scopes.localPath });
this.watchProcess.stdout.on('data', data => {
if (this.helper.debugMode) console.log(`stdout: ${data}`);
if (data.includes(STARTED_WATCHING_MSG)) {
if (this.helper.debugMode) console.log('bit watch is up and running');
resolve();
}
});
this.watchProcess.stderr.on('data', data => {
if (this.helper.debugMode) console.log(`stderr: ${data}`);
reject(data);
});
this.watchProcess.on('close', code => {
if (this.helper.debugMode) console.log(`child process exited with code ${code}`);
runCmd(cmd: string, cwd: string = this.scopes.localPath): string {
if (this.debugMode) console.log(rightpad(chalk.green('cwd: '), 20, ' '), cwd); // eslint-disable-line no-console
if (cmd.startsWith('bit ')) cmd = cmd.replace('bit', this.bitBin);
if (this.debugMode) console.log(rightpad(chalk.green('command: '), 20, ' '), cmd); // eslint-disable-line no-console
// $FlowFixMe
const cmdOutput = childProcess.execSync(cmd, { cwd, shell: true });
if (this.debugMode) console.log(rightpad(chalk.green('output: '), 20, ' '), chalk.cyan(cmdOutput.toString())); // eslint-disable-line no-console
return cmdOutput.toString();
}
runCmd(cmd: string, cwd: string = this.scopes.localPath, stdio: StdioOptions = 'pipe'): string {
if (this.debugMode) console.log(rightpad(chalk.green('cwd: '), 20, ' '), cwd); // eslint-disable-line no-console
if (cmd.startsWith('bit ')) cmd = cmd.replace('bit', this.bitBin);
if (this.debugMode) console.log(rightpad(chalk.green('command: '), 20, ' '), cmd); // eslint-disable-line no-console
// const cmdOutput = childProcess.execSync(cmd, { cwd, shell: true });
const cmdOutput = childProcess.execSync(cmd, { cwd, stdio });
if (this.debugMode) console.log(rightpad(chalk.green('output: '), 20, ' '), chalk.cyan(cmdOutput.toString())); // eslint-disable-line no-console
return cmdOutput.toString();
}
const getInputOutput = input => {
const timeout = input.waitInput || actualDefaultIntervalBetweenInputs;
const label = typeof input.value === 'string' ? input.value : input.value.label;
return `${label}(${timeout})`;
};
const getInputsOutput = inputs => {
const inputsOutput = inputs.map(getInputOutput).join(' ');
return `${chalk.yellow('inputs:')} ${inputsOutput}`;
};
const getEntryOutput = entry => {
const triggerOutput = getTriggerOutput(entry.triggerText);
const inputsOutput = getInputsOutput(entry.inputs);
return `${triggerOutput} ${inputsOutput}`;
};
const output = inputsToPrint.map(getEntryOutput).join('\n');
console.log(rightpad(chalk.green('inputs:\n'), 20, ''), output); // eslint-disable-line no-console
}
groupCommands.forEach(({ commandName, description }) => {
console.log(` ${green(padRight(commandName, maxWidth, ' '))} ${dim(description)}`)
})
})
function calculatePadRightLength(str: string, columnWidth: number): string {
if (!str) return '';
const padRightCount = Math.ceil(str.length / columnWidth) * columnWidth;
return str.length > columnWidth ? rightpad(str, padRightCount, ' ') : rightpad(str, columnWidth, ' ');
}
}