У меня есть два файла: bash.js и commands.js. Я хочу смоделировать команду терминала в пользовательском модуле Node.js.
Пока что это неполный файл command.js:
const fs = require("fs");
//write out data
function done(output) {
process.stdout.write(output);
process.stdout.write('\nprompt > ');
}
//where we will store our commands
function evaluateCmd(userInput) {
//parses the user input to understand which command was typed
const userInputArray = userInput.split(" ");
const command = userInputArray[0];
case "head":
commandLibrary.head(userInputArray.slice(1));
break;
}
//where we will store the logic of our commands
const commandLibrary = {
"head": function(fullPath) {
}
};
module.exports.commandLibrary = commandLibrary;
А это файл bash.js:
const commands = require("./commands.js");
//prompt the user for input
process.stdout.write('prompt > ');
// The stdin 'data' event triggers after a user types in a line
process.stdin.on('data', (userInput) => {
userInput = userInput.toString().trim();