-
Notifications
You must be signed in to change notification settings - Fork 18
/
generator.js
40 lines (32 loc) · 1.04 KB
/
generator.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
"use strict";
const pino = require("pino");
const path = require("path");
const fs = require("fs");
const temp = require("./helpers/template-helper");
const logger = pino({
prettyPrint: true
});
function serializeContract(contract, contracts) {
var template = temp.ContractTemplate;
require("require-all")({
dirname: path.join(__dirname, "serializers"),
filter: /(.+serializer)\.js$/,
resolve: function(serializer) {
template = serializer.serialize(contract, template, contracts);
}
});
return template;
}
module.exports = {
serialize: function(contracts, outputDirectory) {
logger.info("Total contracts: %s.", contracts.length);
for(let i = 0; i < contracts.length; i++) {
const contract = contracts[i];
const result = serializeContract(contract, contracts).replace(/[\r\n]\s*[\r\n]/g, "\n\n");
const file = path.join(outputDirectory, `${contract.contractName}.md`);
logger.info("Writing %s.", file);
fs.writeFileSync(file, result);
}
// console.log(serializers.length);
}
};