export const FILE_MODULE_PREFIX = "file://$MODULE_DIR$"; export const ALT_FILE_MODULE_PREFIX = "file://$MODULE_DIR$/"; export const CONTENT_END_TAG = ""; const createSelfEnclosedTag = (prefix: string) => ``; export const prepareIml = (originalContent: string): string => { let imlContents = originalContent.replace(`url="${ALT_FILE_MODULE_PREFIX}"`, `url="${FILE_MODULE_PREFIX}"`); const selfEnclosedTag = createSelfEnclosedTag(FILE_MODULE_PREFIX); if (imlContents.includes(selfEnclosedTag)) { imlContents = imlContents.replace( selfEnclosedTag, `\n${CONTENT_END_TAG}` ); } return imlContents; }; export const injectToGroup = (imlContents: string, group: string, content: string): string => { const START_TAG = ``; const END_TAG = ``; const startIndex = imlContents.indexOf(START_TAG); const endIndex = imlContents.lastIndexOf(END_TAG); const hasPrevGeneratedExcludes = startIndex !== -1 && endIndex !== -1; let beforeContent; let afterContent; if (hasPrevGeneratedExcludes) { beforeContent = imlContents.substr(0, startIndex); afterContent = imlContents.substr(endIndex + END_TAG.length); } else { const contentEndTagIndex = imlContents.lastIndexOf(CONTENT_END_TAG); beforeContent = imlContents.substr(0, contentEndTagIndex); afterContent = imlContents.substr(contentEndTagIndex); } if(!beforeContent || !afterContent){ throw new Error('💥 failed to parse configuration file - content marker not found') } return [ // beforeContent, // START_TAG, content, END_TAG, // afterContent, ].join("\n"); }; export const injecter = (content: string, group: string, excludes: string[], mapper:(match:string) => string): string => injectToGroup( content, group, excludes.map(mapper).join("\n") ); export const injectExcludes = (content: string, group: string, excludes: string[]): string => injecter( content, group, excludes, (exclude) => `` ); export const injectTestRoots = (content: string, group: string, excludes: string[]): string => injecter( content, group, excludes, (exclude) => `` ); export const injectSourceRoots = (content: string, group: string, excludes: string[]): string => injecter( content, group, excludes, (exclude) => `` );