* Construct the final version of a file by interpolating its includes in dependency order. * @param file - the file whose content we want to construct * @param processed - a cache to keep track of which includes have already been processed
(file, processed)
| 301 | * @param processed - a cache to keep track of which includes have already been processed |
| 302 | */ |
| 303 | interpolate(file, processed) { |
| 304 | processed = processed || new Set(); |
| 305 | let content = file.content; |
| 306 | file.includes.forEach(child => { |
| 307 | const emitted = processed ? processed.has(child.path) : undefined; |
| 308 | const fragment = this.interpolate(child, processed); |
| 309 | const replacement = emitted ? '' : fragment; |
| 310 | |
| 311 | if (!replacement) { |
| 312 | content = replaceAll(content, child.token, ''); |
| 313 | } else { |
| 314 | // replace the first instance with the dependency |
| 315 | content = content.replace(child.token, replacement); |
| 316 | // remove the rest |
| 317 | content = replaceAll(content, child.token, ''); |
| 318 | } |
| 319 | |
| 320 | if (processed) { |
| 321 | processed.add(child.path); |
| 322 | } |
| 323 | }); |
| 324 | |
| 325 | return content; |
| 326 | } |
| 327 | |
| 328 | async loadCommand(filename, cache) { |
| 329 | filename = path.resolve(filename); |
no test coverage detected