mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
feat: improved configuration (#31)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import 'source-map-support/register.js';
|
||||
import '../dist/esm/index.js';
|
||||
import '../dist/esm/src/index.js';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@morten-olsen/mini-loader-cli",
|
||||
"version": "1.0.0",
|
||||
"main": "./dist/esm/index.js",
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"main": "./dist/esm/src/index.js",
|
||||
"types": "./dist/esm/src/index.d.ts",
|
||||
"license": "GPL-3.0",
|
||||
"bin": {
|
||||
"mini-loader": "./bin/index.mjs"
|
||||
@@ -16,11 +16,12 @@
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/index.js"
|
||||
"import": "./dist/esm/src/index.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@morten-olsen/mini-loader-runner": "workspace:^",
|
||||
"@morten-olsen/mini-loader-server": "workspace:^",
|
||||
"@rollup/plugin-auto-install": "^3.0.5",
|
||||
"@rollup/plugin-commonjs": "^25.0.7",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
@@ -40,7 +41,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@morten-olsen/mini-loader-configs": "workspace:^",
|
||||
"@morten-olsen/mini-loader-server": "workspace:^",
|
||||
"@types/inquirer": "^9.0.7",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import 'source-map-support/register.js';
|
||||
import '../dist/esm/index.js';
|
||||
import '../dist/esm/src/index.js';
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"name": "@morten-olsen/mini-loader-server",
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0",
|
||||
"main": "./dist/esm/index.js",
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"main": "./dist/esm/src/index.js",
|
||||
"types": "./dist/esm/src/index.d.ts",
|
||||
"bin": {
|
||||
"mini-loader-server": "./bin/index.mjs"
|
||||
},
|
||||
@@ -16,7 +16,7 @@
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/index.js"
|
||||
"import": "./dist/esm/src/index.js"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -32,6 +32,7 @@
|
||||
"@trpc/server": "^10.45.0",
|
||||
"commander": "^11.1.0",
|
||||
"cron": "^3.1.6",
|
||||
"env-paths": "^3.0.0",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"fastify": "^4.25.2",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
|
||||
@@ -20,10 +20,10 @@ class Auth {
|
||||
|
||||
#setup = async () => {
|
||||
const { config } = this.#options;
|
||||
const secretLocation = resolve(config.files.location, 'secret');
|
||||
const secretLocation = resolve(config.files.data, 'secret');
|
||||
let secret = '';
|
||||
await mkdir(config.files.data, { recursive: true });
|
||||
if (!existsSync(secretLocation)) {
|
||||
await mkdir(config.files.location, { recursive: true });
|
||||
secret = nanoid();
|
||||
await writeFile(secretLocation, secret);
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,8 @@ import { Knex } from 'knex';
|
||||
type Config = {
|
||||
database: Omit<Knex.Config, 'migrations'>;
|
||||
files: {
|
||||
location: string;
|
||||
data: string;
|
||||
cache: string;
|
||||
};
|
||||
auth?: {
|
||||
oidc?: {
|
||||
|
||||
@@ -62,7 +62,7 @@ class LoadRepo extends EventEmitter<LoadRepoEvents> {
|
||||
const db = await database.instance;
|
||||
const id = options.id || nanoid();
|
||||
const script = createHash('sha256').update(options.script).digest('hex');
|
||||
const scriptDir = resolve(this.#options.config.files.location, 'scripts');
|
||||
const scriptDir = resolve(this.#options.config.files.data, 'scripts');
|
||||
await mkdir(scriptDir, { recursive: true });
|
||||
await writeFile(resolve(scriptDir, `${script}.js`), options.script);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class RunnerInstance extends EventEmitter<RunnerInstanceEvents> {
|
||||
const { runs, secrets } = repos;
|
||||
try {
|
||||
const { script: scriptHash, input } = await runs.getById(id);
|
||||
const scriptLocation = resolve(config.files.location, 'scripts', `${scriptHash}.js`);
|
||||
const scriptLocation = resolve(config.files.data, 'scripts', `${scriptHash}.js`);
|
||||
const script = await readFile(scriptLocation, 'utf-8');
|
||||
const allSecrets = await secrets.getAll();
|
||||
await runs.started(id);
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { resolve } from 'path';
|
||||
import envPaths from 'env-paths';
|
||||
import { Database } from '../database/database.js';
|
||||
import { Repos } from '../repos/repos.js';
|
||||
import { Runner } from '../runner/runner.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import { Auth } from '../auth/auth.js';
|
||||
import { resolve } from 'path';
|
||||
import { Scheduler } from '../scheduler/scheduler.js';
|
||||
|
||||
const paths = envPaths('mini-loader-server');
|
||||
|
||||
class Runtime {
|
||||
#repos: Repos;
|
||||
#runner: Runner;
|
||||
@@ -41,12 +44,13 @@ class Runtime {
|
||||
database: {
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: resolve(process.cwd(), 'data', 'database.sqlite'),
|
||||
filename: resolve(paths.data, 'database.sqlite'),
|
||||
},
|
||||
useNullAsDefault: true,
|
||||
},
|
||||
files: {
|
||||
location: resolve(process.cwd(), 'data', 'files'),
|
||||
data: process.env.DATA_DIR || resolve(paths.data, 'data', 'files'),
|
||||
cache: process.env.CACHE_DIR || resolve(paths.cache, 'data', 'cache'),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import pkg from '../../package.json';
|
||||
import { fastifyTRPCPlugin, FastifyTRPCPluginOptions } from '@trpc/server/adapters/fastify';
|
||||
import fastify from 'fastify';
|
||||
import { RootRouter, rootRouter } from '../router/router.js';
|
||||
@@ -13,9 +14,6 @@ const createServer = async (runtime: Runtime) => {
|
||||
level: 'warn',
|
||||
},
|
||||
});
|
||||
server.get('/', async () => {
|
||||
return { hello: 'world' };
|
||||
});
|
||||
|
||||
server.get('/health', async (req) => {
|
||||
let authorized = false;
|
||||
@@ -27,7 +25,7 @@ const createServer = async (runtime: Runtime) => {
|
||||
authorized = true;
|
||||
}
|
||||
} catch (error) {}
|
||||
return { authorized, status: 'ok' };
|
||||
return { authorized, status: 'ok', version: pkg.version };
|
||||
});
|
||||
|
||||
server.register(fastifyTRPCPlugin, {
|
||||
|
||||
Reference in New Issue
Block a user