oak-cli/templateFiles/initialize.dev.ts

67 lines
2.9 KiB
TypeScript

import { mergeConcatMany } from 'oak-domain/lib/utils/lodash';
import BackendRuntimeContext from '@project/context/BackendRuntimeContext';
import FrontendRuntimeContext from '@project/context/FrontendRuntimeContext';
import { EntityDict, storageSchema } from '@project/oak-app-domain';
import triggers from '@project/triggers';
import checkers from '@project/checkers';
import watchers from '@project/watchers';
import timers from '@project/timers';
import data from '@project/data';
import startRoutines from '@project/routines/start';
import { importations, exportations } from '@project/ports';
import { create as createFeatures, FeatureDict } from '@project/features';
import aspects, { AspectDict } from '@project/aspects';
import common from '@project/configuration';
import render from '@project/configuration/render';
import { initialize as initFrontend } from 'oak-frontend-base/es/initialize';
import { BasicFeatures } from 'oak-frontend-base/es/features';
import DebugConnector from 'oak-frontend-base/es/utils/DebugConnector';
export default function initialize() {
const totalTriggers = mergeConcatMany([triggers] as Array<typeof triggers>),
totalAspects = mergeConcatMany([aspects] as Array<typeof aspects>),
totalCheckers = mergeConcatMany([checkers] as Array<typeof checkers>),
totalWatchers = mergeConcatMany([watchers] as Array<typeof watchers>),
totalTimers = mergeConcatMany([timers] as Array<typeof timers>),
totalStartRoutines = mergeConcatMany([startRoutines] as Array<typeof startRoutines>),
totalData = mergeConcatMany([data] as Array<typeof data>),
totalImportations = mergeConcatMany([importations] as Array<typeof importations>),
totalExportations = mergeConcatMany([exportations] as Array<typeof exportations>),
totalCommon = mergeConcatMany([common] as Array<typeof common>),
totalRender = mergeConcatMany([render] as Array<typeof render>);
const debugConnector = new DebugConnector<EntityDict, BackendRuntimeContext, FrontendRuntimeContext>(
storageSchema,
(store) => new BackendRuntimeContext(store),
totalAspects,
totalTriggers,
totalCheckers,
totalWatchers,
totalTimers,
totalStartRoutines,
totalData,
totalCommon,
totalImportations,
totalExportations
);
const totalFeatures = {} as FeatureDict & BasicFeatures<EntityDict>;
const { features } = initFrontend<EntityDict, BackendRuntimeContext, FrontendRuntimeContext, AspectDict>(
storageSchema,
(store) => new FrontendRuntimeContext(store, totalFeatures),
debugConnector,
totalCheckers,
totalCommon,
totalRender
);
Object.assign(totalFeatures, features);
const appFeatures = createFeatures(totalFeatures);
Object.assign(totalFeatures, appFeatures);
return {
features: totalFeatures,
};
}