forked from Think-and-Dev/solidoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.js
46 lines (38 loc) · 1.33 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
41
42
43
44
45
46
"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);
logger.info("Included contracts: %s.", contracts.filter(c => !c.ignore).length);
logger.info("Excluded contracts: %s.", contracts.filter(c => c.ignore).length);
for (let i = 0; i < contracts.length; i++) {
const contract = contracts[i];
if (contract.ignore) {
logger.warn(`-Ignoring ${contract.contractName}`);
continue;
}
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", contract.contractName);
fs.writeFileSync(file, result);
}
// console.log(serializers.length);
}
};