forked from cfjedimaster/cflib2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
99 lines (82 loc) · 2.13 KB
/
generate.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env node
const fs = require('fs');
data = JSON.parse(fs.readFileSync('/mnt/c/websites/static.cflib.org/public/udf/_data.json','UTF-8'));
/*
take a string and replace tabs with 4 spaces
maybe also prefix with " "
*/
function fixForYaml(str) {
//first tabs
str = str.replace(/\t/g, ' ');
//now space in front
let lines = str.split('\n');
lines = lines.map((line) => {
return ' '+line;
});
str = lines.join('\n');
return str;
}
//unlike the above, this is just escaping stuff for values
function formatForYaml(str) {
str = str.replace(/:/g, ":");
str = str.replace(/\n/g, " ");
return str;
}
data.udfs.forEach((udf,idx) => {
if(idx % 100 === 0) process.stdout.write('#');
//fix for nullPad
if(!udf.shortDescription) udf.shortDescription = 'Needs short description.';
if(!udf.javaDoc) udf.javaDoc = '';
// create argument stuff
let argString = '';
let args = '';
udf.args.forEach((arg, idx) => {
if(arg.REQ) {
if(idx !== 0) argString += ', ';
argString += arg.NAME;
} else {
if(idx !== 0) {
argString += '[, ';
} else {
argString += '[';
}
argString += arg.NAME + ']';
}
args += ` - name: ${arg.NAME}\n`;
args += ` desc: ${formatForYaml(arg.DESC)}\n`;
args += ` req: ${arg.REQ?true:false}\n`;
});
let template = `---
layout: udf
title: ${udf.name}
date: ${udf.lastUpdated}
library: ${udf.library}
argString: "${argString}"
author: ${udf.author}
authorEmail: ${udf.authorEmail}
version: ${udf.version}
cfVersion: ${udf.cfVersion}
shortDescription: ${formatForYaml(udf.shortDescription)}
tagBased: ${udf.tagBased}
description: |
${fixForYaml(udf.description)}
returnValue: ${formatForYaml(udf.returnValue)}
example: |
${fixForYaml(udf.example)}
args:
${args}
javaDoc: |
${fixForYaml(udf.javaDoc)}
code: |
${fixForYaml(udf.code)}
oldId: ${udf.oldId}
---
`;
//console.log(template);
//process.exit(1);
let filename = './_udfs/'+udf.name+'.md';
fs.writeFileSync(filename, template, 'UTF-8');
//console.log(filename);
//if(idx === 500) process.exit(1);
});
process.stdout.write('\n');