From 4e3f7a14b311e759194df55518a98bfa0d0c0f96 Mon Sep 17 00:00:00 2001 From: mkitzmann Date: Mon, 8 Jan 2024 21:29:29 +0100 Subject: [PATCH] expose config as env variables --- docker-compose.yml | 4 ++++ package.json | 4 ++-- src/components/CommitGraph.svelte | 6 +++--- src/components/ProjectItem.svelte | 6 +++--- src/lib/createConfig.ts | 11 +++++++++++ src/lib/fetch-github.ts | 12 ++++++------ src/lib/query.ts | 4 ++-- src/lib/repositories.ts | 6 +++--- 8 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 src/lib/createConfig.ts diff --git a/docker-compose.yml b/docker-compose.yml index 642386e..3d2c98b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,10 @@ services: image: mkitzmann/awwesome:latest container_name: awwesome restart: no + environment: + - REQUEST_DELAY=0 + - CHUNK_SIZE=20 + - LOW_COMMIT_COUNT=2 env_file: - .env working_dir: /usr/src/app diff --git a/package.json b/package.json index d5ce24d..7a979e9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "awwesome", "description": "Enhanced user interface for Awesome Selfhosted", - "version": "0.7.8", + "version": "0.7.9", "private": true, "scripts": { "dev": "vite dev", @@ -12,7 +12,7 @@ "test": "vitest", "lint": "eslint src/", "format": "prettier --plugin-search-dir . --write .", - "docker:build": "docker buildx build --push --platform linux/amd64,linux/arm64 --tag mkitzmann/awwesome:latest --tag mkitzmann/awwesome:0.7.8 ." + "docker:build": "docker buildx build --push --platform linux/amd64,linux/arm64 --tag mkitzmann/awwesome:latest --tag mkitzmann/awwesome:0.7.9 ." }, "devDependencies": { "@dimfeld/svelte-lazyload": "^0.0.4", diff --git a/src/components/CommitGraph.svelte b/src/components/CommitGraph.svelte index fa790aa..23e606f 100644 --- a/src/components/CommitGraph.svelte +++ b/src/components/CommitGraph.svelte @@ -1,6 +1,6 @@ diff --git a/src/components/ProjectItem.svelte b/src/components/ProjectItem.svelte index 852b35b..f15b565 100644 --- a/src/components/ProjectItem.svelte +++ b/src/components/ProjectItem.svelte @@ -6,7 +6,7 @@ import CommitGraph from './CommitGraph.svelte'; import { categoryStore } from '../stores/stores'; import type { Project } from '../lib/types/types'; - import { config } from '../config.js'; + import { appConfig } from '../lib/createConfig'; dayjs.extend(relativeTime); const getRelativeTime = (date: Date) => dayjs(date).fromNow(); @@ -106,13 +106,13 @@
{numeral(totalCommits).format('0,0a')} commits past year diff --git a/src/lib/createConfig.ts b/src/lib/createConfig.ts new file mode 100644 index 0000000..7b044a5 --- /dev/null +++ b/src/lib/createConfig.ts @@ -0,0 +1,11 @@ +import type { Config } from '../types'; +import { config } from '../config'; + +export const appConfig: Config = { + requestDelay: process.env.REQUEST_DELAY ? Number(process.env.REQUEST_DELAY) : config.requestDelay, + urls: config.urls, + lowCommitCount: process.env.LOW_COMMIT_COUNT + ? Number(process.env.LOW_COMMIT_COUNT) + : config.lowCommitCount, + chunkSize: process.env.CHUNK_SIZE ? Number(process.env.CHUNK_SIZE) : config.chunkSize +}; diff --git a/src/lib/fetch-github.ts b/src/lib/fetch-github.ts index 9bf4bdc..d09692a 100644 --- a/src/lib/fetch-github.ts +++ b/src/lib/fetch-github.ts @@ -2,7 +2,7 @@ import type { GithubQueryResult, GithubRepo, Project } from './types/types'; import { TOKEN_GITHUB } from '$env/static/private'; import { delay, extractGithubRepoUrls } from './index'; import { createQuery } from './query'; -import { config } from '../config'; +import { appConfig } from './createConfig'; export async function fetchAllGithubRepositories(allProjects: Project[]) { const githubRepoUrls = extractGithubRepoUrls(allProjects); @@ -10,15 +10,15 @@ export async function fetchAllGithubRepositories(allProjects: Project[]) { const urls = [...githubRepoUrls]; let data: GithubRepo[] = []; - for (let i = 0; i < urls.length; i += config.chunkSize) { - const chunk = urls.slice(i, i + config.chunkSize); + for (let i = 0; i < urls.length; i += appConfig.chunkSize) { + const chunk = urls.slice(i, i + appConfig.chunkSize); const query = await createQuery(chunk); const result = await fetchRepoInfoFromGithub(query); data = data.concat(result); - if (config.requestDelay > 0) { - await delay(config.requestDelay); - console.log('delay:', config.requestDelay); + if (appConfig.requestDelay > 0) { + await delay(appConfig.requestDelay); + console.log('delay:', appConfig.requestDelay); } // if (import.meta.env.DEV) { // break; diff --git a/src/lib/query.ts b/src/lib/query.ts index 3712f4c..706b175 100644 --- a/src/lib/query.ts +++ b/src/lib/query.ts @@ -1,4 +1,4 @@ -import { config } from '../config'; +import { appConfig } from '../lib/createConfig'; interface MonthInfo { name: string; @@ -41,7 +41,7 @@ export async function createQuery(urls: string[]) { search( type:REPOSITORY, query: "${searchString}", - first: ${config.chunkSize + 10} + first: ${appConfig.chunkSize + 10} ) { repos: edges { repo: node { diff --git a/src/lib/repositories.ts b/src/lib/repositories.ts index cde4db1..cd6aff7 100644 --- a/src/lib/repositories.ts +++ b/src/lib/repositories.ts @@ -1,7 +1,7 @@ import type { AllCategories, Category, Project } from './types/types'; import slugify from '@sindresorhus/slugify'; import { removeTrailingSlashes } from './index'; -import { config } from '../config'; +import { appConfig } from '../lib/createConfig'; export interface ProjectsAndCategories { projects: Project[]; @@ -140,7 +140,7 @@ async function combineSources(urls: string[]): Promise { export async function getProjectsFromAwesomeList(): Promise { const start = performance.now(); - const markdown = await combineSources(config.urls); + const markdown = await combineSources(appConfig.urls); const { projects } = extractRepositories(markdown); const end = performance.now(); console.log( @@ -150,7 +150,7 @@ export async function getProjectsFromAwesomeList(): Promise { } export async function getAllCategories(): Promise { - const markdown = await combineSources(config.urls); + const markdown = await combineSources(appConfig.urls); const { categories } = extractRepositories(markdown); return categories; }