@dxdeveloperexperience/hygie
Version:
Hygie is an easy-to-use Open-Source REST API allowing you to interact with GIT events. This NestJS API expose a set of customizable rules to automate your project's life cycle.
45 lines (41 loc) • 1.11 kB
text/typescript
import { existsSync } from 'fs-extra';
import { logger } from '../logger/logger.service';
import { HttpService } from '@nestjs/common';
export class Check {
/**
* Check if the given file exit.
* If not, a _warn_ message is logged.
* @param filename
* Relative path
*/
static checkIfFileExist(filename: string): boolean {
if (!existsSync(filename)) {
logger.error(
`${filename} do not exist! Please refer to the documentation: https://zenika-open-source.github.io/hygie/`,
);
return false;
}
return true;
}
/**
* Check if the given needed files exist.
* @param filenames
* Array of relative paths
*/
static checkNeededFiles(filenames: string[]): boolean {
let allFilesOk: boolean = true;
filenames.forEach(f => {
if (!this.checkIfFileExist(f)) {
allFilesOk = false;
}
});
return allFilesOk;
}
static async checkInternet(httpService: HttpService): Promise<boolean> {
return httpService
.get('https://google.com')
.toPromise()
.then(() => true)
.catch(() => false);
}
}