MCPcopy
hub / github.com/OptimalBits/bull / interpolate

Method interpolate

lib/commands/script-loader.js:303–326  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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);

Callers 1

loadCommandMethod · 0.95

Calls 2

replaceAllFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected