1/** 2 * Basic string transform that describes what should be replaced in the input string. 3 */ 4export type StringTransform = { 5 /** 6 * A substring or RegExp matching a part of the input that you want to replace. 7 */ 8 find: RegExp | string; 9 10 /** 11 * A string that replaces matched substrings in the input. 12 */ 13 replaceWith: string | ((substring: string, ...args: any[]) => string); 14}; 15 16/** 17 * A string transform extended by paths glob filter. 18 */ 19export type FileTransform = StringTransform & { 20 /** 21 * An array of glob patterns matching files to which the transform should be applied. 22 * Patterns without slashes will be matched against the basename of the path. 23 */ 24 paths?: string | string[]; 25}; 26 27/** 28 * An object containing both file content transforms and path transforms. 29 */ 30export type FileTransforms = { 31 /** 32 * An array of transforms to apply on each file's content. 33 */ 34 content?: FileTransform[]; 35 36 /** 37 * An array of transforms to apply on the relative file path. 38 */ 39 path?: StringTransform[]; 40}; 41 42/** 43 * An object with options passed to `copyFilesWithTransformsAsync` function. 44 */ 45export type CopyFileOptions = { 46 /** 47 * Path of the file to copy, relative to `sourceDirectory`. 48 */ 49 sourceFile: string; 50 51 /** 52 * A directory from which the files will be copied. 53 */ 54 sourceDirectory: string; 55 56 /** 57 * A directory to which the transformed files will be copied. 58 */ 59 targetDirectory: string; 60 61 /** 62 * An object with transform rules for file paths and contents. 63 */ 64 transforms: FileTransforms; 65}; 66 67/** 68 * The result of copying the file. 69 */ 70export type CopyFileResult = { 71 /** 72 * The final file content after transformations. 73 */ 74 content: string; 75 76 /** 77 * The final target path after transformations. Relative to provided `targetDirectory`. 78 */ 79 targetFile: string; 80}; 81