41c37156af
added formatter type to associate a service with their templates and filepaths
39 lines
1007 B
TypeScript
39 lines
1007 B
TypeScript
import { services } from "./config";
|
|
import { formatcaddyfile } from "./formatter";
|
|
import { formatters } from "./formatters";
|
|
import { ConfigValidator } from "./validator";
|
|
import { ConfigWriter } from "./writer";
|
|
|
|
console.log("Hello via Bun!");
|
|
/**
|
|
entry point / manager
|
|
**/
|
|
async function main() {
|
|
try {
|
|
console.log("starting caddy config");
|
|
|
|
ConfigValidator.validatecaddyfile(services);
|
|
|
|
const output = formatcaddyfile(services);
|
|
|
|
await ConfigWriter.writeLocal("output/etc/caddy/Caddyfile", output);
|
|
|
|
//check for associated formatters for each provider service definition
|
|
for ( const srvc of services ) {
|
|
const srvcformatters = formatters.filter(el => el.serviceid == srvc.name);
|
|
|
|
for (const formatter of srvcformatters) {
|
|
const content = formatter.format(srvc);
|
|
const path = formatter.outputpath(srvc);
|
|
await ConfigWriter.writeLocal(path, content);
|
|
}
|
|
}
|
|
|
|
console.log("completed succesfully");
|
|
} catch (error) {
|
|
console.error("error", error);
|
|
}
|
|
}
|
|
|
|
main();
|