MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / conformFile

Function conformFile

tools/conform-includes.js:58–93  ·  view source on GitHub ↗
(file, libName)

Source from the content-addressed store, hash-verified

56
57const includeRegex = /#include\s*(\<(.+?)\>|\"(.+?)\")/g;
58function conformFile(file, libName) {
59 const fileContents = fs.readFileSync(file, "utf-8");
60 const newContents = fileContents.replace(includeRegex, (str, _, a, b) => {
61 const filePath = a || b;
62 const pathParts = path.parse(filePath);
63 const pathLib = pathParts.dir;
64 const pathFile = pathParts.base;
65 // No directory part of the path name, or it's the current lib anyways
66 if (!pathLib.trim() || pathLib == libName) {
67 // Points to a known header file of this lib
68 if (libs[libName].headerFiles.indexOf(pathFile) != -1) {
69 return `#include <${libName}/${pathFile}>`;
70 }
71
72 // Private include in the source directory
73 if (libs[libName].privateHeaders.indexOf(pathFile) != -1) {
74 return `#include "${pathFile}"`;
75 }
76
77 if (pathLib == libName) {
78 console.error(`${filePath} is supposed to be in lib ${libName} but wasn't found?`);
79 return str;
80 }
81
82 // It's an include we don't know how to deal with, just ignore it
83 return str;
84 }
85
86 if (libs[pathLib] && libs[pathLib].headerFiles.indexOf(pathFile) != -1) {
87 return `#include <${pathLib}/${pathFile}>`;
88 }
89
90 return str;
91 });
92 fs.writeFileSync(file, newContents);
93}
94
95Object.keys(libs).forEach(libName => {
96 libs[libName].files.forEach(f => {

Callers 1

Calls 2

errorMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected