@lenne.tech/cli
Version:
lenne.Tech CLI: lt
107 lines (106 loc) • 4.38 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
/**
* List available templates
*/
const ListTemplatesCommand = {
alias: ['ls'],
description: 'List available templates',
hidden: false,
name: 'list',
run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () {
const { filesystem, print: { colors, info, success }, runtime, } = toolbox;
info('');
info(colors.bold('Available Templates'));
info(colors.dim('─'.repeat(50)));
// Built-in templates
const builtInPath = (0, path_1.join)(__dirname, '..', '..', 'templates');
const builtInTemplates = getTemplatesFromDirectory(filesystem, builtInPath);
if (builtInTemplates.length > 0) {
info('');
info(colors.bold('Built-in Templates:'));
builtInTemplates.forEach((template) => {
info(` ${colors.cyan(template.name)} ${colors.dim(`(${template.type})`)}`);
});
}
// Custom templates from ~/.lt/templates
const customPath = (0, path_1.join)(filesystem.homedir(), `.${runtime.brand}`, 'templates');
const customTemplates = getTemplatesFromDirectory(filesystem, customPath);
if (customTemplates.length > 0) {
info('');
info(colors.bold('Custom Templates:'));
customTemplates.forEach((template) => {
info(` ${colors.cyan(template.name)} ${colors.dim(`(${template.type})`)}`);
});
}
else {
info('');
info(colors.dim('No custom templates found.'));
info(colors.dim(`Add templates to: ${customPath}`));
}
// Project templates from ./lt-templates
const projectPath = (0, path_1.join)(filesystem.cwd(), 'lt-templates');
const projectTemplates = getTemplatesFromDirectory(filesystem, projectPath);
if (projectTemplates.length > 0) {
info('');
info(colors.bold('Project Templates:'));
projectTemplates.forEach((template) => {
info(` ${colors.cyan(template.name)} ${colors.dim(`(${template.type})`)}`);
});
}
info('');
success('Template directories:');
info(` Built-in: ${builtInPath}`);
info(` Custom: ${customPath}`);
info(` Project: ${projectPath}`);
info('');
return {
builtIn: builtInTemplates,
custom: customTemplates,
project: projectTemplates,
};
}),
};
function getTemplatesFromDirectory(filesystem, dirPath) {
const templates = [];
if (!filesystem.exists(dirPath)) {
return templates;
}
const entries = filesystem.list(dirPath) || [];
for (const entry of entries) {
const entryPath = (0, path_1.join)(dirPath, entry);
if (filesystem.isDirectory(entryPath)) {
// Determine template type
let type = 'directory';
if (filesystem.exists((0, path_1.join)(entryPath, 'template.json'))) {
type = 'configured';
}
else if (entry.includes('server')) {
type = 'server';
}
else if (entry.includes('starter')) {
type = 'starter';
}
else if (entry.includes('deployment')) {
type = 'deployment';
}
templates.push({
name: entry,
path: entryPath,
type,
});
}
}
return templates.sort((a, b) => a.name.localeCompare(b.name));
}
exports.default = ListTemplatesCommand;