node package manager

face

Build CLI apps with joy

Face

Build CLI app with joy

 
$ npm install --save face
 
 
const App = require("face");
const app = new App();
 
app.cmd("ask {{name}} {{question}}", (vars) => {
 
    app.println(`Hello (${vars.name}.):green`);
 
    app.ask(`(${vars.question}):blue `, (answer) => {
 
        app.println("Thanks!");
 
    });
 
}).help(() => {
 
    app.println("   Usage:", "bold");
    app.println("      (ask [name] [question]):blue to ask someone a question")
 
});
 

The parsed user input. Using minimist

Execute the callback if the user inputs the template

 
app.cmd("ask {{name}} {{question}}", (vars) => {
 
    console.log(vars.name);
    console.log(vars.question);
 
});
 

Execute the callback if the user inputs the option

 
app.opt(["w", "width"], (value) => {
 
    console.log(value);
 
});

Execute the help function if the user inputs -h, --h or nothing

 
app.help(() => {
 
    console.log("Usage: ...");
 
});
 

Wrapper for process.stdout. Using perfume to stylize output

 
app.print("Hello (World):red", "bold"); // apply `red` to 'World' and `bold` to the whole 
app.print("(:joy:)"); // prints emoji 
 

Wrapper for process.stdout. Using perfume to stylize output

 
app.println("Hello (World):red", "bold"); // apply `red` to 'World' and `bold` to the whole 
app.println("(:joy:)"); // prints emoji 
 

Prompt for user input

 
app.ask("Username: ", (answer) => {
 
    console.log(`Your username is ${answer}`);
 
});
 
// Options 
 
app.ask("Password: ", (answer) => {
 
    user.password = answer;
 
}, {
 
    hide: true, // hide the text 
    mask: "*", // the mask shows instead of the hidden text 
    default: "" // the default value 
 
});
 

Use JSON to store data in path. Creates app.storage to manage data

 
app.store("user.json", {});
app.storage.data.name = "Voyga";
app.storage.save();
 

Execute the callback if there's an update. Using update-notifier

 
app.update(require("./package.json"), () => {
 
    console.log("There's an update for this app!");
 
});
 

The terminal window size

 
console.log(app.size.width);
console.log(app.size.height);
 

Execute the callback on a certain event

 
// Current available events: `exit`, `key` 
 
app.on("exit", () => {
 
    app.println("Exit");
 
}).on("key", (key) => {
 
    app.print(key);
 
});
 

Hide and show the cursor. Using cli-cursor

 
app.cursor.hide();
app.cursor.show();
 

Clear the terminal screen

Clear a line of output

Wrapper for childProcess.exec

Wrapper for process.exit