()
| 112 | } |
| 113 | |
| 114 | run() { |
| 115 | const source = this.readFileString(this.sourcePath); |
| 116 | let flows = JSON.parse(source); |
| 117 | |
| 118 | let credentials; |
| 119 | if (this.sourcePath.toLowerCase().endsWith(".json")) { |
| 120 | const path = this.sourcePath.slice(0, -5) + "_cred_mcu.json"; |
| 121 | if (this.resolveFilePath(path)) |
| 122 | credentials = JSON.parse(this.readFileString(path)).credentials; |
| 123 | } |
| 124 | |
| 125 | if (this.extract) { |
| 126 | const data = this.extractOne(flows, this.extract, credentials); |
| 127 | const parts = { |
| 128 | directory: this.outputDirectory, |
| 129 | name: this.extract.substring(0, this.extract.lastIndexOf(".")), |
| 130 | extension: this.extract.substring(this.extract.lastIndexOf(".")) |
| 131 | }; |
| 132 | const output = new FILE(this.joinPath(parts), "wb"); |
| 133 | output.writeBuffer(data); |
| 134 | output.close(); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | flows = this.transformFlows(flows, credentials); |
| 139 | |
| 140 | const parts = this.splitPath(this.sourcePath); |
| 141 | parts.extension = ".js"; |
| 142 | if (this.outputDirectory) |
| 143 | parts.directory = this.outputDirectory; |
| 144 | const outputPath = this.joinPath(parts); |
| 145 | |
| 146 | const output = new FILE(outputPath, "wb"); |
| 147 | output.writeString(flows); |
| 148 | output.close(); |
| 149 | } |
| 150 | |
| 151 | transformFlows(flows, credentials) { |
| 152 | const imports = new Map([["nodered", ""]]); // ensure that globalThis.RED is available |
nothing calls this directly
no test coverage detected