2024-01-16 09:36:35 +00:00
|
|
|
import 'reflect-metadata';
|
|
|
|
import debug from 'debug';
|
2024-01-17 04:32:06 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
2024-01-30 14:20:53 +00:00
|
|
|
import { OAuthApp } from '@octokit/oauth-app';
|
|
|
|
|
2024-01-17 05:23:01 +00:00
|
|
|
import { Database } from './database';
|
2024-01-16 09:36:35 +00:00
|
|
|
import { createAndStartServer } from './server';
|
2024-01-17 04:32:06 +00:00
|
|
|
import { createResolvers } from './resolvers';
|
2024-01-16 09:36:35 +00:00
|
|
|
import { getConfig } from './utils';
|
2024-01-17 05:23:01 +00:00
|
|
|
import { Config } from './config';
|
2024-01-19 09:52:25 +00:00
|
|
|
import { DEFAULT_CONFIG_FILE_PATH } from './constants';
|
2024-02-02 09:32:12 +00:00
|
|
|
import { Service } from './service';
|
2024-02-12 06:04:01 +00:00
|
|
|
import { Registry } from './registry';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
|
|
|
const log = debug('snowball:server');
|
2024-02-12 06:04:01 +00:00
|
|
|
const OAUTH_CLIENT_TYPE = 'oauth-app';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
|
|
|
export const main = async (): Promise<void> => {
|
|
|
|
// TODO: get config path using cli
|
2024-02-15 11:54:57 +00:00
|
|
|
const { server, database, gitHub, registryConfig } = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
|
2024-01-17 05:23:01 +00:00
|
|
|
|
2024-01-30 14:20:53 +00:00
|
|
|
const app = new OAuthApp({
|
2024-02-12 06:04:01 +00:00
|
|
|
clientType: OAUTH_CLIENT_TYPE,
|
2024-02-15 11:54:57 +00:00
|
|
|
clientId: gitHub.oAuth.clientId,
|
|
|
|
clientSecret: gitHub.oAuth.clientSecret
|
2024-01-30 14:20:53 +00:00
|
|
|
});
|
|
|
|
|
2024-02-08 09:29:19 +00:00
|
|
|
const db = new Database(database);
|
|
|
|
await db.init();
|
2024-02-12 06:04:01 +00:00
|
|
|
|
|
|
|
const registry = new Registry(registryConfig);
|
2024-02-19 08:13:29 +00:00
|
|
|
const service = new Service({ gitHubConfig: gitHub, registryConfig }, db, app, registry);
|
2024-02-08 09:29:19 +00:00
|
|
|
|
2024-01-17 04:32:06 +00:00
|
|
|
const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString();
|
2024-02-08 09:29:19 +00:00
|
|
|
const resolvers = await createResolvers(service);
|
2024-01-17 05:23:01 +00:00
|
|
|
|
2024-02-15 11:54:57 +00:00
|
|
|
await createAndStartServer(server, typeDefs, resolvers, service);
|
2024-01-16 09:36:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
log('Starting server...');
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|