@ts-common/azure-js-dev-tools
Version:
Developer dependencies for TypeScript related projects
71 lines • 3.21 kB
JavaScript
;
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkFileContainsCheck = exports.checkFileContains = void 0;
var tslib_1 = require("tslib");
var fileSystem2_1 = require("./fileSystem2");
var logger_1 = require("./logger");
var path_1 = require("./path");
/**
* Create an AdditionalCheck that verifies that the file at the provided path contains the provided
* text.
* @param filePath The path to the file to check.
* @param textToFind The text to find in the file.
*/
function checkFileContains(filePath, textToFind, options) {
if (options === void 0) { options = {}; }
return {
name: filePath + " contains \"" + textToFind + "\"",
check: function () { return checkFileContainsCheck(filePath, textToFind, options); },
};
}
exports.checkFileContains = checkFileContains;
/**
* Check the source files found under the provided startPaths for only() function calls. Returns the
* number of source files found that reference the only() function.
* @param startPaths The paths to start looking for source files in.
* @param logger The logger to use. If no logger is specified, then a console logger will be used.
* @returns The number of source files found that contain only() function calls.
*/
function checkFileContainsCheck(filePath, textToFind, options) {
if (options === void 0) { options = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var rootedFilePath, logger, exitCode, fileContents;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
rootedFilePath = path_1.isRooted(filePath) ? filePath : path_1.resolvePath(filePath);
logger = options.logger || logger_1.getDefaultLogger();
exitCode = 0;
return [4 /*yield*/, fileSystem2_1.readFileContents(rootedFilePath)];
case 1:
fileContents = _a.sent();
if (!(fileContents == undefined)) return [3 /*break*/, 3];
return [4 /*yield*/, logger.logError(" The file " + filePath + " should exist.")];
case 2:
_a.sent();
exitCode = 1;
return [3 /*break*/, 6];
case 3:
if (!!fileContents.includes(textToFind)) return [3 /*break*/, 5];
return [4 /*yield*/, logger.logError(" The file " + filePath + " should contain \"" + textToFind + "\".")];
case 4:
_a.sent();
exitCode = 1;
return [3 /*break*/, 6];
case 5:
exitCode = 0;
_a.label = 6;
case 6:
process.exitCode = exitCode;
return [2 /*return*/, exitCode];
}
});
});
}
exports.checkFileContainsCheck = checkFileContainsCheck;
//# sourceMappingURL=checkFileContains.js.map