Skip to content

Commit 8f9c231

Browse files
committed
feat: add pretty print for logs
1 parent a09966f commit 8f9c231

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"typescript": "^4.5.3"
4444
},
4545
"dependencies": {
46-
"inquirer": "^8.2.0"
46+
"inquirer": "^8.2.0",
47+
"ora": "^5.4.1"
4748
}
4849
}

src/index.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import { manyOf, oneOf } from "./utils/prompt";
44
import { jsState, jsStateValues } from "./utils/config";
55
import jsOptions from './categories/js';
6+
import ora from 'ora';
7+
import { white } from "./utils/console";
68

79
const categories = ['js'] as const;
810
const configs = {
911
js: { state: jsState, values: jsStateValues, options: jsOptions }
1012
};
1113

1214
const main = async () => {
15+
console.log(white(`Wellcome to Allohamora's cli`));
16+
1317
const choosedCategory = await oneOf('choose a category', categories);
1418
const { state, values, options } = configs[choosedCategory];
1519

@@ -18,9 +22,21 @@ const main = async () => {
1822
setConfig(choosedConfig);
1923

2024
const choosedOptions = await manyOf('choose a options', Object.keys(options));
25+
26+
const spinner = ora('starting install').start();
27+
2128
await choosedOptions.reduce((chain, name) => {
22-
return chain.then(async () => await options[name as keyof typeof options]());
29+
return chain.then(async () => {
30+
const optionName = name as keyof typeof options;
31+
32+
spinner.text = `${name} is installing`;
33+
34+
return await options[optionName]()
35+
});
2336
}, Promise.resolve());
37+
38+
spinner.stop();
39+
console.log(white('Installation completed'));
2440
};
2541

2642
main();

src/utils/console.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const white = (log: string) => `\x1b[22m\x1b[1m${log}`;

src/utils/run-command.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const runCommand = async (command: string) => {
77
}
88

99
export const spawnCommand = async (command: string, args: string[]) => new Promise((res, rej) => {
10-
const child = spawn(command, args, { stdio: 'inherit' });
10+
const child = spawn(command, args);
1111

1212
child.on('error', (err) => rej(err));
1313
child.on('exit', () => res(undefined));

0 commit comments

Comments
 (0)