26 lines
792 B
TypeScript
26 lines
792 B
TypeScript
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;
|
|
}
|
|
}
|