feat: улучшено автодополнение
- Добавлен поиск ближайшей .templates для списка шаблонов и переменных - Добавлен алиас zh для генерации zsh‑completion - Обновлена документация по автодополнению и версия пакета
This commit is contained in:
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
- Генерация скрипта автодополнения для bash/zsh/fish: `gromlab-create completion --shell <shell>`.
|
- Генерация скрипта автодополнения для bash/zsh/fish: `gromlab-create completion --shell <shell>`.
|
||||||
- Автодополнение доступно только для глобальной установки CLI.
|
- Автодополнение доступно только для глобальной установки CLI.
|
||||||
- Автодополнение шаблонов из `.templates/` и переменных `--<var>` выбранного шаблона (кроме `name`).
|
- Автодополнение шаблонов из ближайшей `.templates/` (по дереву вверх) и переменных `--<var>` выбранного шаблона (кроме `name`).
|
||||||
|
|
||||||
## Обновления CLI
|
## Обновления CLI
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@gromlab/create",
|
"name": "@gromlab/create",
|
||||||
"version": "0.1.1",
|
"version": "0.1.3",
|
||||||
"description": "Template-based file generator CLI",
|
"description": "Template-based file generator CLI",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|||||||
@@ -5,14 +5,28 @@ import { detectRunMode } from './runtime';
|
|||||||
|
|
||||||
const BIN_NAMES = ['gromlab-create', 'create'];
|
const BIN_NAMES = ['gromlab-create', 'create'];
|
||||||
|
|
||||||
function templatesDir(cwd: string): string {
|
function findNearestTemplatesDir(startDir: string): string | undefined {
|
||||||
return path.resolve(cwd, '.templates');
|
let current = path.resolve(startDir);
|
||||||
|
while (true) {
|
||||||
|
const candidate = path.join(current, '.templates');
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore errors and keep walking up
|
||||||
|
}
|
||||||
|
const parent = path.dirname(current);
|
||||||
|
if (parent === current) break;
|
||||||
|
current = parent;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function listTemplates(cwd: string): string[] {
|
function listTemplates(cwd: string): string[] {
|
||||||
const dir = templatesDir(cwd);
|
const dir = findNearestTemplatesDir(cwd);
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return [];
|
if (!dir) return [];
|
||||||
return listTemplateNames(dir);
|
return listTemplateNames(dir);
|
||||||
} catch {
|
} catch {
|
||||||
return [];
|
return [];
|
||||||
@@ -20,7 +34,9 @@ function listTemplates(cwd: string): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function listTemplateVars(cwd: string, templateName: string): string[] {
|
function listTemplateVars(cwd: string, templateName: string): string[] {
|
||||||
const dir = path.join(templatesDir(cwd), templateName);
|
const root = findNearestTemplatesDir(cwd);
|
||||||
|
if (!root) return [];
|
||||||
|
const dir = path.join(root, templateName);
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return [];
|
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return [];
|
||||||
const vars = Array.from(collectTemplateVariables(dir))
|
const vars = Array.from(collectTemplateVariables(dir))
|
||||||
@@ -225,7 +241,8 @@ export function handleInternalCommand(args: string[], cwd: string = process.cwd(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalized = shell.trim().toLowerCase();
|
let normalized = shell.trim().toLowerCase();
|
||||||
|
if (normalized === 'zh') normalized = 'zsh';
|
||||||
let script = '';
|
let script = '';
|
||||||
if (normalized === 'bash') script = buildBashCompletion();
|
if (normalized === 'bash') script = buildBashCompletion();
|
||||||
if (normalized === 'zsh') script = buildZshCompletion();
|
if (normalized === 'zsh') script = buildZshCompletion();
|
||||||
|
|||||||
Reference in New Issue
Block a user