93 lines
3.8 KiB
JavaScript
93 lines
3.8 KiB
JavaScript
|
"use strict";
|
||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
// Licensed under the MIT license.
|
||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.prettier = exports.lintFix = exports.lint = void 0;
|
||
|
const office_addin_usage_data_1 = require("office-addin-usage-data");
|
||
|
const defaults = require("./defaults");
|
||
|
const lint_1 = require("./lint");
|
||
|
const defaults_1 = require("./defaults");
|
||
|
/* global process */
|
||
|
/**
|
||
|
* Determines path to files to run lint against. Priority order follows:
|
||
|
* 1 --files option passed through cli
|
||
|
* 2 lint_files config property in package.json
|
||
|
* 3 default location
|
||
|
* @param command command options which can contain files
|
||
|
*/
|
||
|
function getPathToFiles(command) {
|
||
|
const pathToFiles = command.files ? command.files : process.env.npm_package_config_lint_files;
|
||
|
return pathToFiles ? pathToFiles : defaults.lintFiles;
|
||
|
}
|
||
|
function lint(command) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
const pathToFiles = getPathToFiles(command);
|
||
|
const useTestConfig = command.test;
|
||
|
yield (0, lint_1.performLintCheck)(pathToFiles, useTestConfig);
|
||
|
defaults_1.usageDataObject.reportSuccess("lint");
|
||
|
}
|
||
|
catch (err) {
|
||
|
if (typeof err.status == "number") {
|
||
|
process.exitCode = err.status;
|
||
|
}
|
||
|
else {
|
||
|
process.exitCode = defaults.ESLintExitCode.CommandFailed;
|
||
|
defaults_1.usageDataObject.reportException("lint", err);
|
||
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
exports.lint = lint;
|
||
|
function lintFix(command) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
const pathToFiles = getPathToFiles(command);
|
||
|
const useTestConfig = command.test;
|
||
|
yield (0, lint_1.performLintFix)(pathToFiles, useTestConfig);
|
||
|
defaults_1.usageDataObject.reportSuccess("lintFix");
|
||
|
}
|
||
|
catch (err) {
|
||
|
if (typeof err.status == "number") {
|
||
|
process.exitCode = err.status;
|
||
|
}
|
||
|
else {
|
||
|
process.exitCode = defaults.ESLintExitCode.CommandFailed;
|
||
|
defaults_1.usageDataObject.reportException("lintFix", err);
|
||
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
exports.lintFix = lintFix;
|
||
|
function prettier(command) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
const pathToFiles = getPathToFiles(command);
|
||
|
yield (0, lint_1.makeFilesPrettier)(pathToFiles);
|
||
|
defaults_1.usageDataObject.reportSuccess("prettier");
|
||
|
}
|
||
|
catch (err) {
|
||
|
if (typeof err.status == "number") {
|
||
|
process.exitCode = err.status;
|
||
|
}
|
||
|
else {
|
||
|
process.exitCode = defaults.PrettierExitCode.CommandFailed;
|
||
|
defaults_1.usageDataObject.reportException("prettier", err);
|
||
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
exports.prettier = prettier;
|
||
|
//# sourceMappingURL=commands.js.map
|