qraft
Version:
A powerful CLI tool to qraft structured project setups from GitHub template repositories
99 lines ⢠5.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listCommand = listCommand;
const chalk_1 = __importDefault(require("chalk"));
const interactiveMode_1 = require("../interactive/interactiveMode");
async function listCommand(boxManager, options) {
// Use interactive mode if requested
if (options.interactive) {
const interactiveMode = new interactiveMode_1.InteractiveMode(boxManager);
await interactiveMode.listBoxes(options.registry);
return;
}
// Non-interactive mode (existing logic)
console.log(chalk_1.default.blue.bold('š¦ Available Template Boxes\n'));
try {
if (options.allRegistries) {
// List boxes from all registries
const registries = await boxManager.listRegistries();
for (const registry of registries) {
console.log(chalk_1.default.yellow.bold(`\nš Registry: ${registry.name}`));
console.log(chalk_1.default.gray(` Repository: ${registry.repository}`));
if (registry.isDefault) {
console.log(chalk_1.default.green(' (default)'));
}
try {
const boxes = await boxManager.listBoxes(registry.name);
if (boxes.length === 0) {
console.log(chalk_1.default.gray(' No boxes found'));
continue;
}
boxes.forEach(box => {
console.log(` ${chalk_1.default.cyan('ā¢')} ${chalk_1.default.white.bold(box.name)} ${chalk_1.default.gray(`(${box.version})`)}`);
console.log(` ${chalk_1.default.gray(box.description)}`);
});
}
catch (error) {
console.log(chalk_1.default.red(` Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
}
}
}
else {
// List boxes from specific or default registry
const registryName = options.registry;
if (registryName) {
console.log(chalk_1.default.yellow(`Registry: ${registryName}\n`));
}
else {
const defaultRegistry = await boxManager.getDefaultRegistry();
console.log(chalk_1.default.yellow(`Registry: ${defaultRegistry} (default)\n`));
}
const boxes = await boxManager.listBoxes(registryName);
if (boxes.length === 0) {
console.log(chalk_1.default.gray('No boxes found in this registry.'));
console.log(chalk_1.default.gray('Try running with --all-registries to see boxes from all registries.'));
return;
}
// Group boxes by first letter for better organization
const groupedBoxes = boxes.reduce((groups, box) => {
const firstLetter = box.name.charAt(0).toLowerCase();
if (!groups[firstLetter]) {
groups[firstLetter] = [];
}
groups[firstLetter].push(box);
return groups;
}, {});
// Display grouped boxes
Object.keys(groupedBoxes).sort().forEach(letter => {
console.log(chalk_1.default.blue.bold(`\n${letter.toUpperCase()}`));
groupedBoxes[letter].forEach(box => {
console.log(` ${chalk_1.default.cyan('ā¢')} ${chalk_1.default.white.bold(box.name)} ${chalk_1.default.gray(`(${box.version})`)}`);
console.log(` ${chalk_1.default.gray(box.description)}`);
});
});
}
console.log(chalk_1.default.gray('\nUse "qraft copy <box-name>" to copy a box to your project.'));
console.log(chalk_1.default.gray('Use "qraft info <box-name>" to see detailed information about a box.'));
}
catch (error) {
if (error instanceof Error && error.message.includes('Authentication failed')) {
console.error(chalk_1.default.red('\nš Authentication Error'));
console.error(chalk_1.default.gray('This registry requires authentication. Set up your GitHub token:'));
console.error(chalk_1.default.cyan(' qraft auth login'));
console.error(chalk_1.default.gray('Or set a token for this specific registry:'));
console.error(chalk_1.default.cyan(` qraft auth token --registry ${options.registry || 'default'} <your-token>`));
}
else if (error instanceof Error && error.message.includes('rate limit')) {
console.error(chalk_1.default.red('\nā±ļø Rate Limit Exceeded'));
console.error(chalk_1.default.gray('GitHub API rate limit exceeded. Set up authentication to increase limits:'));
console.error(chalk_1.default.cyan(' qraft auth login'));
}
else {
throw error;
}
}
}
//# sourceMappingURL=list.js.map