UNPKG

@lcap/builder

Version:
108 lines (107 loc) 3.95 kB
import * as babel from '@babel/core'; import * as bt from '@babel/types'; import type { MaterialComponentEvent, MaterialComponentMethod, MaterialComponentSlot, MaterialComponentAttr } from '@lcap/material-parser'; export interface APIEditorBaseOptions { type: 'add' | 'update' | 'remove' | 'order'; module: 'info' | 'subComponent' | 'prop' | 'event' | 'slot' | 'method' | 'readableProp'; name: string; } export interface APIUpdateInfoOptions extends APIEditorBaseOptions { type: 'update'; module: 'info'; data: Record<string, any>; } export declare function updateInfo(ast: bt.File, options: APIUpdateInfoOptions): babel.types.File; export interface APIAddSubComponentOptions extends APIEditorBaseOptions { type: 'add'; module: 'subComponent'; data: { name?: string; sourceName?: string; title?: string; description?: string; type?: any; }; } export declare function addSubComponent(ast: bt.File, options: APIAddSubComponentOptions): void; export interface APIRemoveSubComponentOptions extends APIEditorBaseOptions { type: 'remove'; module: 'subComponent'; data: { name: string; }; } export declare function removeSubComponent(ast: bt.File, options: APIRemoveSubComponentOptions): void; export interface APIAddPropOptions extends APIEditorBaseOptions { type: 'add'; module: 'prop'; data: { name: string; group?: string; schema?: MaterialComponentAttr; }; } export declare function addProp(ast: bt.File, options: APIAddPropOptions): void; export interface APIAddEventOptions extends APIEditorBaseOptions { type: 'add'; module: 'event'; data: { name: string; schema?: MaterialComponentEvent; }; } export declare function addEvent(ast: bt.File, options: APIAddEventOptions): void; export interface APIAddSlotOptions extends APIEditorBaseOptions { type: 'add'; module: 'slot'; data: { name: string; schema?: MaterialComponentSlot; }; } export declare function addSlot(ast: bt.File, options: APIAddSlotOptions): void; export interface APIAddReadablePropOptions extends APIEditorBaseOptions { type: 'add'; module: 'readableProp'; data: { name: string; }; } export declare function addReadableProp(ast: bt.File, options: APIAddReadablePropOptions): void; export interface APIAddMethodOptions extends APIEditorBaseOptions { type: 'add'; module: 'method'; data: { name: string; schema?: MaterialComponentMethod; }; } export declare function addMethod(ast: bt.File, options: APIAddMethodOptions): void; export interface APIUpdatePropOptions extends APIEditorBaseOptions { type: 'update'; module: 'prop' | 'event' | 'slot' | 'readableProp' | 'method'; propName: string; data: { name?: string; tsType?: string; defaultValue?: string; [key: string]: any; }; } export declare function updateProp(ast: bt.File, options: APIUpdatePropOptions): void; export interface APIRemovePropOptions extends APIEditorBaseOptions { type: 'remove'; module: 'prop' | 'event' | 'slot' | 'readableProp' | 'method'; propName: string; } export declare function removeProp(ast: bt.File, options: APIRemovePropOptions): void; export interface APIOrderPropOptions extends APIEditorBaseOptions { type: 'order'; data: { names: string[]; isOptions?: boolean; }; } export declare function orderProp(ast: bt.File, options: APIOrderPropOptions): void; export type APIUpdateOptions = APIUpdateInfoOptions | APIAddSubComponentOptions | APIRemoveSubComponentOptions | APIAddPropOptions | APIUpdatePropOptions | APIRemovePropOptions | APIAddEventOptions | APIAddSlotOptions | APIAddReadablePropOptions | APIAddMethodOptions | APIOrderPropOptions; export default function updateAPIFile(tsPath: string, actions: APIUpdateOptions[]): Promise<void>;