Skip to content

Commit

Permalink
expose config as env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mkitzmann committed Jan 8, 2024
1 parent 34b6b2e commit 4e3f7a1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 19 deletions.
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/components/CommitGraph.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { CommitCount } from '../lib/types/types';
import { config } from '../config';
import { appConfig } from '../lib/createConfig';
export let commits: CommitCount;
export let id: string;
Expand All @@ -11,8 +11,8 @@
$: totalCommits = commits ? Object.values(commits).reduce((prev, current) => prev + current) : 0;
$: topColor = totalCommits < config.lowCommitCount ? '#944' : '#216e39';
$: bottomColor = totalCommits < config.lowCommitCount ? '#faa' : '#9be9a8';
$: topColor = totalCommits < appConfig.lowCommitCount ? '#944' : '#216e39';
$: bottomColor = totalCommits < appConfig.lowCommitCount ? '#faa' : '#9be9a8';
</script>

<svg viewBox="0 0 110 20" xmlns="http://www.w3.org/2000/svg">
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProjectItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -106,13 +106,13 @@
<div class="-mb-3">
<span
class="font-bold text-lg text-green-600"
class:text-red-600={totalCommits < config.lowCommitCount}
class:text-red-600={totalCommits < appConfig.lowCommitCount}
>
{numeral(totalCommits).format('0,0a')}
</span>
<span
class="text-xs font-light text-green-600"
class:text-red-600={totalCommits < config.lowCommitCount}
class:text-red-600={totalCommits < appConfig.lowCommitCount}
>
commits past year
</span>
Expand Down
11 changes: 11 additions & 0 deletions src/lib/createConfig.ts
Original file line number Diff line number Diff line change
@@ -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
};
12 changes: 6 additions & 6 deletions src/lib/fetch-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ 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);
const start = performance.now();
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;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { config } from '../config';
import { appConfig } from '../lib/createConfig';

interface MonthInfo {
name: string;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/repositories.ts
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down Expand Up @@ -140,7 +140,7 @@ async function combineSources(urls: string[]): Promise<string> {

export async function getProjectsFromAwesomeList(): Promise<Project[]> {
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(
Expand All @@ -150,7 +150,7 @@ export async function getProjectsFromAwesomeList(): Promise<Project[]> {
}

export async function getAllCategories(): Promise<AllCategories> {
const markdown = await combineSources(config.urls);
const markdown = await combineSources(appConfig.urls);
const { categories } = extractRepositories(markdown);
return categories;
}

0 comments on commit 4e3f7a1

Please sign in to comment.