cis-api-tool
Version:
根据 swagger/yapi/apifox 的接口定义生成 TypeScript/JavaScript 的接口类型及其请求函数代码。
75 lines (74 loc) • 2.35 kB
text/typescript
/// <reference types="lodash" />
import "./type-CDnRd9vn.mjs";
import { Category, CategoryList, Config, Interface, InterfaceList, Project, SyntheticalConfig } from "./types-B8Xpfzsb.mjs";
import * as lodash0 from "lodash";
//#region src/Generator.d.ts
interface OutputFileList {
[outputDir: string]: {
syntheticalConfig: SyntheticalConfig;
content: string[];
requestFunctionFilePath: string;
requestHookMakerFilePath: string;
};
}
declare class Generator {
private options;
/** 配置 */
private config;
private disposes;
constructor(config: Config, options?: {
cwd: string;
});
prepare(): Promise<void>;
/**
* 清理输出目录,删除之前生成的文件但保留requestFunctionFilePath指定的文件
*/
cleanOutputDirectory(): Promise<void>;
generate(): Promise<OutputFileList>;
/**
* 生成index.ts文件,将目录中的所有方法和interface类型导出
* @param directoryPaths 目录路径
* @param outputDir 输出目录,默认为 'src/service'
*/
generateIndexFile(directoryPaths: string[], outputDir?: string): Promise<void>;
private collectSubDirectories;
write(outputFileList: OutputFileList): Promise<OutputFileList>;
tsc(file: string): Promise<void>;
fetchApi<T = any>(url: string, query: Record<string, any>): Promise<T>;
fetchProject: (({
serverUrl,
token
}: SyntheticalConfig) => Promise<Project>) & lodash0.MemoizedFunction;
fetchExport: (({
serverUrl,
token
}: SyntheticalConfig) => Promise<Category[]>) & lodash0.MemoizedFunction;
/** 获取分类的接口列表 */
fetchInterfaceList({
serverUrl,
token,
id
}: SyntheticalConfig): Promise<InterfaceList>;
/** 获取项目信息 */
fetchProjectInfo(syntheticalConfig: SyntheticalConfig): Promise<{
cats: CategoryList;
getMockUrl: () => string;
getDevUrl: (devEnvName: string) => string;
getProdUrl: (prodEnvName: string) => string;
_id: number;
_url: string;
name: string;
desc: string;
basepath: string;
tag: string[];
env: {
name: string;
domain: string;
}[];
}>;
/** 生成接口代码 */
generateInterfaceCode(syntheticalConfig: SyntheticalConfig, interfaceInfo: Interface, categoryUID: string): Promise<string>;
destroy(): Promise<any[]>;
}
//#endregion
export { Generator };