Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const logger = winston.createLogger({
align(),
printf(
(info: any) =>
`[${info.timestamp}] ${info.level}: ${info.message}
${info.stack || ''}`
`[${info.timestamp}] ${info.stack || `${info.level}: ${info.message}`}
`
)
),
transports: [new winston.transports.Console()],
Expand Down
23 changes: 17 additions & 6 deletions src/common/util/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,36 @@ import * as fs from 'fs/promises';
import * as path from 'path';

import * as YAML from 'js-yaml';
import {ERRORS} from '@grnsft/if-core/utils';

const {ReadFileError, WriteFileError} = ERRORS;

/**
* Reads and parses `yaml` file to object.
*/
export const openYamlFileAsObject = async <T>(filePath: string): Promise<T> => {
const yamlFileBuffer = await fs.readFile(filePath, 'utf8');
try {
const yamlFileBuffer = await fs.readFile(filePath, 'utf8');

return YAML.load(yamlFileBuffer) as T;
return YAML.load(yamlFileBuffer) as T;
} catch (error: any) {
throw new ReadFileError(error.message);
}
};

/**
* Saves given `yaml` dump as a file.
*/
export const saveYamlFileAs = async (object: any, pathToFile: string) => {
const dirPath = path.dirname(pathToFile);
await fs.mkdir(dirPath, {recursive: true});
const yamlString = YAML.dump(object, {noRefs: true});
try {
const dirPath = path.dirname(pathToFile);
await fs.mkdir(dirPath, {recursive: true});
const yamlString = YAML.dump(object, {noRefs: true});

return fs.writeFile(pathToFile, yamlString);
return fs.writeFile(pathToFile, yamlString);
} catch (error: any) {
throw new WriteFileError(error.message);
}
};

/**
Expand Down