MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / mergeNodeRed

Method mergeNodeRed

tools/mcmanifest.js:2869–2936  ·  view source on GitHub ↗
(manifests)

Source from the content-addressed store, hash-verified

2867 });
2868 }
2869 mergeNodeRed(manifests) {
2870 if (!this.environment.NODEREDMCU)
2871 return;
2872 this.nodeRedExtracts = new Map;
2873 let nodeTypes = {};
2874
2875 try {
2876 const path = this.resolveFilePath(this.resolveVariable("$(NODEREDMCU)/node_types.json"));
2877 if (path)
2878 nodeTypes = JSON.parse(this.readFileString(path));
2879 }
2880 catch {
2881 }
2882
2883 manifests.forEach(manifest => {
2884 const modules = manifest.modules?.["*"];
2885 if (!modules) return;
2886
2887 for (const specifier in modules) {
2888 const module = modules[specifier];
2889 if ("object" !== typeof module)
2890 continue;
2891 if ("nodered2mcu" !== module.transform)
2892 return;
2893
2894 this.currentDirectory = manifest.directory;
2895 const source = this.resolveFilePath(this.resolveVariable(module.source) + ".json");
2896 const flows = JSON.parse(this.readFileString(source));
2897
2898 let credentials;
2899 if (source.toLowerCase().endsWith(".json")) {
2900 const path = source.slice(0, -5) + "_cred_mcu.json";
2901 if (this.resolveFilePath(path))
2902 credentials = JSON.parse(this.readFileString(path)).credentials;
2903 }
2904
2905 flows.forEach((node, i) => {
2906 let manifest;
2907 if(("comment" === node.type)&&(node.name?.startsWith("moddable_manifest"))&&(node.info?.startsWith("{"))){
2908 manifest = JSON.parse(node.info);
2909 }
2910 else if (node.moddable_manifest)
2911 manifest = {...node.moddable_manifest};
2912 else if (nodeTypes[node.type])
2913 manifest = {include: nodeTypes[node.type]};
2914 else
2915 return;
2916
2917 switch (node.type) {
2918 case "tls-config":
2919 if (node.ca || credentials?.[node.id]?.cadata)
2920 this.nodeRedExtracts.set(`${node.id}-ca.der`, source)
2921 if (node.cert || credentials?.[node.id]?.certdata)
2922 this.nodeRedExtracts.set(`${node.id}-cert.der`, source)
2923 if (node.key || credentials?.[node.id]?.keydata)
2924 this.nodeRedExtracts.set(`${node.id}-key.der`, source)
2925 break;
2926 }

Callers 1

runMethod · 0.95

Calls 6

resolveVariableMethod · 0.95
parseManifestMethod · 0.95
resolveFilePathMethod · 0.80
parseMethod · 0.65
sliceMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected