(directoryUrl: string, variableToUUIDMap: Map<string, string>)
| 82 | } |
| 83 | |
| 84 | function generateMacroJSON(directoryUrl: string, variableToUUIDMap: Map<string, string>): void { |
| 85 | const macrosDirectory = path.join(directoryUrl, 'macros') |
| 86 | |
| 87 | const filesList: string[] = fs.readdirSync(macrosDirectory) |
| 88 | const result: { [key: string]: string } = {} |
| 89 | |
| 90 | for (const file of filesList) { |
| 91 | const filePath = path.join(macrosDirectory, file) |
| 92 | if (fs.lstatSync(filePath).isFile()) { |
| 93 | let data = fs.readFileSync(filePath, { encoding: 'utf8' }) |
| 94 | |
| 95 | // foreach ofthis hashmap |
| 96 | Array.from(variableToUUIDMap).forEach(([key, value]) => { |
| 97 | data = data.replace(new RegExp(key, 'g'), value) |
| 98 | console.log('replacing', key, value) |
| 99 | }) |
| 100 | |
| 101 | result[variableToUUIDMap.get(file.replace('.njk', ''))!] = data |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | const outputFile = path.join(directoryUrl, 'macros.json') |
| 106 | |
| 107 | fs.writeFileSync(outputFile, JSON.stringify(result)) |
| 108 | } |
| 109 | |
| 110 | const rootDirectory: string = path.join(__dirname, '..') |
| 111 | readDirectoriesAndConvertToJSON(rootDirectory) |
no outgoing calls
no test coverage detected