-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.ts
41 lines (34 loc) · 1.32 KB
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {load as loadYaml } from 'js-yaml';
import { GCPObjects, ProjectInfo } from './process_object';
const fs = require('fs');
import { resolve } from 'path';
const log4js = require("log4js");
log4js.configure({
appenders: { projectLogger: { type: "file", filename: "typescriptL.log" } },
categories: { default: { appenders: ["projectLogger"], level: "info" } },
});
export const logger = log4js.getLogger();
export function readYamlFileSync(filePath:String): any {
return loadYaml(fs.readFileSync(filePath,'utf-8'));
}
export function readDir(dirPath: string): ProjectInfo {
let projectInfo: ProjectInfo = {};
let gcpObjects: GCPObjects[] = [];
try {
logger.info("DirPath is : ", dirPath);
fs.readdirSync(dirPath).forEach((file: string) => {
const resolvedFilePath = resolve(dirPath, file);
logger.info(resolvedFilePath);
if(file.includes("project.yaml")){
projectInfo = (<ProjectInfo> readYamlFileSync(resolvedFilePath));
}else{
gcpObjects.push(<GCPObjects> readYamlFileSync(resolvedFilePath));
}
});
projectInfo.gcpObjects = gcpObjects;
logger.info("ProjectInfo: ",projectInfo);
} catch (error) {
logger.error(error);
}
return projectInfo;
}