Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

453 Zeilen
10KB

  1. /**
  2. * ResourceManager 配置文件
  3. */
  4. type ResourceManagerConfig = {
  5. /**
  6. * 构建与发布配置
  7. */
  8. buildConfig: (param: BuildConfigParam) => UserConfig,
  9. /**
  10. * 设置资源类型
  11. */
  12. typeSelector: (path: string) => (string | null | undefined)
  13. /**
  14. * 设置资源的合并策略
  15. */
  16. mergeSelector?: (path: string) => (string | null | undefined),
  17. /**
  18. * 设置资源的命名策略
  19. * beta 功能,请勿随意使用
  20. */
  21. nameSelector?: (path: string) => (string | null | undefined)
  22. }
  23. /**
  24. * 构建配置
  25. */
  26. type UserConfig = {
  27. /**
  28. * 输出路径
  29. */
  30. outputDir: string,
  31. /**
  32. * 插件
  33. */
  34. commands: (string | plugins.Command)[]
  35. }
  36. type BuildConfigParam = {
  37. /**
  38. * 当前命令,build 或者 command
  39. */
  40. readonly command: string;
  41. /**
  42. * 发布平台
  43. */
  44. readonly target: string;
  45. /**
  46. * 开发者指定的版本号
  47. */
  48. readonly version: string;
  49. /**
  50. * 项目名称
  51. */
  52. readonly projectName: string;
  53. /**
  54. * 项目路径
  55. */
  56. readonly projectRoot: string;
  57. /**
  58. * 项目配置
  59. */
  60. readonly projectConfig: ProjectConfig;
  61. }
  62. type ProjectConfig = {
  63. entryClassName: string;
  64. orientation: string;
  65. frameRate: number;
  66. scaleMode: string;
  67. contentWidth: number;
  68. contentHeight: number;
  69. showFPS: boolean;
  70. fpsStyles: string;
  71. showLog: boolean;
  72. maxTouches: number;
  73. }
  74. /**
  75. * 匹配机制,将满足 from 的文件输出为 to 格式的文件
  76. * from 采用 glob 表达式 , to 包含 [path][name][hash][ext]四个变量
  77. * 示例:{ from:"resource/**.*" , to:"[path][name]_[hash].[ext]" }
  78. */
  79. type Matcher = {
  80. from: string,
  81. to: string
  82. }
  83. declare namespace plugins {
  84. interface CommandContext {
  85. /**
  86. * 可以用此接口进行文件创建
  87. */
  88. createFile(relativeFilePath: string, contents: Buffer);
  89. /**
  90. * 构建配置
  91. */
  92. buildConfig: BuildConfigParam;
  93. /**
  94. * 项目绝对路径
  95. */
  96. projectRoot: string;
  97. /**
  98. * 项目输出绝对路径
  99. */
  100. outputDir: string;
  101. }
  102. /**
  103. * 构建管线命令
  104. */
  105. interface Command {
  106. /**
  107. * 项目中的每个文件都会执行此函数,返回 file 表示保留此文件,返回 null 表示将此文件从构建管线中删除,即不会发布
  108. */
  109. onFile?(file: File): Promise<File | null>
  110. /**
  111. * 项目中所有文件均执行完后,最终会执行此函数。
  112. * 这个函数主要被用于创建新文件
  113. */
  114. onFinish?(pluginContext?: CommandContext): Promise<void>
  115. [options: string]: any;
  116. }
  117. interface File {
  118. /**
  119. * 文件内容的二进制流,如果开发者需要修改文件内容,请修改此属性
  120. */
  121. contents: Buffer;
  122. /**
  123. * 文件绝对路径,如果开发者需要对文件进行重命名,请修改此属性
  124. */
  125. path: string;
  126. /**
  127. * 文件所在的项目的项目路径
  128. */
  129. readonly base: string;
  130. /**
  131. * 文件的相对于 base 属性的相对路径
  132. */
  133. readonly relative: string;
  134. /**
  135. * 文件变更历史,history[0] 即 origin 属性
  136. */
  137. readonly history: ReadonlyArray<string>;
  138. /**
  139. * 文件所在的文件夹的绝对路径
  140. */
  141. readonly dirname: string;
  142. /**
  143. * 文件的文件名
  144. */
  145. readonly basename: string;
  146. /**
  147. * 文件的扩展名
  148. */
  149. readonly extname: string;
  150. /**
  151. * 文件的初始文件名
  152. */
  153. readonly origin: string;
  154. /**
  155. * 其他自定义属性
  156. */
  157. [customProperty: string]: any;
  158. }
  159. }
  160. declare module 'built-in' {
  161. /**
  162. * 混淆插件参数,设置源代码和目标代码
  163. */
  164. type UglifyPluginOption = { sources: string[], target: string };
  165. type UglifyPluginOptions = UglifyPluginOption[];
  166. /**
  167. * 混淆插件
  168. */
  169. export class UglifyPlugin implements plugins.Command {
  170. constructor(mergeSelector: UglifyPluginOptions);
  171. }
  172. type LibraryType = "debug" | "release";
  173. type CompilePluginOptions = { libraryType: LibraryType, defines?: any };
  174. /**
  175. * 编译命令
  176. */
  177. export class CompilePlugin implements plugins.Command {
  178. constructor(options: CompilePluginOptions);
  179. }
  180. /**
  181. * EXML 插件,用于发布 EXML 文件
  182. */
  183. export class ExmlPlugin implements plugins.Command {
  184. constructor(publishPolicy: EXML_Publish_Policy);
  185. }
  186. /**
  187. * 发布策略
  188. * * debug : 默认策略,用于开发环境
  189. * * contents : 将 EXML 的内容写入到主题文件中
  190. * * gjs : 将生成的JS文件写入到主题文件中
  191. * * commonjs : 将EXML合并为一个 CommonJS 风格的文件
  192. * * commonjs2 : 将EXML合并为一个含有解析方法和皮肤定义的文件,且皮肤抽离为一份配置
  193. * * json : 将每个EXML文件生成一份配置
  194. */
  195. type EXML_Publish_Policy = "debug" | "contents" | "gjs" | "commonjs" | "commonjs2" | "json"
  196. /**
  197. * 生成 manifest 文件,这个文件会被用于记录 JavaScript 文件的版本号
  198. */
  199. export class ManifestPlugin implements plugins.Command {
  200. constructor(options?: ManifestPluginOptions)
  201. }
  202. /**
  203. * 生成文件的文件名
  204. * 支持 json 与 js 两种格式
  205. */
  206. type ManifestPluginOptions = {
  207. output: string,
  208. hash?: "crc32",
  209. /**
  210. * 是否输出转换过程
  211. */
  212. verbose?: boolean,
  213. /**
  214. * 其他传递的消息参数
  215. */
  216. info?:any
  217. /**
  218. * use wechat engine plugin
  219. */
  220. useWxPlugin?: boolean
  221. /**
  222. * use QQgame engine plugin
  223. */
  224. qqPlugin?: { use: boolean, pluginList: string[] }
  225. }
  226. /**
  227. * EmitResConfigFilePlugin 的参数
  228. * * output: 生成路径,可以指定生成为 *.res.js 文件或者 *.res.json 文件
  229. * * typeSelector: 根据文件路径决定文件类型
  230. * * nameSelector: 根据文件路径决定文件的资源名
  231. * * groupSelector: 根据文件路径决定资源所述的资源组
  232. */
  233. type EmitResConfigFilePluginOptions = {
  234. output: string,
  235. typeSelector: (path: string) => string | null | undefined,
  236. nameSelector: (path: string) => string | null | undefined,
  237. groupSelector: (path: string) => string | null | undefined,
  238. }
  239. /**
  240. * 生成 res.json 文件或者 res.js 文件
  241. */
  242. export class EmitResConfigFilePlugin implements plugins.Command {
  243. constructor(options: EmitResConfigFilePluginOptions)
  244. }
  245. export type ConvertResourceConfigPluginOption = {
  246. resourceConfigFiles: { filename: string, root: string }[];
  247. nameSelector: (url: string) => string;
  248. TM_Verbose: boolean;
  249. }
  250. export class ConvertResConfigFilePlugin implements plugins.Command {
  251. constructor(options: ConvertResourceConfigPluginOption);
  252. }
  253. /**
  254. * 增量编译
  255. * 这个插件生成的 JavaScript 代码不会被添加到构建管线中,后续其他插件无法获取生成的 js 文件
  256. * 这个功能将会在未来被 watch 模式代替掉
  257. */
  258. export class IncrementCompilePlugin implements plugins.Command {
  259. }
  260. type TextureMergerOptions = {
  261. textureMergerRoot: string[];
  262. }
  263. /**
  264. * 使用 TextureMerger 实现纹理自动合并,依赖 TextureMerger 1.7 以上的版本
  265. */
  266. export class TextureMergerPlugin implements plugins.Command {
  267. constructor(options: TextureMergerOptions);
  268. }
  269. type CleanPluginOptions = {
  270. matchers: string[]
  271. }
  272. export class CleanPlugin implements plugins.Command {
  273. constructor(options: CleanPluginOptions);
  274. }
  275. type RenamePluginOptions = {
  276. /**
  277. * 是否输出日志
  278. * Whether to output the log
  279. */
  280. verbose?: boolean
  281. /**
  282. * 采用何种 hash 算法,目前暂时只支持 crc32
  283. * What hash algorithm is used, currently only crc32 is supported
  284. */
  285. hash?: "crc32"
  286. /**
  287. * 设置匹配规则,将指定文件进行改名
  288. * 该参数是个数组,允许设置多个匹配规则
  289. * Set up matching rules to copy specified files to other folders
  290. * This parameter is an array that allows multiple matching rules to be set
  291. */
  292. matchers: Matcher[]
  293. /**
  294. * 回调函数,返回值里包括文件的一些信息
  295. * The callback function, return value includes some information about the file
  296. */
  297. callback?: Function
  298. }
  299. /**
  300. * 修改文件名插件
  301. */
  302. export class RenamePlugin implements plugins.Command {
  303. constructor(options: RenamePluginOptions);
  304. }
  305. type ResSplitPluginOptions = {
  306. /**
  307. * 是否输出日志
  308. * Whether to output the log
  309. */
  310. verbose?: boolean
  311. /**
  312. * 设置匹配规则,将指定文件拷贝至其他文件夹
  313. * 该参数是个数组,允许设置多个匹配规则
  314. * Set up matching rules to copy specified files to other folders
  315. * This parameter is an array that allows multiple matching rules to be set
  316. */
  317. matchers: Matcher[]
  318. }
  319. export class ResSplitPlugin implements plugins.Command {
  320. constructor(options: ResSplitPluginOptions);
  321. }
  322. type ZipPluginOptions = {
  323. mergeSelector: (p: string) => string
  324. }
  325. export class ZipPlugin implements plugins.Command {
  326. constructor(option: ZipPluginOptions);
  327. }
  328. type MergeEuiJsonPluginOptions = {
  329. mergeSelector?: (p: string) => string | null,
  330. createConfig?: boolean
  331. }
  332. export class MergeEuiJsonPlugin implements plugins.Command {
  333. constructor(option?: MergeEuiJsonPluginOptions);
  334. }
  335. }