1/** 2 * Basic string transform that describes what should be replaced in the input string. 3 */ 4export type ReplaceTransform = { 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 16export type RawTransform = { 17 /** 18 * Function that takes string as an argument and returns result of the transformations. 19 */ 20 transform: (text: string) => string; 21}; 22 23export type StringTransform = RawTransform | ReplaceTransform; 24 25/** 26 * A string transform extended by paths glob filter. 27 */ 28export type FileTransform = StringTransform & { 29 /** 30 * An array of glob patterns matching files to which the transform should be applied. 31 * Patterns without slashes will be matched against the basename of the path. 32 */ 33 paths?: string | string[]; 34}; 35 36/** 37 * An object containing both file content transforms and path transforms. 38 */ 39export type FileTransforms = { 40 /** 41 * An array of transforms to apply on each file's content. 42 */ 43 content?: FileTransform[]; 44 45 /** 46 * An array of transforms to apply on the relative file path. 47 */ 48 path?: StringTransform[]; 49}; 50 51/** 52 * An object with options passed to `copyFilesWithTransformsAsync` function. 53 */ 54export type CopyFileOptions = { 55 /** 56 * Path of the file to copy, relative to `sourceDirectory`. 57 */ 58 sourceFile: string; 59 60 /** 61 * A directory from which the files will be copied. 62 */ 63 sourceDirectory: string; 64 65 /** 66 * A directory to which the transformed files will be copied. 67 */ 68 targetDirectory: string; 69 70 /** 71 * An object with transform rules for file paths and contents. 72 */ 73 transforms: FileTransforms; 74}; 75 76/** 77 * The result of copying the file. 78 */ 79export type CopyFileResult = { 80 /** 81 * The final file content after transformations. 82 */ 83 content: string; 84 85 /** 86 * The final target path after transformations. Relative to provided `targetDirectory`. 87 */ 88 targetFile: string; 89}; 90