Skip to content

Commit

Permalink
fix progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
knowbee committed Apr 6, 2020
1 parent bdd3992 commit 65c81a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ const figlet = require("figlet");
const inquirer = require("inquirer");
const { templates, questions } = require("./lib/constants");
const { helper } = require("./lib/help");
const { generateTemplate } = require("./lib/generate")
const { generateTemplate } = require("./lib/generate");
const path = require("path");

const bar = require("cli-progress");
const progress = new bar.SingleBar({
format: "Done |" + chalk.magenta("{bar}") + "| {percentage}%",
barCompleteChar: "\u2588",
hideCursor: true,
});
clear();
helper();
console.log(chalk.magenta(figlet.textSync("Keza", { horizontalLayout: "full" })));
console.log(
chalk.magenta(figlet.textSync("Keza", { horizontalLayout: "full" }))
);
console.log(chalk.green("generate template files very fast"));
if (process.argv.length == 2) {
inquirer.prompt(questions).then((answers) => {
Expand All @@ -24,8 +31,11 @@ if (process.argv.length == 2) {
}
});
});
progress.start(choices.length);
choices.forEach((choice) => {
generateTemplate(choice, path.basename(choice));
});
progress.update(100);
progress.stop();
});
}
9 changes: 0 additions & 9 deletions lib/generate.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
const fs = require("fs")
const bar = require("cli-progress");
const chalk = require("chalk");
const progress = new bar.SingleBar({
format: "Done |" + chalk.magenta("{bar}") + "| {percentage}%",
barCompleteChar: "\u2588",
hideCursor: true,
});
exports.generateTemplate = (from, to) => {
progress.start(to.length);
try {
fs.copyFileSync(from, to);
progress.update(100);
progress.stop();
} catch (error) {
console.log("\n");
console.log(chalk.yellow("oooh no! try again"));
Expand Down

0 comments on commit 65c81a7

Please sign in to comment.