modular-core
Version:
JavaScript application modular support
98 lines (97 loc) • 3.35 kB
TypeScript
/*!
* Copyright (c) 2021 han_feng@foxmail.com
*
* 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.
*/
import Modular from './Modular';
/**
* 扩展点类型,默认值为 array,可选值有以下几种:
* array: 数组形式,支持多值,所有扩展配置都有效;
* mixin: 混合形式,由多个扩展配置混合形成最后有效的配置;
* single: 单一对象,只有最后的扩展配置有效
*/
export declare const Type: Readonly<{
Single: string;
Mixin: string;
Multiple: string;
}>;
/**
* 扩展点声明接口
*/
export interface ExtensionPoint {
type: string;
module?: string;
}
/**
* 扩展配置预处理器接口
*/
export interface Preprocessor {
/**
* 扩展配置预处理
* @param extensions 待处理扩展配置对象数组
* @returns 处理后的扩展配置对象数组
*/
process(extensions: any[], extensionPoint?: ExtensionPoint, modular?: Modular): any;
}
/**
* 默认的扩展点声明实现类
*/
export declare class DefaultExtensionPoint implements ExtensionPoint {
readonly type: string;
module?: string;
modular?: Modular;
/**
* 原始配置对象
*/
private readonly extensions;
/**
* 处理过的配置对象
*/
private extension;
/**
* 预处理器
*/
private readonly preprocessors;
private processed;
constructor(point: ExtensionPoint, modular?: Modular);
/**
* 添加扩展
* @param module 扩展提供模块名称
* @param extensions 扩展配置集合
*/
addExtension(module: string, ...extensions: any[]): void;
/**
* 获取扩展配置对象
* @returns 当扩展点类型为 Multiple 时,返回扩展配置对象数组;
* 当扩展点类型为 Single 时,返回最后加入的扩展配置对象;
* 当扩展点类型为 Mixin 时,返回所有扩展配置对象混合后的结果
*/
getExtension(): any;
/**
* 获取原始配置对象数组,这些配置对象未经任何加工处理
*/
getExtensions(): any[];
/**
* 添加预处理器
* @param proprocessors 预处理器集合
*/
addPreprocessors(...proprocessors: Preprocessor[]): void;
private preprocess;
private processExtensions;
}