From 74e9748b431f7785f6021174cb08a28de5d98043 Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Sun, 15 Dec 2024 22:55:42 +0100 Subject: [PATCH] move to deno --- .dockerignore | 4 +- .vscode/settings.json | 3 + Dockerfile | 14 +-- bun.lockb | Bin 17201 -> 0 bytes deno.jsonc | 8 ++ deno.lock | 228 ++++++++++++++++++++++++++++++++++++++++++ package.json | 20 ---- src/api/gitea.ts | 8 +- src/api/github.ts | 6 +- src/config.ts | 4 +- src/core.ts | 12 ++- src/index.ts | 6 +- src/logger.ts | 2 +- tsconfig.json | 12 --- 14 files changed, 269 insertions(+), 58 deletions(-) create mode 100644 .vscode/settings.json delete mode 100755 bun.lockb create mode 100644 deno.jsonc create mode 100644 deno.lock delete mode 100644 package.json delete mode 100644 tsconfig.json diff --git a/.dockerignore b/.dockerignore index e3ef112..3509af5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ * -!package.json -!bun.lockb +!deno.jsonc +!deno.lock !src diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cbac569 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} diff --git a/Dockerfile b/Dockerfile index eda8b4c..75911ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM oven/bun:1 as base +FROM denoland/deno AS builder WORKDIR /app -FROM base as builder COPY . . -RUN bun install --production --frozen-lockfile -RUN bun build --target bun --minify src/index.ts --outfile app.js +RUN deno install --frozen +RUN deno compile --allow-net --allow-env --no-prompt --output /app/sync ./src/index.ts -FROM base -COPY --from=builder /app/app.js . -ENTRYPOINT [ "bun", "run", "app.js" ] +FROM debian:stable-slim +WORKDIR /app +COPY --from=builder /app/sync . +ENTRYPOINT [ "/app/sync" ] diff --git a/bun.lockb b/bun.lockb deleted file mode 100755 index 7005452bd8b6b57b1b33f9329cdf3c6c7f47fef0..0000000000000000000000000000000000000000 GIT binary patch literal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b( parse?: (value: string) => T, validator?: (s: string | T) => boolean ): T | string { - const value = process.env[key] + const value = Deno.env.get(key) const parsed = value === undefined ? fallback : parse ? parse(value) : value if (validator && !validator(parsed)) { console.error(`Invalid or missing value for ${key}: ${value}`) - process.exit(1) + Deno.exit(1) } return parsed } diff --git a/src/core.ts b/src/core.ts index 8e84463..619061f 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,7 +1,7 @@ -import { listAllRepositories as giteaRepos, mirror, MirrorOptions, updateRepository } from './api/gitea.js' -import { listAllRepositories as githubRepos } from './api/github.js' -import { Config } from './config.js' -import { logger } from './logger.js' +import { listAllRepositories as giteaRepos, mirror, MirrorOptions, updateRepository } from './api/gitea.ts' +import { listAllRepositories as githubRepos } from './api/github.ts' +import { Config } from './config.ts' +import { logger } from './logger.ts' let running = false @@ -27,6 +27,10 @@ export async function sync() { else { lr.info('visibility changed, updating') const [owner, repository] = sameName.full_name.split('/') + if (!owner || !repository) { + lr.error('invalid repository name', { full_name: sameName.full_name }) + continue + } await updateRepository(owner, repository, { private: repo.private }) } } else { diff --git a/src/index.ts b/src/index.ts index 20c8b46..4793f83 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ import cron from 'node-cron' -import { Config } from './config.js' -import { sync } from './core.js' -import { logger } from './logger.js' +import { Config } from './config.ts' +import { sync } from './core.ts' +import { logger } from './logger.ts' logger.info(`Mirror manager - ${Config.version}`, { version: Config.version }) diff --git a/src/logger.ts b/src/logger.ts index 5e4b3b2..f934842 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,6 +1,6 @@ import winston from 'winston' -import { Config } from './config.js' +import { Config } from './config.ts' export const logger = winston.createLogger({ level: Config.logging.level, diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 0d109f8..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, - "module": "ES2022" /* Specify what module code is generated. */, - "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, - "outDir": "./dist" /* Specify an output folder for all emitted files. */, - "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, - "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, - "strict": true /* Enable all strict type-checking options. */, - "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } -}