UNPKG

@ices/locale-webpack-plugin

Version:
70 lines (69 loc) 2.57 kB
/** * 指令解析规则: * 类似于 c 语言的 #include 指令,选择 # 开头是因为,# 在 yml 里表示注释,不会破坏原有语言规范,文件也能由其他解析器正常解析 * - 每一条 include 指令,都应该以单独的一行声明,且有效内容以 #include 开头 * - \#include "xxx"、#include 'xxx'、#include xxx 以当前上下文目录为根目录匹配相对路径 * - \#include <xxx> 以 node_modules 目录为根目录匹配"绝对"路径 * - \#include "./xxx"、#include "../xxx"、#include "xxx" 为有效指令,即都是从当前上下文目录起计算相对路径匹配 * - \#include <./xxx> 、#include <../xxx>、#include </xxx> 为无效指令,即从 node_modules 目录匹配时,不能使用相对路径或斜杠开头路径 * - \#include <.xxx> 为有效路径,表示 node_modules 目录下面的 .xxx 文件 * - ••#include••"••xxx••"••、••#include••<••xxx••>•• 为有效指令,其中••为空格字符 * * 新增 <<: 规则支持。 * <<: *xx 为标准中的引用锚点。 * 扩展规则为 <<: "xxx", <<: <xxx>, <<: xxx 为从文件xxx中导入到当前文件。 * * 文件名解析规则: * 不带后缀时,以 .yml 和 .yaml 为规则进行解析 * 文件为目录时,以目录下面的 index.yml 和 index.yaml 进行解析 */ /// <reference types="node" /> import fs from 'fs'; export declare type FileNodeType = { context: string; exists: boolean; file: string; source: string; content?: string; isDir?: boolean; children?: FileNodeType[]; cycleIncluded?: boolean; warnings?: Warning[]; }; /** * 用于去除警告信息的堆栈内容。 */ declare class Warning extends Error { constructor(message: string); } /** * 清除文件中的指令声明行。 * @param source 文件内容。 */ export declare function removeDirectives(source: string): string; /** * 解析yml文件导入指令。 * @param file 待解析文件的路径。 * @param fileSystem webpack可缓存的文件系统。 * @param resolveAlias 解析别名配置。 */ export default function parseIncludeAsync(file: string, fileSystem?: typeof fs, resolveAlias?: { [p: string]: string; } | null): Promise<{ files: { file: string; source: string; context: string; }[]; warnings: Warning[]; error: null; } | { files: { file: string; source: string; context: string; }[]; warnings: Warning[]; error: Error; }>; export {};