From 8ddf0e1c7f323d3f921deb82431f0ad93faa0ce5 Mon Sep 17 00:00:00 2001 From: "S.Gromov" Date: Wed, 1 Apr 2026 18:55:41 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=BF=D1=83=D0=B1=D0=BB?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D0=B8=20npm-=D0=BF=D0=B0=D0=BA?= =?UTF-8?q?=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - переименование в @gromlab/api-codegen, версия 1.0.3 - добавлена MIT лицензия - динамическое чтение версии из package.json - настроен build с копированием шаблонов и external biome - загрузка спецификации по URL для извлечения title - moduleNameFirstTag: true, cleanOutput: false --- LICENSE | 21 +++++++++++++++++++++ package.json | 18 +++++++++++++----- src/cli.ts | 11 ++++++++++- src/config.ts | 2 ++ src/generator.ts | 8 +++++--- src/utils/file.ts | 2 ++ 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a045cf0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Gromlab + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/package.json b/package.json index e5ce9e1..1731997 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,27 @@ { - "name": "api-codegen", - "version": "1.0.0", + "name": "@gromlab/api-codegen", + "version": "1.0.3", "description": "CLI tool to generate TypeScript API client from OpenAPI specification", "type": "module", "bin": { - "api-codegen": "./dist/cli.js" + "api-codegen": "dist/cli.js" + }, + "files": [ + "dist", + "package.json" + ], + "engines": { + "node": ">=18" }, "scripts": { - "build": "bun build src/cli.ts --target=node --outdir=dist --format=esm", + "build": "bun build src/cli.ts --target=node --outdir=dist --format=esm --external=@biomejs/* && cp -r src/templates dist/", "dev": "bun run src/cli.ts", "test": "bun test", "test:unit": "bun test tests/unit", "test:integration": "bun test tests/integration", "test:watch": "bun test --watch", - "test:coverage": "bun test --coverage" + "test:coverage": "bun test --coverage", + "prepublishOnly": "bun run build" }, "dependencies": { "@biomejs/wasm-bundler": "^2.3.0", diff --git a/src/cli.ts b/src/cli.ts index 269b757..5e93fbd 100644 --- a/src/cli.ts +++ b/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 to OpenAPI specification file (JSON or YAML)') .requiredOption('-o, --output ', 'Output directory for generated files') .option('-n, --name ', 'Name of generated file (without extension)') @@ -50,3 +57,5 @@ program program.parse(); + + diff --git a/src/config.ts b/src/config.ts index 0928290..2d669b6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -33,3 +33,5 @@ export function validateConfig(config: Partial): config is Gene return true; } + + diff --git a/src/generator.ts b/src/generator.ts index 6059c7d..0b20a76 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -28,7 +28,9 @@ export async function generate(config: GeneratorConfig): Promise { 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(inputPath); @@ -56,12 +58,12 @@ export async function generate(config: GeneratorConfig): Promise { 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, diff --git a/src/utils/file.ts b/src/utils/file.ts index ceda5fb..16e84ff 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -64,3 +64,5 @@ export function resolvePath(path: string): string { return join(process.cwd(), path); } + +