snowballtools-base/packages/backend/src/utils.ts

40 lines
1.0 KiB
TypeScript
Raw Normal View History

import fs from 'fs-extra';
import path from 'path';
import toml from 'toml';
import debug from 'debug';
import { Project } from './entity/Project';
const log = debug('snowball:utils');
export const getConfig = async <ConfigType>(
configFile: string
): Promise<ConfigType> => {
const configFilePath = path.resolve(configFile);
const fileExists = await fs.pathExists(configFilePath);
if (!fileExists) {
throw new Error(`Config file not found: ${configFilePath}`);
}
const config = toml.parse(await fs.readFile(configFilePath, 'utf8'));
log('config', JSON.stringify(config, null, 2));
return config;
};
export const projectToGqlType = (dbProject: Project): any => {
return {
id: dbProject.id,
owner: dbProject.owner,
name: dbProject.name,
repository: dbProject.repository,
prodBranch: dbProject.prodBranch,
description: dbProject.description,
template: dbProject.template,
framework: dbProject.framework,
webhooks: dbProject.webhooks,
createdAt: dbProject.createdAt,
updatedAt: dbProject.updatedAt
};
};