copykitku/src/copykitku.ts
2021-02-15 00:36:13 +01:00

34 lines
1.1 KiB
TypeScript

/*
* Copykitku. 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, CopykitkuConfig, CopykitkuProfile } from './types';
import { getConfig, DEFAULT_CONFIG } from './utils';
export default class Copykitku {
vendorManagers: VendorManager[] = [];
config: CopykitkuConfig = 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, CopykitkuProfile],
)
.map(([VendorMgr, vendor]) => new VendorMgr(vendor.config) as VendorManager)
.map((VendorMgr) => VendorMgr.initialize()),
);
return this;
}
}