@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
36 lines • 1.55 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeWikiTo = writeWikiTo;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
/* eslint-disable */
const IgnoreRegex = /[0-9]+(\.[0-9]+)? ?ms|"timing":\s*[0-9]+(\.0-9)?,?|tmp-[A-Za-z0-9-]+/g;
/* eslint-enable */
/**
* Checks whether the file contains a different content, but ignores timing and some other non-semantic changes.
*/
function didFileChange(filePath, content) {
if (!fs_1.default.existsSync(filePath)) {
return true; // If the file does not exist, it is considered changed.
}
const currentContent = fs_1.default.readFileSync(filePath, 'utf-8');
const cleanedCurrentContent = currentContent.replace(IgnoreRegex, '');
const cleanedNewContent = content.replace(IgnoreRegex, '');
return cleanedCurrentContent !== cleanedNewContent;
}
/**
* Writes the wiki documentation to the specified output path.
* Returns true if the file was updated, false if it was unchanged.
*/
function writeWikiTo(text, output_path, check_change = true) {
if (!check_change || didFileChange(output_path, text)) {
fs_1.default.mkdirSync(path_1.default.dirname(output_path), { recursive: true });
fs_1.default.writeFileSync(output_path, text, 'utf-8');
return true;
}
return false;
}
//# sourceMappingURL=doc-print.js.map