cpp-merge
Version:
Command line tool to produce single source file from multiple C/C++ files
35 lines • 1.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.readFile = exports.findFile = void 0;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const errors_1 = require("./errors");
/**
* Searches for file in specified directories.
* @param fileName - Name of searched file.
* @param searchDirectories - List of directories where file will be searched for.
* @return Full path to the found file or `undefined` if file was not found in any of search directories.
*/
function findFile(fileName, searchDirectories) {
for (const searchDirectory of searchDirectories) {
const searchFilePath = path_1.default.resolve(searchDirectory, fileName);
if (fs_1.default.existsSync(searchFilePath)) {
return searchFilePath;
}
}
}
exports.findFile = findFile;
function readFile(filePath) {
try {
return fs_1.default.readFileSync(filePath, "utf-8");
}
catch (error) {
const cause = error instanceof Error ? error : undefined;
throw new errors_1.FileReadError(`Error reading file '${filePath}'`, filePath, cause);
}
}
exports.readFile = readFile;
//# sourceMappingURL=utils.js.map