UNPKG

@ts-common/azure-js-dev-tools

Version:

Developer dependencies for TypeScript related projects

159 lines 7.77 kB
"use strict"; /** * 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.checkForUnstagedChangesCheck = exports.checkForUnstagedChanges = void 0; var tslib_1 = require("tslib"); var logger_1 = require("./logger"); var git_1 = require("./git"); function checkForUnstagedChanges(options) { if (options === void 0) { options = {}; } return { name: "No unstaged changes", check: function () { return checkForUnstagedChangesCheck(options); }, }; } exports.checkForUnstagedChanges = checkForUnstagedChanges; /** * 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 checkForUnstagedChangesCheck(options) { if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var logger, exitCode, git, gitStatusResult, notStagedDeletedFileCount, notStagedModifiedFileCount, untrackedFileCount, _a, _b, notStagedDeletedFilePath, e_1_1, _c, _d, notStagedModifiedFilePath, e_2_1, _e, _f, untrackedFilePath, e_3_1; var e_1, _g, e_2, _h, e_3, _j; return tslib_1.__generator(this, function (_k) { switch (_k.label) { case 0: logger = options.logger || logger_1.getDefaultLogger(); exitCode = 0; if (!(options.enable === false)) return [3 /*break*/, 2]; return [4 /*yield*/, logger.logWarning("Check is disabled. Allowing unstaged changes if they exist.")]; case 1: _k.sent(); return [3 /*break*/, 33]; case 2: return [4 /*yield*/, logger.logSection("Looking for unstaged changes...")]; case 3: _k.sent(); git = new git_1.ExecutableGit(); return [4 /*yield*/, git.status()]; case 4: gitStatusResult = _k.sent(); notStagedDeletedFileCount = gitStatusResult.notStagedDeletedFiles.length; notStagedModifiedFileCount = gitStatusResult.notStagedModifiedFiles.length; untrackedFileCount = gitStatusResult.untrackedFiles.length; exitCode = notStagedDeletedFileCount + notStagedModifiedFileCount + untrackedFileCount; if (!(exitCode === 0)) return [3 /*break*/, 6]; return [4 /*yield*/, logger.logInfo(" No unstaged changes found.")]; case 5: _k.sent(); return [3 /*break*/, 33]; case 6: if (!(notStagedDeletedFileCount !== 0)) return [3 /*break*/, 15]; return [4 /*yield*/, logger.logInfo(" Found " + notStagedDeletedFileCount + " not staged deleted file" + (notStagedDeletedFileCount === 1 ? "" : "s") + ":")]; case 7: _k.sent(); _k.label = 8; case 8: _k.trys.push([8, 13, 14, 15]); _a = tslib_1.__values(gitStatusResult.notStagedDeletedFiles), _b = _a.next(); _k.label = 9; case 9: if (!!_b.done) return [3 /*break*/, 12]; notStagedDeletedFilePath = _b.value; return [4 /*yield*/, logger.logInfo(" " + notStagedDeletedFilePath)]; case 10: _k.sent(); _k.label = 11; case 11: _b = _a.next(); return [3 /*break*/, 9]; case 12: return [3 /*break*/, 15]; case 13: e_1_1 = _k.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 15]; case 14: try { if (_b && !_b.done && (_g = _a.return)) _g.call(_a); } finally { if (e_1) throw e_1.error; } return [7 /*endfinally*/]; case 15: if (!(notStagedModifiedFileCount !== 0)) return [3 /*break*/, 24]; return [4 /*yield*/, logger.logInfo(" Found " + notStagedModifiedFileCount + " not staged modified file" + (notStagedModifiedFileCount === 1 ? "" : "s") + ":")]; case 16: _k.sent(); _k.label = 17; case 17: _k.trys.push([17, 22, 23, 24]); _c = tslib_1.__values(gitStatusResult.notStagedModifiedFiles), _d = _c.next(); _k.label = 18; case 18: if (!!_d.done) return [3 /*break*/, 21]; notStagedModifiedFilePath = _d.value; return [4 /*yield*/, logger.logInfo(" " + notStagedModifiedFilePath)]; case 19: _k.sent(); _k.label = 20; case 20: _d = _c.next(); return [3 /*break*/, 18]; case 21: return [3 /*break*/, 24]; case 22: e_2_1 = _k.sent(); e_2 = { error: e_2_1 }; return [3 /*break*/, 24]; case 23: try { if (_d && !_d.done && (_h = _c.return)) _h.call(_c); } finally { if (e_2) throw e_2.error; } return [7 /*endfinally*/]; case 24: if (!(untrackedFileCount !== 0)) return [3 /*break*/, 33]; return [4 /*yield*/, logger.logInfo(" Found " + untrackedFileCount + " untracked file" + (untrackedFileCount === 1 ? "" : "s") + ":")]; case 25: _k.sent(); _k.label = 26; case 26: _k.trys.push([26, 31, 32, 33]); _e = tslib_1.__values(gitStatusResult.untrackedFiles), _f = _e.next(); _k.label = 27; case 27: if (!!_f.done) return [3 /*break*/, 30]; untrackedFilePath = _f.value; return [4 /*yield*/, logger.logInfo(" " + untrackedFilePath)]; case 28: _k.sent(); _k.label = 29; case 29: _f = _e.next(); return [3 /*break*/, 27]; case 30: return [3 /*break*/, 33]; case 31: e_3_1 = _k.sent(); e_3 = { error: e_3_1 }; return [3 /*break*/, 33]; case 32: try { if (_f && !_f.done && (_j = _e.return)) _j.call(_e); } finally { if (e_3) throw e_3.error; } return [7 /*endfinally*/]; case 33: process.exitCode = exitCode; return [2 /*return*/, exitCode]; } }); }); } exports.checkForUnstagedChangesCheck = checkForUnstagedChangesCheck; //# sourceMappingURL=checkForUnstagedChanges.js.map