@shba007/unstack
Version:
Print your favorite framework info into cli
120 lines (115 loc) • 4.15 kB
JavaScript
import { select } from '@inquirer/prompts';
import { defineCommand, runMain as runMain$1 } from 'citty';
import { consola } from 'consola';
import chalk from 'chalk';
import stringWidth from 'string-width';
import wrapAnsi from 'wrap-ansi';
import { getColor, getImage, getDetails } from './index.mjs';
import 'ofetch';
import 'date-fns';
import '@shba007/unascii';
import 'ora';
const name = "@shba007/unstack";
const version = "1.0.1";
const description = "Print your favorite framework info into cli";
var FrameworkName = /* @__PURE__ */ ((FrameworkName2) => {
FrameworkName2["Angular"] = "angular";
FrameworkName2["React"] = "react";
FrameworkName2["Vue.js"] = "vue";
FrameworkName2["Svelte"] = "svelte";
FrameworkName2["Preact"] = "preact";
FrameworkName2["Solid.js"] = "solid";
FrameworkName2["Remix"] = "remix";
FrameworkName2["Qwik"] = "qwik";
FrameworkName2["Lit"] = "lit";
FrameworkName2["Tini"] = "tinijs";
FrameworkName2["Alpine.js"] = "alpine";
FrameworkName2["Stencil"] = "stencil";
FrameworkName2["Mithril"] = "mithril";
FrameworkName2["Astro"] = "astro";
FrameworkName2["Vuepress"] = "vuepress";
FrameworkName2["Vitepress"] = "vitepress";
FrameworkName2["Docus"] = "docus";
FrameworkName2["Express"] = "express";
FrameworkName2["Fastify"] = "fastify";
FrameworkName2["Koa"] = "koa";
FrameworkName2["Feathers"] = "feathers";
FrameworkName2["NestJS"] = "nestjs";
FrameworkName2["Nitro"] = "nitro";
FrameworkName2["Analog"] = "analog";
FrameworkName2["Next.js"] = "next";
FrameworkName2["Gatsby"] = "gatsby";
FrameworkName2["Nuxt"] = "nuxt";
FrameworkName2["Gridsome"] = "gridsome";
FrameworkName2["Svelte Kit"] = "svelte-kit";
FrameworkName2["Ember"] = "ember";
FrameworkName2["Fresh"] = "fresh";
FrameworkName2["Redwood"] = "redwood";
FrameworkName2["Meteor"] = "meteor";
FrameworkName2["Hydrogen"] = "hydrogen";
return FrameworkName2;
})(FrameworkName || {});
function camelToSentence(key) {
const withSpaces = key.replace(/([A-Z])/g, " $1");
return withSpaces.charAt(0).toUpperCase() + withSpaces.slice(1);
}
const main = defineCommand({
meta: {
name,
description,
version
},
args: {
framework: {
type: "string",
description: "Name of the Framework"
}
},
async run({ args }) {
const framework = args.framework ?? await select({
message: "Select framework",
choices: Object.entries(FrameworkName).map(([name2, value]) => ({
name: chalk.hex(getColor(value))(name2),
value
}))
});
const validFrameworks = Object.values(FrameworkName);
if (!validFrameworks.includes(framework)) {
consola.error(`Invalid framework: ${framework}`);
process.exit(1);
}
const artLines = (await getImage(framework)).split("\n");
const artWidth = Math.max(...artLines.map((line) => stringWidth(line)));
const rawMeta = Object.entries(await getDetails(framework)).map(([k, v]) => {
const label = camelToSentence(k);
const colored = chalk.hex(getColor(framework))(label);
const valueText = typeof v === "string" ? v : JSON.stringify(v, void 0, 2);
return {
text: `${colored}: ${valueText}`,
indent: stringWidth(label) + 2
};
});
const gutter = " ";
const termWidth = process.stdout.columns || 80;
const metaWidth = termWidth - artWidth - gutter.length;
const metaLines = [
...Array.from({ length: 4 }).fill(""),
...rawMeta.flatMap(({ text, indent }) => {
const wrapped = wrapAnsi(text, metaWidth, { hard: true }).split("\n");
return wrapped.map((line, i) => i === 0 ? line : " ".repeat(indent) + line);
})
];
const total = Math.max(artLines.length, metaLines.length);
const out = [];
for (let i = 0; i < total; i++) {
const line = artLines[i] || "";
const padCount = artWidth - stringWidth(line);
const left = line + " ".repeat(padCount);
const right = metaLines[i] || "";
out.push(`${left} ${right}`);
}
consola.log(out.join("\n"));
}
});
const runMain = () => runMain$1(main);
export { main, runMain };