forked from KaKi87/dynapt
60 lines
No EOL
2.3 KiB
JavaScript
60 lines
No EOL
2.3 KiB
JavaScript
import { join as joinPath } from 'https://deno.land/std@0.224.0/path/mod.ts';
|
|
import Joi from 'npm:joi@^17';
|
|
|
|
import dirname from '../dirname.js';
|
|
import Loxer from '../lib/loxer.js';
|
|
|
|
const configPath = joinPath(dirname, './config.json');
|
|
|
|
export const getConfig = async () => {
|
|
let configText, isChanged;
|
|
try {
|
|
configText = await Deno.readTextFile(configPath);
|
|
}
|
|
catch {
|
|
Loxer.log('Not configured');
|
|
Deno.exit(1);
|
|
}
|
|
const config = await Promise
|
|
.resolve(configText)
|
|
.then(JSON.parse)
|
|
.then(_ =>
|
|
Joi
|
|
.object({
|
|
port: Joi.number().integer().positive().required(),
|
|
concurrency: Joi.number().integer().positive().allow(null),
|
|
apps: Joi.array().items(
|
|
Joi
|
|
.object({
|
|
name: Joi.string().required(),
|
|
id: Joi.string().uuid().default(() => {
|
|
isChanged = true;
|
|
return crypto.randomUUID();
|
|
}),
|
|
url: Joi.string().uri({ scheme: 'https' }),
|
|
jq: Joi.string(),
|
|
github: Joi.object({
|
|
repo: Joi.string().regex(/^[\w.-]+\/[\w.-]+$/).required(),
|
|
filter: Joi.string(),
|
|
prerelease: Joi.boolean()
|
|
}),
|
|
appimage: [
|
|
Joi.boolean().valid(true),
|
|
Joi.object({
|
|
bin: Joi.string()
|
|
}).min(1)
|
|
]
|
|
})
|
|
.xor('url', 'github')
|
|
.with('jq', 'url')
|
|
),
|
|
githubAccessToken: Joi.string()
|
|
})
|
|
.validateAsync(_)
|
|
);
|
|
if(isChanged)
|
|
await Promise
|
|
.resolve(JSON.stringify(config, null, 4))
|
|
.then(_ => Deno.writeTextFile(configPath, _));
|
|
return config;
|
|
}; |