-
Notifications
You must be signed in to change notification settings - Fork 3
/
exporter.js
88 lines (59 loc) · 2.24 KB
/
exporter.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var path = require('path');
var ejs = require('ejs');
var fs = require('fs');
var version = require('./model/version.js');
var currentVersion = version.current();
var tag = require('./model/tag.js');
var func = require('./model/function.js');
var obj = require('./model/object.js');
var exporttype = process.env.TYPE ? process.env.TYPE: 'markdown';
var extension = 'md';
var versionMarkdownPath = './export/' + currentVersion + '/' + exporttype;
var tagMarkdownPath = versionMarkdownPath + '/tags/';
var funcMarkdownPath = versionMarkdownPath + '/functions/';
var objMarkdownPath = versionMarkdownPath + '/objects/';
var exportpath = {
'tag': path.resolve(versionMarkdownPath + '/tags/'),
'func': path.resolve(versionMarkdownPath + '/functions/'),
'obj': path.resolve(versionMarkdownPath + '/objects/')
};
var templates = {
'tag': path.resolve('./templates/' + exporttype + '/tag.ejs'),
'func': path.resolve('./templates/' + exporttype + '/func.ejs'),
'obj': path.resolve('./templates/' + exporttype + '/obj.ejs')
};
checkAndCreatePath(versionMarkdownPath);
checkAndCreatePath(funcMarkdownPath);
checkAndCreatePath(tagMarkdownPath);
checkAndCreatePath(objMarkdownPath);
renderItems(tag, currentVersion, "tag", tagMarkdownPath);
renderItems(func, currentVersion, "func", funcMarkdownPath);
renderItems(obj, currentVersion, "obj", objMarkdownPath);
console.log("finished export");
function checkAndCreatePath(path){
if(!fs.existsSync(path)){
console.log("Creating folder", path);
fs.mkdirSync(path);
}
}
function renderFile(model, name, version, type, exportPath) {
console.log("Rendering", name);
var data = model.get(name, version);
var opts = {};
opts[type] = data;
var filename = exportpath[type] + '/' + name + "." + extension;
console.log("Writing", filename);
ejs.renderFile(templates[type], opts, function(err, html){
fs.writeFile(filename, html, function(err){
if (err) throw err;
});
});
return {data: data, opts: opts};
}
function renderItems(model, version, type, exportPath){
var items = model.list(version);
for(var i in items) {
var name = items[i];
renderFile(model, name, version, type, exportPath);
}
}