@hz-lib/hz-build-cli
Version:
hz-build-cli 脚手架
32 lines (29 loc) • 772 B
JavaScript
/*
* @Author: your name
* @Date: 2021-10-22 14:03:57
* @LastEditTime: 2021-10-22 14:03:57
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \hz-cli\lib\util.js
*/
const ora = require('ora')
// 添加加载动画
async function wrapLoading(fn, message, ...args) {
// 使用 ora 初始化,传入提示信息 message
const spinner = ora(message+'\r\n');
// 开始加载动画
spinner.start();
try {
// 执行传入方法 fn
const result = await fn(...args);
// 状态为修改为成功
spinner.succeed();
return result;
} catch (error) {
// 状态为修改为失败
spinner.fail('Request failed, refetch ...')
}
}
module.exports = {
wrapLoading
}