-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate-cqrs-es.js
52 lines (43 loc) · 1.87 KB
/
generate-cqrs-es.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs');
const Handlebars = require("handlebars");
const Generator = require("lb.generator.handlebars");
const PrepareModel = require("./models/prepare-cqrs-es-model-es");
// You can load any JSON file to use as a model
const model = require("./models/sample-cqrs-es-model.json");
PrepareModel.prepare(model);
Handlebars.registerHelper('hasTag', function(context, options) {
var item = this;
if (!item.Tags || !item.Tags.includes(context))
return;
return options.fn(item);
});
// By default, the templates will be generated with the following default global static values:
Generator.TemplateSettings.DefaultTarget = "Model";
Generator.TemplateSettings.DefaultTargetItem = "entity";
Generator.TemplateSettings.DefaultTargetProperty = "entities";
Generator.TemplateSettings.DefaultModelProperty = "domain";
Generator.TemplateSettings.DefaultTargetItemNameProperty = "Name";
// Create a Template Loader and pass it the directory containing the templates.
// The loader will automatically load all template files ending in ".hbs" and their corresponding settings ".hbs.settings.json"
var loader = new Generator.TemplateLoader([
'./templates/cqrs.es'
]);
// Load the templates
loader.load();
// Generate the loaded templates.
loader.generate(model, (loader) => { console.log("Templates Generated."); });
// Load and generate
//loader.loadAndGenerate(model, (loader) => { console.log('Templates loaded and generated.'); });
/*
// Load the templates with a callback containing the list of loaded templates
loader.load(function (templates) {
// Interate the templates and generate each with the supplied model
for (const template of templates) {
console.log(`Generating template: ${template.name}`)
// Generate the template
template.generate(model);
// Write the generated template to file
template.write();
}
});
*/