(
rootPath: string,
sandboxes: SandboxFileInformation[],
chunkMode: string,
writeContents: (file, contents) => Promise<string>)
| 89 | } |
| 90 | |
| 91 | export function buildSandboxFileContents( |
| 92 | rootPath: string, |
| 93 | sandboxes: SandboxFileInformation[], |
| 94 | chunkMode: string, |
| 95 | writeContents: (file, contents) => Promise<string>) { |
| 96 | const promises: Promise<string>[] = []; |
| 97 | |
| 98 | const filename = joinPath(rootPath, 'sandboxes.ts'); |
| 99 | createSandboxesFileIfNotExists(filename); |
| 100 | |
| 101 | let contents = readFileSync(filename, 'utf8'); |
| 102 | |
| 103 | if (contents.indexOf('*GET_SANDBOX*') !== -1) { |
| 104 | const sandboxMenuItemsMethodBody = buildGetSandboxMenuItemMethodBodyContent(sandboxes); |
| 105 | contents = contents.replace( |
| 106 | /(\/\*GET_SANDBOX_MENU_ITEMS\*\/).*?(?=\/\*END_GET_SANDBOX_MENU_ITEMS\*\/)/s, |
| 107 | `$1\n ${sandboxMenuItemsMethodBody} \n` |
| 108 | ); |
| 109 | const sandboxMethodBody = buildGetSandboxMethodBodyContent(sandboxes, chunkMode); |
| 110 | contents = contents.replace(/(\/\*GET_SANDBOX\*\/).*?(?=\/\*END_GET_SANDBOX\*\/)/s, `$1\n ${sandboxMethodBody} \n`); |
| 111 | promises.push(writeContents(filename, contents)); |
| 112 | } |
| 113 | |
| 114 | return Promise.all(promises); |
| 115 | } |
| 116 | |
| 117 | export function createSandboxesFileIfNotExists(filename: string) { |
| 118 | if (!existsSync(filename)) { |
no test coverage detected