@lakutata/cli
Version:
Lakutata CLI tool
62 lines (61 loc) • 2.31 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Spinner = void 0;
const cli_spinners_1 = require("cli-spinners");
const di_1 = require("lakutata/decorator/di");
const lakutata_1 = require("lakutata");
let Spinner = class Spinner extends lakutata_1.Component {
constructor() {
super(...arguments);
this.style = cli_spinners_1.dots;
this.spinnerInterval = null;
}
/**
* Initializer
* @protected
*/
async init() {
const logUpdatePackage = await import('log-update');
this.logUpdate = logUpdatePackage.default;
}
/**
* Start spinner
* @param description
*/
start(description) {
this.stop();
let i = 0;
this.spinnerInterval = setInterval(() => {
const { frames } = this.style;
const text = description ? `${frames[i = ++i % frames.length]} ${typeof description === 'function' ? description() : description}` : frames[i = ++i % frames.length];
this.logUpdate(text);
}, cli_spinners_1.dots.interval);
}
/**
* Stop spinner
*/
stop() {
if (this.spinnerInterval) {
clearInterval(this.spinnerInterval);
this.spinnerInterval = null;
this.logUpdate.clear();
}
}
};
exports.Spinner = Spinner;
__decorate([
(0, di_1.Configurable)(),
__metadata("design:type", Object)
], Spinner.prototype, "style", void 0);
exports.Spinner = Spinner = __decorate([
(0, di_1.Singleton)()
], Spinner);