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

Function generateBlockJSON

backend/script/generate.ts:39–82  ·  view source on GitHub ↗
(directoryPath: string)

Source from the content-addressed store, hash-verified

37}
38
39const generateBlockJSON = async (directoryPath: string): Promise<Map<string, string> | undefined> => {
40 // Check if block.ts file exists
41 let blocksFilePath: string = path.join(directoryPath, 'blocks.ts')
42 const doesBlockFileExist: boolean = fs.existsSync(blocksFilePath)
43
44 if (!doesBlockFileExist) {
45 console.error('blocks.ts file does not exist in the directory: ', directoryPath)
46 return
47 }
48
49 // if windows, we have to add file:// to the path
50 if (process.platform === 'win32') {
51 blocksFilePath = 'file://' + blocksFilePath
52 }
53
54 const variableToUUIDMap: Map<string, string> = new Map()
55
56 const importedData = await import(blocksFilePath)
57 const data: FullTemplate = importedData.default
58
59 data.functions.forEach((func: IFunction) => {
60 // Update the macros name
61 const functionUUID = uuidv4().replaceAll('-', '')
62 variableToUUIDMap.set(func.function, functionUUID)
63 func.function = functionUUID
64
65 func.variables.forEach((variable: Variable) => {
66 const variableUUID = uuidv4().replaceAll('-', '')
67 variableToUUIDMap.set(variable.name, variableUUID)
68 variable.name = variableUUID
69 })
70 })
71
72 data.startupBlocks = data.startupBlocks.map((element) => variableToUUIDMap.get(element)!)
73
74 fs.writeFile(path.join(directoryPath, 'blocks.json'), JSON.stringify(data), (err) => {
75 if (err) {
76 console.error('Error writing blocks.json file: ', err)
77 return undefined
78 }
79 })
80
81 return variableToUUIDMap
82}
83
84function generateMacroJSON(directoryUrl: string, variableToUUIDMap: Map<string, string>): void {
85 const macrosDirectory = path.join(directoryUrl, 'macros')

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected