@vortex.so/cli
Version:
CLI to interact with Vortex.
113 lines (107 loc) • 3.53 kB
JavaScript
;
const os = require('node:os');
const process = require('node:process');
const citty = require('citty');
const Table = require('cli-table3');
const fs$1 = require('fs-extra');
const yaml = require('js-yaml');
const pathe = require('pathe');
const c = require('chalk');
require('figures');
require('jiti');
const fs = require('../../../utils/fs.cjs');
const index$1 = require('../../../utils/log/index.cjs');
const index = require('../../../utils/package/index.cjs');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const os__default = /*#__PURE__*/_interopDefaultCompat(os);
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
const Table__default = /*#__PURE__*/_interopDefaultCompat(Table);
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs$1);
const yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
const c__default = /*#__PURE__*/_interopDefaultCompat(c);
const log = new index$1.Log("Info");
const infoCommand = citty.defineCommand({
meta: {
name: "info",
description: c__default.dim("Info.")
},
args: {},
async run() {
try {
const rootDir = pathe.resolve(".");
const { name, description, version, build } = findManifest(
rootDir
);
findPackage(rootDir);
let manager = index.getPackageManager(rootDir);
if (manager) {
manager += `@${index.getPackageManagerVersion(manager)}`;
}
log.ok(c__default.bold.green("Vortex CLI"), { title: null });
log.info(c__default.dim(rootDir), { title: "Directory" });
console.log("");
const table = new Table__default({
chars: {
"top": "",
"top-mid": "",
"top-left": "",
"top-right": "",
"bottom": "",
"bottom-mid": "",
"bottom-left": "",
"bottom-right": "",
"left": "",
"left-mid": "",
"mid": "",
"mid-mid": "",
"right": "",
"right-mid": "",
"middle": " "
},
style: {
"padding-left": 0,
"padding-right": 0,
"compact": true
}
});
table.push([c__default.bold("System")]);
table.push(line("Operating system ", os__default.type()));
table.push(line("Node version", process__default.version));
table.push(line("Package manager", manager || "unknown"));
table.push([""]);
table.push([c__default.bold("Project")]);
table.push(line("Name", name));
table.push(line("Description", description));
table.push(line("Version", version));
table.push(line("Build", build));
console.log(table.toString());
console.log(
"\nFor more information, check ",
c__default.underline.red("https://cli.vortex.so"),
"\n"
);
} catch (error) {
log.fail(error?.message);
}
}
});
function findManifest(rootDir) {
return fs.findup(rootDir, (dir) => {
const p = pathe.resolve(dir, "vortex.yaml");
if (fs__default.existsSync(p)) {
return yaml__default.load(fs__default.readFileSync(p, "utf-8"));
}
}) || {};
}
function findPackage(rootDir) {
return fs.findup(rootDir, (dir) => {
const p = pathe.resolve(dir, "package.json");
if (fs__default.existsSync(p)) {
return fs__default.readJSONSync(p);
}
}) || {};
}
function line(key, value) {
return [c__default.dim(key), c__default.dim(":"), value];
}
exports.infoCommand = infoCommand;