feat: подготовка к публикации npm-пакета
- переименование в @gromlab/api-codegen, версия 1.0.3 - добавлена MIT лицензия - динамическое чтение версии из package.json - настроен build с копированием шаблонов и external biome - загрузка спецификации по URL для извлечения title - moduleNameFirstTag: true, cleanOutput: false
This commit is contained in:
11
src/cli.ts
11
src/cli.ts
@@ -2,16 +2,23 @@
|
||||
|
||||
import { Command } from 'commander';
|
||||
import chalk from 'chalk';
|
||||
import { readFileSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
import { validateConfig, type GeneratorConfig } from './config.js';
|
||||
import { generate } from './generator.js';
|
||||
import { fileExists } from './utils/file.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.name('api-codegen')
|
||||
.description('Generate TypeScript API client from OpenAPI specification')
|
||||
.version('1.0.0')
|
||||
.version(pkg.version)
|
||||
.requiredOption('-i, --input <path>', 'Path to OpenAPI specification file (JSON or YAML)')
|
||||
.requiredOption('-o, --output <path>', 'Output directory for generated files')
|
||||
.option('-n, --name <name>', 'Name of generated file (without extension)')
|
||||
@@ -50,3 +57,5 @@ program
|
||||
|
||||
program.parse();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,3 +33,5 @@ export function validateConfig(config: Partial<GeneratorConfig>): config is Gene
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,9 @@ export async function generate(config: GeneratorConfig): Promise<void> {
|
||||
|
||||
if (isUrl) {
|
||||
url = config.inputPath;
|
||||
// Для URL не читаем спецификацию заранее, swagger-typescript-api сделает это сам
|
||||
// Загружаем спецификацию для получения info.title
|
||||
const response = await fetch(url);
|
||||
spec = await response.json();
|
||||
} else {
|
||||
inputPath = resolve(config.inputPath);
|
||||
spec = await readJsonFile<any>(inputPath);
|
||||
@@ -56,12 +58,12 @@ export async function generate(config: GeneratorConfig): Promise<void> {
|
||||
extractRequestParams: true,
|
||||
extractRequestBody: true,
|
||||
extractEnums: true,
|
||||
cleanOutput: true,
|
||||
cleanOutput: false,
|
||||
singleHttpClient: true,
|
||||
unwrapResponseData: true,
|
||||
defaultResponseAsSuccess: true,
|
||||
enumNamesAsValues: false,
|
||||
moduleNameFirstTag: false,
|
||||
moduleNameFirstTag: true,
|
||||
generateUnionEnums: false,
|
||||
extraTemplates: [],
|
||||
addReadonly: false,
|
||||
|
||||
@@ -64,3 +64,5 @@ export function resolvePath(path: string): string {
|
||||
return join(process.cwd(), path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user