file-lane
Version:
File conversion tool, can be one-to-one, one to N, N to one
142 lines (141 loc) • 3.51 kB
TypeScript
import IFileLaneConfig from './interface/IFileLaneConfig';
import FileLaneTriggerType from './enum/FileLaneTriggerType';
import IFileLaneEvents from './interface/IFileLaneEvents';
export interface IBuilderParam {
fileList: string[];
trigger: FileLaneTriggerType;
}
/**
* FileLane
*
* 文件车道,用于将文件进行对应转换,支持1对1、1对N、N对1
*
* @example
* ```
* new FileLane<IJavascriptCompileOption>(
* fileLaneConfig,
* projectPath,
* compilerOption,
* {
* onBuildSuccess: (data) => {},
* onBuildError: (data) => {},
* onLog: (logs) => {}
* }).start()
* ```
*
* @description
*/
declare class FileLane<O = any> {
readonly config: IFileLaneConfig<O>;
readonly compilerOption?: O | undefined;
private readonly events?;
private context;
private watcher?;
/**
* 每次编译的数据对象
*/
private compilation?;
private changeFileList;
private triggerCount;
private building;
private nextBuildParam;
private fileHashCache;
/**
* 实例化FileLane
* @param config fileLane 配置
* @param projectPath 项目路径
* @param compilerOption 编译参数,不同语言的项目具有的参数不同,即使同一项目开发者也会设置不同的参数
* @param events 事件监听器
*/
constructor(config: IFileLaneConfig<O>, projectPath?: string, compilerOption?: O | undefined, events?: IFileLaneEvents | undefined);
private addProcessListener;
/**
* 运行
* @param params
* @returns
*/
start(params?: {
/**
* 是否开启文件监听
* 不开启--只运行一次
* 开启--文件变化时会自动再次运行
*/
watch?: boolean;
}): Promise<void>;
private validateConfig;
private processBeforeExitHandler;
private sigintHandler;
dispose(): Promise<void>;
/**
* 触发编译
*
* 如果:在编译过程中,则记录统参数,待本次 build 完成后,开始下一次
* 否则:直接触发编译
*/
private triggerBuild;
/**
*
* @param fileList 原始文件列表
*/
private build;
private initCompilation;
private buildFile;
private runLoaders;
/**
* 处理日志
* 1. 触发onLog事件
* 2. 如果有错误日志,则抛出错误
* @param logs
* @param onError
* @returns
*/
private handlerLogs;
private writeFiles;
private runLoader;
/**
* 匹配符合条件的loader
* @param filePath
* @returns
*/
private findLoader;
private triggerPlugins;
/**
* start开始时的准备工作
*/
private complyBeforeWorks;
/**
* start结束后的收尾工作
*/
private complyAfterWork;
/**
* 执行项目转换的前置工作
*/
private complyBeforeCompile;
/**
* 执行项目转换的后续工作
*/
private complyAfterCompile;
private watch;
/**
* 采集所有要处理的真实文件路径列表
* @param entryFileList
* @returns
*/
private collectFile;
/**
* 监听文件变化
* @param onChange
*/
private listenFileChange;
/**
* 清除输出文件夹
*/
private cleanOutput;
/**
* 1. 配置的忽略文件夹
* 2. 默认应该忽略的文件及文件夹
* @returns
*/
private getIgnoreConfig;
}
export default FileLane;