xref: /expo/tools/src/Transforms.types.ts (revision 1a8a11e6)
19657025fSTomasz Sapeta/**
29657025fSTomasz Sapeta * Basic string transform that describes what should be replaced in the input string.
39657025fSTomasz Sapeta */
423e91912SWojciech Kozyraexport type ReplaceTransform = {
59657025fSTomasz Sapeta  /**
69657025fSTomasz Sapeta   * A substring or RegExp matching a part of the input that you want to replace.
79657025fSTomasz Sapeta   */
89657025fSTomasz Sapeta  find: RegExp | string;
99657025fSTomasz Sapeta
109657025fSTomasz Sapeta  /**
119657025fSTomasz Sapeta   * A string that replaces matched substrings in the input.
129657025fSTomasz Sapeta   */
139657025fSTomasz Sapeta  replaceWith: string | ((substring: string, ...args: any[]) => string);
149657025fSTomasz Sapeta};
159657025fSTomasz Sapeta
1623e91912SWojciech Kozyraexport type RawTransform = {
1723e91912SWojciech Kozyra  /**
1823e91912SWojciech Kozyra   * Function that takes string as an argument and returns result of the transformations.
1923e91912SWojciech Kozyra   */
2023e91912SWojciech Kozyra  transform: (text: string) => string;
2123e91912SWojciech Kozyra};
2223e91912SWojciech Kozyra
2323e91912SWojciech Kozyraexport type StringTransform = RawTransform | ReplaceTransform;
2423e91912SWojciech Kozyra
259657025fSTomasz Sapeta/**
269657025fSTomasz Sapeta * A string transform extended by paths glob filter.
279657025fSTomasz Sapeta */
289657025fSTomasz Sapetaexport type FileTransform = StringTransform & {
299657025fSTomasz Sapeta  /**
309657025fSTomasz Sapeta   * An array of glob patterns matching files to which the transform should be applied.
319657025fSTomasz Sapeta   * Patterns without slashes will be matched against the basename of the path.
329657025fSTomasz Sapeta   */
339657025fSTomasz Sapeta  paths?: string | string[];
34f194f574SWojciech Kozyra
35f194f574SWojciech Kozyra  /**
36f194f574SWojciech Kozyra   * When truthy every transform that changes anything will print a diff
37f194f574SWojciech Kozyra   * and wait for confirm to continue. If value is a string it will be used to identify
38f194f574SWojciech Kozyra   * the transformation in the output
39f194f574SWojciech Kozyra   */
40f194f574SWojciech Kozyra  debug?: boolean | string;
419657025fSTomasz Sapeta};
429657025fSTomasz Sapeta
439657025fSTomasz Sapeta/**
449657025fSTomasz Sapeta * An object containing both file content transforms and path transforms.
459657025fSTomasz Sapeta */
469657025fSTomasz Sapetaexport type FileTransforms = {
479657025fSTomasz Sapeta  /**
489657025fSTomasz Sapeta   * An array of transforms to apply on each file's content.
499657025fSTomasz Sapeta   */
509657025fSTomasz Sapeta  content?: FileTransform[];
519657025fSTomasz Sapeta
529657025fSTomasz Sapeta  /**
539657025fSTomasz Sapeta   * An array of transforms to apply on the relative file path.
549657025fSTomasz Sapeta   */
559657025fSTomasz Sapeta  path?: StringTransform[];
569657025fSTomasz Sapeta};
579657025fSTomasz Sapeta
589657025fSTomasz Sapeta/**
599657025fSTomasz Sapeta * An object with options passed to `copyFilesWithTransformsAsync` function.
609657025fSTomasz Sapeta */
619657025fSTomasz Sapetaexport type CopyFileOptions = {
629657025fSTomasz Sapeta  /**
639657025fSTomasz Sapeta   * Path of the file to copy, relative to `sourceDirectory`.
649657025fSTomasz Sapeta   */
659657025fSTomasz Sapeta  sourceFile: string;
669657025fSTomasz Sapeta
679657025fSTomasz Sapeta  /**
689657025fSTomasz Sapeta   * A directory from which the files will be copied.
699657025fSTomasz Sapeta   */
709657025fSTomasz Sapeta  sourceDirectory: string;
719657025fSTomasz Sapeta
729657025fSTomasz Sapeta  /**
739657025fSTomasz Sapeta   * A directory to which the transformed files will be copied.
749657025fSTomasz Sapeta   */
759657025fSTomasz Sapeta  targetDirectory: string;
769657025fSTomasz Sapeta
779657025fSTomasz Sapeta  /**
789657025fSTomasz Sapeta   * An object with transform rules for file paths and contents.
799657025fSTomasz Sapeta   */
809657025fSTomasz Sapeta  transforms: FileTransforms;
814ab6f4c5SKudo Chien
824ab6f4c5SKudo Chien  /**
834ab6f4c5SKudo Chien   * Whether to keep original file mode (the mode for `chmod`), e.g. 755.
844ab6f4c5SKudo Chien   */
854ab6f4c5SKudo Chien  keepFileMode?: boolean;
869657025fSTomasz Sapeta};
879657025fSTomasz Sapeta
889657025fSTomasz Sapeta/**
899657025fSTomasz Sapeta * The result of copying the file.
909657025fSTomasz Sapeta */
919657025fSTomasz Sapetaexport type CopyFileResult = {
929657025fSTomasz Sapeta  /**
939657025fSTomasz Sapeta   * The final file content after transformations.
949657025fSTomasz Sapeta   */
959657025fSTomasz Sapeta  content: string;
969657025fSTomasz Sapeta
979657025fSTomasz Sapeta  /**
989657025fSTomasz Sapeta   * The final target path after transformations. Relative to provided `targetDirectory`.
999657025fSTomasz Sapeta   */
1009657025fSTomasz Sapeta  targetFile: string;
101*1a8a11e6Saleqsio  /**
102*1a8a11e6Saleqsio   * A set of transforms that were used to transform the file.
103*1a8a11e6Saleqsio   */
104*1a8a11e6Saleqsio  transformsUsed: Set<FileTransform>;
1059657025fSTomasz Sapeta};
106