Skip to content

Commit 9fea970

Browse files
Add spinner during project initialization
1 parent 6eaed6c commit 9fea970

File tree

3 files changed

+72
-17
lines changed

3 files changed

+72
-17
lines changed

index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const meow = require('meow');
66
const puppeteer = require('puppeteer');
77
const liveServer = require('live-server');
88
const chalk = require('chalk');
9+
const ora = require('ora');
910

1011
const cli = meow({
1112
description: false,
@@ -93,16 +94,17 @@ function serve() {
9394
}
9495

9596
function init(flags) {
97+
const spinner = ora('Initializing ...').start();
9698
const {name} = flags;
9799
const presentationPath = path.resolve(name);
98-
const presentationName = path.basename(presentationPath);
99100

100101
if (fs.existsSync(presentationPath)) {
101-
abort(`The directory '${presentationName}' is already existing.`);
102+
abort(`The directory ${chalk.underline(name)} is already existing.`, spinner);
102103
}
103104

104105
fs.mkdirSync(presentationPath);
105106
fs.copySync(path.resolve(__dirname, 'template'), presentationPath);
107+
spinner.succeed(`Directory ${chalk.underline(name)} has been initialized.`);
106108
}
107109

108110
function update() {
@@ -148,8 +150,13 @@ function print(flags) {
148150
})();
149151
}
150152

151-
function abort(message) {
152-
console.error(message);
153+
function abort(message, spinner = null) {
154+
if (spinner) {
155+
spinner.fail(message);
156+
} else {
157+
console.error(message);
158+
}
159+
153160
console.error('Aborting.');
154161
process.exit(1);
155162
}

package-lock.json

Lines changed: 60 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"fs-extra": "^8.1.0",
3737
"live-server": "^1.2.1",
3838
"meow": "^6.0.0",
39+
"ora": "^4.0.3",
3940
"puppeteer": "2.0.0"
4041
},
4142
"devDependencies": {

0 commit comments

Comments
 (0)