import * as commander from "commander" ; import { logErrorMessage } from "office-addin-cli" ; import * as defaults from "./defaults" ; import { makeFilesPrettier , performLintCheck , performLintFix } from "./lint" ; import { usageDataObject } from "./defaults" ; param command function getPathToFiles ( command ) { const pathToFiles = command . files ? command . files : process . env . npm_package_config_lint_files ; return pathToFiles ? pathToFiles : defaults . lintFiles ; } export async function lint ( command ) { try { const pathToFiles = getPathToFiles ( command ) ; const useTestConfig = command . test ; await performLintCheck ( pathToFiles , useTestConfig ) ; usageDataObject . reportSuccess ( "lint" ) ; } catch ( err ) { if ( typeof err . status == "number" ) { process . exitCode = err . status ; } else { process . exitCode = defaults . ESLintExitCode . CommandFailed ; usageDataObject . reportException ( "lint" , err ) ; logErrorMessage ( err ) ; } } } export async function lintFix ( command ) { try { const pathToFiles = getPathToFiles ( command ) ; const useTestConfig = command . test ; await performLintFix ( pathToFiles , useTestConfig ) ; usageDataObject . reportSuccess ( "lintFix" ) ; } catch ( err ) { if ( typeof err . status == "number" ) { process . exitCode = err . status ; } else { process . exitCode = defaults . ESLintExitCode . CommandFailed ; usageDataObject . reportException ( "lintFix" , err ) ; logErrorMessage ( err ) ; } } } export async function prettier ( command ) { try { const pathToFiles = getPathToFiles ( command ) ; await makeFilesPrettier ( pathToFiles ) ; usageDataObject . reportSuccess ( "prettier" ) ; } catch ( err ) { if ( typeof err . status == "number" ) { process . exitCode = err . status ; } else { process . exitCode = defaults . PrettierExitCode . CommandFailed ; usageDataObject . reportException ( "prettier" , err ) ; logErrorMessage ( err ) ; } } }