UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

52 lines 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrAnalyzerDescriptionFilePlugin = exports.DescriptionFile = exports.descriptionFileLog = void 0; const flowr_analyzer_file_plugin_1 = require("./flowr-analyzer-file-plugin"); const semver_1 = require("semver"); const log_1 = require("../../../util/log"); const flowr_description_file_1 = require("./files/flowr-description-file"); const flowr_file_1 = require("../../context/flowr-file"); const built_in_source_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-source"); exports.descriptionFileLog = log_1.log.getSubLogger({ name: 'flowr-analyzer-loading-order-description-file-plugin' }); const DescriptionFilePattern = /^DESCRIPTION(\.(txt|in))?$/i; /** Access to the `DESCRIPTION` file of the analyzed project. */ exports.DescriptionFile = { name: 'DescriptionFile', /** The project's only `DESCRIPTION` file, `undefined` if there is none; `missing` states what cannot be done then. */ single(ctx, missing) { const descFiles = ctx.files.getFilesByRole(flowr_file_1.FileRole.Description); if (descFiles.length === 0) { exports.descriptionFileLog.debug(missing); return undefined; } else if (descFiles.length > 1) { exports.descriptionFileLog.warn(`Found ${descFiles.length} description files, expected exactly one.`); } return descFiles[0]; } }; /** * This plugin provides support for R `DESCRIPTION` files. */ class FlowrAnalyzerDescriptionFilePlugin extends flowr_analyzer_file_plugin_1.FlowrAnalyzerFilePlugin { name = 'flowr-analyzer-description-file-plugin'; description = 'Reads DESCRIPTION files into key-value pairs.'; version = new semver_1.SemVer('0.1.0'); pattern; /** * Creates a new instance of the DESCRIPTION file plugin. * @param filePattern - The pattern to identify DESCRIPTION files, see {@link DescriptionFilePattern} for the default pattern. */ constructor(filePattern = DescriptionFilePattern) { super(); this.pattern = filePattern; } applies(file) { return this.pattern.test((0, built_in_source_1.platformBasename)(file.toString())); } process(_ctx, file) { return flowr_description_file_1.FlowrDescriptionFile.from(file, flowr_file_1.FileRole.Description); } } exports.FlowrAnalyzerDescriptionFilePlugin = FlowrAnalyzerDescriptionFilePlugin; //# sourceMappingURL=flowr-analyzer-description-file-plugin.js.map