import { ConstructorType, ReflectUtils } from '@dooboostore/core'; import { ScriptRunnable } from '../script/ScriptRunnable'; export const scripts = new Map>(); export interface ScriptConfig { name?: string } export const ScriptMetadataKey = Symbol.for('simple-boot-front:script-metadata'); export type GenericClassDecorator = (target: T) => void; export const Script = (config?: ScriptConfig): GenericClassDecorator> => { return (target: ConstructorType) => { // default set if (!config) { config = {} } if (!config.name) { config.name = target.name; } scripts.set(config.name, target); ReflectUtils.defineMetadata(ScriptMetadataKey, config, target); return target; } } export const getScript = (target: ConstructorType | Function | any): ScriptConfig | undefined => { if (target && typeof target === 'object') { target = target.constructor; } try { return ReflectUtils.getMetadata(ScriptMetadataKey, target); } catch (e) { } } // Alias for @script (lowercase) export const script = Script;