UNPKG

@vortex.so/cli

Version:

CLI to interact with Vortex.

102 lines (99 loc) 2.83 kB
import os from 'node:os'; import process from 'node:process'; import { defineCommand } from 'citty'; import Table from 'cli-table3'; import fs from 'fs-extra'; import yaml from 'js-yaml'; import { resolve } from 'pathe'; import c from 'chalk'; import 'figures'; import 'jiti'; import { findup } from '../../../utils/fs.mjs'; import { Log } from '../../../utils/log/index.mjs'; import { getPackageManager, getPackageManagerVersion } from '../../../utils/package/index.mjs'; const log = new Log("Info"); const infoCommand = defineCommand({ meta: { name: "info", description: c.dim("Info.") }, args: {}, async run() { try { const rootDir = resolve("."); const { name, description, version, build } = findManifest( rootDir ); findPackage(rootDir); let manager = getPackageManager(rootDir); if (manager) { manager += `@${getPackageManagerVersion(manager)}`; } log.ok(c.bold.green("Vortex CLI"), { title: null }); log.info(c.dim(rootDir), { title: "Directory" }); console.log(""); const table = new Table({ 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.bold("System")]); table.push(line("Operating system ", os.type())); table.push(line("Node version", process.version)); table.push(line("Package manager", manager || "unknown")); table.push([""]); table.push([c.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.underline.red("https://cli.vortex.so"), "\n" ); } catch (error) { log.fail(error?.message); } } }); function findManifest(rootDir) { return findup(rootDir, (dir) => { const p = resolve(dir, "vortex.yaml"); if (fs.existsSync(p)) { return yaml.load(fs.readFileSync(p, "utf-8")); } }) || {}; } function findPackage(rootDir) { return findup(rootDir, (dir) => { const p = resolve(dir, "package.json"); if (fs.existsSync(p)) { return fs.readJSONSync(p); } }) || {}; } function line(key, value) { return [c.dim(key), c.dim(":"), value]; } export { infoCommand };