copykitku/src/copycat.ts
2020-08-21 11:53:55 +02:00

34 lines
1.1 KiB
TypeScript

/*
* Copycat. Copyright (C) 2020 selfisekai <laura@selfisekai.rocks> and other contributors.
*
* This is free software, and you are welcome to redistribute it
* under the GNU General Public License 3.0 or later; see the LICENSE file for details,
* or, if the file is unavailable, visit <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
*/
import path from 'path';
import { VendorManager, CopycatConfig, CopycatProfile } from './types';
import { getConfig, DEFAULT_CONFIG } from './utils';
export default class Copycat {
vendorManagers: VendorManager[] = [];
config: CopycatConfig = DEFAULT_CONFIG;
public async initialize() {
this.config = getConfig();
this.vendorManagers = await Promise.all(
this.config.vendorConfigs
.map(
(profile) =>
[
require(path.join(__dirname, 'vendor', profile.vendor.type, 'vendormgr')).default,
profile,
] as [any, CopycatProfile],
)
.map(([VendorMgr, vendor]) => new VendorMgr(vendor.config) as VendorManager)
.map((VendorMgr) => VendorMgr.initialize()),
);
return this;
}
}