MCPcopy Create free account
hub / github.com/ShaanCoding/makeread.me / generateMacroJSON

Function generateMacroJSON

backend/script/generate.ts:84–108  ·  view source on GitHub ↗
(directoryUrl: string, variableToUUIDMap: Map<string, string>)

Source from the content-addressed store, hash-verified

82}
83
84function 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
110const rootDirectory: string = path.join(__dirname, '..')
111readDirectoriesAndConvertToJSON(rootDirectory)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected