如何在Node.js模块中实现头终端命令

时间:2018-09-02 19:28:41

标签: node.js terminal node-modules

我有两个文件:bash.js和commands.js。我想在自定义Node.js模块中模拟终端命令。

到目前为止,这是不完整的commands.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();

0 个答案:

没有答案
相关问题