@vortex.so/cli
Version:
CLI to interact with Vortex.
154 lines (148 loc) • 4.08 kB
JavaScript
;
const path = require('node:path');
const c = require('chalk');
const consola$1 = require('consola');
const fig = require('figures');
const notifier = require('node-notifier');
const ora = require('ora');
const string_line = require('../string/string.line.cjs');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
const c__default = /*#__PURE__*/_interopDefaultCompat(c);
const fig__default = /*#__PURE__*/_interopDefaultCompat(fig);
const notifier__default = /*#__PURE__*/_interopDefaultCompat(notifier);
const ora__default = /*#__PURE__*/_interopDefaultCompat(ora);
const consola = consola$1.createConsola({
formatOptions: {
date: false
}
});
class Log {
title;
constructor(title) {
this.title = title;
}
intro(message) {
this.ok(c__default.bold.green(message));
return this;
}
space() {
console.log("");
return this;
}
start(message, opts) {
const msg = this.message(message || "Starting...", {
icon: opts?.icon || c__default.gray(fig__default.tick),
title: opts?.title
});
consola.log(msg);
return this;
}
wait(message) {
const o = ora__default({
text: this.message(message || "Loading..."),
color: "yellow"
}).start();
return {
ora: o,
text: (message2, opts) => {
o.text = this.message(message2, opts);
},
persist: (message2, opts) => {
let msg = message2 || "";
const hasNewLine = !!string_line.detectNewline(msg);
if (hasNewLine) {
msg = `${c__default.dim("...")}
${msg}`;
}
o.stopAndPersist({
text: this.message(msg, opts),
symbol: c__default.dim(opts?.icon || fig__default.info)
});
o.start();
},
ok: (message2) => {
let msg = message2 || "";
const hasNewLine = !!string_line.detectNewline(msg);
if (hasNewLine) {
msg = `${c__default.dim("...")}
${msg}`;
}
o.succeed(this.message(msg || "Done!"));
},
fail: (message2) => {
let msg = message2 || "";
const hasNewLine = !!string_line.detectNewline(msg);
if (hasNewLine) {
msg = `${c__default.dim("...")}
${msg}`;
}
o.fail(this.message(msg || "Failed!"));
}
};
}
abort(message, opts) {
const msg = this.message(message || "Aborted.", {
icon: opts?.icon || c__default.yellow(fig__default.cross),
title: opts?.title
});
consola.log(msg);
}
ok(message, opts) {
const msg = this.message(message || "Done!", {
icon: opts?.icon || c__default.green(fig__default.tick),
title: opts?.title
});
consola.log(msg);
}
fail(message, opts) {
const msg = this.message(message || "Failed!", {
icon: opts?.icon || c__default.red(fig__default.cross),
title: opts?.title
});
consola.log(msg);
}
warn(message, opts) {
const msg = this.message(message, {
icon: opts?.icon || c__default.yellow(fig__default.warning),
title: opts?.title
});
consola.log(msg);
}
info(message, opts) {
const msg = this.message(message, {
icon: opts?.icon || c__default.blue(fig__default.info),
title: opts?.title
});
consola.log(msg);
}
notify(subtitle, message) {
const icon = path__default.join(__dirname, "vrt-icon.png");
notifier__default.notify({
title: `Vortex CLI`,
subtitle,
message,
icon,
contentImage: icon,
sound: "Ping",
wait: true
});
}
message(message, opts) {
const parts = [];
if (opts?.icon) {
parts.push(opts?.icon);
}
if (opts?.title !== null) {
parts.push(c__default.dim.bold(opts?.title || this.title));
}
if (opts?.title !== null && message) {
parts.push(c__default.dim(fig__default.pointerSmall));
}
if (message) {
parts.push(message);
}
return parts.join(" ");
}
}
exports.Log = Log;