@angstone/monostone
Version:
monolitic event-sourced framework
40 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const uuid = require("uuid");
const _1 = require("./");
const error_1 = require("../error");
function createEffect(effectRecipe) {
let effect;
try {
effect = require(effectRecipe.featurePath + "/effects/" +
effectRecipe.effectName + ".effect").effect;
}
catch (e) {
error_1.error.fatal(e, "failed to load effect " + effectRecipe.effectName);
}
if (!effect) {
error_1.error.fatal("failed to load effect " + effectRecipe.effectName);
}
if (!effect.name)
effect.name = effectRecipe.effectName;
return effect;
}
exports.createEffect = createEffect;
function createEffects(effectsRecipe) {
if (effectsRecipe.effects.length == 0) {
try {
const effectNames = _1.FolderTools.getFiles(effectsRecipe.featurePath + '/effects')
.filter(_1.StringTools.filters.lastCharactersMustBe('ts'))
.map(_1.FolderTools.firstNameOfFileSeparatedBySlashes)
.filter(effectName => process.env.NODE_ENV == 'development' || !_1.StringTools.stringStartWith(effectName, 'fake'));
effectsRecipe.effects = effectNames.map(effectName => createEffect({ effectName, featurePath: effectsRecipe.featurePath }));
}
catch (e) { }
}
return effectsRecipe.effects.map((effect) => {
effect.name = effect.name || ('unknown.' + uuid() + '.effect');
return effect;
});
}
exports.createEffects = createEffects;
//# sourceMappingURL=effect.tools.js.map